From 2e22db67e273e382c70c4a52d558922239fb67cd Mon Sep 17 00:00:00 2001 From: DTTerastar Date: Mon, 15 Mar 2021 21:11:55 -0400 Subject: [PATCH] Roundtrip the firmware urls --- platformio.ini | 5 +++++ src/ESP32-mqtt-room.ino | 42 ++++++++++++++++++++++++++--------------- src/Settings.h | 4 ++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/platformio.ini b/platformio.ini index 0684cc8..70d08ab 100644 --- a/platformio.ini +++ b/platformio.ini @@ -27,6 +27,8 @@ lib_deps = lib_ignore = ESPAsyncTCP board_build.partitions = partitions_singleapp.csv monitor_speed = 115200 +build_flags = + -D FIRMWARE=esp32 [env:m5stickc] platform = espressif32 @@ -47,6 +49,7 @@ board_build.partitions = partitions_singleapp.csv monitor_speed = 115200 build_flags = -D M5STICK + -D FIRMWARE=m5stickc [env:m5stickc-plus] platform = espressif32 @@ -68,6 +71,7 @@ monitor_speed = 115200 build_flags = -D M5STICK -D PLUS + -D FIRMWARE=m5stickc-plus [env:verbose] platform = espressif32 @@ -88,3 +92,4 @@ board_build.partitions = partitions_singleapp.csv monitor_speed = 115200 build_flags = -D CONFIG_LOG_DEFAULT_LEVEL=4 + -D FIRMWARE=verbose diff --git a/src/ESP32-mqtt-room.ino b/src/ESP32-mqtt-room.ino index fcd23ba..4439c6c 100644 --- a/src/ESP32-mqtt-room.ino +++ b/src/ESP32-mqtt-room.ino @@ -476,6 +476,10 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice) Serial.print(mac_address); int rssi = advertisedDevice.getRSSI(); +#ifdef M5STICK + M5.Lcd.println(mac_address); +#endif + if (advertisedDevice.haveName()) { String nameBLE = String(advertisedDevice.getName().c_str()); @@ -677,10 +681,9 @@ void scanForDevices(void *parameter) Serial.printf("Scan done! Devices found: %d\n\r", devicesCount); #ifdef M5STICK + M5.Lcd.setCursor(0, 0); M5.Lcd.fillScreen(TFT_BLACK); - M5.Lcd.setTextDatum(MC_DATUM); - M5.Lcd.drawNumber(devicesCount, 40, 80, 7); - M5.Lcd.setTextDatum(MC_DATUM); + #endif int devicesReported = 0; @@ -803,8 +806,6 @@ void setup() #ifdef M5STICK M5.begin(); - //M5.Lcd.setRotation(1); - M5.Lcd.fillScreen(TFT_BLACK); M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK); #endif @@ -851,23 +852,34 @@ void firmwareUpdate(void) WiFiClientSecure client; client.setInsecure(); + httpUpdate.setLedPin(LED_BUILTIN, LOW); httpUpdate.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS); +#ifdef M5STICK +#ifdef PLUS + String firmwareUrl = String("https://github.com/DTTerastar/ESP32-mqtt-room/releases/latest/download/m5stickc-plus.bin"); +#else + String firmwareUrl = String("https://github.com/DTTerastar/ESP32-mqtt-room/releases/latest/download/m5stickc.bin"); +#endif +#else + String firmwareUrl = String("https://github.com/DTTerastar/ESP32-mqtt-room/releases/latest/download/esp32.bin"); +#endif - t_httpUpdate_return ret = httpUpdate.update(client, "https://github.com/DTTerastar/ESP32-mqtt-room/releases/latest/download/firmware.bin"); + Serial.printf("Updating from %s\n", firmwareUrl.c_str()); + t_httpUpdate_return ret = httpUpdate.update(client, firmwareUrl); switch (ret) { - case HTTP_UPDATE_FAILED: - Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); - break; + case HTTP_UPDATE_FAILED: + Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); + break; - case HTTP_UPDATE_NO_UPDATES: - Serial.println("HTTP_UPDATE_NO_UPDATES"); - break; + case HTTP_UPDATE_NO_UPDATES: + Serial.println("HTTP_UPDATE_NO_UPDATES"); + break; - case HTTP_UPDATE_OK: - Serial.println("HTTP_UPDATE_OK"); - break; + case HTTP_UPDATE_OK: + Serial.println("HTTP_UPDATE_OK"); + break; } } diff --git a/src/Settings.h b/src/Settings.h index bd19437..0fdb99c 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -23,7 +23,11 @@ #define DEFAULT_ROOM "living-room" //Specify the LED pin. For most dev boards, this is GPIO2 +#ifdef M5STICK +#define LED_BUILTIN 10 +#else #define LED_BUILTIN 2 +#endif // Logic level for turning the led on. Most boards use active low, meaning LED_ON should be set to 0 #define LED_ON 0