Hello everyone! I was having problems with a my arduino code and the guys on my last thread really helped me out, but now it seens like some hardware issue! My objective here is to send that data of temp/humi to a channel on thingspeak. When i try to upload the code, all the AT commands fails (Im using a 8266 on a ESP 01 Adapter, connected to a Arduino Mega2560. My question is: is this a problem with the ESP8266 or what? Im really confused because it is supposed to call the sendCommands function, but it cannot read the readPlay on the function. This is my actual code:
#include <SoftwareSerial.h>
#include <dht11.h>
#define RX 18
#define TX 19
#define dht_apin 11 // Analog Pin sensor is connected to
dht11 dhtObject;
String AP = "FGNH"; // AP NAME
String PASS = "cp04182126"; // AP PASSWORD
String API = "PT46QPZM2QBBDND1"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX,TX);
void setup() {
Serial.begin(9600);
esp8266.begin(9600);
// char const *ok = "OK";
sendCommand("AT",5,(char*) "OK");
sendCommand("AT+CWMODE=1",5, (char*) "OK");
sendCommand("AT+CWJAP=\""+ AP +"\",\""+ PASS +"\"",20, (char*) "OK");
}
void loop() {
String getData = "GET /update?api_key="+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue();
sendCommand("AT+CIPMUX=1",5, (char*) "OK");
sendCommand("AT+CIPSTART=0,\"TCP\",\""+ HOST +"\","+ PORT,15, (char*) "OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4, (char*) ">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5, (char*)"OK");
}
String getTemperatureValue(){
dhtObject.read(dht_apin);
Serial.print(" Temperature(C)= ");
int temp = dhtObject.temperature;
Serial.println(temp);
delay(50);
return String(temp);
}
String getHumidityValue(){
dhtObject.read(dht_apin);
Serial.print(" Humidity in %= ");
int humidity = dhtObject.humidity;
Serial.println(humidity);
delay(50);
return String(humidity);
}
void sendCommand(String command, int maxTime, char readReplay[]) {
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
Serial.print(esp8266.readString());
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("OYI");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
And this is the error that im getting:
0. at command => AT Fail
0. at command => AT+CWMODE=1 Fail
0. at command => AT+CWJAP="FGNH","myPassword" Fail
Humidity in %= 0
Temperature(C)= 0
0. at command => AT+CIPMUX=1 Fail
0. at command => AT+CIPSTART=0,"TCP","api.thingspeak.com",80 Fail
0. at command => AT+CIPSEND=0,58
Based on my code, its returning fail because the condiction if(esp8266.find(readReplay)) is returning false. Why it cand find this readReplay? Thanks !!