diff options
| author | manuel <manuel@mausz.at> | 2020-12-28 10:17:18 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-12-28 10:17:18 +0100 |
| commit | 1783df2792956e63de1bbae3ed7b036bdefec9a1 (patch) | |
| tree | 8b71a6c1d245b7ee17cb2c3a4b30e02fcf28d76f | |
| parent | 0988bbec7e2a8dfd36108ded1c5821c93b031354 (diff) | |
| download | arduino-1783df2792956e63de1bbae3ed7b036bdefec9a1.tar.gz arduino-1783df2792956e63de1bbae3ed7b036bdefec9a1.tar.bz2 arduino-1783df2792956e63de1bbae3ed7b036bdefec9a1.zip | |
Rename dr_desk to dr_table
| -rw-r--r-- | oliver/dr_table/.gitignore (renamed from oliver/dr_desk/.gitignore) | 0 | ||||
| -rw-r--r-- | oliver/dr_table/platformio.ini (renamed from oliver/dr_desk/platformio.ini) | 0 | ||||
| -rw-r--r-- | oliver/dr_table/src/main.cpp (renamed from oliver/dr_desk/src/main.cpp) | 28 |
3 files changed, 15 insertions, 13 deletions
diff --git a/oliver/dr_desk/.gitignore b/oliver/dr_table/.gitignore index 89cc49c..89cc49c 100644 --- a/oliver/dr_desk/.gitignore +++ b/oliver/dr_table/.gitignore | |||
diff --git a/oliver/dr_desk/platformio.ini b/oliver/dr_table/platformio.ini index e5c54f1..e5c54f1 100644 --- a/oliver/dr_desk/platformio.ini +++ b/oliver/dr_table/platformio.ini | |||
diff --git a/oliver/dr_desk/src/main.cpp b/oliver/dr_table/src/main.cpp index 8791c80..309c4a1 100644 --- a/oliver/dr_desk/src/main.cpp +++ b/oliver/dr_table/src/main.cpp | |||
| @@ -11,10 +11,10 @@ | |||
| 11 | #define MQTT_BROKER_PORT 1883 | 11 | #define MQTT_BROKER_PORT 1883 |
| 12 | //#define MQTT_USERNAME "" | 12 | //#define MQTT_USERNAME "" |
| 13 | //#define MQTT_PASSWORD "" | 13 | //#define MQTT_PASSWORD "" |
| 14 | #define MQTT_BASE "home/diningroom/desk" | 14 | #define MQTT_BASE "home/diningroom/table" |
| 15 | 15 | ||
| 16 | const char* mqtt_mode_sub = MQTT_BASE; | 16 | const char* mqtt_mode_sub = MQTT_BASE "/mode"; |
| 17 | const char* mqtt_mode_pub = MQTT_BASE "/status"; | 17 | const char* mqtt_mode_pub = MQTT_BASE "/mode/status"; |
| 18 | 18 | ||
| 19 | const char* mqtt_color_sub = MQTT_BASE "/color"; | 19 | const char* mqtt_color_sub = MQTT_BASE "/color"; |
| 20 | const char* mqtt_color_pub = MQTT_BASE "/color/status"; | 20 | const char* mqtt_color_pub = MQTT_BASE "/color/status"; |
| @@ -30,9 +30,9 @@ const char* mqtt_brightness_pub = MQTT_BASE "/brightness/status"; | |||
| 30 | 30 | ||
| 31 | // fw update | 31 | // fw update |
| 32 | // - increment number + build | 32 | // - increment number + build |
| 33 | // - scp .pio/build/$ENV/firmware.bin manuel@mausz.at:public_html/coding/.firmware/olidrdesk.bin | 33 | // - scp .pio/build/$ENV/firmware.bin manuel@mausz.at:public_html/coding/.firmware/olidrtable.bin |
| 34 | // - reboot device or send "fwupdate" to mqtt_topic_cmd | 34 | // - reboot device or send "fwupdate" to mqtt_topic_cmd |
| 35 | // - fw update state is published in mqtt_topic_state | 35 | // - fw update state is published in mqtt_topic_status |
| 36 | #define FIRMWARE_VERSION 1 | 36 | #define FIRMWARE_VERSION 1 |
| 37 | //#define FIRMWARE_URL "" | 37 | //#define FIRMWARE_URL "" |
| 38 | 38 | ||
| @@ -41,9 +41,9 @@ const char* mqtt_brightness_pub = MQTT_BASE "/brightness/status"; | |||
| 41 | 41 | ||
| 42 | const String mqtt_clientId = "DrDesk-" + String(ESP.getChipId()) | 42 | const String mqtt_clientId = "DrDesk-" + String(ESP.getChipId()) |
| 43 | + "/v" + STR(FIRMWARE_VERSION); | 43 | + "/v" + STR(FIRMWARE_VERSION); |
| 44 | const char* mqtt_topic_ping = MQTT_BASE "/ping"; | 44 | const char* mqtt_topic_ping = MQTT_BASE "/ping"; |
| 45 | const char* mqtt_topic_cmd = MQTT_BASE "/command"; | 45 | const char* mqtt_topic_status = MQTT_BASE "/status"; |
| 46 | const String mqtt_topic_state = String(MQTT_BASE) + "/" + String(ESP.getChipId()); | 46 | const char* mqtt_topic_cmd = MQTT_BASE "/command"; |
| 47 | 47 | ||
| 48 | bool mqttLoop(); | 48 | bool mqttLoop(); |
| 49 | void mqttCallback(char *topic, byte *payload, unsigned int length); | 49 | void mqttCallback(char *topic, byte *payload, unsigned int length); |
| @@ -124,11 +124,13 @@ bool mqttLoop() | |||
| 124 | if (!mqtt.connected()) | 124 | if (!mqtt.connected()) |
| 125 | { | 125 | { |
| 126 | Serial.printf_P(PSTR("Connecting to MQTT\n")); | 126 | Serial.printf_P(PSTR("Connecting to MQTT\n")); |
| 127 | if (!mqtt.connect(mqtt_clientId.c_str(), MQTT_USERNAME, MQTT_PASSWORD)) | 127 | if (!mqtt.connect(mqtt_clientId.c_str(), MQTT_USERNAME, MQTT_PASSWORD, |
| 128 | mqtt_topic_status, 0, true, "offline")) | ||
| 128 | return false; | 129 | return false; |
| 129 | 130 | ||
| 130 | Serial.printf_P(PSTR("MQTT connected\n")); | 131 | Serial.printf_P(PSTR("MQTT connected\n")); |
| 131 | mqtt.publish(mqtt_topic_ping, mqtt_clientId.c_str()); | 132 | mqtt.publish(mqtt_topic_ping, mqtt_clientId.c_str()); |
| 133 | mqtt.publish(mqtt_topic_status, "online", true); | ||
| 132 | mqtt.subscribe(mqtt_topic_ping); | 134 | mqtt.subscribe(mqtt_topic_ping); |
| 133 | mqtt.subscribe(mqtt_topic_cmd); | 135 | mqtt.subscribe(mqtt_topic_cmd); |
| 134 | 136 | ||
| @@ -281,7 +283,7 @@ void checkFirmwareUpdate() | |||
| 281 | BearSSL::WiFiClientSecure update_client; | 283 | BearSSL::WiFiClientSecure update_client; |
| 282 | update_client.setInsecure(); | 284 | update_client.setInsecure(); |
| 283 | 285 | ||
| 284 | mqtt.publish(mqtt_topic_state.c_str(), "fwupdate running"); | 286 | mqtt.publish(mqtt_topic_status, "fwupdate running"); |
| 285 | ESPhttpUpdate.setLedPin(LED_BUILTIN, HIGH); | 287 | ESPhttpUpdate.setLedPin(LED_BUILTIN, HIGH); |
| 286 | ESPhttpUpdate.rebootOnUpdate(true); | 288 | ESPhttpUpdate.rebootOnUpdate(true); |
| 287 | t_httpUpdate_return ret = ESPhttpUpdate.update(update_client, FIRMWARE_URL, STR(FIRMWARE_VERSION)); | 289 | t_httpUpdate_return ret = ESPhttpUpdate.update(update_client, FIRMWARE_URL, STR(FIRMWARE_VERSION)); |
| @@ -292,18 +294,18 @@ void checkFirmwareUpdate() | |||
| 292 | Serial.printf_P(PSTR("HTTP_UPDATE_FAILED Error (%d): %s\n"), | 294 | Serial.printf_P(PSTR("HTTP_UPDATE_FAILED Error (%d): %s\n"), |
| 293 | ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); | 295 | ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str()); |
| 294 | String tmp = String("fwupdate error: ") + ESPhttpUpdate.getLastErrorString(); | 296 | String tmp = String("fwupdate error: ") + ESPhttpUpdate.getLastErrorString(); |
| 295 | mqtt.publish(mqtt_topic_state.c_str(), tmp.c_str()); | 297 | mqtt.publish(mqtt_topic_status, tmp.c_str()); |
| 296 | } | 298 | } |
| 297 | break; | 299 | break; |
| 298 | 300 | ||
| 299 | case HTTP_UPDATE_NO_UPDATES: | 301 | case HTTP_UPDATE_NO_UPDATES: |
| 300 | Serial.printf_P(PSTR("HTTP_UPDATE_NO_UPDATES\n")); | 302 | Serial.printf_P(PSTR("HTTP_UPDATE_NO_UPDATES\n")); |
| 301 | mqtt.publish(mqtt_topic_state.c_str(), "fwupdate noupdates"); | 303 | mqtt.publish(mqtt_topic_status, "fwupdate noupdates"); |
| 302 | break; | 304 | break; |
| 303 | 305 | ||
| 304 | case HTTP_UPDATE_OK: | 306 | case HTTP_UPDATE_OK: |
| 305 | Serial.printf_P(PSTR("HTTP_UPDATE_OK\n")); | 307 | Serial.printf_P(PSTR("HTTP_UPDATE_OK\n")); |
| 306 | mqtt.publish(mqtt_topic_state.c_str(), "fwupdate ok"); | 308 | mqtt.publish(mqtt_topic_status, "fwupdate ok"); |
| 307 | break; | 309 | break; |
| 308 | } | 310 | } |
| 309 | } | 311 | } |
