diff --git a/Makefile b/Makefile index 24750dc..cad8624 100644 --- a/Makefile +++ b/Makefile @@ -61,6 +61,13 @@ SHA := $(shell if git diff --quiet HEAD; then git rev-parse --short HEAD | c else echo "development"; fi) VERSION ?=esp-link $(BRANCH) - $(DATE) - $(SHA) +# --------------- esp-link config options --------------- + +# If CHANGE_TO_STA is set to "yes" the esp-link module will switch to station mode +# once successfully connected to an access point. Else it will stay in AP+STA mode. + +CHANGE_TO_STA ?= yes + # --------------- esphttpd config options --------------- # If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed @@ -118,7 +125,7 @@ CFLAGS = -Os -ggdb -std=c99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno- -D__ets__ -DICACHE_FLASH -D_STDINT_H -Wno-address -DFIRMWARE_SIZE=$(ESP_FLASH_MAX) \ -DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \ -DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_PIN) \ - "-DVERSION=$(VERSION)" + -DVERSION="$(VERSION)" # linker flags used to generate the main object file LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--gc-sections @@ -181,6 +188,10 @@ ifeq ("$(USE_HEATSHRINK)","yes") CFLAGS += -DESPFS_HEATSHRINK endif +ifeq ("$(CHANGE_TO_STA)","yes") +CFLAGS += -DCHANGE_TO_STA +endif + vpath %.c $(SRC_DIR) define compile-objects diff --git a/html/wifi/wifi.js b/html/wifi/wifi.js index c9a2661..0024248 100644 --- a/html/wifi/wifi.js +++ b/html/wifi/wifi.js @@ -106,8 +106,10 @@ function getStatus() { showWifiInfo(data); blockScan = 0; - var txt2 = "esp-link will switch to STA-only mode in a few seconds"; - window.setTimeout(function() { showNotification(txt2); }, 4000); + if (data.modechange == "yes") { + var txt2 = "esp-link will switch to STA-only mode in a few seconds"; + window.setTimeout(function() { showNotification(txt2); }, 4000); + } $("#reconnect").removeAttribute("hidden"); $("#reconnect").innerHTML = diff --git a/user/cgiwifi.c b/user/cgiwifi.c index 92f93b9..13d7d40 100644 --- a/user/cgiwifi.c +++ b/user/cgiwifi.c @@ -243,11 +243,13 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) { if (x == STATION_GOT_IP) { if (m != 1) { +#ifdef CHANGE_TO_STA // We're happily connected, go to STA mode os_printf("Wifi got IP. Going into STA mode..\n"); wifi_set_opmode(1); wifi_set_sleep_type(SLEEP_MODE); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); +#endif //os_timer_disarm(&deepTimer); //os_timer_setfn(&deepTimer, deepSleepCb, NULL); //os_timer_arm(&deepTimer, 1000, 1); @@ -485,6 +487,11 @@ int ICACHE_FLASH_ATTR printWifiInfo(char *buff) { uint8_t op = wifi_get_opmode() & 0x3; char *mode = wifiMode[op]; +#ifdef CHANGE_TO_STA + char *modechange = "yes"; +#else + char *modechange = "no"; +#endif char *status = "unknown"; int st = wifi_station_get_connect_status(); if (st > 0 && st < sizeof(connStatuses)) status = connStatuses[st]; @@ -497,9 +504,9 @@ int ICACHE_FLASH_ATTR printWifiInfo(char *buff) { wifi_get_macaddr(0, mac_addr); len = os_sprintf(buff, - "\"mode\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", " + "\"mode\": \"%s\", \"modechange\": \"%s\", \"ssid\": \"%s\", \"status\": \"%s\", \"phy\": \"%s\", " "\"rssi\": \"%ddB\", \"warn\": \"%s\", \"mac\":\"%02x:%02x:%02x:%02x:%02x:%02x\"", - mode, (char*)stconf.ssid, status, phy, rssi, warn, + mode, modechange, (char*)stconf.ssid, status, phy, rssi, warn, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); struct ip_info info;