Websocket client question.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
topovich
Posts: 2
Joined: Wed Nov 24, 2021 3:33 pm
Location: Argentina

Websocket client question.

Post by topovich » Wed Nov 24, 2021 10:11 pm

Hello, I'm working on a project (with an ESP32-WROOM-32 board) that needs to entablish a connection and listen to a websocket, more specifically to get realtime data from the Binance websocket (not much data, only the latest prices of two or three pairs).
I found several examples and tutorials about how to code a websocket server, but almost none examples or code on how to connect as a client (in this case to the Binance websocket) and wait/listen for data from it.

Came across to this library: https://github.com/jczic/MicroWebSrv2
which looks great and have examples to code a webserver, but due to my lack of experience in websockets I cannot realize (or understand) how to connect to a websocket (as a client) with this library...or another one.

The websocket I want to connect to is: wss://stream.binance.com:9443
API Docs: https://binance-docs.github.io/apidocs/ ... et-streams

Can someone provide some example or give me some clue on how to do what I'm trying to do?

Thanks in advance.

User avatar
karfas
Posts: 54
Joined: Sat Jan 16, 2021 12:53 pm
Location: Vienna, Austria

Re: Websocket client question.

Post by karfas » Thu Nov 25, 2021 7:28 pm

What's wrong with google ?
Asking for "websocket client" gives me e.g. in the 5th link https://github.com/websocket-client/websocket-client (not for microypython, but enough code to steal from).
A few hours of debugging might save you from minutes of reading the documentation! :D
My repositories: https://github.com/karfas

topovich
Posts: 2
Joined: Wed Nov 24, 2021 3:33 pm
Location: Argentina

Re: Websocket client question.

Post by topovich » Fri Nov 26, 2021 9:02 pm

Thanks karfas for your reply.
As you said, it's not for Micropython (I couldnt be able to install it). I searched A LOT in Google, found some libraries (like the one I posted in my original question) but none of them show how to use them as client. So I though that it could be something simple to do with the available Micropython websocket libraries...I'm starting to think that I was wrong.

Sorry if it is a very simple thing, I just can't find anything related.

Thank you.

jomas
Posts: 54
Joined: Mon Dec 25, 2017 1:48 pm
Location: Netherlands

Re: Websocket client question.

Post by jomas » Sat Nov 27, 2021 1:18 pm

topovich wrote:
Fri Nov 26, 2021 9:02 pm
I searched A LOT in Google
Are you serious?

When I google for "micropython websocket client", the first hit gives a websocket client for micropython. (And it is a topic from this micropython forum, which you also could have searched for".

Post Reply