added CHANGE_TO_STA define so that you can disable the automatic mode change via the makefile

pull/30/head
iothing 9 years ago
parent fc784cc6b5
commit 776b9d4d76
  1. 13
      Makefile
  2. 2
      html/wifi/wifi.js
  3. 11
      user/cgiwifi.c

@ -61,6 +61,13 @@ SHA := $(shell if git diff --quiet HEAD; then git rev-parse --short HEAD | c
else echo "development"; fi) else echo "development"; fi)
VERSION ?=esp-link $(BRANCH) - $(DATE) - $(SHA) 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 --------------- # --------------- esphttpd config options ---------------
# If GZIP_COMPRESSION is set to "yes" then the static css, js, and html files will be compressed # 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) \ -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) \ -DMCU_RESET_PIN=$(MCU_RESET_PIN) -DMCU_ISP_PIN=$(MCU_ISP_PIN) \
-DLED_CONN_PIN=$(LED_CONN_PIN) -DLED_SERIAL_PIN=$(LED_SERIAL_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 # linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--gc-sections 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 CFLAGS += -DESPFS_HEATSHRINK
endif endif
ifeq ("$(CHANGE_TO_STA)","yes")
CFLAGS += -DCHANGE_TO_STA
endif
vpath %.c $(SRC_DIR) vpath %.c $(SRC_DIR)
define compile-objects define compile-objects

@ -106,8 +106,10 @@ function getStatus() {
showWifiInfo(data); showWifiInfo(data);
blockScan = 0; blockScan = 0;
if (data.modechange == "yes") {
var txt2 = "esp-link will switch to STA-only mode in a few seconds"; var txt2 = "esp-link will switch to STA-only mode in a few seconds";
window.setTimeout(function() { showNotification(txt2); }, 4000); window.setTimeout(function() { showNotification(txt2); }, 4000);
}
$("#reconnect").removeAttribute("hidden"); $("#reconnect").removeAttribute("hidden");
$("#reconnect").innerHTML = $("#reconnect").innerHTML =

@ -243,11 +243,13 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
if (x == STATION_GOT_IP) { if (x == STATION_GOT_IP) {
if (m != 1) { if (m != 1) {
#ifdef CHANGE_TO_STA
// We're happily connected, go to STA mode // We're happily connected, go to STA mode
os_printf("Wifi got IP. Going into STA mode..\n"); os_printf("Wifi got IP. Going into STA mode..\n");
wifi_set_opmode(1); wifi_set_opmode(1);
wifi_set_sleep_type(SLEEP_MODE); wifi_set_sleep_type(SLEEP_MODE);
os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
#endif
//os_timer_disarm(&deepTimer); //os_timer_disarm(&deepTimer);
//os_timer_setfn(&deepTimer, deepSleepCb, NULL); //os_timer_setfn(&deepTimer, deepSleepCb, NULL);
//os_timer_arm(&deepTimer, 1000, 1); //os_timer_arm(&deepTimer, 1000, 1);
@ -485,6 +487,11 @@ int ICACHE_FLASH_ATTR printWifiInfo(char *buff) {
uint8_t op = wifi_get_opmode() & 0x3; uint8_t op = wifi_get_opmode() & 0x3;
char *mode = wifiMode[op]; char *mode = wifiMode[op];
#ifdef CHANGE_TO_STA
char *modechange = "yes";
#else
char *modechange = "no";
#endif
char *status = "unknown"; char *status = "unknown";
int st = wifi_station_get_connect_status(); int st = wifi_station_get_connect_status();
if (st > 0 && st < sizeof(connStatuses)) status = connStatuses[st]; 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); wifi_get_macaddr(0, mac_addr);
len = os_sprintf(buff, 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\"", "\"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]); mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
struct ip_info info; struct ip_info info;

Loading…
Cancel
Save