|
@ -102,6 +102,7 @@ volatile unsigned long geiger_counts = 0; |
|
|
unsigned long geiger_previousMillis; |
|
|
unsigned long geiger_previousMillis; |
|
|
unsigned long last_dhcp = 0; |
|
|
unsigned long last_dhcp = 0; |
|
|
unsigned long previousMillis = 0; |
|
|
unsigned long previousMillis = 0; |
|
|
|
|
|
unsigned long lastSuccess = 0; |
|
|
IPAddress ip, dns, gateway, subnet; |
|
|
IPAddress ip, dns, gateway, subnet; |
|
|
char ssid[64]; |
|
|
char ssid[64]; |
|
|
char password[64]; |
|
|
char password[64]; |
|
@ -226,7 +227,7 @@ void ICACHE_FLASH_ATTR getValuesJSON(char* buffer, const size_t buf_len, int for |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ICACHE_FLASH_ATTR sendValues() { |
|
|
void ICACHE_FLASH_ATTR sendValues() { |
|
|
int errors = 0; |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
|
|
|
|
|
|
sd.temperature = dht.readTemperature(); |
|
|
sd.temperature = dht.readTemperature(); |
|
|
sd.humidity = dht.readHumidity(); |
|
|
sd.humidity = dht.readHumidity(); |
|
@ -357,6 +358,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
|
|
|
|
|
|
if (httpCode > 0) { |
|
|
if (httpCode > 0) { |
|
|
if (httpCode == HTTP_CODE_CREATED) { |
|
|
if (httpCode == HTTP_CODE_CREATED) { |
|
|
|
|
|
lastSuccess = currentMillis; |
|
|
#ifdef USERDEBUG |
|
|
#ifdef USERDEBUG |
|
|
httpclient.writeToStream(&Serial); |
|
|
httpclient.writeToStream(&Serial); |
|
|
DEBUG_MSG("\n"); |
|
|
DEBUG_MSG("\n"); |
|
@ -369,7 +371,6 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
httpclient.end(); |
|
|
httpclient.end(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
if (httpCode != HTTP_CODE_CREATED) errors++; |
|
|
|
|
|
|
|
|
|
|
|
net.setInsecure(); |
|
|
net.setInsecure(); |
|
|
mqttclient.begin(mqttserver, 8883, net); |
|
|
mqttclient.begin(mqttserver, 8883, net); |
|
@ -382,10 +383,10 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
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))) { |
|
|
|
|
|
lastSuccess = currentMillis; |
|
|
DEBUG_MSG("mqtt done\n"); |
|
|
DEBUG_MSG("mqtt done\n"); |
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG("mqtt failed\n"); |
|
|
DEBUG_MSG("mqtt failed\n"); |
|
|
errors++; |
|
|
|
|
|
} |
|
|
} |
|
|
mqttclient.loop(); |
|
|
mqttclient.loop(); |
|
|
mqttclient.disconnect(); |
|
|
mqttclient.disconnect(); |
|
@ -394,8 +395,8 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
sd.rssi = WiFi.RSSI(); |
|
|
sd.rssi = WiFi.RSSI(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (errors >= 2) { |
|
|
if (currentMillis - lastSuccess > 5* postingInterval) { |
|
|
DEBUG_MSG("[ERROR] could not send any values\nRebooting..\n"); |
|
|
DEBUG_MSG("[ERROR] could not send any values for 5 times\nRebooting..\n"); |
|
|
ESP.restart(); |
|
|
ESP.restart(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|