Z
Good again.
I return to post, because I would need the LoPy that receives the txt file is the one that starts the wifi as
wlan = WLAN (mode = WLAN.AP,
ssid = 'Gateway1',
auth = (WLAN.WPA2, 'password'),
antenna = WLAN.INT_ANT)
I have tried to modify the code as I have the partner that works so that it is but I get error everywhere.
Once trying once more, if I do not restart the board and try to execute the code, I always get the error:
Traceback (most recent call last):
File "<stdin>", line 17, in <module>
OSError: [Errno 12] ENOMEM
Because it is ? If someone can give me a hand code please!
Capture Errors:
used code:
Server And Wifi AP:
from network import WLAN
import socket
import select
import time
#Setup WiFi AP
wlan = WLAN(mode=WLAN.AP,
ssid='Gateway1',
auth=(WLAN.WPA2,'password'),
antenna=WLAN.INT_ANT)
port = 12345
s = socket.socket()
s.bind(socket.getaddrinfo("0.0.0.0", port)[0][4])
s.listen(1)
print("Running server")
while True:
cl, remote_addr = s.accept()
cl.setblocking(True)
print("Client connection from:", remote_addr)
file = "/flash/registro2.txt"
with open(file, 'wb') as f:
try:
data = s.recv(1024)
print(data)
f.write(data)
except TimeoutError:
break
Client and Lopy and in charge to send file:
from network import WLAN
import socket
import select
import machine
import time
# Abrimos wifi
wlan = WLAN(mode=WLAN.STA)
nets = wlan.scan()
for net in nets:
if net.ssid == 'Gateway1':
print('Network found!')
wlan.connect(net.ssid, auth=(net.sec, 'password'), timeout=5000)
while not wlan.isconnected():
machine.idle() # save power while waiting
print('WLAN connection succeeded!')
break
else:
raise Exception("WiFi network not found")
# sleep just to make sure the wifi is connected
time.sleep(1)
ip, subnet, gateway, dns = wlan.ifconfig()
# Connect to server
# Bind to the port
port = 12345
s = socket.socket()
s.connect((gateway, port))
s.setblocking(True)
s.settimeout(2)
while True:
readable, writable, errored = select.select([s], [], [])
for s in readable:
cl, remote_addr = s.accept()
cl.setblocking(True)
print("Client connection from:", remote_addr)
file = "/flash/registro.txt"
print("Sending: ", file)
with open(file, 'rb') as f:
data = f.read(1024)
while(data):
print("sending", data)
cl.sendall(data)
data = f.read(1024)
print("Done Sending")
cl.close()