introduce global var device clientId

This commit is contained in:
cyberman54 2021-03-25 14:03:13 +01:00
parent bad60592c3
commit 5777df2c48
6 changed files with 11 additions and 25 deletions

View File

@ -127,6 +127,7 @@ extern std::array<uint64_t, 0xff>::iterator it;
extern std::array<uint64_t, 0xff> 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

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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) {