How to send data from mbed to thingspeak

Dependencies:   HTTPClient WiflyInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
maman95
Date:
Mon Feb 12 02:32:21 2018 +0000
Commit message:
How to send data from mbed to thingspeak;

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.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/HTTPClient.lib	Mon Feb 12 02:32:21 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/HTTPClient/#cca5d89e6a2b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiflyInterface.lib	Mon Feb 12 02:32:21 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/WiflyInterface/#108340829acc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 12 02:32:21 2018 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+#include "WiflyInterface.h"
+#include "HTTPClient.h"
+
+
+WiflyInterface wifly(p9, p10, p30, p29, "Don", "don123456", WPA);
+Serial pc (USBTX, USBRX);
+AnalogIn moisture(p15);
+AnalogIn LM35(p16);
+DigitalOut myled1(LED1);
+HTTPClient http;
+//I2C tempsensor(p28, p27); //sda, sc1
+//const int addr = 0x90;
+//char config_t[2];
+//char temp_read[2];
+//float temp;
+char* url = "http://35.176.39.52/mbed_data.php"; //URL for transmit data to server
+
+int main() {
+    
+    wifly.init(); //Use DHCP
+ 
+    wifly.connect(); // Initiate connection to wifi
+    pc.printf("\nClient IP Address is %s\n\r", wifly.getIPAddress());
+    
+    float value=0;
+    float tempC,a[10],avg;
+int i;
+    
+    
+while(1) {
+
+avg=0;
+for(i=0;i<10;i++)
+{
+a[i]=LM35.read();
+wait(.02);
+}
+for(i=0;i<10;i++)
+{
+avg=avg+(a[i]/10);  // For more accurate value in determining temperature
+}
+    
+    //char buf[24];
+        char urlBuffer[100];
+        //sprintf (buf, value1);
+        value = moisture;
+        tempC=(avg*3.68*100)-4;
+        //int id = 1;
+        int value1 = (int)(value * 1000);
+        int temp = (int)(tempC);
+        /*time_t seconds = time(NULL);
+        seconds = seconds + 28800;
+        char buffer[32];
+        strftime(buffer, 64, "%H:%M:%S_%d-%m-%Y", localtime(&seconds));*/ //For Time configuration
+        
+        sprintf(urlBuffer, "%s?value=%d&field=%d", url , value1 , temp ); // Convert it to buffer
+        printf("Send to %s\r\n", urlBuffer);
+        http.get(urlBuffer, urlBuffer , 10); // Execute the URL of urlBuffer
+        wait(28.8); // Wifi module will execute the http.get every 31.2 seconds. Thus, waiting for 28.8 seconds means it will transmit data every 1 minute.
+       
+ 
+}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 12 02:32:21 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/235179ab3f27
\ No newline at end of file