Is it possible to switch back and forth between connecting to an existing network or running a softAP in the arduino code? I'm interested in having a softAP landing page after programming where you can specify a network ssid and password. Once that is stored, have the device try to connect to that network as a client instead. If for any reason that fails, after so many attempts or a given period of time go back to softAP mode and the configuration page again until the information is again changed.
Someone in the ESP8266.com forums said it was possible with the .mode() method, but didn't say anything else so I'm not sure what all needs to be done. (i.e. does the old instance handle need to be re-initialize in any way? Do I have to 'shut down' one before starting the other in some way, etc)
Hardware: ESP-12 / nodemcu
Problem description
Module: NodeMCU v0.9
CPU Frequency: 80Mhz
Upload Using: SERIAL
Reset Method: nodemcu
Hi treii28 ,
I believe the functionality you are looking for is already provided by great WiFiManager.
I would check it out before implementing on my own. WiFiManager should provide the best insight into nuances of changing the modes, etc. For instance you may face problems to establish connection if using SDK 1.5.3 (core 2.3.0) as documented here.
If you like to start testing on your own this is also great and below is quick and rough summary.
Mode changes are possible with:
WiFi.mode(WIFI_AP)
WiFi.mode(WIFI_STA)
WiFi.mode(WIFI_AP_STA)
WiFi.mode(WIFI_OFF)
In between of WIFI_STA and WIFI_AP_STA mode changes I am using:
WiFi.reconnect()
After switching to WIFI_STA orWIFI_AP_STA from other modes, use:
WiFi.begin()
or
WiFi.config()
Extra reference on API and functionality of particular functions is here, but I am not sure what core version it reflects.
Krzysztof
In NodeMCU, a simple way is to use the FLASH button(D3) as a reset( or mode switch ) button,
you can count the times of pushed or count hold time with digitalRead(D3) ( exmaple http://playground.arduino.cc/Code/HoldButton) to determine the trigger of mode change.
Answer is documented, and already provided, closing.
Most helpful comment
Hi treii28 ,
I believe the functionality you are looking for is already provided by great WiFiManager.
I would check it out before implementing on my own. WiFiManager should provide the best insight into nuances of changing the modes, etc. For instance you may face problems to establish connection if using SDK 1.5.3 (core 2.3.0) as documented here.
If you like to start testing on your own this is also great and below is quick and rough summary.
Mode changes are possible with:
In between of
WIFI_STAandWIFI_AP_STAmode changes I am using:After switching to
WIFI_STAorWIFI_AP_STAfrom other modes, use:or
Extra reference on API and functionality of particular functions is here, but I am not sure what core version it reflects.
Krzysztof