maintenance mode adjustments

This commit is contained in:
cyberman54 2021-03-03 19:16:14 +01:00
parent 439ea0c057
commit ad2c889889
4 changed files with 17 additions and 14 deletions

View File

@ -149,6 +149,5 @@ extern TaskHandle_t irqHandlerTask, ClockTask, macProcessTask;
extern TimerHandle_t WifiChanTimer;
extern Timezone myTZ;
extern RTC_DATA_ATTR runmode_t RTC_runmode;
extern char clientId[20]; // generated device name
#endif

View File

@ -93,7 +93,6 @@ uint8_t batt_level = 0; // display value
uint8_t volatile channel = WIFI_CHANNEL_MIN; // channel rotation counter
uint8_t volatile rf_load = 0; // RF traffic indicator
uint16_t volatile macs_wifi = 0, macs_ble = 0; // globals for display
char clientId[20]; // generated device name
hw_timer_t *ppsIRQ = NULL, *displayIRQ = NULL, *matrixDisplayIRQ = NULL;
@ -143,12 +142,6 @@ void setup() {
do_after_reset();
// generate unique clientId from device's MAC
uint8_t mac[6];
esp_eth_get_mac(mac);
const uint32_t hashedmac = hash((const char *)mac, 6);
snprintf(clientId, 20, "paxcounter_%08x", hashedmac);
// print chip information on startup if in verbose mode after coldstart
#if (VERBOSE)

View File

@ -43,6 +43,13 @@ 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 = hash((const char *)mac, 6);
snprintf(clientId, 20, "paxcounter_%08x", hashedmac);
ESP_LOGI(TAG, "MQTT name is %s", MQTT_CLIENTNAME);

View File

@ -330,15 +330,15 @@ void show_progress(unsigned long current, unsigned long size) {
#endif
}
// start local web user with user interface for maintenance mode
// currently used only for manually uploading a firmware file via wifi
// start local web server with user interface for maintenance mode
// used for manually uploading a firmware file via wifi
void start_maintenance(void) {
// code snippets taken from
// https://github.com/espressif/arduino-esp32/blob/master/libraries/ArduinoOTA/examples/OTAWebUpdater/OTAWebUpdater.ino
// github.com/espressif/arduino-esp32/blob/master/libraries/ArduinoOTA/examples/OTAWebUpdater/OTAWebUpdater.ino
const char *host = MQTT_CLIENTNAME;
const char *host = "paxcounter";
const char *ssid = WIFI_SSID;
const char *password = WIFI_PASS;
@ -388,10 +388,11 @@ void start_maintenance(void) {
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
while (WiFi.status() != WL_CONNECTED)
delay(500);
}
ESP_LOGI(TAG, "Connected to %s", ssid);
ESP_LOGI(TAG, "Open http://%s.local in your browser", host);
// use mdns for host name resolution
if (!MDNS.begin(host)) {
@ -399,6 +400,7 @@ void start_maintenance(void) {
delay(3000);
do_reset(false);
}
server.on("/", HTTP_GET, [&server, &serverIndex]() {
server.sendHeader("Connection", "close");
server.send(200, "text/html", serverIndex);
@ -439,7 +441,9 @@ void start_maintenance(void) {
do_reset(false);
}
});
server.begin();
MDNS.addService("http", "tcp", 80);
while (1) {
server.handleClient();