Pages: [1] 2 3 ... 5   Go Down
Author Topic: WebSockets with Yun?  (Read 8462 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a WebSockets (like Socket.IO) implementation either for the Arduino or the Linino site of  the Yun?
Logged

Offline Offline
Edison Member
*
Karma: 38
Posts: 1328
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the yun in preinstalled spacebrew, that uses websocket with python. Check this out https://github.com/julioterra/yunSpacebrew
Logged

Have you upgraded the Yún? If you've just got it, then it needs to be upgraded! Check out the tutorial

Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.
And how would one listen in a sketch like by using Noduino?
Logged

Offline Offline
Edison Member
*
Karma: 38
Posts: 1328
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

noduino is a nodejs application that runs on your pc and that talks to arduino via serial. There are no websockets running on the board.

There are some contributed packages for installing nodejs on the yun, although there are no official ones yet.

You'll also need to change the way linino and 32u4 talk, as right now 32u4 sees the linino terminal: instead noduino speaks its own protocol, much like the bridge does.

In essence: check out own spacebrew works, it's pretty much the same stuff
Logged

Have you upgraded the Yún? If you've just got it, then it needs to be upgraded! Check out the tutorial

Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the yun in preinstalled spacebrew, that uses websocket with python. Check this out https://github.com/julioterra/yunSpacebrew
If I get it right from the Spacebrew docu, it uses the serial port to communicate with the python scripts on the Linino site and transfers the data to their cloud hub.
But that is not what I want to do.
I would like to have an event based API in my sketch and a WebSocket provider on the Linino site.
That would be awesome and enable a very reactive web interface to the sketch.
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If I get it right from the Spacebrew docu, it uses the serial port to communicate with the python scripts on the Linino site and transfers the data to their cloud hub.
The spacebrew code implements a websocket client. For the Yun a websocket server would be a great addition.
I looked at some python implementations but most of them use the gevent package which is not available for OpenWRT.

PyWebsocket might work, looks like they do not use any native code that needs to be cross-compiled.
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The echo example for pywebsockets works on the Yun.

Tested it like this:
It looks like the library does not have any external requirements in standalone mode. If performance is not the major concern pywebsocket looks like a good starting point.

Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That sounds good.
And how would my data from the Arduino sketch get pasted to the WebSockets server?
I would like to have an event handler in my sketch, put some data as a result, and get it past as JSON to my clients JavaScript.
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And how would my data from the Arduino sketch get pasted to the WebSockets server?
I would like to have an event handler in my sketch, put some data as a result, and get it past as JSON to my clients JavaScript.

There is a forum post which collects some ideas to communicate with a Sketch running on the ATMega from python code running on the linux machine.

The idead would be to send your JSON data  from the sketch to the python code over Serial1. Then the python code forwards the data to your Websocket-Client.



 
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is a forum post which collects some ideas to communicate with a Sketch running on the ATMega from python code running on the linux machine.

The idead would be to send your JSON data  from the sketch to the python code over Serial1. Then the python code forwards the data to your Websocket-Client.
Doesn't this sound like what Spacebrew does?
Logged

Wuppertal/Germany
Offline Offline
God Member
*****
Karma: 1
Posts: 895
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Doesn't this sound like what Spacebrew does?
I don't know much about what spacebrew does.
With the outline for the pywebsocket code, a typical application would be :
  • You run the  WebSocket server on the Yun
  • You open a html page with your browser, that brings in the javascript code to open,read and write to the websocket
  • Some code that is run on the server handles the communication with the Arduino.
  • Your browser window gets updated by some javascript code that interprets the data returned from the Yun
Spacebrew seems to add a lot of extra stuff to this basic layout for an app.
Running a Spacebrew server depends on Node.js which is not available as a package for the Yun AFAIK.

But ...already mentioned ... I didn't look into Spacebrew that much...



Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With the outline for the pywebsocket code, a typical application would be :
  • You run the  WebSocket server on the Yun
  • You open a html page with your browser, that brings in the javascript code to open,read and write to the websocket
  • Some code that is run on the server handles the communication with the Arduino.
  • Your browser window gets updated by some javascript code that interprets the data returned from the Yun
You're absolutely right, that is exactly what I would like to have/do!
I hoped to find this missing link going from Arduino sketch to the Linino out of the box.
Plus I would like to see the lib on the Arduino to have an event like registration API.

BTW: There are already node.js implementations for Yun.

Logged

Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do that using the serial communication to pass info between the two environments. In the forum there is a thread talking about...
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 224
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can do that using the serial communication to pass info between the two environments. In the forum there is a thread talking about...
Did you mean this one? http://forum.arduino.cc//index.php?topic=191820.0
Logged

Spain
Offline Offline
Newbie
*
Karma: 0
Posts: 39
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes I got the comunication via serial and ussing firdata. You can modify python program to interact with sockets and serial. I'm working on too...
Logged

Pages: [1] 2 3 ... 5   Go Up
Jump to: