Code on Raspberry Pi Pico W:
SSID = "abcdefg"
PASSWORD = "123456"
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
print(wlan.isconnected())
response = urequests.get("http://username:[email protected]/status.html")
print(response)
I want the Raspberry Pi Pico to get status.html from an LSW-3 stick logger by solar man. It connects to Wi-Fi. GET request returns:
Traceback (most recent call last):
File "<stdin>", line 16, in <module>
File "urequests.py", line 180, in get
File "urequests.py", line 74, in request
ValueError: invalid syntax for integer with base 10
URL works in browser when the computer is connected to the stick logger's Wi-Fi.
I got it working like this:
import network
import socket
SSID = "ssid"
PASSWORD = "password"
socketObject = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if wlan.isconnected():
request = "GET /status.html HTTP/1.1\r\nHost: 10.10.100.254\r\nAuthorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=\r\n\r\n"
socketObject.connect(socket.getaddrinfo('10.10.100.254', 80)[0][-1])
socketObject.send(request)
print(socketObject.readline())
print(socketObject.readline())
print(socketObject.readline())
data = socketObject.recv(512)
print(data)
socketObject.close()
dXNlcm5hbWU6cGFzc3dvcmQ= is username:password in base64