Here is the code:-
Code: Select all
import network
import time
station=network.WLAN(network.STA_IF)
station.active(True)
station.connect("TP-LINK_EB850C", "ju87bstuka")
while (not (station.isconnected())):
print("waiting to Connect")
print (station.ifconfig())
time.sleep(1)
station.ifconfig()
print ("Connected")
Context:-
This is the initial stage of a monitoring and control system.
There are 5 esp32's performing inner-loop monitoring and control.
The raspberry pi is outer-loop control.
The esp's confine their activity to low level interrupt handling, enabling and disabling interrupts from IR sensors dependent on their physical location. They also control low level functions concerning speed and error recognition. They communicate back to the raspberry pi which performs overall mode, control and health monitoring.
The Raspberry pi sets the mode of operation, monitors the low level speed and position data, and control sequencing of commands to its own actuators (of whatever form) and the esp simple network. It also deals with configuration and calibration.
The esp32's all act as clients to the Raspberry pi server.
However, the top node esp32 operates as a WIFI access point, and all remaining esp32's and raspberry pi must log onto that secure private network. There is no access to external LANs. It is a private LAN.
The above code establishes a connection with the esp32 wifi access point. The station 'connect' parameters are merely examples.
This is a monitoring and control system.
It is autonomous, and must restart after glitch or power fail.
The raspberry pi being a general purpose machine at other times, logs on to one of its listed Wifi access points for normal internet and Lan connection.
For this application it must be directed to log off any of the WAN/LAN connections and connect to the ESP32's control system's isolated access point. Here enumerated as 'Control-net'
The above code runs as expected on the esp32 (micropython) with python module 'network' imported and the attributes as above.
This is output:-
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0')
waiting to Connect
('0.0.0.0', '0.0.0.0', '0.0.0.0', '192.168.1.254')
Connected
All good and as desired.
After the connections are established, the sockets are instantiated, used, closed in the normal manner.
This is the first stage in setting up the private control network. It's very very simple. All the esp's and the raspberry pi need to perform this initial step.
Similar control is needed for the raspberry pi. It appears that there are no such wlan control objects in the raspberry module 'network'.
Am I right?
If so, I'll chuck the Pi away and use something more predicative.
Best wishes,
Robin Mosedale