void IRAM_ATTR timer_1ms() {
timer_20ms++;
timer_100ms++;
if(timer_20ms / 20)
{
can_flag = true;
timer_20ms = 0;
}
if(timer_100ms / 5000)
{
DB_flag = true;
timer_100ms = 0;
}
}
void timer_Int() {
timer = timerBegin(0, 80, true);
timerAttachInterrupt(timer, &timer_1ms, true);
timerAlarmWrite(timer, 1000, true);
timerAlarmEnable(timer);
timer_flag = true;
}
void setup() {
Serial.begin(115200);
ESP32Can_Init();
WiFi_Init(WIFI_SSID, WIFI_PASSWORD);
timeSync(TZ_INFO, “pool.ntp.org”, “time.nis.gov”);
InfluxDB_Init(client, SN);
timer_Int();
}
void loop() {
if(DB_flag) {
DB_flag = false;
fuelcellsystem.clearFields();
point.addField("rssi", WiFi.RSSI());
Serial.print("Writing");
Serial.println(point.toLineProtocol());
if (!client.writePoint(point)) {
Serial.print("InfluxDB write failed: ");
Serial.println(client.getLastErrorMessage());
}
count++;
Serial.println(count);
}
if (wifiMulti.run() != WL_CONNECTED) {
Serial.println("Wifi connection lost");
timerAlarmDisable(timer);
timer_flag = false;
timer_20ms = 0;
timer_100ms = 0;
can_flag = false;
DB_flag = false;
}
else {
if(timer_flag == false) {
timerAlarmEnable(timer);
timer_flag = true;
}
}
}
I want to fix the issue where the ESP32 Nano reboots during client.writePoint(point) when the Wi-Fi connection is lost and then reconnected, typically after 2–3 write attempts
