JAndrassy / WiFiEspAT

Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.
GNU Lesser General Public License v2.1
271 stars 44 forks source link

Several requests fail when connecting to web server #94

Closed raulperez closed 1 year ago

raulperez commented 1 year ago

Hi

I am writing with the hope somebody can give me a hand.

Several request get a 400 'bad request' or 406 'not acceptable' code in return from the web server. Some other times there is not even a response from the server. It seems the connection dies before it reaches the server, since I cannot see any logs on the server console.

Retrying the same request sometimes work.

I have an Arduino Mega 2560 R3 + WiFi Esp8266 with firmware 1.7 (Non OS SDK3).

What could be the issue?

Thanks in advance.

JAndrassy commented 1 year ago

how is it wired? how is the esp8266 powered? what serial baud rate? did you try to turn on debug log?

raulperez commented 1 year ago

The esp8266 is embedded. It is part of the Mega 2560 R3 board:

[https://arduinotech.dk/shop/mega-r3wifi-atmega328pesp8266-32mb-memory-usb-ttl-ch340g-compatible-for-arduino-mega-nodemcu-esp8266/]

I know about the serial baud rate for the monitor and the communication between the Mega 2560 and the esp8266 but don't know the baud rate of the esp8266/WiFi. How could I know that?

I haven't tried to turn on the debug log. How do I do that?

Thanks for the help. I am new to Arduino/embedded programming.

raulperez commented 1 year ago

Found logging level here :)

src/utils/EspAtDrvLogging.h

raulperez commented 1 year ago

This is a typical example where first attempts fails, second works:

21:56:25.813 -> node_id: Node1

<< from here starts the first attempt that will fail......

21:56:25.813 -> temperature_am2320: 26.80 21:56:25.813 -> humidity_am2320: 47.20 21:56:25.813 -> temperature_bmp180: 26.30 21:56:25.813 -> pressure_bmp180: 100644.00 21:56:25.813 -> altitude_bmp180: 165.61 21:56:25.813 -> timestamp: 1667598971 21:56:25.813 -> [WS] Sent ACK: 1667598971 21:56:25.813 -> esp INFO: AP query 21:56:25.813 -> esp> AT+CWJAP? ...sent 21:56:25.813 -> esp> +CWJAP:"TaoWiFi2.4GHz","30:23:03:b8:00:5e",12,-60,0 ...matched 21:56:25.813 -> esp> OK ...matched 21:56:25.813 -> [WiFi] Signal strength (RSSI): -60 dBm 21:56:25.846 -> [WiFi] Connecting to 192.168.1.32 at port 8000esp INFO: free linkId is 4 21:56:25.846 -> esp INFO: start TCP to 192.168.1.32:8000 on link 4 21:56:25.846 -> esp> AT+CIPSTART=4,"TCP","192.168.1.32",8000 ...sent 21:56:26.828 -> esp> ? 21:56:26.828 -> esp> busy p... ...ignored 21:56:27.840 -> esp> ? 21:56:27.840 -> esp> busy p... ...ignored 21:56:28.852 -> esp> ? 21:56:28.852 -> esp> busy p... ...ignored 21:56:28.950 -> esp> ERROR ...error 21:56:28.950 -> esp ERROR: expected OK got ERROR 21:56:28.982 -> .esp> 4,CLOSED ...processed 21:56:29.472 -> esp INFO: closed linkId 4 21:56:29.472 -> esp INFO: free linkId is 4 21:56:29.472 -> esp INFO: start TCP to 192.168.1.32:8000 on link 4 21:56:29.472 -> esp> AT+CIPSTART=4,"TCP","192.168.1.32",8000 ...sent 21:56:30.483 -> esp> ? 21:56:30.483 -> esp> busy p... ...ignored 21:56:31.492 -> esp> ? 21:56:31.492 -> esp> busy p... ...ignored 21:56:32.467 -> esp> ? 21:56:32.467 -> esp> busy p... ...ignored 21:56:32.697 -> esp> ERROR ...error 21:56:32.697 -> esp ERROR: expected OK got ERROR 21:56:32.697 -> .esp> 4,CLOSED ...processed 21:56:33.188 -> esp INFO: closed linkId 4 21:56:33.188 -> esp INFO: free linkId is 4 21:56:33.188 -> esp INFO: start TCP to 192.168.1.32:8000 on link 4 21:56:33.188 -> esp> AT+CIPSTART=4,"TCP","192.168.1.32",8000 ...sent 21:56:34.200 -> esp> ? 21:56:34.200 -> esp> busy p... ...ignored 21:56:35.209 -> esp> ? 21:56:35.209 -> esp> busy p... ...ignored 21:56:36.189 -> esp> ? 21:56:36.189 -> esp> busy p... ...ignored 21:56:36.417 -> esp> ERROR ...error 21:56:36.417 -> esp ERROR: expected OK got ERROR 21:56:36.417 -> .esp> 4,CLOSED ...processed 21:56:36.906 -> esp INFO: closed linkId 4 21:56:36.906 -> esp INFO: free linkId is 4 21:56:36.906 -> esp INFO: start TCP to 192.168.1.32:8000 on link 4 21:56:36.939 -> esp> AT+CIPSTART=4,"TCP","192.168.1.32",8000 ...sent 21:56:37.916 -> esp> ? 21:56:37.916 -> esp> busy p... ...ignored 21:56:38.924 -> esp> ? 21:56:38.924 -> esp> ? 21:56:38.924 -> esp> busy p... ...ignored 21:56:39.085 -> esp> 4,CONNECT ...ignored

<<<< after a few tries seems to connect with the service

21:56:39.085 -> esp> OK ...matched 21:56:39.085 -> esp INFO: BuffManager returned buff.stream at 0 for linkId 4 21:56:39.118 -> 21:56:39.183 -> [WS] Node Id: 21:56:39.183 -> [WS] Processing latest data received... 21:56:39.215 -> [WS] Retry:0 21:56:39.215 -> [WS] WiFi client connected: YES 21:56:39.215 -> [WS] Sending request: 21:56:39.215 -> POST /api/weather-logs/ HTTP/1.1 21:56:39.215 -> Connection: keep-alive 21:56:39.215 -> Host: 192.168.1.32 21:56:39.215 -> Content-Type: application/json 21:56:39.215 -> Content-Length: 202 21:56:39.215 -> 21:56:39.215 -> {"node_id" : "Node1", "temperature_am2320" : 26.80,"humidity_am2320" : 47.20,"temperature_bmp180" : 26.30,"pressure_bmp180" : 100644.00,"altitude_bmp180" : 165.61,"timestamp" : 1667598971,"retries" : 0} 21:56:39.247 -> [WS] Waiting for response...esp INFO: send data on link 4.

<<<< sends and wait for the response...

21:56:39.247 -> esp> AT+CIPSEND=4,335 ...sent 21:56:39.247 -> esp> OK ...ignored 21:56:39.247 -> esp> > ...matched 21:56:39.280 -> esp> Recv 335 bytes ...matched 21:56:40.259 -> esp> ? 21:56:40.259 -> esp> busy s... ...ignored 21:56:41.276 -> esp> ? 21:56:41.276 -> esp> busy s... ...ignored 21:56:42.289 -> esp> ? 21:56:42.289 -> esp> busy s... ...ignored 21:56:43.265 -> esp> ? 21:56:43.265 -> esp> busy s... ...ignored 21:56:44.274 -> esp> ? 21:56:44.274 -> esp> busy s... ...ignored 21:56:45.289 -> esp> ? 21:56:45.289 -> esp> busy s... ...ignored 21:56:46.266 -> esp> ? 21:56:46.266 -> esp> busy s... ...ignored 21:56:46.363 -> esp> 4,CLOSED ...processed 21:56:46.363 -> esp INFO: closed linkId 4 21:56:46.363 -> esp> SEND FAIL ...matched 21:56:46.363 -> esp ERROR: failed to send data 21:56:46.363 -> esp INFO: send data on link 4 21:56:46.363 -> esp ERROR: link is not connected. 21:56:46.887 -> .......... 21:56:51.392 -> esp INFO: send data on link 4 21:56:51.424 -> esp ERROR: link is not connected. 21:56:52.402 -> [WS] Unexpected response (retrying):

<<<<<< something went wrong... and don't see anything on the server side...

21:56:54.393 -> 21:56:54.393 -> [WiFi] Client stopped... 21:56:54.491 -> esp INFO: AP query

<<<< here starts the second retry....

21:56:54.491 -> esp> AT+CWJAP? ...sent 21:56:54.523 -> esp> +CWJAP:"TaoWiFi2.4GHz","30:23:03:b8:00:5e",12,-61,0 ...matched 21:56:54.523 -> esp> OK ...matched 21:56:54.523 -> [WiFi] Signal strength (RSSI): -61 dBm 21:56:54.523 -> [WiFi] Connecting to 192.168.1.32 at port 8000esp INFO: free linkId is 4 21:56:54.523 -> esp INFO: start TCP to 192.168.1.32:8000 on link 4 21:56:54.523 -> esp> AT+CIPSTART=4,"TCP","192.168.1.32",8000 ...sent

<<< this time connects faster...

21:56:54.751 -> esp> 4,CONNECT ...ignored 21:56:54.751 -> esp> OK ...matched 21:56:54.751 -> esp INFO: BuffManager returned buff.stream at 0 for linkId 4 21:56:54.751 -> 21:56:54.848 -> [WS] Node Id: 21:56:54.848 -> [WS] Processing latest data received... 21:56:54.848 -> [WS] Retry:1 21:56:54.848 -> [WS] WiFi client connected: YES 21:56:54.848 -> [WS] Sending request: 21:56:54.848 -> POST /api/weather-logs/ HTTP/1.1 21:56:54.848 -> Connection: keep-alive 21:56:54.848 -> Host: 192.168.1.32 21:56:54.848 -> Content-Type: application/json 21:56:54.848 -> Content-Length: 202 21:56:54.880 -> 21:56:54.880 -> {"node_id" : "Node1", "temperature_am2320" : 26.80,"humidity_am2320" : 47.20,"temperature_bmp180" : 26.30,"pressure_bmp180" : 100644.00,"altitude_bmp180" : 165.61,"timestamp" : 1667598971,"retries" : 1} 21:56:54.880 -> [WS] Waiting for response...esp INFO: send data on link 4.

<<< waiting for response from the server side...

21:56:54.880 -> esp> AT+CIPSEND=4,335 ...sent 21:56:54.880 -> esp> OK ...ignored 21:56:54.880 -> esp> > ...matched 21:56:54.912 -> esp> Recv 335 bytes ...matched 21:56:55.924 -> esp> ? 21:56:55.924 -> esp> busy s... ...ignored 21:56:56.908 -> esp> ? 21:56:56.908 -> esp> busy s... ...ignored 21:56:57.885 -> esp> SEND OK ...matched.

<<<< this time looks ok and I can see the request on the server side...

21:56:57.885 -> esp INFO: sent 335 bytes on link 4 21:56:57.885 -> esp INFO: send data on link 4 21:56:57.885 -> esp> AT+CIPSEND=4,2 ...sent 21:56:57.885 -> esp> OK ...ignored 21:56:57.885 -> esp> > ...matched 21:56:57.918 -> esp> Recv 2 bytes ...matched 21:56:57.918 -> esp> +IPD,4,31 ...processed 21:56:57.918 -> esp> +IPD,4,68 ...processed 21:56:57.918 -> esp> +IPD,4,107 ...processed 21:56:57.950 -> esp> +IPD,4,248 ...processed 21:56:57.950 -> esp> +IPD,4,387 ...processed 21:56:58.962 -> esp> ? 21:56:58.962 -> esp> busy s... ...ignored 21:56:59.942 -> esp> ? 21:56:59.942 -> esp> busy s... ...ignored 21:57:00.105 -> esp> SEND OK ...matched 21:57:00.105 -> esp INFO: sent 2 bytes on link 4 21:57:00.105 -> 21:57:00.105 -> esp INFO: get data on link 4 21:57:00.105 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.105 -> esp> +CIPRECVDATA,64 ...matched 21:57:00.105 -> esp> OK ...matched 21:57:00.105 -> esp INFO: got 64 bytes on link 4 21:57:00.105 -> [WS] Transmission cancelled: HTTP/1.1 208 Already Reported

<<<<< this was the expected because the record already existed on the server side...

21:57:00.105 -> esp> 4,CLOSED ...processed 21:57:00.138 -> esp INFO: closed linkId 4 21:57:00.138 -> esp INFO: get data on link 4 21:57:00.138 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.138 -> esp> +CIPRECVDATA,64 ...matched 21:57:00.138 -> esp> OK ...matched 21:57:00.138 -> esp INFO: got 64 bytes on link 4 21:57:00.138 -> esp INFO: get data on link 4 21:57:00.138 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.138 -> esp> +CIPRECVDATA,64 ...matched 21:57:00.138 -> esp> OK ...matched 21:57:00.138 -> esp INFO: got 64 bytes on link 4 21:57:00.138 -> esp INFO: get data on link 4 21:57:00.138 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.171 -> esp> +CIPRECVDATA,64 ...matched 21:57:00.171 -> esp> OK ...matched 21:57:00.171 -> esp INFO: got 64 bytes on link 4 21:57:00.171 -> esp INFO: get data on link 4 21:57:00.171 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.171 -> esp> +CIPRECVDATA,64 ...matched 21:57:00.171 -> esp> OK ...matched 21:57:00.171 -> esp INFO: got 64 bytes on link 4 21:57:00.171 -> esp INFO: get data on link 4 21:57:00.171 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.171 -> esp> +CIPRECVDATA,64 ...matched 21:57:00.171 -> esp> OK ...matched 21:57:00.171 -> esp INFO: got 64 bytes on link 4 21:57:00.204 -> esp INFO: get data on link 4 21:57:00.204 -> esp> AT+CIPRECVDATA=4,64 ...sent 21:57:00.204 -> esp> +CIPRECVDATA,3 ...matched 21:57:00.204 -> esp> OK ...matched 21:57:00.204 -> esp INFO: got 3 bytes on link 4 21:57:00.204 -> esp INFO: send data on link 4 21:57:00.204 -> esp ERROR: link is not connected.

<<<< something disconnected before I closed the connection???

21:57:01.183 -> {"message": ":Weather log added recently within the same span of time. Record will be skipped for node id Node1 and timestamp: 1667598971"} 21:57:01.216 -> [WiFi] Client stopped...

JAndrassy commented 1 year ago

how did you upload the AT firmware? I usually see this strange behavior if the wifi calibration data of the esp are corrupted

raulperez commented 1 year ago

I used this command:

esptool.py --port /dev/cu.usbserial-144230 write_flash --flash_mode dio --flash_size 1MB 0x0 boot_v1.7.bin 0x01000 at/512+512/user1.1024.new.2.bin 0xfb000 blank.bin 0xfc000 esp_init_data_default_v08.bin 0xfe000 blank.bin 0x7e000 blank.bin

I updated it to the latest version you suggested on a link I found in an Arduino forum.

How could I verify that and calibrate the esp?

raulperez commented 1 year ago

During last night the transmission has been quite acceptable just a few retries and every 15 minutes as expected. But sometimes I am unable to see a record in hours.

{ "logs": [ { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 50.9, "temperature_bmp180": 24.8, "pressure_bmp180": 100716.0, "altitude_bmp180": 159.27, "timestamp": 1667610119, "retries": 0, "created_at": "2022-11-05T00:02:37.904Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 51.2, "temperature_bmp180": 24.8, "pressure_bmp180": 100725.0, "altitude_bmp180": 157.93, "timestamp": 1667611048, "retries": 0, "created_at": "2022-11-05T00:17:54.027Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 51.4, "temperature_bmp180": 24.8, "pressure_bmp180": 100738.0, "altitude_bmp180": 158.18, "timestamp": 1667611977, "retries": 0, "created_at": "2022-11-05T00:33:25.545Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 51.5, "temperature_bmp180": 24.8, "pressure_bmp180": 100743.0, "altitude_bmp180": 157.6, "timestamp": 1667612906, "retries": 0, "created_at": "2022-11-05T00:48:51.654Z" }, { "node_id": "Node1", "temperature_am2320": 25.6, "humidity_am2320": 51.5, "temperature_bmp180": 24.8, "pressure_bmp180": 100744.0, "altitude_bmp180": 157.43, "timestamp": 1667613835, "retries": 0, "created_at": "2022-11-05T01:04:20.028Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 51.6, "temperature_bmp180": 24.7, "pressure_bmp180": 100739.0, "altitude_bmp180": 157.76, "timestamp": 1667614764, "retries": 0, "created_at": "2022-11-05T01:19:56.881Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 51.7, "temperature_bmp180": 24.7, "pressure_bmp180": 100748.0, "altitude_bmp180": 156.85, "timestamp": 1667615693, "retries": 4, "created_at": "2022-11-05T01:36:36.395Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 51.7, "temperature_bmp180": 24.7, "pressure_bmp180": 100745.0, "altitude_bmp180": 157.51, "timestamp": 1667616622, "retries": 1, "created_at": "2022-11-05T01:51:06.569Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 51.8, "temperature_bmp180": 24.7, "pressure_bmp180": 100753.0, "altitude_bmp180": 155.68, "timestamp": 1667617551, "retries": 0, "created_at": "2022-11-05T02:06:17.957Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 51.9, "temperature_bmp180": 24.7, "pressure_bmp180": 100753.0, "altitude_bmp180": 156.09, "timestamp": 1667618480, "retries": 0, "created_at": "2022-11-05T02:21:44.718Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.0, "temperature_bmp180": 24.7, "pressure_bmp180": 100746.0, "altitude_bmp180": 156.59, "timestamp": 1667619409, "retries": 0, "created_at": "2022-11-05T02:37:16.780Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.1, "temperature_bmp180": 24.7, "pressure_bmp180": 100749.0, "altitude_bmp180": 156.85, "timestamp": 1667620338, "retries": 0, "created_at": "2022-11-05T02:52:46.015Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.2, "temperature_bmp180": 24.8, "pressure_bmp180": 100755.0, "altitude_bmp180": 156.09, "timestamp": 1667621267, "retries": 0, "created_at": "2022-11-05T03:08:20.816Z" }, { "node_id": "Node1", "temperature_am2320": 25.6, "humidity_am2320": 52.1, "temperature_bmp180": 24.8, "pressure_bmp180": 100771.0, "altitude_bmp180": 154.84, "timestamp": 1667622196, "retries": 0, "created_at": "2022-11-05T03:24:17.616Z" }, { "node_id": "Node1", "temperature_am2320": 25.6, "humidity_am2320": 52.1, "temperature_bmp180": 24.8, "pressure_bmp180": 100773.0, "altitude_bmp180": 154.84, "timestamp": 1667623125, "retries": 0, "created_at": "2022-11-05T03:39:10.606Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.2, "temperature_bmp180": 24.8, "pressure_bmp180": 100778.0, "altitude_bmp180": 153.76, "timestamp": 1667624054, "retries": 0, "created_at": "2022-11-05T03:54:38.973Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.2, "temperature_bmp180": 24.8, "pressure_bmp180": 100776.0, "altitude_bmp180": 153.93, "timestamp": 1667624983, "retries": 0, "created_at": "2022-11-05T04:10:15.837Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.2, "temperature_bmp180": 24.8, "pressure_bmp180": 100787.0, "altitude_bmp180": 153.43, "timestamp": 1667625912, "retries": 0, "created_at": "2022-11-05T04:25:38.587Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.2, "temperature_bmp180": 24.8, "pressure_bmp180": 100797.0, "altitude_bmp180": 152.76, "timestamp": 1667626841, "retries": 0, "created_at": "2022-11-05T04:41:08.632Z" }, { "node_id": "Node1", "temperature_am2320": 25.4, "humidity_am2320": 52.3, "temperature_bmp180": 24.8, "pressure_bmp180": 100797.0, "altitude_bmp180": 152.51, "timestamp": 1667627770, "retries": 0, "created_at": "2022-11-05T04:56:36.831Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.4, "temperature_bmp180": 24.8, "pressure_bmp180": 100792.0, "altitude_bmp180": 152.84, "timestamp": 1667628699, "retries": 0, "created_at": "2022-11-05T05:12:17.064Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.4, "temperature_bmp180": 24.8, "pressure_bmp180": 100797.0, "altitude_bmp180": 152.68, "timestamp": 1667629628, "retries": 1, "created_at": "2022-11-05T05:27:56.267Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.4, "temperature_bmp180": 24.8, "pressure_bmp180": 100811.0, "altitude_bmp180": 150.92, "timestamp": 1667630557, "retries": 1, "created_at": "2022-11-05T05:43:25.865Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.4, "temperature_bmp180": 24.8, "pressure_bmp180": 100821.0, "altitude_bmp180": 151.09, "timestamp": 1667631486, "retries": 1, "created_at": "2022-11-05T05:58:47.561Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.5, "temperature_bmp180": 24.8, "pressure_bmp180": 100820.0, "altitude_bmp180": 151.09, "timestamp": 1667632415, "retries": 0, "created_at": "2022-11-05T06:14:05.143Z" }, { "node_id": "Node1", "temperature_am2320": 25.5, "humidity_am2320": 52.5, "temperature_bmp180": 24.9, "pressure_bmp180": 100829.0, "altitude_bmp180": 150.0, "timestamp": 1667633344, "retries": 1, "created_at": "2022-11-05T06:29:50.424Z" } ], "count": 26 }

JAndrassy commented 1 year ago

this is the upload command for a 1 MB flash. the README for WiFiEspAT has the command for larger flash. erase flash with esptool to reset the calibration data and then upload the AT firmware with the right command.

raulperez commented 1 year ago

It seems more stable after the update you suggested. Let's test it for a few hours and let's see how it behaves.

What is the difference?

raulperez commented 1 year ago

It seems to fails still but with a little improvement. At least it seems that is not missing data after a few retries.

Let's leave it until tomorrow to get a better sample of data.

{
        "node_id": "Node1",
        "temperature_am2320": 24.4,
        "humidity_am2320": 46.6,
        "temperature_bmp180": 23.5,
        "pressure_bmp180": 101085.0,
        "altitude_bmp180": 128.85,
        "timestamp": 1667670432,
        "retries": 0,
        "created_at": "2022-11-05T16:47:39.583Z"
    },
    {
        "node_id": "Node1",
        "temperature_am2320": 24.1,
        "humidity_am2320": 46.6,
        "temperature_bmp180": 23.4,
        "pressure_bmp180": 101094.0,
        "altitude_bmp180": 128.27,
        "timestamp": 1667671361,
        "retries": 3,
        "created_at": "2022-11-05T17:03:54.424Z"
    },
    {
        "node_id": "Node1",
        "temperature_am2320": 24.3,
        "humidity_am2320": 46.7,
        "temperature_bmp180": 23.4,
        "pressure_bmp180": 101103.0,
        "altitude_bmp180": 127.43,
        "timestamp": 1667672290,
        "retries": 1,
        "created_at": "2022-11-05T17:18:54.597Z"
    },
    {
        "node_id": "Node1",
        "temperature_am2320": 24.3,
        "humidity_am2320": 46.7,
        "temperature_bmp180": 23.3,
        "pressure_bmp180": 101102.0,
        "altitude_bmp180": 127.68,
        "timestamp": 1667673219,
        "retries": 0,
        "created_at": "2022-11-05T17:34:05.904Z"
    },
    {
        "node_id": "Node1",
        "temperature_am2320": 24.2,
        "humidity_am2320": 46.8,
        "temperature_bmp180": 23.3,
        "pressure_bmp180": 101109.0,
        "altitude_bmp180": 126.85,
        "timestamp": 1667674148,
        "retries": 1,
        "created_at": "2022-11-05T17:49:50.052Z"
    },
    {
        "node_id": "Node1",
        "temperature_am2320": 24.2,
        "humidity_am2320": 46.9,
        "temperature_bmp180": 23.3,
        "pressure_bmp180": 101103.0,
        "altitude_bmp180": 127.18,
        "timestamp": 1667675077,
        "retries": 3,
        "created_at": "2022-11-05T18:05:58.717Z"
    },
    {
        "node_id": "Node1",
        "temperature_am2320": 24.2,
        "humidity_am2320": 47.1,
        "temperature_bmp180": 23.3,
        "pressure_bmp180": 101092.0,
        "altitude_bmp180": 127.77,
        "timestamp": 1667676006,
        "retries": 3,
        "created_at": "2022-11-05T18:21:20.014Z"
    }
],
raulperez commented 1 year ago

There have been a few retries during the night and only one record missing out of 29. Unfortunately I could not see the logs for the missing record. My computer got stuck yesterday in the evening apparently .. :(

Is it possible to improve it with any other adjustments?

JAndrassy commented 1 year ago

logging slows down everything so there can be some loss of data on the Serial to esp8266. turn off logging or at least log at very high baud rate

raulperez commented 1 year ago

Ok I will disable logging also for a while to see how it goes.

I have also removed all delays and all String. I am using F() for the literals.

How can I remove this String? is the only one left:

String request = F("POST ");
request.concat(URI);
request.concat(F(" HTTP/1.1"));
request.concat(F("\r\n"));
request.concat(F("Connection: keep-alive"));
request.concat(F("\r\n"));
request.concat(F("Host: "));
request.concat(String(API_SERVER_IP));
request.concat(F("\r\n"));
request.concat(F("Content-Type: application/json"));
request.concat(F("\r\n"));
request.concat(F("Content-Length: "));
request.concat(tempData.length());
request.concat(F("\r\n"));
request.concat(F("\r\n"));
request.concat(tempData);
raulperez commented 1 year ago

Seems more estable now. Sometimes it requires a few retries but it is much better than before. Thank you Juraj.

I will try to replace the String concatenation with char array.