In Arduino, you can do this with WiFi.mode(x), where x can be WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF, for example:
WiFi.mode(WIFI_STA);
will set the ESP into client ("Station") mode.
I also use a little "reset" script in a separate sketch, but I have avoided using persistent...
WiFi.softAPdisconnect();
WiFi.disconnect();
ESP.eraseConfig();
while(1); // deliberately crash
The forced crash is because apparently there is a bug in the SDK firmware / hardware that ESP.restart doesn't always clear things - again this may have subsequently been fixed.
Next time the code comes up I nake sure the following runs:
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
Because for my project(s) I always want my devices to autoconnect in STA mode (which is the factory-delivered state)
WiFi.softAPdisconnect();
WiFi.disconnect();
WiFi.mode(WIFI_STA);
delay(100);
esp8266 as WiFi client
Pi as access point
UDP protocol on esp8266 to talk with Pi
python code to talk with esp8266 using UDP
python UDP implementation On Pi
https://wiki.python.org/moin/UdpCommunication
guide for setup Access Point on Pi
https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/overview
in esp8266 arduino IDE go to example select wifi--> wifiUDPSendReceiveString Example and change #include <WiFi.h> to #include <ESP8266WiFi.h> and Loadit to your nodeMcu..
with some noise control filtering
USB WEMOS D1 mini
GND -------------> GND
ID
D+ -------------> D1
D- -------------> D2
|-- 1k+ --> 3V3
VBUS ----------> 5V