Go Down

Topic: WebSocket (Read 3496 times) previous topic - next topic

lucifer

does anyone have an example or library that uses websockets?

federicofissore

SpaceBrew: the spacebrew examples have a python counterpart that connects to the spacebrew servers using websocket
PS: the code loaded on the yun may have become a bit outdated. Check https://github.com/julioterra/yunSpacebrew

lucifer

Thanks for the suggestion. I have seen that, but i would like another alternative since i already a websocket server integrated with an app to control the arduino.

magi2556


Run following commands:
scp -r ./spacebrew root@juliyun.local:/usr/lib/python2.7

sorry
where must be run?

lucifer



Run following commands:
scp -r ./spacebrew root@juliyun.local:/usr/lib/python2.7

sorry
where must be run?


in the terminal if you are on mac or linux. use putty if you are on windows.

wayoda


I have seen that, but i would like another alternative since i already a websocket server integrated with an app to control the arduino.

You have an app (Android? IOs???) with a Websocket server? Are you looking for a Websocket client then?

lucifer



I have seen that, but i would like another alternative since i already a websocket server integrated with an app to control the arduino.

You have an app (Android? IOs???) with a Websocket server? Are you looking for a Websocket client then?



yeah that's right. I am looking for a websocket client that could send and receive. 

federicofissore

Uhm I'd take a look at websocket-client for python (stored on the yun at /usr/lib/python2.7/websocket/websocket.py and also viewable at https://github.com/julioterra/yunSpacebrew/blob/master/linino/websocket/websocket.py)
But if you want to keep the connection open (that's what websockets are about, no?) then I guess you'll have to build your own protocol between the running process and the sketch, much like spacebrew did
Maybe you can take inspiration from their code

federicofissore

Another idea: maybe you can start a websocket client as a background process and have it put some data on the bridge storage (using bridgeclient.py)
This will make everything easier since, from the sketch side, you'll just have to poll the bridge storage in the loop

lucifer


Another idea: maybe you can start a websocket client as a background process and have it put some data on the bridge storage (using bridgeclient.py)
This will make everything easier since, from the sketch side, you'll just have to poll the bridge storage in the loop


that'a great idea, if you wan't to keep things simple. but how about if i were to send messages to the websocket server? use curl? httpclient?

federicofissore

Uhm, well maybe you can make it using the storage as a message queue
Your background process connects to your websocket server. When messages arrive to the yun, they are accumulated under an "inbox" key of the storage. When the sketch wants to send a message, places it under an "outbox" key and the background process consumes the outdoing messages

However, this is very fragile. I see synchronization problems ahead. Best would be to have kind of "push" and "pop" functions available with the bridgeclient.py (there already is the Mailbox class at the sketch side that does just that)
But if you limit the whole thing saying that a maximum of 1 message can be in the inbox and 1 in the outbox, it may work pretty well

Go Up