diy-pda/apps/sync.py

46 lines
1.5 KiB
Python

class sync():
def __init__(self, parent_object):
import gc
parent_object.destroy()
import socket
import network
gc.collect()
station = network.WLAN(network.STA_IF)
station.active(True)
user_settings = {}
with open('sd/appdata/settings/settings.json') as json_file:
user_settings = json.load(json_file)
#station.connect("THE INTERNET", "aG22p]H{")
station.connect(user_settings["wifi_ssid"], user_settings["wifi_password"])
while not station.isconnected():
time.sleep(1)
print(station.ifconfig())
### MAYBE WE'RE LOSING CONNECTION???
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
s = socket.socket()
s.bind(addr)
s.listen(1)
print("listening on ", addr)
while True:
print ('waiting for you uwu')
cl, addr = s.accept()
print('client connected from', addr)
cl_file = cl.makefile('rwb', 0)
while True:
line = cl_file.readline()
if not line or line == b'\r\n':
break
rows = ['<tr><td>%s</td><td>%d</td></tr>' % (str(p), p.value()) for p in pins]
response = html % '\n'.join(rows)
cl.send('HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n')
cl.send(response)
cl.close()
def destroy(self):
for obj in self.objects:
obj.delete()
self.objects.remove(obj)
n = sync(launcher)