WebSocket

does anyone have an example or library that uses websockets?

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

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.

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

sorry where must be run?

magi2556: 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.

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?

wayoda:

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.

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

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

[quote author=Federico Fissore link=topic=190078.msg1406477#msg1406477 date=1380210891] 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 [/quote]

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?

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