|
|
@ -37,7 +37,7 @@ const char* mqttusername PROGMEM = "esp-weatherstation"; |
|
|
|
const char* mqttpassword PROGMEM = PWD_MQTT; |
|
|
|
|
|
|
|
constexpr unsigned int postingInterval = 60000; //Uploadintervall in Millisekunden
|
|
|
|
constexpr unsigned int dhcp_interval = 60*60*1000; |
|
|
|
constexpr unsigned int dhcp_interval = 3*60*1000; |
|
|
|
|
|
|
|
uint32_t loop_count = 0; |
|
|
|
|
|
|
@ -301,6 +301,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
|
|
|
|
} else { |
|
|
|
DEBUG_MSG("dhcp\n"); |
|
|
|
WiFi.disconnect(); |
|
|
|
int tries = 0; |
|
|
|
constexpr unsigned int retry_delay = 500; |
|
|
|
constexpr unsigned int max_retry_delay = 12000; |
|
|
@ -362,23 +363,12 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
net.setInsecure(); |
|
|
|
mqttclient.begin(mqttserver, 8883, net); |
|
|
|
int tries = 0; |
|
|
|
bool mqtt_error = false; |
|
|
|
constexpr unsigned int retry_delay = 500; |
|
|
|
constexpr unsigned int max_retry_delay = 5000; |
|
|
|
while (!mqttclient.connect(mqttusername, mqttusername, mqttpassword)) { |
|
|
|
tries++; |
|
|
|
for (int tries=0; tries<5 && !mqttclient.connect(mqttusername, mqttusername, mqttpassword); tries++ ) { |
|
|
|
DEBUG_MSG("."); |
|
|
|
if (tries*retry_delay >= max_retry_delay) { |
|
|
|
DEBUG_MSG(" [ERROR]\n"); |
|
|
|
//DEBUG_MSG("Rebooting..\n");
|
|
|
|
//ESP.restart();
|
|
|
|
mqtt_error = true; |
|
|
|
} |
|
|
|
delay(retry_delay); |
|
|
|
} |
|
|
|
|
|
|
|
if (!mqtt_error) { |
|
|
|
|
|
|
|
mqttclient.loop(); |
|
|
|
getValuesJSON(buffer, MQTT_MAX_PACKET_SIZE, 2); |
|
|
|
if (mqttclient.publish("sensor/esp-weatherstation/01/json", buffer, strlen(buffer))) { |
|
|
@ -389,8 +379,6 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
mqttclient.loop(); |
|
|
|
mqttclient.disconnect(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (sd.rssi == 0) { // re-read rssi if zero
|
|
|
|
sd.rssi = WiFi.RSSI(); |
|
|
|
} |
|
|
@ -404,7 +392,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
loop_count++; |
|
|
|
|
|
|
|
net.stop(); |
|
|
|
WiFi.disconnect(); |
|
|
|
WiFi.disconnect(true); |
|
|
|
WiFi.mode(WIFI_OFF); |
|
|
|
WiFi.forceSleepBegin(); |
|
|
|
delay(1); // yield();
|
|
|
|