Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8621

General • Re: Pico 2W hangs on: client, address = s.accept()

$
0
0

Code:

from connect import wlanimport socketimport machinesensor_temp = machine.ADC(4)conversion_factor = 3.3 / (65535)address = socket.getaddrinfo("0.0.0.0", 80)[0][-1]s = socket.socket()s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)s.bind(address)s.listen(1)print("Listening for connections on", wlan.ifconfig()[0])while True:    try:        reading = sensor_temp.read_u16() * conversion_factor        temperature = 27 - (reading - 0.706) / 0.001721        print("before client,...")        client, address = s.accept()        print("before print...")        print("Connection accepted from", address)        client_file = client.makefile("rwb", 0)        while True:            line = client_file.readline()            if not line or line == b"\r\n":                break        client.send("HTTP/1.0 200 OK\r\n")        client.send("Content-type: text/plain\r\n\r\n")        client.send("Hello from Raspberry Pi Pico 2W!\r\n")        response = f"The temperature is {str(temperature)} C.\r\n"        client.send(response)        client.close()        print("Response sent, connection closed.")    except OSError as e:        client.close()        print("Error, connection closed.")

Statistics: Posted by Greatnessguru — Thu Jun 05, 2025 2:14 pm



Viewing all articles
Browse latest Browse all 8621

Trending Articles