Mcu1 is Server: loop.call_soon(asyncio.start_server(ServAP, WAp.ifconfig()[0], 80))
Mcu2 is Client :ComReader, ComWriter = await asyncio.open_connection(Address[0], 80)
See Sources herafter
After 15-20s Messages appear showing sequence of Join/leave
on coro-client if a new coro send message through the socket, before end of 20s inactivity, socket is still alive
passed this term socket returns ERRCONNECT 103
This entails blocked coro both sides keeping their ressources
If Coro Client through ISP joins WebServer, a tmo will be notified by endind the read with RecMessage of 0 length
So question: is it possible to parametrize this inactivity timer, if not, to obtain information on Socket close in this sequence of attach detach ?
---MESSAGES--
Code: Select all
SERverSide :
station: a0:20:a6:2f:72:61 join, AID = 1
station: a0:20:a6:2f:72:61 leave, AID = 1
rm 1
add 1
aid 1
station: a0:20:a6:2f:72:61 join, AID = 1
station: a0:20:a6:2f:72:61 leave, AID = 1
rm 1
CLIENTSide:
connected with WifiServer, channel 1
dhcp client start...
ip:192.168.2.2,mask:255.255.255.0,gw:192.168.1.1
pm open,type:2 0
state: 5 -> 2 (4a0)
rm 0
pm close 7
reconnect
state: 2 -> 0 (0)
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 1
SERVER
Code: Select all
import network,socket
import time,machine,gc
import uasyncio as asyncio
import os,json
import esp,uos,gc
Socket=None
esp.osdebug(0)
NumSAP=1
Comreader=Comwriter=None
async def ServAP(reader,writer):
global Socket,NumSAP,Comreader,Comwriter
print('..SerAP Start ',NumSAP)
Comreader=reader
Comwriter=writer
NumSAP+=1
nb=1
while True:
Rec=await reader.read()
await writer.awrite(Rec+' AP%s\r\n'%nb)
nb+=1
WSta=network.WLAN(network.STA_IF)
WSta.disconnect()
WAp =network.WLAN(network.AP_IF)
WAp.config(essid='WifiServer',password='PASSWORD')
ConfAP=('192.168.2.1', '255.255.255.0', '192.168.1.1', '192.168.1.1')
WAp.ifconfig(ConfAP)
print ('WifiNetConfig',WAp.ifconfig())
loop = asyncio.get_event_loop()
loop.call_soon(asyncio.start_server(ServAP, WAp.ifconfig()[0], 80))
loop.run_forever()
Code: Select all
import network,socket
import time,machine,gc
import uasyncio as asyncio
import os,json,esp
SocketCom=None
async def WrSta (Address): #Serveur de remontée (Machine AC)
global SocketCom
ComReader, ComWriter = await asyncio.open_connection(Address[0], 80)
print ('Connected',ComReader,ComWriter)
SocketCom=ComWriter.s
ComWriter.s.send ('WrSta start')
while True:
Rec=await ComReader.read()
print ('WrstRec',Rec)
async def Maintain():
global SocketCom
t0= time.mktime(time.localtime())
while True:
print (time.mktime(time.localtime())-t0)
t0= time.mktime(time.localtime())
if SocketCom:
SocketCom.send('Maintain')
else : print ('No Socket')
await asyncio.sleep(30)
esp.osdebug(0)
WAp =network.WLAN(network.AP_IF)
WAp.active(False)
WSta=network.WLAN(network.STA_IF)
if not WSta.active(): WSta.active(True)
print ('Scan',WSta.scan())
WSta.connect('WifiServer','PASSWORD') # bytes !!
for i in range(20):
St=WSta.status()
if St == network.STAT_GOT_IP : break
print ('St',St)
time.sleep(1)
if St !=network.STAT_GOT_IP : print('WSta No Connect %s'%St)
print(WSta.ifconfig())
ConfAP=('192.168.2.1',)
loop = asyncio.get_event_loop()
loop.create_task(WrSta(ConfAP))
loop.call_soon(Maintain())
loop.run_forever()