Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DHT ESP8266 mbed
Fork of temp_hum by
Revision 9:32443e001090, committed 2017-04-03
- Comitter:
- siddharthp
- Date:
- Mon Apr 03 17:06:13 2017 +0000
- Parent:
- 8:f14bdc09a319
- Commit message:
- Minor changes
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 03 13:40:05 2017 +0000
+++ b/main.cpp Mon Apr 03 17:06:13 2017 +0000
@@ -4,24 +4,26 @@
Serial pc(USBTX,USBRX);
DigitalOut RED(LED1);
char snd[255],rcv[1000];
+char http_cmd[300];
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
+#define IP "http://184.106.153.149/update" // thingspeak.com IP Address
void wifi_send(void);
int main()
{
- pc.baud(115200);
+ pc.baud(115200);
+ wifi.Reset();
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.Join("moto x play", "motoxplay"); // 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
@@ -31,20 +33,28 @@
//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
+ strcpy(snd,"AT+CIPMODE=0");//Setting WiFi into MultiChannel mode
wifi.SendCMD(snd);
pc.printf(snd);
- wait(2.0);
wifi.RcvReply(rcv, 1000);
- pc.printf("%s\n", rcv);
+ pc.printf("%s", rcv);
+
+ //WIFI updates the Status to Thingspeak servers//
+ strcpy(snd,"AT+CIPMUX=1");//Setting WiFi into MultiChannel mode
+ wifi.SendCMD(snd);
+ pc.printf(snd);
+ wifi.RcvReply(rcv, 1000);
+ pc.printf("%s", rcv);
+
+
+ sprintf(snd,"AT+CIPSTART=4,\"TCP\",\"%s\",80",IP); //Initiate connection with THINGSPEAK server
+ wifi.SendCMD(snd);
+ //pc.printf(snd);
+ wifi.RcvReply(rcv, 1000);
+ pc.printf("%s", 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
+ strcpy(http_cmd,"GET http://api.thingspeak.com/update?api_key=54JPIP9GVWVX9BMV&field1=%f&field2=%f&field3=%f&field4=%f&field5=%f&field6=%f HTTP/1.0\r\n");
+ sprintf(snd,"AT+CIPSEND=4,%d\r\n",strlen(http_cmd)); //Send Number of open connections,Characters to send
wifi.SendCMD(snd);
pc.printf(snd);
wait(2.0);
@@ -62,9 +72,9 @@
}
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);
+ sprintf(http_cmd,"GET http://api.thingspeak.com/update?api_key=54JPIP9GVWVX9BMV&field1=%f&field2=%f&field3=%f&field4=%f&field5=%f&field6=%f HTTP/1.0\r\n", cur,comp,temp,hum,co,pres); //Post values to thingspeak
+ pc.printf("%s",http_cmd);
+ wifi.SendCMD(http_cmd);
wifi.RcvReply(rcv, 1000);
pc.printf("%s", rcv);
}
\ No newline at end of file
