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