Nodemcu esp8266 - Arduino Serial AT command code problem

I'm trying to use the below code, which I got from some Arduino project online which updates Arduino data to google sheets cloud. This code controls Nodemcu using a serial AT Commands sent from Arduino serial.

I tried several times and in diff ways to communicate with Nodemcu from Arduino using the code, but no response from nodemcu esp 8266 module. is there any error or modifications to be made in the code, as because my circuit and modules are working perfectly independently.

below is the code, some plz suggest!!!

// code to communicate with nodemcu esp8266 module using AT commands from arduino serial & upload data to google cloud using pushingbox.

#define DST_HOST "213.186.33.19" //IP Address (Pushingbox)
String devid="vAFCC5109D44ADC6"; //Device Id
unsigned long server_update=0;

void setup()
{

Serial.begin(9600);
wifi_setup();
delay(2000);

}

void loop()
{

if(millis()-server_update>14000)
{
delay(200);
google();
server_update=millis();
}
delay(600);
}

void wifi_setup()
{

Serial2.begin(115200);
String ssid ="xxxxxxxxx";
String password="xxxxxxxx";
Serial2.println("AT+RST"); //To Reset Module

if(Serial2.find("CONNECTED"))
{
}
else;

delay(4000);

String cmd ="AT+CWJAP="" + ssid + "","" + password + """;
Serial2.println(cmd); //To Setup wifi

if(Serial2.find("CONNECTED"))
{
Serial.println("connected");
}
else
{
Serial.println("error not connected");
}

Serial2.println("AT+CIPMUX=0"); //To setup a single link

delay(3000);
}

void google() //Google Data Update
{

String cmd = "AT+CIPSTART="TCP","";
cmd += DST_HOST;
cmd += "",80";

Serial2.println(cmd);
delay(500);

cmd = "GET /pushingbox?devid=";
cmd += devid;
cmd += "Host: api.pushingbox.com\r\n\r\n";

String str= "AT+CIPSEND=";
str += String(cmd.length());
Serial2.println(str);

delay(500);

Serial2.println(cmd);

}

someone plz help

You're using Serial2, but where is it defined? The NodeMCU has only one serial port AFAIK, contrary to the Arduino Mega which has 4, one of them being Serial2.

sir, it is defined in the wifi setup function

you are using Serial2.println("AT+RST");              //To Reset Modulebut println() uses newline as a line-ending while AT firmware requires “\r\n” trySerial2.print("AT+RST\r\n");              //To Reset Module for all lie of code that do the same.
i am assuming you were previously using “Serial pass through” sketch successfully. Probably with line-ending set to “both” in the Serial monitor.

nandhu123:
sir, it is defined in the wifi setup function

It's initialized but not defined

sir...still not solved...my esp8266 is not at all responding to AT commands independently...i tried even flashing AT firmware, but no use...plz suggest some chances

What have you got at the moment ? (please post latest sketch within </> code-tags )
how exactly have you got the nodeMCU connected to which Arduino ?

actually I found that it’s not related to Arduino code… myne is an ESP 8266 development board by itself.
so as to send AT commands directly, no need Arduino. just connected ESP8266 USB to the laptop and started sending AT commands… it’s not responding still. tried to change the firmware to AT firmware, but still not responding. my both esp modules are behaving the same way.

i have attached the picture of my esp module. plz check it out sir.

nodemcu-esp8266-india-228x228.jpg

but in your first post you said :

is there any error or modifications to be made in the code, as because my circuit and modules are working perfectly independently.

and so this is obviously not the case.

  • Have you successfully uploaded new firmware ? (or not) using which flasher & firmware version (provide links)
    Assuming that your ESP (NodeMCU, it looks like a 12E but the picture is very grainy) shows up in the '->tools->port' and you have selected it.
  • What Baud-rate are you using in the Serial monitor ? And do you have the line-ending set to "Both CR & NL" ?

In General i tend to advise people to drop the whole AT-commands thing fairly soon after you've gotten it working, since it is incredibly clunky to control an ESP unit from an Arduino board using AT-commands compared to just uploading your own firmware as if it is 'just another type of Arduino' using the Arduino IDE.

thanks for responding sir.

  1. I’m sorry about my first reply that my esp 8266 is working good independently which I mean to say that, if I load any code( except AT command code) to esp from Arduino ide library, my esp is responding sir. but not with AT command. later found that there is no wrong in arduino AT code, but some issue with ESP 8266 itself.

  2. I attached my esp development board pics below sir. plz check. as myne is not original AI Thinkers ESP board, as most of them @ some forums told, Except his modules, some china modules wont accept AT commands unless you load AT firmware.

  3. Reg Firmware, i tried with 2 to 3 sir, but all failed. i will share you one of its file below.

  4. i droughted the baud rate and tried with 9600,15200,74880 ( around not exact baud), but still no use sir.

  5. i followed the following youtube video sir, to flash the AT firmware initially, followed by many other.but no use sir

files attached:-

ESP8266_AT-master.zip (314 KB)

here is my esp board pics sir and the first AT firmware i flashed. The previous file I attached is also AT firmware sir, that I tried second time.

V1.3.0.2_AT_Firmware.bin.zip (234 KB)

V1.3.0.2_AT_Firmware.bin.zip (234 KB)

if I load any code( except AT command code) to esp from Arduino ide library, my esp is responding sir. but not with AT command. later found that there is no wrong in arduino AT code, but some issue with ESP 8266 itself.

So you are loading code onto the ESP using the IDE ? That is the same as uploading (your own) firmware. That means that the AT-commands firmware is not on the board from then on. You can then load any program onto the ESP using the ESP core (blink as a test is a good one..) And set up webpages, directly access the GPIO pins, send data over the serial port etc, just like you can with a Arduino.
The code you posted originally is not supposed to be loaded onto an ESP, but is supposed to be loaded onto an Arduino (one with at least 2 Serial ports btw) which then can be connected to an ESP that has the AT-command firmware on it (1 Serial of the Arduino to the Serial of the ESP) and can then communicate with that.
Since i don't think you have another Arduino, it is just not the right code.

For uploading the AT-firmware onto the ESP (which i haven't done in over 2 yrs so bare with me) I actually struggled with it for a day or 2 but succesfully manged using this instructable. Though i then found an uploader program that was easier to use, but i can't find where i got it from by now. (i just have instructions for myself on how to use it on my HD but it is to big to add as an attachment here)

As i said using the AT-command set is clunky and cumbersome, compare to writing your own firmware to make the board do what you want it to do, but successfully loading the AT-firmware is a good exercise, and helps in understanding on how it works.