-->
Page 1 of 1

anny one can help?

PostPosted: Wed Jun 10, 2015 11:21 pm
by ketsayay
i can't sand data to thingspeak with this code

#‎include‬<TEE_ESP_WIFI.h>
#include <SoftwareSerial.h>
‪#‎define‬ pinEN 9
#define ESP_Rx 10
#define ESP_Tx 11
#include "DHT.h"
DHT dht;
String apiKey = "3699EKAIV6AFTZ27";
String ssid="kimui";
String pwd="yaranika";
ESP wifi(ESP_Rx,ESP_Tx,pinEN);
SoftwareSerial ser(10, 11);
void print_debug(String data)
{ Serial.print(data);}
void setup()
{
dht.setup(13);
Serial.begin(9600);
wifi.begin(9600);
// ser.begin(9600); without this line i can connect to ap
Serial.println("ESP8226");
wifi.Event_debug = print_debug;
wifi.reset();
wifi.setmode(STATION);
wifi.disconnectAP();
wifi.connectAP(ssid,pwd);
wifi.multipleconnect(MULTIPLE);
String ip = wifi.myip();
}
void loop()
{
float temp = dht.getTemperature();

// convert to string
char buf[16];
String strTemp = dtostrf(temp, 4, 1, buf);
Serial.println(strTemp);
// TCP connection
String cmd = "AT+CIPSTART=\"TCP\",\"";
cmd += "184.106.153.149"; // api.thingspeak.com
cmd += "\",80";
ser.println(cmd);
if(ser.find("Error")){
Serial.println("AT+CIPSTART error");
return;
}
// prepare GET string
String getStr = "GET /update?api_key=";
getStr += apiKey;
getStr +="&field1=";
getStr += String(strTemp);
getStr += "\r\n\r\n";
// send data length
cmd = "AT+CIPSEND=";
cmd += String(getStr.length());
ser.println(cmd);
if(ser.find(">")){
ser.print(getStr);
}
else{
ser.println("AT+CIPCLOSE");
// alert user
Serial.println("AT+CIPCLOSE");
}
// thingspeak needs 15 sec delay between updates
delay(16000);

}

Re: anny one can help?

PostPosted: Thu Jun 11, 2015 5:12 pm
by tytower
I've put my code URL below . If you have a look at the Thingspeak bit that should help
download/file.php?id=1089
viewtopic.php?f=6&t=2872&start=10