diff --git a/esp8266-geigercounter.ino b/esp8266-geigercounter.ino index b87d501..df474e6 100644 --- a/esp8266-geigercounter.ino +++ b/esp8266-geigercounter.ino @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "settings.h" @@ -18,31 +19,26 @@ float lastuSv = 0, currentuSv = 0; void setup() { - WiFi.hostname("ESP-GeigerCounter"); + WiFi.hostname(WIFI_HOSTNAME); WiFi.mode(WIFI_STA); - - mqttClient.setClient(wifiClient); - mqttClient.setServer(mqttHost, 1883); Serial.begin(115200); geigerCounterSerial.begin(BAUD_GEIGERCOUNTER); delay(10); - - Serial.print("Connecting to "); - Serial.println(ssid); - - WiFi.begin(ssid, password); + WiFi.begin(WIFI_SSID, WIFI_PASSWORD); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); delay(500); } - Serial.println(""); - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); + mqttClient.setClient(wifiClient); + mqttClient.setServer(mqttHost, 1883); + + ArduinoOTA.setHostname(WIFI_HOSTNAME); + ArduinoOTA.setPassword(OTA_PASSWORD); + ArduinoOTA.begin(); timer.setInterval(UPDATE_INTERVAL_SECONDS * 1000L, updateRadiationValues); } @@ -150,4 +146,6 @@ void loop() { Serial.write(in); } + + ArduinoOTA.handle(); } diff --git a/settings.h.example b/settings.h.example index fe8ff78..38f19f2 100644 --- a/settings.h.example +++ b/settings.h.example @@ -15,8 +15,11 @@ #define BAUD_GEIGERCOUNTER 9600 -const char* ssid = "----"; -const char* password = "----"; +const char* WIFI_HOSTNAME = "ESP-GeigerCounter"; +const char* WIFI_SSID = "----"; +const char* WIFI_PASSWORD = "----"; + +const char* OTA_PASSWORD = "foobar"; #define MQTT_TOPIC_CPM "sensor/radiation/cpm" #define MQTT_TOPIC_USV "sensor/radiation/uSv"