B4R Question ESP8266 WiFi Access Point mode

Bert Oudshoorn

Member
Licensed User
Erel, thank you, it works great! Made a little UDP server. In Station and Access Point mode. However, after a wifi.StartAccessPoint2(...) the AP mode cannot be switched off anymore. Only, via the Arduino IDE by setting a WiFi.mode(WIFI_STA) which terminates the mode WIFI_AP or WIFI_AP_STA. It looks as if the wifi configuration is saved in a reserved memory area. It is not removed after flashing a new program, without new mode/configuration settings. I noticed something similar with LUA-NodeMCU.

Something else, it is probably not possible to set the channel in AP mode? I used it with LUA-NodeMCU firmware, where a configuration structure can be specified: cfg={}, cfg.ssid="...", cfg.psw="...", cfg.channel=8 (1-14, 6 default), wifi.ap.config(cfg)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
See this post: https://www.b4x.com/android/forum/threads/esp8266-wifi-and-socket.69164/#post-438940

You can set these parameters with:
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private channel As Int = 14 'ignore
   Private ssid As String = "ssid" 'ignore
   Private password As String = "12345678" 'ignore
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   RunNative("setSoftAP", Null)
End Sub

#if C
void setSoftAP(B4R::Object* o) {
   WiFi.softAP(b4r_main::_ssid->data, b4r_main::_password->data, b4r_main::_channel);
}
#end if
 
Upvote 0

Bert Oudshoorn

Member
Licensed User
Thank you, it works! Did set the channel to 4 (14 did not work).
Had to change the "Private" Globals into "Public".

Could switch off the AP mode in a similar way, via (C) WiFi.mode(WIFI_STA);
There exists even a WiFi.softAPdisconnect(true); statement, which removes the AP config.
 
Upvote 0
Top