Sending data to thingspeak
Dependencies: DHT ESP8266 mbed
Fork of temp_hum by
main.cpp
- Committer:
- siddharthp
- Date:
- 2017-04-03
- Revision:
- 8:f14bdc09a319
- Parent:
- 7:00c31738f232
- Child:
- 9:32443e001090
File content as of revision 8:f14bdc09a319:
#include "mbed.h" #include "ESP8266.h" ESP8266 wifi(PTC17, PTC16, 115200); Serial pc(USBTX,USBRX); DigitalOut RED(LED1); char snd[255],rcv[1000]; float cur = 0.0f;//current value float comp = 0.0f;//compressed air flow float temp = 0.0f;//temperature float hum = 0.0f;// humidity float co = 0.0f;// CO2 float pres = 0.0f;//pressure #define IP "184.106.153.149" // thingspeak.com IP Address void wifi_send(void); int main() { pc.baud(115200); pc.printf("SET mode to AP\r\n"); wifi.SetMode(1); // set ESP mode to 1 wifi.RcvReply(rcv, 1000); //receive a response from ESP pc.printf("%s",rcv); //Print the response onscreen pc.printf("Conneting to Wifi\r\n"); wifi.Join("SSID", "password"); // Your wifi username & Password wifi.RcvReply(rcv, 1000); //receive a response from ESP pc.printf("%s\n", rcv); //Print the response onscreen wait(8); //waits for response from ESP pc.printf("Getting IP\r\n"); //get IP addresss from the connected AP wifi.GetIP(rcv); //receive an IP address from the AP pc.printf("%s\n", rcv); //WIFI updates the Status to Thingspeak servers// pc.printf("PLEASE STAY AWAY\r\n"); pc.printf("Sending WiFi information\r\n"); strcpy(snd,"AT+CIPMUX=1\r\n");//Setting WiFi into MultiChannel mode wifi.SendCMD(snd); pc.printf(snd); wait(2.0); wifi.RcvReply(rcv, 1000); pc.printf("%s\n", rcv); wait(2); sprintf(snd,"AT+CIPSTART=4,\"TCP\",\"%s\",80\r\n",IP); //Initiate connection with THINGSPEAK server pc.printf(snd); wait(3.0); wifi.RcvReply(rcv, 1000); pc.printf("%s\n", rcv); wait(2); strcpy(snd,"AT+CIPSEND=4,121\r\n"); //Send Number of open connections,Characters to send wifi.SendCMD(snd); pc.printf(snd); wait(2.0); wifi.RcvReply(rcv, 1000); pc.printf("%s\n", rcv); wait(2); while (1) { wifi_send(); RED=1; wait(10); RED=0; wait(10); } } void wifi_send(void) { sprintf(snd,"GET http://api.thingspeak.com/update?api_key=54JPIP9GVWVX9BMV&field1=%f&field2=%f&field3=%f&field4=%f&field5=%f&field6=%f\r\n", cur,comp,temp,hum,co,pres); //Post values to thingspeak pc.printf("%s",snd); wifi.SendCMD(snd); wifi.RcvReply(rcv, 1000); pc.printf("%s", rcv); }