Bonjour à tous,
Je teste actuellement un ESP32 800, pour se connecter sur une web API. Celui-ci fonctionne bien durant plusieurs heures, mais qui fini par le plis vouloir se connecter.
C’est à dire il fonctionne bien après reboot et durant la journée, puis à un moment n’arrive plus à se connecter à l’API, pourtant l’ESP semble toujours connecté sur le réseau.
J’utilise le code ci-dessous :
#include <esp_now.h>
#include <WiFi.h>
// Please select the corresponding model
#define SIM800L_IP5306_VERSION_20190610
// #define SIM800L_AXP192_VERSION_20200327
// #define SIM800C_AXP192_VERSION_20200609
#include "utilities.h"
#define SerialMon Serial
#define SerialAT Serial1
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
#include <TinyGsmClient.h>
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
// Structure d'échange
typedef struct struct_message {
String vcc;
} struct_message;
struct_message myData;
char senderMacAddress[19];
String IMEI;
const char server[] = "www.xxx.fr";
const char resource[] = "/detection/";
const char apn[] = "free"; // Your APN
const char gprsUser[] = ""; // User
const char gprsPass[] = ""; // Password
const char simPIN[] = ""; // SIM card PIN code, if any
TinyGsmClient client(modem);
const int port = 80;
void setupModem()
{
#ifdef MODEM_RST
// Keep reset high
pinMode(MODEM_RST, OUTPUT);
digitalWrite(MODEM_RST, HIGH);
#endif
pinMode(MODEM_PWRKEY, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
// Turn on the Modem power first
digitalWrite(MODEM_POWER_ON, HIGH);
// Pull down PWRKEY for more than 1 second according to manual requirements
digitalWrite(MODEM_PWRKEY, HIGH);
delay(100);
digitalWrite(MODEM_PWRKEY, LOW);
delay(1000);
digitalWrite(MODEM_PWRKEY, HIGH);
// Initialize the indicator as an output
pinMode(LED_GPIO, OUTPUT);
digitalWrite(LED_GPIO, LED_OFF);
}
void turnOffNetlight()
{
SerialMon.println("Turning off SIM800 Red LED...");
modem.sendAT("+CNETLIGHT=0");
}
void turnOnNetlight()
{
SerialMon.println("Turning on SIM800 Red LED...");
modem.sendAT("+CNETLIGHT=1");
}
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&myData, incomingData, sizeof(myData));
sprintf(senderMacAddress, "%02x:%02x:%02x:%02x:%02x:%02x",mac[0], mac[1], mac[2], mac[3], mac[4],mac[5]);
Serial.print("Réception request from : ");
Serial.println(senderMacAddress);
Serial.print("Voltage : ");
Serial.println(myData.vcc);
SerialMon.print("Connecting to ");
SerialMon.print(server);
if (!client.connect(server, port)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
//// Make a HTTP GET request:
SerialMon.println("Performing HTTP POST request...");
String PostData = (String)"uuid=" + IMEI + "&sma=" + senderMacAddress + "&vcc=" + myData.vcc;
client.println(String("POST ") + resource + " HTTP/1.1");
client.println(String("Host: ") + server);
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.println(PostData.length());
client.println();
client.println(PostData);
client.println();
// unsigned long timeout = millis();
// while (client.connected() && millis() - timeout < 10000L) {
// // Print available data
// while (client.available()) {
// char c = client.read();
// //SerialMon.print(c);
// timeout = millis();
// }
// }
// SerialMon.println();
// Shutdown
client.stop();
SerialMon.println(F("Server disconnected"));
}
void setup() {
SerialMon.begin(115200);
delay(10);
if (setupPMU() == false) Serial.println("Setting power error");
setupModem();
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
SerialMon.println("Initializing modem...");
modem.restart();
//turnOffNetlight();
// The status light cannot be turned off, only physically removed
//turnOffStatuslight();
// Or, use modem.init() if you don't need the complete restart
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
digitalWrite(LED_GPIO, LED_ON);
if (modem.isNetworkConnected()) SerialMon.println("Network connected"); else { SerialMon.println("Network not connected !!!"); return;}
SerialMon.print(F("Connecting to "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
IMEI = modem.getIMEI();
SerialMon.print("Activation ESP-NOW.....");
WiFi.mode(WIFI_STA);
if (esp_now_init() != 0) {
Serial.println("échec");
return;
}
//esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
esp_now_register_recv_cb(OnDataRecv);
SerialMon.println("succès");
}
void loop()
{
}
Ci-dessous un exemple de log daté :
23:58:17.655 -> ets Jun 8 2016 00:22:57
23:58:17.655 ->
23:58:17.655 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
23:58:17.655 -> configsip: 0, SPIWP:0xee
23:58:17.655 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
23:58:17.655 -> mode:DIO, clock div:1
23:58:17.655 -> load:0x3fff0018,len:4
23:58:17.655 -> load:0x3fff001c,len:1044
23:58:17.655 -> load:0x40078000,len:8896
23:58:17.655 -> load:0x40080400,len:5816
23:58:17.655 -> entry 0x400806ac
23:58:17.936 -> Setting power error
23:58:19.003 -> Initializing modem...
23:58:26.809 -> Modem: SIM800 R14.18
23:58:26.809 -> Waiting for network... OK
23:58:31.887 -> Network connected
23:58:31.887 -> Connecting to free OK
23:58:39.061 -> Activation ESP-NOW.....succès
23:58:43.895 -> Réception request from : 84:f3:eb:72:c1:45
23:58:43.895 -> Voltage : 4466
23:58:43.895 -> Connecting to www.xxx.fr OK
23:58:44.926 -> Performing HTTP POST request...
23:58:45.113 -> Server disconnected
23:59:05.983 -> Réception request from : 84:f3:eb:72:c1:45
23:59:05.983 -> Voltage : 4466
23:59:05.983 -> Connecting to www.xxx.fr OK
23:59:06.629 -> Performing HTTP POST request...
23:59:06.865 -> Server disconnected
05:50:14.654 -> Réception request from : 84:f3:eb:72:c1:45
05:50:14.654 -> Voltage : 4466
05:50:14.654 -> Connecting to www.xxx.fr fail
Quelqu’un aurait une idée du pourquoi ?