|
@ -149,7 +149,7 @@ void inline lightsleep() { |
|
|
Serial.flush(); |
|
|
Serial.flush(); |
|
|
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time // this does not work: (uint32_t)postingInterval*1000
|
|
|
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time // this does not work: (uint32_t)postingInterval*1000
|
|
|
delay(1); // go to sleep now
|
|
|
delay(1); // go to sleep now
|
|
|
DEBUG_MSG("woken\n"); |
|
|
DEBUG_MSG("[DEBUG] woken\n"); |
|
|
//wifi_fpm_do_wakeup();
|
|
|
//wifi_fpm_do_wakeup();
|
|
|
wifi_fpm_close(); |
|
|
wifi_fpm_close(); |
|
|
} |
|
|
} |
|
@ -288,7 +288,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
&& (rtcMillis() - last_dhcp < dhcp_interval) |
|
|
&& (rtcMillis() - last_dhcp < dhcp_interval) |
|
|
) { |
|
|
) { |
|
|
|
|
|
|
|
|
DEBUG_MSG("static ip\n"); |
|
|
DEBUG_MSG("[WiFi] STATIC IP\n"); |
|
|
WiFi.config(ip, dns, gateway, subnet); |
|
|
WiFi.config(ip, dns, gateway, subnet); |
|
|
WiFi.begin(ssid, password); |
|
|
WiFi.begin(ssid, password); |
|
|
int tries = 0; |
|
|
int tries = 0; |
|
@ -298,7 +298,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
tries++; |
|
|
tries++; |
|
|
DEBUG_MSG("."); |
|
|
DEBUG_MSG("."); |
|
|
if (tries*retry_delay >= max_retry_delay) { |
|
|
if (tries*retry_delay >= max_retry_delay) { |
|
|
DEBUG_MSG(" [ERROR]\n"); |
|
|
DEBUG_MSG(" [ERROR] could not connect to WiFi\n"); |
|
|
DEBUG_MSG("Rebooting..\n"); |
|
|
DEBUG_MSG("Rebooting..\n"); |
|
|
ESP.restart(); |
|
|
ESP.restart(); |
|
|
} |
|
|
} |
|
@ -309,7 +309,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
DEBUG_MSG("%s\n", WiFi.localIP().toString().c_str()); |
|
|
DEBUG_MSG("%s\n", WiFi.localIP().toString().c_str()); |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG("dhcp\n"); |
|
|
DEBUG_MSG("[WiFi] DHCP\n"); |
|
|
WiFi.disconnect(); |
|
|
WiFi.disconnect(); |
|
|
int tries = 0; |
|
|
int tries = 0; |
|
|
constexpr unsigned int retry_delay = 500; |
|
|
constexpr unsigned int retry_delay = 500; |
|
@ -318,7 +318,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
tries++; |
|
|
tries++; |
|
|
DEBUG_MSG("."); |
|
|
DEBUG_MSG("."); |
|
|
if (tries*retry_delay >= max_retry_delay) { |
|
|
if (tries*retry_delay >= max_retry_delay) { |
|
|
DEBUG_MSG(" [ERROR]\n"); |
|
|
DEBUG_MSG(" [ERROR] could not connect to WiFi\n"); |
|
|
DEBUG_MSG("Rebooting..\n"); |
|
|
DEBUG_MSG("Rebooting..\n"); |
|
|
ESP.restart(); |
|
|
ESP.restart(); |
|
|
} |
|
|
} |
|
@ -366,7 +366,7 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
DEBUG_MSG("\n"); |
|
|
DEBUG_MSG("\n"); |
|
|
#endif |
|
|
#endif |
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG("[HTTP] POST... failed, error: %s\n", httpclient.errorToString(httpCode).c_str()); |
|
|
DEBUG_MSG("[ERROR] HTTP POST... failed, error: %s\n", httpclient.errorToString(httpCode).c_str()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -386,9 +386,9 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
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; |
|
|
lastSuccess = currentMillis; |
|
|
DEBUG_MSG("mqtt done\n"); |
|
|
DEBUG_MSG("[DEBUG] MQTT done\n"); |
|
|
} else { |
|
|
} else { |
|
|
DEBUG_MSG("mqtt failed\n"); |
|
|
DEBUG_MSG("[ERROR] MQTT failed\n"); |
|
|
} |
|
|
} |
|
|
mqttclient.loop(); |
|
|
mqttclient.loop(); |
|
|
mqttclient.disconnect(); |
|
|
mqttclient.disconnect(); |
|
@ -433,7 +433,7 @@ void setup() { |
|
|
|
|
|
|
|
|
Wire.begin(BMP_SDA, BMP_SCL); |
|
|
Wire.begin(BMP_SDA, BMP_SCL); |
|
|
if (!bmp.begin(BMP085_MODE_STANDARD)) { |
|
|
if (!bmp.begin(BMP085_MODE_STANDARD)) { |
|
|
DEBUG_MSG("No valid BMP085 sensor!\n"); |
|
|
DEBUG_MSG("[ERROR] No valid BMP085 sensor!\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dht.begin(); |
|
|
dht.begin(); |
|
@ -450,7 +450,7 @@ void setup() { |
|
|
wifiMulti.addAP("Freifunk", ""); |
|
|
wifiMulti.addAP("Freifunk", ""); |
|
|
|
|
|
|
|
|
previousMillis = rtcMillis(); |
|
|
previousMillis = rtcMillis(); |
|
|
DEBUG_MSG("ready.\n"); //Serial.flush();
|
|
|
DEBUG_MSG("[DEBUG] ready.\n"); //Serial.flush();
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void loop() { |
|
|
void loop() { |
|
@ -458,14 +458,14 @@ void loop() { |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
unsigned long currentMillis = rtcMillis(); |
|
|
if ((currentMillis - previousMillis) >= postingInterval) { |
|
|
if ((currentMillis - previousMillis) >= postingInterval) { |
|
|
previousMillis = currentMillis; |
|
|
previousMillis = currentMillis; |
|
|
DEBUG_MSG("sending values... previousMillis:%u, millis():%u, difference:%d\n", previousMillis, currentMillis, currentMillis-previousMillis); |
|
|
DEBUG_MSG("[DEBUG] sending values... previousMillis:%u, millis():%u, difference:%d\n", previousMillis, currentMillis, currentMillis-previousMillis); |
|
|
sendValues(); |
|
|
sendValues(); |
|
|
DEBUG_MSG("resetting geiger counts. was: %d\n", geiger_counts); |
|
|
DEBUG_MSG("[DEBUG] resetting geiger counts. was: %d\n", geiger_counts); |
|
|
geiger_previousMillis = rtcMillis(); |
|
|
geiger_previousMillis = rtcMillis(); |
|
|
geiger_counts = 0; |
|
|
geiger_counts = 0; |
|
|
} |
|
|
} |
|
|
DEBUG_MSG("heap: %d\n", ESP.getFreeHeap()); |
|
|
DEBUG_MSG("[DEBUG] heap: %d\n", ESP.getFreeHeap()); |
|
|
DEBUG_MSG("sleeping now... (%u)\n", currentMillis); |
|
|
DEBUG_MSG("[DEBUG] sleeping now... (%u)\n", currentMillis); |
|
|
|
|
|
|
|
|
delay(10); |
|
|
delay(10); |
|
|
detachInterrupt(digitalPinToInterrupt(GEIGER_PIN)); |
|
|
detachInterrupt(digitalPinToInterrupt(GEIGER_PIN)); |
|
|