Esp8266 with AT commands

Hello,

I would like to use a ESP8266 module with my arduino in order to have the weather of my town.
When I use the monitor with AT commands, it works fine.
but when I try to do this with my code, it doesn’t work.
I am using TX and RX for communicate with esp8266.
Could you help me please to find where is my mistake ?
Thanks for advance
Fabien

#include <SoftwareSerial.h>
#include <JsonParser.h>

SoftwareSerial dbgSerial(10, 11);
JsonParser<32> parser;

void setup() {
  Serial.begin(115200);
  Serial.setTimeout(10000);
  dbgSerial.begin(9600);
  dbgSerial.println("Init");
}

void loop() {
  Serial.println("AT+CIPMUX=1");
  delay(2000);
  dbgSerial.println(Serial.read());
  Serial.println("AT+CIPSTART=4,\"TCP\",\"176.31.236.219\",80");
  delay(2000);
  String cmd = "GET /public-api/gfs/json?_ll=45.83744,4.7718&_auth=";
  cmd += "VkxXQFUrUnBRfFFmAXcFLARsADVcKlB3C3dWNVgwXiMBalQzAWVRN1c8Ui9Qfwo6Un8FYgkxCTAKYQV9XC5ePVY1VzNVS1JNUSFRLAE1BTUEPwBjXGpQdwt3VjlYMF4jAWNUNgFrUS1XOVIzUGcKIFJgBWMJPgkuCnYFY1w0Xj9WPVcyVTVSOFE9UToBNgUuBCgAZVwxUGkLbVY5WGReNAE2VGIBY1E2Vz1SOFBnCiBSYAVnCTcJMApqBWtcMl4%2BVipXLFVPUkNRI1FzAXMFZARxAH1cNlA2Czw%3D&_c=4b50a522ad0a93f3bd24028dea3261ef";
  cmd += " HTTP/1.0\r\nHost: www.infoclimat.fr\r\n\r\n";
  Serial.println("AT+CIPSEND=4,420");
  delay(1000);

  dbgSerial.println(cmd);
  Serial.println(cmd);
  Serial.println("\r\n");
  
  //this line only returns numbers (I guess it is, may be, the lenght of each line)
  dbgSerial.println(Serial.read());

  delay(60000);
}

When I use the monitor with AT commands, it works fine.

What speed is the communication?

I see your code uses 115200. Atmega328 at 8MHz is not reliable at this speed. In any case, try a lower speed.

Hello,

Thank you for your answer. I tried different speeds, but it doesn't work. Any other idea ? Thanks Fabien

Fabien69002: When I use the monitor with AT commands, it works fine.

What is the setting of the baudrate menu at the bottom right corner of the Serial Monitor when it's working find?

Fabien69002: but when I try to do this with my code, it doesn't work. I am using TX and RX for communicate with esp8266.

Please tell us exactly how you have the ESP8266 connected to the Arduino board when you're doing this.

It works fin with a baudrate set to 115200
I show the result in the picture join to this message (capture01.jpeg)
I use the PIN 0 (RX) and 1 (TX) for the communication.
I have to swap them according to whether I upload or execute
The schema is describe in the picture 2 (capture02.jpeg)
thanks

Capture02.JPG

Fabien69002: but when I try to do this with my code, it doesn't work.

Please explain exactly what you mean by "it doesn't work". What do you expect? What do you experience that is not as you expected?

Perhaps I have the answer to my question here:

Fabien69002:   //this line only returns numbers (I guess it is, may be, the lenght of each line)   dbgSerial.println(Serial.read());

Serial.read() will return the ASCII value of the first character in the Serial input buffer. So dbgSerial.println(Serial.read()); will print a number. If you wanted the character associated with that ASCII value then you should do this:

dbgSerial.write(Serial.read());

But keep in mind that Serial.read() only returns one character. The ESP8266 is returning multiple characters so this code is almost certainly not going to work in any useful manner. That second Serial.read() in loop() is still going to be getting part of the response from the first AT command you sent to the ESP8266. I think you need to take some time to learn how to work with serial data before you even start messing with the ESP8266.

Thank you for your help. My goal is to read a json file send by a weather API. The first step is to recover the file. The next step will be to parse the file and retrieve datas and display them on a TFT screen. Now I can see a part of this file in the debug serial port. But there is only the beginning.