Skip to content

Is switching between softAP and client connection possible? #2352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
treii28 opened this issue Jul 31, 2016 · 3 comments
Closed

Is switching between softAP and client connection possible? #2352

treii28 opened this issue Jul 31, 2016 · 3 comments

Comments

@treii28
Copy link

treii28 commented Jul 31, 2016

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)

Basic Infos

Hardware

Hardware: ESP-12 / nodemcu

Description

Problem description

Settings in IDE

Module: NodeMCU v0.9
CPU Frequency: 80Mhz
Upload Using: SERIAL
Reset Method: nodemcu

@krzychb
Copy link
Contributor

krzychb commented Jul 31, 2016

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

@johnpengwot
Copy link

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.

@devyte
Copy link
Collaborator

devyte commented Oct 14, 2017

Answer is documented, and already provided, closing.

@devyte devyte closed this as completed Oct 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants