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:
10:313495291942
Parent:
9:ce77a3614cd7
diff -r ce77a3614cd7 -r 313495291942 main.cpp
--- a/main.cpp	Sun Nov 15 22:11:42 2015 +0000
+++ b/main.cpp	Sat Mar 19 19:20:07 2016 +0000
@@ -13,7 +13,7 @@
 #define TRIG_PIN A2
 #define ECHO_PIN A1
 #define MOISTURE_PIN A3
-#define HTTP_ENDPOINT "http://192.241.205.91/sensor"
+#define HTTP_ENDPOINT "http://104.236.187.29/sensor"
 #define SENSOR_NAME "Throop"
 
 #define CELLULAR_NETWORK 1
@@ -29,10 +29,11 @@
 #endif
 
 int main() 
-{
+{   
+    Serial console(USBTX, USBRX); // tx, rx
     char macAddress[6];
     mbed_mac_address(macAddress);
-    printf("MAC address is %02X%02X%02X%02X%02X%02X\r\n", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]);
+    console.printf("MAC address is %02X%02X%02X%02X%02X%02X\r\n", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]);
     
     Watchdog wdt;
     
@@ -74,23 +75,23 @@
         distS.start();
         wait_ms(500); 
         distV = distS.get_dist_cm();
-        printf("Distance reading: %0.2f cm\r\n", distV);
+        console.printf("Distance reading: %0.2f cm\r\n", distV);
         
         // Temperature sensor
         tempV = tempS.getTemp();
-        printf("Temperature reading: %0.2f C\r\n", tempV);
+        console.printf("Temperature reading: %0.2f C\r\n", tempV);
         
         // Moisture sensor
         moistureV = 1.0 - moistureS;
-        printf("Moisture reading: %0.1f%%\r\n", moistureV * 100);
+        console.printf("Moisture reading: %0.1f%%\r\n", moistureV * 100);
         
         // GPS
-        printf("Checking for GPS messages\r\n");
+        console.printf("Checking for GPS messages\r\n");
         while ((gpsRet = gps.getMessage(gpsBuf, sizeof(gpsBuf))) > 0)
         {
             int len = LENGTH(gpsRet);
             char ch;
-            //printf("NMEA: %.*s\r\n", len-2, gpsBuf); 
+            //console.printf("NMEA: %.*s\r\n", len-2, gpsBuf); 
             if ((PROTOCOL(gpsRet) == GPSParser::NMEA) && (len > 6)
              && strncmp(gpsBuf, "$G", 2) == 0
              && strncmp(gpsBuf + 3, "GLL", 3) == 0
@@ -99,7 +100,7 @@
              && gps.getNmeaItem(6,gpsBuf,len,ch)
              && ch == 'A')
             {
-                printf("GPS Location: %.5f %.5f\r\n", lat, lon);
+                console.printf("GPS Location: %.5f %.5f\r\n", lat, lon);
                 break;
             }
         }
@@ -129,16 +130,16 @@
         map.put("name", SENSOR_NAME);
         map.put("value", json);
         map.put("mac", hmacHex);
-        printf("\r\nTrying to POST data to server...\r\n");
+        console.printf("\r\nTrying to POST data to server...\r\n");
         int ret = http.post(HTTP_ENDPOINT, map, &inText);
         if (!ret)
         {
-          printf("Executed POST successfully - read %d characters\r\n", strlen(str));
-          printf("Result: %s\r\n", str);
+          console.printf("Executed POST successfully - read %d characters\r\n", strlen(str));
+          console.printf("Result: %s\r\n", str);
         }
         else
         {
-          printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
+          console.printf("Error - ret = %d - HTTP return code = %d\r\n", ret, http.getHTTPResponseCode());
         }
         
         first = false;
@@ -147,3 +148,4 @@
         wdt.kick();
     }
 }
+