#define esp8266 Serial1 // use esp8266 to talk to esp8266 #define SSID "AAABBBCCC" // put here the name of your wifi network #define PASS "" // put here the password of your wifi network #define IP "184.106.153.149" // thingspeak.com's IP String GET = "GET /update?key=[THINGSPEAK_KEY]&"; // put here your thingspeak key instead of [THINGSPEAK_KEY] String GET1 = "field1="; String valuetosend = "10"; // for this first test we send a simple value void updateFunction(String valuetosend){ String cmd = "AT+CIPSTART=\"TCP\",\""; cmd += IP; cmd += "\",80"; esp8266.println(cmd); delay(2000); if(esp8266.find("Error")){ Serial.print("Error1"); return; } cmd = GET + GET1; cmd += valuetosend; cmd += "\r\n"; Serial.print(cmd); esp8266.print("AT+CIPSEND="); esp8266.println(cmd.length()); if(esp8266.find(">")){ esp8266.print(cmd); }else{ esp8266.println("AT+CIPCLOSE"); } } boolean connectWiFi(){ esp8266.println("AT+CWMODE=1"); delay(2000); String cmd="AT+CWJAP=\""; cmd+=SSID; cmd+="\",\""; cmd+=PASS; cmd+="\""; esp8266.println(cmd); delay(5000); if(esp8266.find("OK")){ Serial.println("OK"); return true; }else{ Serial.println("KO"); return false; } } void setup() { Serial.begin(9600); esp8266.begin(115200); // sensors.begin(); esp8266.println("AT"); delay(5000); if(esp8266.find("OK")){ connectWiFi(); } } void loop(){ updateFunction(valuetosend); delay(5000); }