mirror of
https://github.com/schinken/esp8266-geigercounter.git
synced 2024-11-23 09:00:21 +01:00
Add OTA
This commit is contained in:
parent
6d88f6c013
commit
3c78d20461
2 changed files with 16 additions and 15 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <PubSubClient.h>
|
#include <PubSubClient.h>
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
#include <SimpleTimer.h>
|
#include <SimpleTimer.h>
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
@ -18,31 +19,26 @@ float lastuSv = 0, currentuSv = 0;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
WiFi.hostname("ESP-GeigerCounter");
|
WiFi.hostname(WIFI_HOSTNAME);
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
mqttClient.setClient(wifiClient);
|
|
||||||
mqttClient.setServer(mqttHost, 1883);
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
geigerCounterSerial.begin(BAUD_GEIGERCOUNTER);
|
geigerCounterSerial.begin(BAUD_GEIGERCOUNTER);
|
||||||
|
|
||||||
delay(10);
|
delay(10);
|
||||||
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||||
Serial.print("Connecting to ");
|
|
||||||
Serial.println(ssid);
|
|
||||||
|
|
||||||
WiFi.begin(ssid, password);
|
|
||||||
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("");
|
mqttClient.setClient(wifiClient);
|
||||||
Serial.println("WiFi connected");
|
mqttClient.setServer(mqttHost, 1883);
|
||||||
Serial.println("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
ArduinoOTA.setHostname(WIFI_HOSTNAME);
|
||||||
|
ArduinoOTA.setPassword(OTA_PASSWORD);
|
||||||
|
ArduinoOTA.begin();
|
||||||
|
|
||||||
timer.setInterval(UPDATE_INTERVAL_SECONDS * 1000L, updateRadiationValues);
|
timer.setInterval(UPDATE_INTERVAL_SECONDS * 1000L, updateRadiationValues);
|
||||||
}
|
}
|
||||||
|
@ -150,4 +146,6 @@ void loop() {
|
||||||
|
|
||||||
Serial.write(in);
|
Serial.write(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,11 @@
|
||||||
|
|
||||||
#define BAUD_GEIGERCOUNTER 9600
|
#define BAUD_GEIGERCOUNTER 9600
|
||||||
|
|
||||||
const char* ssid = "----";
|
const char* WIFI_HOSTNAME = "ESP-GeigerCounter";
|
||||||
const char* password = "----";
|
const char* WIFI_SSID = "----";
|
||||||
|
const char* WIFI_PASSWORD = "----";
|
||||||
|
|
||||||
|
const char* OTA_PASSWORD = "foobar";
|
||||||
|
|
||||||
#define MQTT_TOPIC_CPM "sensor/radiation/cpm"
|
#define MQTT_TOPIC_CPM "sensor/radiation/cpm"
|
||||||
#define MQTT_TOPIC_USV "sensor/radiation/uSv"
|
#define MQTT_TOPIC_USV "sensor/radiation/uSv"
|
||||||
|
|
Loading…
Reference in a new issue