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
main.cpp
- Committer:
- siddharthp
- Date:
- 2017-04-02
- Revision:
- 5:0d98bbc39c7b
- Parent:
- 4:aa3e25ccc05d
- Child:
- 6:fd279a17f523
File content as of revision 5:0d98bbc39c7b:
#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,100\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=NVG5E6ZAB970OMRF&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);
}
