I am building a soil sensor for the garden on the micropython esp32, I have a problem with the microWebsrv library .
I wanted to know when a client will connect to the server and when it will disconnect. I have not found any example of this:(
in short, my program is supposed to do this...
1.After pressing the button on the sensor, the esp32 will be reset,
2.Check machine.reset_cause() if HARD_RESET -- 2 or PWRON_RESET -- 1 then...
3.WIFI AP starts,
4.microWebserv strats (In threaded , websocket)
5.ReplWeb starts,
6.Some time is waiting for the connection (loop in new thread)
7. If not then import and run main2.py
8. else =>>>>>
"""needs some function that detects connected clients and the moment of disconnection (microWebsrv websocket) to break AP WIFI mode () and start normal mode"""
oryginal function from microWebsrv not work..
Code: Select all
def _acceptWebSocketCallback(webSocket, httpClient) :
print("WS ACCEPT")
webSocket.RecvTextCallback = _recvTextCallback
webSocket.RecvBinaryCallback = _recvBinaryCallback
webSocket.ClosedCallback = _closedCallback
def _recvTextCallback(webSocket, msg) :
print("WS RECV TEXT : %s" % msg)
webSocket.SendText("Reply for %s" % msg)
def _recvBinaryCallback(webSocket, data) :
print("WS RECV DATA : %s" % data)
def _closedCallback(webSocket) :
print("WS CLOSED")
Code: Select all
from microWebSrv.microWebSrv import MicroWebSrv
mws = MicroWebSrv(webPath='www/') # TCP port 80 and files in /flash/www
#mws.SetNotFoundPageUrl(url='/www/index.html')
mws.MaxWebSocketRecvLen = 256 # Default is set to 1024
mws.WebSocketThreaded = False # WebSockets without new threads
mws.AcceptWebSocketCallback = _acceptWebSocketCallback # Function to receive WebSockets
mws.Start(threaded=True) # Starts server in a new thread
#mws.Start()