Temperature Monitoring with thingspeak (IoT)

Dependencies:   HTTPClient LM75B mbed-rtos mbed

Fork of TCPSocket_HelloWorld by mbed official

Revision:
16:91200554b881
Parent:
15:bc7fc13dc5f6
--- a/main.cpp	Fri Feb 09 02:19:29 2018 +0000
+++ b/main.cpp	Mon Feb 12 07:14:33 2018 +0000
@@ -1,16 +1,42 @@
 #include "mbed.h"
 #include "EthernetInterface.h"
-int main() {
-    
-static const char*          mbedIp       = "192.168.137.2";  //IP
-static const char*          mbedMask     = "255.255.255.0";  // Mask
-static const char*          mbedGateway  = "192.168.137.1";    //Gateway
+#include "LM75B.h"
+#include "HTTPClient.h"
+
+
+LM75B tmp(p28,p27); // temperature sensor
+char* thingSpeakUrl = "http://api.thingspeak.com/update";
+char* thingSpeakKey = "C9T47QDLBY4NU7MW";
+char buffer[256];
 
-    EthernetInterface eth;
- //   eth.init(); //Use DHCP
- eth.init(mbedIp,mbedMask,mbedGateway); 
+
+void ethernetSetup(){
+//static const char*          mbedIp       = "192.168.137.2";  //IP
+//static const char*          mbedMask     = "255.255.255.0";  // Mask
+//static const char*          mbedGateway  = "192.168.137.1";    //Gateway
+
+EthernetInterface eth;
+    eth.init(); //Use DHCP
+//eth.init(mbedIp,mbedMask,mbedGateway); 
     eth.connect();
     printf("IP Address is %s\n", eth.getIPAddress());
+    
+    }
+    
+void thingspeak(){
+    HTTPClient http;
+    buffer[0] = 0;
+    sprintf(buffer,"%s?key=%s&field2=%2f",thingSpeakUrl,thingSpeakKey,tmp.read());
+    printf("Send to %s\r\n", buffer);
+    http.get(buffer, buffer , 10); // Execute the URL of urlBuffer
+    
+    }
 
-    while(1) {}
+int main() {
+    ethernetSetup();
+    
+    while(1) {
+        thingspeak();
+        
+        }
 }