AT Commands Failling

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 !!

No clue about your actual question, but you may want to remove that API key from public view.
Too bad, that a simple edit still leaves it accessible through the post history. Ask a moderator, maybe? Or check at thingspeak (whatever that is) if you can request a new key and invalidate this one.

Yes i can simply delete the channel using that API or change it, no worries.

The AT-firmware is a nightmare to use.
If you can afford to buy a small ESP8266 Wemos D1 Mini-Board
or a ESP8266 nodeMCU-board I would do that.

With the ESP8266 Wemos D1 Mini or nodeMCU-board you could connect the DHT sensor to the EPS8266 and run the whole program stand-alone in the ESP8266-board

Those ESP8266-boards have their own USB-connector and you can program them with the arduino IDE after installing the ESP8266-board support exact the same way as your arduino. Just the usual differencies about IO-pins and 5V/3.3V like with different Arduino-boards too.

If you search for ESP8266-boards you can find them starting at $5

There is even a possability to re-program an ESP8266-01
but this requieres a USB-to-serial-converter and some additional hardware So same price in the end.

IMHO the ESP32-nodeMCU is the better arduino:

  • faster CPU-clock
  • more flash
  • more RAM
  • more ADC-pins
  • more interrupt-pins
  • WiFi and Bluetooth onboard
  • tutorials on getting started using them with Arduino-IDE

best regards Stefan

Software serial is not supported on those pins.
See https://www.arduino.cc/en/Reference/softwareSerial
Why use software serial on a mega?

G

Since you get a 'fail' on "AT" which does nothing but echo "OK" I think the problem is either your connection to the board is bad (wrong baud rate? wiring?) or the ESP8266 is not in command mode.

I got it runing with a ESP32, much easir to code as well. Im having some troubles but i will leave that to another post, thanks!!!

I got it runing with a ESP32, but still having troubles with the code. Gonna leave that for a new post, thanks john!

Dear Mr.Henry
maybe this article can help you, i already use it and it works using Arduino Mega with Module Wifi ESP8266 Using the ESP8266 WiFi Module with Arduino Uno publishing to ThingSpeak | by Christopher Grant | Medium using AT COMMAND

and there's another way using THINGSPEAK LIBRARIES ,
I already tried and its working in Arduino MEGA + Module Wifi ESP8266 + One Sensor Analog,
open example in libraries Thingspeak, first you should download Thingspeak Library , next open arduino ->file_> example->thingspeak->esp8266->via AT Command ->WriteSingleField then change the RX TX pin using 18 and 19 wiring diagram is in the description of example

if you have an ESP32 it will be much easier to write a new program that runs on the ESP32 to make the connection to thingspeak and hand over your values from your Arduino Mega over a serial connection that you code on your own.

Self coded = full understanding and full control over every detail

or if the IO-pins of a ESP32 nodeMCU-board has enough IO-pins for everything you need in this project to throw out the Arduino-Mega
best regards Stefan

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.