From 5777df2c48033ac1d6b927e3a8ea87ba914ac57c Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 25 Mar 2021 14:03:13 +0100 Subject: [PATCH] introduce global var device clientId --- include/globals.h | 1 + src/boot.cpp | 8 -------- src/main.cpp | 9 +++++++++ src/mqttclient.cpp | 8 +------- src/ota.cpp | 7 ------- src/reset.cpp | 3 --- 6 files changed, 11 insertions(+), 25 deletions(-) diff --git a/include/globals.h b/include/globals.h index d63e5b7f..eb4f58b4 100644 --- a/include/globals.h +++ b/include/globals.h @@ -127,6 +127,7 @@ extern std::array::iterator it; extern std::array beacons; extern configData_t cfg; // current device configuration +extern char clientId[20]; // unique clientID extern char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer extern uint8_t volatile channel; // wifi channel rotation counter extern uint8_t volatile rf_load; // RF traffic indicator diff --git a/src/boot.cpp b/src/boot.cpp index 889476d1..c4679a95 100644 --- a/src/boot.cpp +++ b/src/boot.cpp @@ -76,14 +76,6 @@ void IRAM_ATTR watchdog() { xTaskResumeFromISR(RestartHandle); } void start_boot_menu(void) { - uint8_t mac[6]; - char clientId[20]; - - // hash 6 byte MAC to 4 byte hash - esp_eth_get_mac(mac); - const uint32_t hashedmac = myhash((const char *)mac, 6); - snprintf(clientId, 20, "paxcounter_%08x", hashedmac); - const char *host = clientId; const char *ssid = WIFI_SSID; const char *password = WIFI_PASS; diff --git a/src/main.cpp b/src/main.cpp index fbf7780e..79ebb1c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,6 +91,7 @@ configData_t cfg; // struct holds current device configuration char lmic_event_msg[LMIC_EVENTMSG_LEN]; // display buffer for LMIC event message uint8_t batt_level = 0; // display value uint8_t volatile rf_load = 0; // RF traffic indicator +char clientId[20] = {0}; // unique ClientID hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL; @@ -137,6 +138,14 @@ void setup() { // load device configuration from NVRAM and set runmode do_after_reset(); + // hash 6 byte device MAC to 4 byte clientID + uint8_t mac[6]; + esp_eth_get_mac(mac); + const uint32_t hashedmac = myhash((const char *)mac, 6); + snprintf(clientId, 20, "paxcounter_%08x", hashedmac); + ESP_LOGI(TAG, "Starting %s v%s (runmode=%d / restarts=%d)", clientId, + PROGVERSION, RTC_runmode, RTC_restarts); + // print chip information on startup if in verbose mode after coldstart #if (VERBOSE) diff --git a/src/mqttclient.cpp b/src/mqttclient.cpp index caba854f..dd0770f8 100644 --- a/src/mqttclient.cpp +++ b/src/mqttclient.cpp @@ -42,14 +42,8 @@ esp_err_t mqtt_init(void) { } int mqtt_connect(const char *my_host, const uint16_t my_port) { - IPAddress mqtt_server_ip; - uint8_t mac[6]; - char clientId[20]; - // hash 6 byte MAC to 4 byte hash - esp_eth_get_mac(mac); - const uint32_t hashedmac = myhash((const char *)mac, 6); - snprintf(clientId, 20, "paxcounter_%08x", hashedmac); + IPAddress mqtt_server_ip; ESP_LOGI(TAG, "MQTT name is %s", MQTT_CLIENTNAME); diff --git a/src/ota.cpp b/src/ota.cpp index 4c8b7140..792dd4f0 100644 --- a/src/ota.cpp +++ b/src/ota.cpp @@ -42,13 +42,6 @@ inline String getHeaderValue(String header, String headerName) { void start_ota_update() { - uint8_t mac[6]; - char clientId[20]; - - // hash 6 byte MAC to 4 byte hash - esp_eth_get_mac(mac); - const uint32_t hashedmac = myhash((const char *)mac, 6); - snprintf(clientId, 20, "paxcounter_%08x", hashedmac); const char *host = clientId; switch_LED(LED_ON); diff --git a/src/reset.cpp b/src/reset.cpp index 67deadf5..f9ad8dd3 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -88,9 +88,6 @@ void do_after_reset(void) { RTC_restarts++; break; } - - ESP_LOGI(TAG, "Starting Software v%s (runmode=%d / restarts=%d)", PROGVERSION, - RTC_runmode, RTC_restarts); } void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {