i doing the project to upload sensor value to Thinkspeak,everthing is ok ,but my Thingspeak webpage not show any value??
[/#include <SoftwareSerial.h>
#include<Wire.h>
#include<Adafruit_MLX90614.h>
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
float tempa=0;
float tempo=0;
SoftwareSerial espSerial = SoftwareSerial(0,1); // arduino RX pin=2 arduino TX pin=3 connect the arduino RX pin to esp8266 module TX pin - connect the arduino TX pin to esp8266 module RX pin
String apiKey = "UWGF5N4MU47TLWEF"; // replace with your channel's thingspeak WRITE API key
String ssid="Hope No DC"; // Wifi network SSID
String password ="98798798777"; // Wifi network password
boolean DEBUG=true;
//======================================================================== showResponce
void showResponce(int waitTime){
long t=millis();
char c;
while (t+waitTime>millis()){
if (espSerial.available()){
c=espSerial.read();
if (DEBUG) Serial.print(c);
}
}
}
//========================================================================
boolean thingSpeakWrite(String tempStr){
String cmd = "AT+CIPSTART=\"TCP\",\""; // TCP connection
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
espSerial.println(cmd);
if (DEBUG) Serial.println(cmd);
if(espSerial.find("Error")){
if (DEBUG) Serial.println("AT+CIPSTART error");
return false;
}
String getStr = "GET /update?api_key="; // prepare GET string
getStr += apiKey;
getStr +="&field1=";
getStr += String(tempStr);
//getStr +="&field2=";
// getStr += String(value2);
// getStr +="&field3=";
// getStr += String(value3);
// ...
getStr += "\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
espSerial.println(cmd);
if (DEBUG) Serial.println(cmd);
delay(100);
if(espSerial.find(">")){
espSerial.print(getStr);
if (DEBUG) Serial.print(getStr);
}
else{
espSerial.println("AT+CIPCLOSE");
// alert user
if (DEBUG) Serial.println("AT+CIPCLOSE");
return false;
}
return true;
}
//================================================================================ setup
void setup() {
DEBUG=true; // enable debug serial
Serial.begin(9600);
mlx.begin(); // Start temp sensor
espSerial.begin(9600); // enable software serial
// Your esp8266 module's speed is probably at 115200.
// For this reason the first time set the speed to 115200 or to your esp8266 configured speed
// and upload. Then change to 9600 and upload again
espSerial.println("AT+CIOBAUD=9600"); // set esp8266 serial speed to 9600 bps
espSerial.println("AT+UART_CUR=9600,8,1,0,0"); // set esp8266 serial speed to 9600 bps
showResponce(1000);
espSerial.println("AT+RST"); // reset esp8266
showResponce(1000);
espSerial.println("AT+CWMODE=1"); // set esp8266 as client
showResponce(1000);
espSerial.println("AT+CWJAP=\""+ssid+"\",\""+password+"\""); // set your home router SSID and password
showResponce(5000);
if (DEBUG) Serial.println("Setup completed");
}
// ====================================================================== loop
void loop() {
char buffer[10];
// Read sensor values
float t = mlx.readObjectTempC();
if (isnan(t) ) {
if (DEBUG) Serial.println("Failed to read from TEMP");
}
else {
if (DEBUG) Serial.println("Temp="+String(t)+" *C");
String tempStr = dtostrf(t, 4, 1, buffer);
thingSpeakWrite(tempStr); // Write values to thingspeak
}
// thingspeak needs 15 sec delay between updates,
delay(20000);
}]