mirror of
https://github.com/schinken/esp8266-geigercounter.git
synced 2024-12-22 05:03:08 +01:00
Re-Apply patch from @NKnusperer for default hostname
This commit is contained in:
parent
cff085ba59
commit
6b361a813b
2 changed files with 13 additions and 7 deletions
|
@ -14,12 +14,12 @@ SoftwareSerial geigerCounterSerial(PIN_UART_RX, PIN_UART_TX);
|
|||
|
||||
uint8_t idx = 0;
|
||||
char buffer[64];
|
||||
char hostname[24];
|
||||
|
||||
int lastCPM = 0, currentCPM = 0;
|
||||
float lastuSv = 0, currentuSv = 0;
|
||||
unsigned long lastPublishMs = 0;
|
||||
|
||||
|
||||
void setup() {
|
||||
// power up wait
|
||||
delay(3000);
|
||||
|
@ -27,8 +27,14 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
geigerCounterSerial.begin(9600);
|
||||
delay(10);
|
||||
|
||||
#ifdef WIFI_HOSTNAME
|
||||
strncpy(hostname, WIFI_HOSTNAME, sizeof(hostname));
|
||||
#else
|
||||
snprintf(hostname, sizeof(hostname), "ESP-GEIGER-%X", ESP.getChipId());
|
||||
#endif
|
||||
|
||||
WiFi.hostname(WIFI_HOSTNAME);
|
||||
WiFi.hostname(hostname);
|
||||
WiFi.mode(WIFI_STA);
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||||
|
||||
|
@ -41,7 +47,7 @@ void setup() {
|
|||
mqttClient.setServer(MQTT_HOST, 1883);
|
||||
|
||||
#ifdef OTA_PASSWORD
|
||||
ArduinoOTA.setHostname(WIFI_HOSTNAME);
|
||||
ArduinoOTA.setHostname(hostname);
|
||||
ArduinoOTA.setPassword(OTA_PASSWORD);
|
||||
ArduinoOTA.begin();
|
||||
#endif
|
||||
|
@ -68,7 +74,7 @@ void publishValues() {
|
|||
void connectMqtt() {
|
||||
|
||||
while (!mqttClient.connected()) {
|
||||
if (mqttClient.connect(WIFI_HOSTNAME, MQTT_TOPIC_LAST_WILL, 1, true, "disconnected")) {
|
||||
if (mqttClient.connect(hostname, MQTT_TOPIC_LAST_WILL, 1, true, "disconnected")) {
|
||||
mqttClient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
|
||||
Serial.println("MQTT connected");
|
||||
} else {
|
||||
|
|
|
@ -11,9 +11,9 @@
|
|||
|
||||
#define BAUD_GEIGERCOUNTER 9600
|
||||
|
||||
const char* WIFI_HOSTNAME = "ESP-GeigerCounter";
|
||||
const char* WIFI_SSID = "xxxxxxxxxx";
|
||||
const char* WIFI_PASSWORD = "xxxxxxxxxxx";
|
||||
//#define WIFI_HOSTNAME "ESP-GeigerCounter";
|
||||
#define WIFI_SSID "xxxx"
|
||||
#define WIFI_PASSWORD "xxxxx"
|
||||
|
||||
//#define OTA_PASSWORD "foobar"
|
||||
|
||||
|
|
Loading…
Reference in a new issue