Hey guys,
Im new to arduino and i'm trying to uses it to read some humidity sensor information and send it to thingspeak website.
The program ive put together is able to connect to the access point but when it tries to send the information to thingspeak it starts a loop and no information is sent.
Im lost here, i dont know if its something wrong with the code or if it's a lack of memory from arduino (because it isn't even displaying the print messages esp8266.println( "RECEIVED: OK" ))
This is the answer from the serial monitor:
AT+RST
OK
"qXÑzÂC! ™±[!ÿ ÐS!=Ñnä ÐS!}ÑFä Ð!HÕòIÔ!1¤(ÙÃÖa#)t+ a0Ø aŸÉr’÷
Ai-Thinker Technology Co.,Ltd.
ready
AT+CWJAP="teste","qwertyuiop"
WIFI CONNECTED
WIFI GOT IP
AT+CWMODE=1
busy p...
OK
AT+CIFSR
+CIFSR:STAIP,"192.168.43.123"
+CIFSR:STAMAC,"5c:cf:7f:8b:51:19"
OK
AT+CIPMUX=1
OK
AT+CIPSTART="TCP","184.106.153.149",80
AT+CIPSEND=46
AT+CIPCLOSE
AT+CIPSTART="TCP","184.106.153.149",80
AT+CIPSEND=46
AT+CIPCLOSE
This is my program:
#include <SoftwareSerial.h>
int sensor_humid = A0; //entrada do botao, mudar para A0 para o sensor.
int value_humid;
//-- Hardware Serial
//#define _baudrate 9600
//RX pino 2, TX pino 3
SoftwareSerial esp8266(2, 3);
#define DEBUG true
//*-- IoT Information
#define SSID "test"
#define PASS "qwertyuiop"
#define IP "184.106.153.149" // ThingSpeak IP Address: 184.106.153.149
// GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&field2=[data 2]...;
String GET = "GET /update?key=UTY2RG15WLM53test";
void setup()
{
Serial.begin(9600);
esp8266.begin(19200);
sendData("AT+RST\r\n", 2000, DEBUG); // rst
// Conecta a rede wireless
sendData("AT+CWJAP=\"teste\",\"qwertyuiop\"\r\n", 2000, DEBUG);
delay(3000);
sendData("AT+CWMODE=1\r\n", 1000, DEBUG);
// Mostra o endereco IP
sendData("AT+CIFSR\r\n", 1000, DEBUG);
// Configura para multiplas conexoes
sendData("AT+CIPMUX=1\r\n", 1000, DEBUG);
// Inicia o web server na porta 80
//sendData("AT+CIPSERVER=1,80\r\n", 1000, DEBUG);
}
void loop() {
value_humid = analogRead(sensor_humid); //digital para botao e analogRead para o sensor
String humid=String(value_humid);// turn integer to string
updateTS(humid);
delay(3000); //
}
//----- update the Thingspeak string with 3 values
void updateTS(String H)
{
// ESP8266 Client
String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
cmd += IP;
cmd += "\",80";
sendDebug(cmd);
delay(2000);
if( Serial.find( "Error" ) )
{
esp8266.print( "RECEIVED: Error\nExit1" );
return;
}
cmd = GET + "&field1=" + H +"\r\n";
Serial.print( "AT+CIPSEND=" );
Serial.println( cmd.length() );
if(Serial.find( ">" ) )
{
esp8266.print(">");
esp8266.print(cmd);
Serial.print(cmd);
}
else
{
sendDebug( "AT+CIPCLOSE" );//close TCP connection
}
if( Serial.find("OK") )
{
esp8266.println( "RECEIVED: OK" );
}
else
{
esp8266.println( "RECEIVED: Error\nExit2" );
}
}
String sendData(String command, const int timeout, boolean debug)
{
// Envio dos comandos AT para o modulo
String response = "";
esp8266.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}
void sendDebug(String cmd)
{
esp8266.print("SEND: ");
esp8266.println(cmd);
Serial.println(cmd);
}
Im using an arduino UNO, esp8266-esp01, and sensor yl-69.
ss.ino (2.5 KB)