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

Revision:
0:284e9c16e92d
Child:
1:929b55ff96b0
--- /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);
+}