Added SOFTAP hard-coded settings

Set the values of SOFTAP config straight in the Makefile
pull/84/head
KatAst 9 years ago
parent 59d4bdf99e
commit ff5a74b20a
  1. 73
      Makefile
  2. 96
      esp-link/cgiwifi.c
  3. 22
      esp-link/main.c

@ -4,6 +4,7 @@
# Makefile heavily adapted to esp-link and wireless flashing by Thorsten von Eicken # Makefile heavily adapted to esp-link and wireless flashing by Thorsten von Eicken
# Lots of work, in particular to support windows, by brunnels # Lots of work, in particular to support windows, by brunnels
# Original from esphttpd and others... # Original from esphttpd and others...
# Added support for SOFTAP hard-coded configuration by KatAst
# VERBOSE=1 # VERBOSE=1
# #
# Start by setting the directories for the toolchain a few lines down # Start by setting the directories for the toolchain a few lines down
@ -22,6 +23,34 @@
# STA_SSID ?= # STA_SSID ?=
# STA_PASS ?= # STA_PASS ?=
# The SOFTAP configuration can be hard-coded here, the minimum parameters to set are AP_SSID && AP_PASS
# The AP SSID has to be at least 8 characters long, same for AP PASSWORD
# The AP AUTH MODE can be set to ( default = AUTH_WPA_WPA2_PSK )
# AUTH_OPEN = 0,
# AUTH_WEP,
# AUTH_WPA_PSK,
# AUTH_WPA2_PSK,
# AUTH_WPA_WPA2_PSK
# SSID hidden default 0, ( 0 | 1 )
# Max connections default 4, ( 1 ~ 4 )
# Beacon interval default 100, ( 100 ~ 60000ms )
AP_SSID ?=esp-link-test
AP_PASS ?=esp-link-test
# AP_AUTH_MODE ?=AUTH_WPA_WPA2_PSK
# AP_SSID_HIDDEN ?=0
# AP_MAX_CONN ?=3
# AP_BEACON_INTERVAL ?=150
# 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 STA+AP mode.
CHANGE_TO_STA ?= no
# hostname or IP address for wifi flashing
ESP_HOSTNAME ?= esp-link
# --------------- toolchain configuration --------------- # --------------- toolchain configuration ---------------
# Base directory for the compiler. Needs a / at the end. # Base directory for the compiler. Needs a / at the end.
@ -30,7 +59,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
# Base directory of the ESP8266 SDK package, absolute # Base directory of the ESP8266 SDK package, absolute
# Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5 # Typically you'll download from Espressif's BBS, http://bbs.espressif.com/viewforum.php?f=5
SDK_BASE ?= $(abspath ../esp_iot_sdk_v1.5.0) SDK_BASE ?= $(abspath ../esp-open-sdk/esp_iot_sdk_v1.5.0)
# Esptool.py path and port, only used for 1-time serial flashing # Esptool.py path and port, only used for 1-time serial flashing
# Typically you'll use https://github.com/themadinventor/esptool # Typically you'll use https://github.com/themadinventor/esptool
@ -39,15 +68,6 @@ ESPTOOL ?= $(abspath ../esp-open-sdk/esptool/esptool.py)
ESPPORT ?= /dev/ttyUSB0 ESPPORT ?= /dev/ttyUSB0
ESPBAUD ?= 460800 ESPBAUD ?= 460800
# The Wifi station configuration can be hard-coded here, which makes esp-link come up in STA+AP
# mode trying to connect to the specified AP *only* if the flash wireless settings are empty!
# This happens on a full serial flash and avoids having to hunt for the AP...
# STA_SSID ?=
# STA_PASS ?=
# hostname or IP address for wifi flashing
ESP_HOSTNAME ?= esp-link
# --------------- chipset configuration --------------- # --------------- chipset configuration ---------------
# Pick your flash size: "512KB", "1MB", or "4MB" # Pick your flash size: "512KB", "1MB", or "4MB"
@ -64,14 +84,9 @@ LED_CONN_PIN ?= 0
# GPIO pin used for "serial activity" LED, active low # GPIO pin used for "serial activity" LED, active low
LED_SERIAL_PIN ?= 14 LED_SERIAL_PIN ?= 14
# --------------- esp-link config options --------------- # --------------- esp-link modules 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
# Optional Modules # Optional Modules mqtt
MODULES ?= mqtt rest syslog MODULES ?= mqtt rest syslog
# --------------- esphttpd config options --------------- # --------------- esphttpd config options ---------------
@ -268,6 +283,30 @@ ifneq ($(strip $(STA_PASS)),)
CFLAGS += -DSTA_PASS="$(STA_PASS)" CFLAGS += -DSTA_PASS="$(STA_PASS)"
endif endif
ifneq ($(strip $(AP_SSID)),)
CFLAGS += -DAP_SSID="$(AP_SSID)"
endif
ifneq ($(strip $(AP_PASS)),)
CFLAGS += -DAP_PASS="$(AP_PASS)"
endif
ifneq ($(strip $(AP_AUTH_MODE)),)
CFLAGS += -DAP_AUTH_MODE="$(AP_AUTH_MODE)"
endif
ifneq ($(strip $(AP_SSID_HIDDEN)),)
CFLAGS += -DAP_SSID_HIDDEN="$(AP_SSID_HIDDEN)"
endif
ifneq ($(strip $(AP_MAX_CONN)),)
CFLAGS += -DAP_MAX_CONN="$(AP_MAX_CONN)"
endif
ifneq ($(strip $(AP_BEACON_INTERVAL)),)
CFLAGS += -DAP_BEACON_INTERVAL="$(AP_BEACON_INTERVAL)"
endif
ifeq ("$(GZIP_COMPRESSION)","yes") ifeq ("$(GZIP_COMPRESSION)","yes")
CFLAGS += -DGZIP_COMPRESSION CFLAGS += -DGZIP_COMPRESSION
endif endif

@ -1,6 +1,6 @@
/* /*
Cgi/template routines for the /wifi url. Cgi/template routines for the /wifi url.
*/ */
/* /*
* ---------------------------------------------------------------------------- * ----------------------------------------------------------------------------
@ -26,11 +26,20 @@ Cgi/template routines for the /wifi url.
#define DBG(format, ...) do { } while(0) #define DBG(format, ...) do { } while(0)
#endif #endif
# define VERS_STR_STR(V) #V
# define VERS_STR(V) VERS_STR_STR(V)
bool mdns_started = false; bool mdns_started = false;
// ===== wifi status change callbacks // ===== wifi status change callbacks
static WifiStateChangeCb wifi_state_change_cb[4]; static WifiStateChangeCb wifi_state_change_cb[4];
// Temp store for new ap info.
static struct station_config stconf;
// Temp store for new ap config
static struct softap_config apconf;
uint8_t wifiState = wifiIsDisconnected; uint8_t wifiState = wifiIsDisconnected;
// reasons for which a connection failed // reasons for which a connection failed
uint8_t wifiReason = 0; uint8_t wifiReason = 0;
@ -301,9 +310,15 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
log_uart(false); log_uart(false);
// no more resetTimer at this point, gotta use physical reset to recover if in trouble // no more resetTimer at this point, gotta use physical reset to recover if in trouble
} else { } else {
if (m != 3) { if (m != 3) {
DBG("Wifi connect failed. Going into STA+AP mode..\n"); DBG("Wifi connect failed. Going into STA+AP mode..\n");
// Set STA+AP mode
wifi_set_opmode(3); wifi_set_opmode(3);
#ifdef AP_SSID
// Call ap set after mode change to AP or STA+AP
wifi_softap_set_config(&apconf);
#endif
} }
log_uart(true); log_uart(true);
DBG("Enabling/continuing uart log\n"); DBG("Enabling/continuing uart log\n");
@ -311,8 +326,6 @@ static void ICACHE_FLASH_ATTR resetTimerCb(void *arg) {
} }
} }
// Temp store for new ap info.
static struct station_config stconf;
// Reassociate timer to delay change of association so the original request can finish // Reassociate timer to delay change of association so the original request can finish
static ETSTimer reassTimer; static ETSTimer reassTimer;
@ -494,6 +507,9 @@ int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
int m = atoi(buff); int m = atoi(buff);
DBG("Wifi switching to mode %d\n", m); DBG("Wifi switching to mode %d\n", m);
wifi_set_opmode(m&3); wifi_set_opmode(m&3);
// Call softap set after changing to AP or STA+AP
wifi_softap_set_config(&apconf);
if (m == 1) { if (m == 1) {
// STA-only mode, reset into STA+AP after a timeout if we don't get an IP address // STA-only mode, reset into STA+AP after a timeout if we don't get an IP address
os_timer_disarm(&resetTimer); os_timer_disarm(&resetTimer);
@ -617,10 +633,76 @@ int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) {
// Init the wireless, which consists of setting a timer if we expect to connect to an AP // Init the wireless, which consists of setting a timer if we expect to connect to an AP
// so we can revert to STA+AP mode if we can't connect. // so we can revert to STA+AP mode if we can't connect.
void ICACHE_FLASH_ATTR wifiInit() { void ICACHE_FLASH_ATTR wifiInit() {
// wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
// Check te wifi opmode
int x = wifi_get_opmode() & 0x3; int x = wifi_get_opmode() & 0x3;
x = x;
DBG("Wifi init, mode=%s\n", wifiMode[x]); #ifdef CGIWIFI_DBG
os_printf("Wifi init, mode=%s\n",wifiMode[x]);
#endif
// STATION parameters only on a full flash
#if defined(STA_SSID) && defined(STA_PASS)
if( x == 2 ){
// Create struct for station config
struct station_config stconf;
// Call it
wifi_station_get_config(&stconf);
// Set parameters
if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) {
os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32);
os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64);
#ifdef CGIWIFI_DBG
os_printf("Wifi pre-config trying to connect to AP %s pw %s\n",(char*)stconf.ssid, (char*)stconf.password);
#endif
// wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
// Set wifi mode
wifi_set_opmode(3); // sta+ap, will switch to sta-only 15 secs after connecting
stconf.bssid_set = 0;
wifi_station_set_config(&stconf);
}
}
#endif
// SOFT_AP parameters
#if defined(AP_SSID) && defined(AP_PASS)
// Call it
wifi_softap_get_config(&apconf);
// Clean memory and set the value of SSID
memset(apconf.ssid, 0, sizeof(apconf.ssid));
os_memcpy(apconf.ssid, VERS_STR(AP_SSID), strlen(VERS_STR(AP_SSID)));
// Clean memory and set the value of PASS
memset(apconf.password, 0, sizeof(apconf.password));
os_memcpy(apconf.password, VERS_STR(AP_PASS), strlen(VERS_STR(AP_PASS)));
// Specify the length of pass
apconf.ssid_len= os_strlen((char*)VERS_STR(AP_PASS));
#ifdef AP_AUTH_MODE
// If set, use specified auth mode
apconf.authmode = AP_AUTH_MODE;
#else
// If not, use wpa wpa2 psk
apconf.authmode = AUTH_WPA_WPA2_PSK;
#endif
#ifdef AP_SSID_HIDDEN
// If set, use specified ssid hidden parameter
apconf.ssid_hidden = AP_SSID_HIDDEN;
#endif
#ifdef AP_MAX_CONN
// If set, use specified max conn number
apconf.max_connection = AP_MAX_CONN;
#endif
#ifdef AP_BEACON_INTERVAL
// If set use specified beacon interval
apconf.beacon_interval = AP_BEACON_INTERVAL;
#endif
// Set to use the new conf
#ifdef CGIWIFI_DBG
os_printf("Wifi AP parameters: %s pw %s\n",(char*)apconf.ssid, (char*)apconf.password);
#endif
// MUST BE called after enabling AP or STA+AP mode
wifi_softap_set_config(&apconf);
#endif // AP_SSID && AP_PASS
configWifiIP(); configWifiIP();
// The default sleep mode should be modem_sleep, but we set it here explicitly for good // The default sleep mode should be modem_sleep, but we set it here explicitly for good

@ -123,28 +123,6 @@ void user_init(void) {
os_printf("\n\n** %s\n", esp_link_version); os_printf("\n\n** %s\n", esp_link_version);
os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*");
#if defined(STA_SSID) && defined(STA_PASS)
int x = wifi_get_opmode() & 0x3;
if (x == 2) {
// we only force the STA settings when a full flash of the module has been made, which
// resets the wifi settings not to have anything configured
struct station_config stconf;
wifi_station_get_config(&stconf);
if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) {
os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32);
os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64);
#ifdef CGIWIFI_DBG
os_printf("Wifi pre-config trying to connect to AP %s pw %s\n",
(char*)stconf.ssid, (char*)stconf.password);
#endif
wifi_set_opmode(3); // sta+ap, will switch to sta-only 15 secs after connecting
stconf.bssid_set = 0;
wifi_station_set_config(&stconf);
}
}
#endif
// Status LEDs // Status LEDs
statusInit(); statusInit();
serledInit(); serledInit();

Loading…
Cancel
Save