I created a code that allows me to connect to a html page and print my Data there but the problem that everytime I execute the code I'm obliged to change this ports.bind("","80)
manuelly because after I try to stop the code the port still running (In use) So I change to another values in order to execute my code
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('', 80))
s.listen(5)
while True:
conn, addr = s.accept()
print('Got a connection from %s' % str(addr))
request = conn.recv(1024)
request = str(request)
print('Content = %s' % request)
led_on = request.find('/?led=on')
led_off = request.find('/?led=off')
response =""
if led_on == 6:
print('LED ON')
led.value(1)
if led_off == 6:
i2c= I2C ( scl = Pin(5) , sda = Pin(4))
acc = mpu.accel(i2c)
r = accelerometer.get_values()
result.append(r)
if len(result) > 8:
result = result[1:]
# print(str(r))
print('LED OFF')
led.value(0)
response = web_page()
conn.send('HTTP/1.1 200 OK\n')
conn.send('Content-Type: text/html\n')
conn.send('Connection: close\n\n')
conn.sendall(response)
conn.close()
Any Idea on preventing this ?