WebSockets with Yun?

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.

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

wayoda:
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?

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

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

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? Tty for serial port to Arduino from Linino - Arduino Yún - Arduino Forum

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

Do you think one can make node.js Serialport to point to the matching tty?
Which tty is the one used by the sketch? ttyATH0?

I'm working with tornado python web server... it's ok for me.

ok and on which serial port are you listening?

For linux side check the tty trhead in forum. The name isis some think like ttyATH....: in arduino side use serial1. Excuse me I dont have yun here with me. Yo can find the names in the sources of bridge library & in the source of bridge.py in linux side.

Hm, sorry, I was not able to find the serial port names in any of the two files.

The name of the serial device used by the ar9331 and 32u4 to communicate is /dev/ttyATH0

Thank you very much.

Do you think that the following will work?

  • Install node.js on Arduino Linino
  • Make the SerialPort library listen on /dev/ttyATH0
  • Communicate from an Arduino sketch using Serial1

I'm not sure, because on that device there is the linux terminal, so if you just write something it will be interpreted as a command (and probably issue a "command not found")
But it may depend on the way node takes control (or not) of the serial (maybe it consumes the output before it reaches the linux prompt?). It definitely something worth experimenting with

Okay I will try and report here.

I confirm you that it work. I achieved to communicate the environments through the serial1 port at 57000 ... installing pyserial in python.

Sounds great.
Did you establish a two way communication ?
Would you mind to post your server configs?

At this moment I worked in sending from linino to arduino... I'm still working on.