1 parent
f9f04494fa
commit
6ec2773b20
2 files changed
+30
-1
No files matched your search
+29
-1
@@ -107,6 +107,9 @@ unsigned long timer_led_receive = 0;
|
|||||||
unsigned long timer_led_send = 0;
|
unsigned long timer_led_send = 0;
|
||||||
unsigned long timer_led_error = 0;
|
unsigned long timer_led_error = 0;
|
||||||
|
|
||||||
|
//Time used to wait for an interval before checking system measures
|
||||||
|
unsigned long timer_sys_measures = 0;
|
||||||
|
|
||||||
//Wifi manager parameters
|
//Wifi manager parameters
|
||||||
//flag for saving data
|
//flag for saving data
|
||||||
bool shouldSaveConfig = true;
|
bool shouldSaveConfig = true;
|
||||||
@@ -115,10 +118,19 @@ boolean connected_once = false;
|
|||||||
|
|
||||||
//callback notifying us of the need to save config
|
//callback notifying us of the need to save config
|
||||||
void saveConfigCallback () {
|
void saveConfigCallback () {
|
||||||
Serial.println("Should save config");
|
trc("Should save config");
|
||||||
shouldSaveConfig = true;
|
shouldSaveConfig = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
void WiFiEvent(WiFiEvent_t event){
|
||||||
|
if(event == SYSTEM_EVENT_STA_DISCONNECTED){
|
||||||
|
trc("Event: SYSTEM_EVENT_STA_DISCONNECTED, reconnecting");
|
||||||
|
WiFi.reconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
boolean reconnect() {
|
boolean reconnect() {
|
||||||
|
|
||||||
int failure_number = 0;
|
int failure_number = 0;
|
||||||
@@ -309,6 +321,7 @@ void setup()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#if defined(ESP32) || defined(ESPWifiManualSetup)
|
#if defined(ESP32) || defined(ESPWifiManualSetup)
|
||||||
void setup_wifi() {
|
void setup_wifi() {
|
||||||
delay(10);
|
delay(10);
|
||||||
@@ -445,6 +458,7 @@ void setup_wifimanager(boolean reset_settings){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#else // Arduino case
|
#else // Arduino case
|
||||||
void setup_ethernet() {
|
void setup_ethernet() {
|
||||||
Ethernet.begin(mac, ip); //Comment and uncomment the following line if you want to use advanced network config
|
Ethernet.begin(mac, ip); //Comment and uncomment the following line if you want to use advanced network config
|
||||||
@@ -489,9 +503,15 @@ void setup_ethernet() {
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
//MQTT client connexion management
|
//MQTT client connexion management
|
||||||
if (!client.connected()) { // not connected
|
if (!client.connected()) { // not connected
|
||||||
|
|
||||||
|
#if defined(ESP32) // if wifi disconnected on ESP32 we reconnect
|
||||||
|
if(WiFi.getAutoReconnect()) WiFi.onEvent(WiFiEvent);
|
||||||
|
#endif
|
||||||
|
|
||||||
//RED ON
|
//RED ON
|
||||||
digitalWrite(led_error, LOW);
|
digitalWrite(led_error, LOW);
|
||||||
|
|
||||||
@@ -576,6 +596,14 @@ void loop()
|
|||||||
if(RFM69toMQTT())
|
if(RFM69toMQTT())
|
||||||
trc(F("RFM69toMQTT OK"));
|
trc(F("RFM69toMQTT OK"));
|
||||||
#endif
|
#endif
|
||||||
|
unsigned long now = millis();
|
||||||
|
if (now > (timer_sys_measures + TimeBetweenReadingSYS)) {//retriving value of memory ram every TimeBetweenReadingSYS
|
||||||
|
timer_sys_measures = millis();
|
||||||
|
trc("Remaining memory");
|
||||||
|
uint32_t freeMem;
|
||||||
|
freeMem = ESP.getFreeHeap();
|
||||||
|
trc(String(freeMem));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,7 @@ const byte subnet[] = { 255, 255, 255, 0 }; //ip adress
|
|||||||
//variables to avoid duplicates
|
//variables to avoid duplicates
|
||||||
#define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
|
#define time_avoid_duplicate 3000 // if you want to avoid duplicate mqtt message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
|
||||||
|
|
||||||
|
#define TimeBetweenReadingSYS 30000 // time between system readings (like memory)
|
||||||
/*-------------------ACTIVATE TRACES----------------------*/
|
/*-------------------ACTIVATE TRACES----------------------*/
|
||||||
#define TRACE 1 // 0= trace off 1 = trace on
|
#define TRACE 1 // 0= trace off 1 = trace on
|
||||||
|
|
||||||
Reference in new issue
Block a user