trash over HTTP

Dependencies:   C027_Support HTTPClient TrashSensors mbed Crypto

Fork of SLOTrashHTTP by Corey Ford

Collects sensor readings and sends them to https://trash.coreyford.name/

Server code: https://github.com/coyotebush/trash-map

Files at this revision

API Documentation at this revision

Comitter:
coyotebush
Date:
Sun May 24 23:40:27 2015 +0000
Child:
1:929b55ff96b0
Commit message:
Initial sensor loop

Changed in this revision

C027_Support.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
TrashSensors.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C027_Support.lib	Sun May 24 23:40:27 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/ublox/code/C027_Support/#db878a234544
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Sun May 24 23:40:27 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#277279a1891e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TrashSensors.lib	Sun May 24 23:40:27 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/coyotebush/code/TrashSensors/#3f335fc50cef
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 24 23:40:27 2015 +0000
@@ -0,0 +1,87 @@
+#include "mbed.h"
+#include "HTTPClient.h"
+
+//------------------------------------------------------------------------------------
+// You need to configure these cellular modem / SIM parameters.
+// These parameters are ignored for LISA-C200 variants and can be left NULL.
+//------------------------------------------------------------------------------------
+#include "MDM.h"
+//! Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
+#define SIMPIN      NULL
+/*! The APN of your network operator SIM, sometimes it is "internet" check your 
+    contract with the network operator. You can also try to look-up your settings in 
+    google: https://www.google.de/search?q=APN+list */
+#define APN         "Broadband"
+//! Set the user name for your APN, or NULL if not needed
+#define USERNAME    NULL
+//! Set the password for your APN, or NULL if not needed
+#define PASSWORD    NULL 
+//------------------------------------------------------------------------------------
+
+#include "hcsr04.h"
+
+#define TRIG_PIN D6
+#define ECHO_PIN D5
+#define SENSOR_NAME "Throop"
+
+char str[512];
+
+int main() 
+{
+    HCSR04 distS(TRIG_PIN, ECHO_PIN);
+    double distV;
+    char distString[10];
+    
+    // turn on the supplies of the Modem
+    MDMSerial mdm;
+    //mdm.setDebug(4); // enable this for debugging issues 
+    if (!mdm.connect(SIMPIN, APN,USERNAME,PASSWORD))
+        return -1;
+    HTTPClient http;
+  
+    //GET data
+    printf("\r\nTrying to fetch page...\r\n");
+    int ret = http.get("http://developer.mbed.org/media/uploads/donatien/hello.txt", str, 128);
+    if (!ret)
+    {
+      printf("Page fetched successfully - read %d characters\r\n", strlen(str));
+      printf("Result: %s\r\n", str);
+    }
+    else
+    {
+      printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
+    }
+    
+    while (true) {
+        distS.start();
+        wait_ms(500); 
+        distV = distS.get_dist_cm();
+        snprintf(distString, 10, "%0.2f", distV);
+        printf("sensor reading: %s\r\n", distString);
+        
+        //POST data
+        HTTPMap map;
+        HTTPText inText(str, 512);
+        map.put("name", SENSOR_NAME);
+        map.put("value", distString);
+        printf("\r\nTrying to post data...\r\n");
+        ret = http.post("http://trash.coreyford.name/sensor", map, &inText);
+        if (!ret)
+        {
+          printf("Executed POST successfully - read %d characters\r\n", strlen(str));
+          printf("Result: %s\r\n", str);
+        }
+        else
+        {
+          printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
+        }
+        
+        wait_ms(5000);
+    }
+
+
+    mdm.disconnect();
+    mdm.powerOff();
+
+    while(true);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun May 24 23:40:27 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/dbbf35b96557
\ No newline at end of file