# A simple example that:
# - Connects to a WiFi Network defined by "ssid" and "password"
# - Performs a GET request (loads a webpage)
# - Queries the current time from a server
import network # handles connecting to WiFi
import urequests # handles making and servicing network requests
import websocket
import machine
gp0 = machine.Pin(0, machine.Pin.OUT)
gp0.value(1)
# Connect to network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
# Fill in your network name (ssid) and password here:
ssid = 'enet-2.4'
password = '12345678'
wlan.connect(ssid, password)
# Example 1. Make a GET request for google.com and print HTML
# Print the html content from google.com
#print("1. Querying google.com:")
#r = urequests.get("http://www.google.com")
#print(r.content)
#r.close()
# Example 2. urequests can also handle basic json support! Let's get the current time from a server
#print("\n\n2. Querying the current GMT+0 time:")
#r = urequests.get("http://date.jsontest.com") # Server that returns the current GMT+0 time.
#print(r.json())
# WebSocket server address
server_address = "IP:port"
# Create a WebSocket instance
ws = websocket.websocket(server_address)
# Connect to the WebSocket server
ws.connect(server_address)
# Send a message to the server
ws.send("Hello, WebSocket server!")
# Receive and print the response from the server
response = ws.recv()
print("Received response:", response)
# Close the WebSocket connection
ws.close()
#๐ OSError: stream operation not supported - Trying to use Web Sockets on Pi Pico W
30 messages ยท Page 1 of 1 (latest)
@rotund tulip
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
whatever I install needs to be compatible with MicroPython if websocket doesn't work, I have no idea why it's throwing an error
also i just doxxed myself rofl woopsies
IP:port is a working ip and port with a websocket server listening for connections
So TLDR the docs are fubar and the internet is unhelpful, contradictory, and flat wrong
The flattening of the error message appears to be due to stack traces being off for memory and performance reasons
If you're upset with thonny pycharm has a plugin for this
The internet suggests MicroDot for a library to use for this
It appears microdot is the more modern alternative to what used to be done more manually with uasyncio. Microdot uses the functioning asyncio library so it should be less janky.
I see you're using urequests
the relevant websockets library that comes itwh that is uasyncio.websocket.server
Hopefully that's all helpful
also I'm using Thonny if you couldn't tell
using MicroPython (RP2040) for the Raspberry Pi Pico W
anyway tldr websockets doesnt micropython
they have a built in library called websocket and there absolutely has to be a way to do this
the whole point of the pico W is wifi connectivity I dunno how you can really use that effectively without websockets
I'm not giving up on this if I find something I'll put it here but it's not looking promising
so I'm starting to think bluetooth might be the way to go
see this
you have some options
oh my messages were incredibly delayed and I didn't see any of that
does usyncio have a client? the pi is supposed to be the client
its seeming like the only way to do this is either use socket and manually set up the actual websocket stuff or use microdot and do essentially that minus a little bit of the work
I am so confused on why websocket exists if it doesn't work
It works on other devices. It's unfortunately designed for systems that don't mind a bit of heavier weight for more convenient development.
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.