Autobahn + serial port

#1

Is it possible to transfer data from and embedded device(PIC, Cortex)
to websockets via serial port using Autobahn?

thanks and keep it up!

0 Likes

#2

It depends what you mean ..

Autobahn WebSockets for Python is based on Twisted.

Twisted has first class support for serial ports.

So you can transfer data from/to serial port and forward that via WebSockets (using Autobahn).

In other words: when you have a device which is able to run Python/Twisted, and that device
has a serial port which connects to your microcontroller, it'll work.

However I don't think you can run Python/Twisted on i.e. PIC _itself_ ..

Hope that helps,

Tobias

···

Am 24.01.2012 00:01, schrieb yOPERO:

Is it possible to transfer data from and embedded device(PIC, Cortex)
to websockets via serial port using Autobahn?

thanks and keep it up!

0 Likes

#3

Tobias

Thanks for your answer, you got it right. So far I have been able to
transfer data to/from a microcontroller to the PC using a python
script based on PySerial.

I have been doing some data plotting using PyQt but I want to achive
the same functionality using a web browser. Autobahn looks perfect I
will keep testing the examples provided and hopefully at some point I
will grab the concept and make it work.

Thanks again.

···

On Jan 24, 11:05 am, Tobias Oberstein <tobias.o...@gmail.com> wrote:

It depends what you mean ..

Autobahn WebSockets for Python is based on Twisted.

Twisted has first class support for serial ports.

So you can transfer data from/to serial port and forward that via
WebSockets (using Autobahn).

In other words: when you have a device which is able to run
Python/Twisted, and that device
has a serial port which connects to your microcontroller, it'll work.

However I don't think you can run Python/Twisted on i.e. PIC _itself_ ..

Hope that helps,

Tobias

Am 24.01.2012 00:01, schrieb yOPERO:

> Is it possible to transfer data from and embedded device(PIC, Cortex)
> to websockets via serial port using Autobahn?

> thanks and keep it up!

0 Likes

#4

This sounds interesting!

Let me help you (hopefully) a bit ...

1)
The first thing to get working is your serial port transfer using Twisted serial support, instead of PySerial.

I have not done that before .. but it should be documented .. there should be code you can look at.
Ask on Twisted mailing list if you run into questions.

2)
When you got that, you will want the Twisted event loop to run both your serial port factory/protocol
_and_ Autobahn.

In general with Twisted, you "add" factories/protocol to the reactor, and then start the reactor.

In your serial port factory, you then need to have a reference to the Autobahn factory
and vice versa to shuffle data between both.

I can help you with that ..

3)
I would suggest the following: you want browser clients .. i.e. to render to a canvas receiving
data from serial mediated via Autobahn.

You could use raw WebSockets and "invent your own pubsub" over WebSockets.

But why reinvent the wheel?

Autobahn has built-in RPC/PubSub on top of WebSockets. See WAMP ..

You get that for free, plus the appropriate JavaScript lib for browsers.

If you go that route, essentially, after having received data from serial, you just need to
call

WampServerProtocol.dispatch
https://github.com/oberstet/Autobahn/blob/master/lib/python/autobahn/wamp.py#L410

WampServerFactory._dispatch
https://github.com/oberstet/Autobahn/blob/master/lib/python/autobahn/wamp.py#L704

and the data gets published to all subscribed clients .. incl. JS in browser.

You then only need to subscribe to your topics in JS and are ready to go.

So:

serial port => your Twisted serial protocol => WAMP factory => WAMP clients (like browsers).

The point is: with WAMP PubSub usually _clients_ publish to a topic, and that gets dispatched
to all (other) clients subscribed to that topic.

In your case, you want to publish not from client, but from server. No problem. See the "dispatch"
methods above ..

If it's unclear what I suggest with above, feel free to ask here ..

Tobias

···

Am 24.01.2012 12:15, schrieb yOPERO:

Tobias

Thanks for your answer, you got it right. So far I have been able to
transfer data to/from a microcontroller to the PC using a python
script based on PySerial.

I have been doing some data plotting using PyQt but I want to achive
the same functionality using a web browser. Autobahn looks perfect I
will keep testing the examples provided and hopefully at some point I
will grab the concept and make it work.

Thanks again.

On Jan 24, 11:05 am, Tobias Oberstein<tobias.o...@gmail.com> > wrote:

It depends what you mean ..

Autobahn WebSockets for Python is based on Twisted.

Twisted has first class support for serial ports.

So you can transfer data from/to serial port and forward that via
WebSockets (using Autobahn).

In other words: when you have a device which is able to run
Python/Twisted, and that device
has a serial port which connects to your microcontroller, it'll work.

However I don't think you can run Python/Twisted on i.e. PIC _itself_ ..

Hope that helps,

Tobias

Am 24.01.2012 00:01, schrieb yOPERO:

Is it possible to transfer data from and embedded device(PIC, Cortex)
to websockets via serial port using Autobahn?
thanks and keep it up!

0 Likes

#5

Hi Tobias

Glad you are also interested on this topic!

First things first... I have been looking to point 1 in the list you
gave me and I found out that "serialport.py" on Twisted calls
pyserial.

Also I found this code http://pastebin.com/2EJ22wXa where people
connects to a AVR via serial port using twister.
Once I get it working I will pass the code and see how we can atack
point 2.

yOPERO.

···

On Jan 24, 1:16 pm, Tobias Oberstein <tobias.o...@gmail.com> wrote:

This sounds interesting!

Let me help you (hopefully) a bit ...

1)
The first thing to get working is your serial port transfer using
Twisted serial support, instead of PySerial.

I have not done that before .. but it should be documented .. there
should be code you can look at.
Ask on Twisted mailing list if you run into questions.

2)
When you got that, you will want the Twisted event loop to run both your
serial port factory/protocol
_and_ Autobahn.

In general with Twisted, you "add" factories/protocol to the reactor,
and then start the reactor.

In your serial port factory, you then need to have a reference to the
Autobahn factory
and vice versa to shuffle data between both.

I can help you with that ..

3)
I would suggest the following: you want browser clients .. i.e. to
render to a canvas receiving
data from serial mediated via Autobahn.

You could use raw WebSockets and "invent your own pubsub" over WebSockets.

But why reinvent the wheel?

Autobahn has built-in RPC/PubSub on top of WebSockets. See WAMP ..

You get that for free, plus the appropriate JavaScript lib for browsers.

If you go that route, essentially, after having received data from
serial, you just need to
call

WampServerProtocol.dispatchhttps://github.com/oberstet/Autobahn/blob/master/lib/python/autobahn/...

WampServerFactory._dispatchhttps://github.com/oberstet/Autobahn/blob/master/lib/python/autobahn/...

and the data gets published to all subscribed clients .. incl. JS in
browser.

You then only need to subscribe to your topics in JS and are ready to go.

So:

serial port => your Twisted serial protocol => WAMP factory => WAMP
clients (like browsers).

The point is: with WAMP PubSub usually _clients_ publish to a topic, and
that gets dispatched
to all (other) clients subscribed to that topic.

In your case, you want to publish not from client, but from server. No
problem. See the "dispatch"
methods above ..

If it's unclear what I suggest with above, feel free to ask here ..

Tobias

Am 24.01.2012 12:15, schrieb yOPERO:

> Tobias

> Thanks for your answer, you got it right. So far I have been able to
> transfer data to/from a microcontroller to the PC using a python
> script based on PySerial.

> I have been doing some data plotting using PyQt but I want to achive
> the same functionality using a web browser. Autobahn looks perfect I
> will keep testing the examples provided and hopefully at some point I
> will grab the concept and make it work.

> Thanks again.

> On Jan 24, 11:05 am, Tobias Oberstein<tobias.o...@gmail.com> > > wrote:
>> It depends what you mean ..

>> Autobahn WebSockets for Python is based on Twisted.

>> Twisted has first class support for serial ports.

>> So you can transfer data from/to serial port and forward that via
>> WebSockets (using Autobahn).

>> In other words: when you have a device which is able to run
>> Python/Twisted, and that device
>> has a serial port which connects to your microcontroller, it'll work.

>> However I don't think you can run Python/Twisted on i.e. PIC _itself_ ..

>> Hope that helps,

>> Tobias

>> Am 24.01.2012 00:01, schrieb yOPERO:

>>> Is it possible to transfer data from and embedded device(PIC, Cortex)
>>> to websockets via serial port using Autobahn?
>>> thanks and keep it up!

0 Likes

#6

Hi

I have been able to get data from my microcontroller using twisted. Find the code in the below link:

http://pastebin.com/PGLqURWP

It will be very much apreciated if you could help me out with adding the factory/protocols to the reactor.

Cheers

0 Likes

#7

ok, see here:

http://pastebin.com/mhUjm6Mh

(caution: I couldn't test it, since I lack a serial source and have problems on Windows .. see later).

I walk you through the code:

1) lines 34/35
=> need to import relevant Autobahn stuff .. here we directly use WAMP modules, since this will
be easier to achieve what you want than to use raw WS (which you could do of course also, if you insist)

2) lines 18/19/37/38
=> this is not relevant for you .. but relevant to my problem of getting serial work under windows ..see later

3) lines 132-136
here we create the WS/WAMP factory/protocol. line 136 will connect it to the reactor

4) line 152, line 69-72
your serial protocol instance Echo() now gets a reference to wsMcuFactory

5) line 108
this is the core of the gateway code .. upon receiving stuff via serial, we dispatch a PubSub event
to the topic URI.

=> all clients subscribed to that topic will receive it. I'll show you how to do that for JS later

6) lines 40-47
this is our WS-MCU protocol ... nothing to do here but register the topic we want to use.

there is a complete PubSub example with JS and Python clients, and Python server here:
https://github.com/oberstet/Autobahn/tree/master/demo/pubsub/simple

thats it.

please try it (I couldnt .. se later).

if that works, we then go on from here ..
a) JS client
b) add RPC so that you can push something from JS client to MCU
...

···

Am 24.01.2012 23:52, schrieb yOPERO:

Hi

I have been able to get data from my microcontroller using twisted. Find the code in the below link:
http://pastebin.com/PGLqURWP

It will be very much apreciated if you could help me out with adding the factory/protocols to the reactor.

Cheers

===

Now my problem: Windows .. I installed PySerial ... now I get:

oberstet@THINKPAD-T410S /f
$ python sser.py
using Twisted reactor <class 'twisted.internet.selectreactor.SelectReactor'>

Traceback (most recent call last):
   File "sser.py", line 152, in <module>
     s = SerialPort(Echo(wsMcuFactory), port, reactor, baudrate=baudrate)
   File "c:\Python27\lib\site-packages\twisted\internet\_win32serialport.py", line 56, in __init__
     self.reactor.addEvent(self._overlappedRead.hEvent, self, 'serialReadEvent')
AttributeError: 'SelectReactor' object has no attribute 'addEvent'

and when using IOCP reactor (the commented lines at the top):

oberstet@THINKPAD-T410S /f
$ python sser.py
using Twisted reactor <class 'twisted.internet.iocpreactor.reactor.IOCPReactor'>

Traceback (most recent call last):
   File "sser.py", line 152, in <module>
     s = SerialPort(Echo(wsMcuFactory), port, reactor, baudrate=baudrate)
   File "c:\Python27\lib\site-packages\twisted\internet\_win32serialport.py", line 56, in __init__
     self.reactor.addEvent(self._overlappedRead.hEvent, self, 'serialReadEvent')
AttributeError: 'IOCPReactor' object has no attribute 'addEvent'

Do you know whats going on? What platform are you running?

Cheers,
Tobias

0 Likes

#8

never mind .. solved my prob:

on Windows when using Twisted/Serial, you need to use the "Wait for
Multiple Objects" event reactor

from twisted.internet import win32eventreactor
win32eventreactor.install()

http://twistedmatrix.com/trac/ticket/3802

···

==

The code will now start ... still can't really test, since I lack a
serial port MCU source .. what are you using? Arduino?

0 Likes

#9

I've modified the code to use Twisted log system, and added a HTML5
client

http://pastebin.com/bq7sHGUf

http://pastebin.com/B33UAJB4

Please check out those.

You need Chrome or Firefox .. recent one. Or IE10 from Win8 dev
preview ..

Please report if that works for you .. I'd be interested in further
improving/polishing this .. maybe add it as a demo to Autobahn if you
don't mind ..

···

On Jan 25, 11:45 am, tgo <tobias.o...@gmail.com> wrote:

never mind .. solved my prob:

on Windows when using Twisted/Serial, you need to use the "Wait for
Multiple Objects" event reactor

from twisted.internet import win32eventreactor
win32eventreactor.install()

http://twistedmatrix.com/trac/ticket/3802

==

The code will now start ... still can't really test, since I lack a
serial port MCU source .. what are you using? Arduino?

0 Likes

#10

It works for me:

* I am getting data from MCU on localhost:2000. note: I do
press F5 do get new date on the browser.
* Autobahn WebSockets 0.4.10 on localhost:9000
Now I am going to look at the PubSub example.

Looking good! isn´t it?

···

On Jan 25, 11:45 am, tgo <tobias.o...@gmail.com> wrote:

never mind .. solved my prob:

on Windows when using Twisted/Serial, you need to use the "Wait for
Multiple Objects" event reactor

from twisted.internet import win32eventreactor
win32eventreactor.install()

http://twistedmatrix.com/trac/ticket/3802

==

The code will now start ... still can't really test, since I lack a
serial port MCU source .. what are you using? Arduino?

0 Likes

#11

Nice one!!!

see what I have got:

http://i219.photobucket.com/albums/cc309/yopero/autobahn_MCU.jpg

···

On Jan 25, 12:12 pm, tgo <tobias.o...@gmail.com> wrote:

I've modified the code to use Twisted log system, and added a HTML5
client

http://pastebin.com/bq7sHGUf

http://pastebin.com/B33UAJB4

Please check out those.

You need Chrome or Firefox .. recent one. Or IE10 from Win8 dev
preview ..

Please report if that works for you .. I'd be interested in further
improving/polishing this .. maybe add it as a demo to Autobahn if you
don't mind ..

On Jan 25, 11:45 am, tgo <tobias.o...@gmail.com> wrote:

> never mind .. solved my prob:

> on Windows when using Twisted/Serial, you need to use the "Wait for
> Multiple Objects" event reactor

> from twisted.internet import win32eventreactor
> win32eventreactor.install()

>http://twistedmatrix.com/trac/ticket/3802

> ==

> The code will now start ... still can't really test, since I lack a
> serial port MCU source .. what are you using? Arduino?

0 Likes

#12

cool!

that was a fast start;)

so now you have the basics MCU => JS running ..

btw: should you eveer need a native Android app, Autobahn/WS+WAMP is available for that also.

···

==

Now, for the other direction (JS => MCU) .. do you need that also? If so, I can extend the code so you can do that via RPC (part of WAMP).

What MCU hardware are you using?

And how do you connect that to your PC? I mean: last time I saw a DSUB-9 connector on a PC is long ago ... do you use USB?

I wanna try myself;)

0 Likes

#13

About Android of course, nowadays it is kind of easy to connect an
MCU to android via Blueetooth.

For the other direction (JS => MCU) .. I need that also. To make it
simple I am going to put a led to the MCU which is programmed to
switch on when it receives 1 and switch of when receiving a 0. so
please change the code if you have time to.

Yesterday I was working with a PIC but today I have an arduino
arduino.cc it is a ready made unit no need of soldering,etc. you
should give it a try it is very straight forward similar to C++ but
much more easier.

Yes I do connect the Arduino using a USB, in general you can connect a
MCU using usb(serial port) bluetooth(serial port) you have also an
ethernet module you can attached to it(can work as server or client)
finally you have wireless technologies such wifi and xbee.

What I am trying to achive is this:
http://mbed.org/blog/entry/HTML5-for-Microcontrollers/

I do still have a question, how do I do for displaying that data on a
webpage.

Regards,

yOPERO

···

On Jan 25, 12:51 pm, Tobias Oberstein <tobias.o...@gmail.com> wrote:

cool!

that was a fast start;)

so now you have the basics MCU => JS running ..

btw: should you eveer need a native Android app, Autobahn/WS+WAMP is
available for that also.

==

Now, for the other direction (JS => MCU) .. do you need that also? If
so, I can extend the code so you can do that via RPC (part of WAMP).

What MCU hardware are you using?

And how do you connect that to your PC? I mean: last time I saw a DSUB-9
connector on a PC is long ago ... do you use USB?

I wanna try myself;)

0 Likes

#14

here you go ..

sser.py
http://pastebin.com/8Z8fG5Af

sser.html
http://pastebin.com/M92qHGw0

needed to refactor the code a little .. if it doesnt make sense to you, ask ..

start, then open:

http://localhost:2000/sser.html

in browser.

press buttons.

you need to implement your actual control code in

McuProtocol.controlLed

=> should work by self.transport.write .. send to serial

···

===

regarding Android .. I meant the following:

You have PC<=>MCU running ... then you can connect to PC from any browser to get your UI.

OR

you can connect from Android native app to PC for alternative UI.

when your PC has a public IP (that is, its on the internet), you can access the UI (browser and Android)
from anywhere ...

===

about your UI: I'd suggest a so-called "single-page app" approach.

this is: you have only a single html page, and all the interesting stuff happens via JS.

thanks for explaing USB/serial/MCU btw ...

hope that gets you going ..

would be nice if you keep us up to date about your progress on this list ..

cheers,
Tobias

Am 25.01.2012 13:08, schrieb yOPERO:

About Android of course, nowadays it is kind of easy to connect an
MCU to android via Blueetooth.

For the other direction (JS => MCU) .. I need that also. To make it
simple I am going to put a led to the MCU which is programmed to
switch on when it receives 1 and switch of when receiving a 0. so
please change the code if you have time to.

Yesterday I was working with a PIC but today I have an arduino
arduino.cc it is a ready made unit no need of soldering,etc. you
should give it a try it is very straight forward similar to C++ but
much more easier.

Yes I do connect the Arduino using a USB, in general you can connect a
MCU using usb(serial port) bluetooth(serial port) you have also an
ethernet module you can attached to it(can work as server or client)
finally you have wireless technologies such wifi and xbee.

What I am trying to achive is this:
http://mbed.org/blog/entry/HTML5-for-Microcontrollers/

I do still have a question, how do I do for displaying that data on a
webpage.

Regards,

yOPERO

On Jan 25, 12:51 pm, Tobias Oberstein<tobias.o...@gmail.com> > wrote:

cool!

that was a fast start;)

so now you have the basics MCU => JS running ..

btw: should you eveer need a native Android app, Autobahn/WS+WAMP is
available for that also.

==

Now, for the other direction (JS => MCU) .. do you need that also? If
so, I can extend the code so you can do that via RPC (part of WAMP).

What MCU hardware are you using?

And how do you connect that to your PC? I mean: last time I saw a DSUB-9
connector on a PC is long ago ... do you use USB?

I wanna try myself;)

0 Likes

#15

Thanks Tobias, of course I will be publishing here what I do with this
project, I owe you that.

Later on I am going to implement the McuProtocol.controlLed

I have got another question. How do I display on the sser.html page
the humity and temp values that I am currently getting?

cheers

yOPERO

···

On Jan 25, 1:53 pm, Tobias Oberstein <tobias.o...@gmail.com> wrote:

here you go ..

sser.pyhttp://pastebin.com/8Z8fG5Af

sser.htmlhttp://pastebin.com/M92qHGw0

needed to refactor the code a little .. if it doesnt make sense to you,
ask ..

start, then open:

http://localhost:2000/sser.html

in browser.

press buttons.

you need to implement your actual control code in

McuProtocol.controlLed

=> should work by self.transport.write .. send to serial

===

regarding Android .. I meant the following:

You have PC<=>MCU running ... then you can connect to PC from any
browser to get your UI.

OR

you can connect from Android native app to PC for alternative UI.

when your PC has a public IP (that is, its on the internet), you can
access the UI (browser and Android)
from anywhere ...

===

about your UI: I'd suggest a so-called "single-page app" approach.

this is: you have only a single html page, and all the interesting stuff
happens via JS.

thanks for explaing USB/serial/MCU btw ...

hope that gets you going ..

would be nice if you keep us up to date about your progress on this list ..

cheers,
Tobias

Am 25.01.2012 13:08, schrieb yOPERO:

> About Android of course, nowadays it is kind of easy to connect an
> MCU to android via Blueetooth.

> For the other direction (JS => MCU) .. I need that also. To make it
> simple I am going to put a led to the MCU which is programmed to
> switch on when it receives 1 and switch of when receiving a 0. so
> please change the code if you have time to.

> Yesterday I was working with a PIC but today I have an arduino
> arduino.cc it is a ready made unit no need of soldering,etc. you
> should give it a try it is very straight forward similar to C++ but
> much more easier.

> Yes I do connect the Arduino using a USB, in general you can connect a
> MCU using usb(serial port) bluetooth(serial port) you have also an
> ethernet module you can attached to it(can work as server or client)
> finally you have wireless technologies such wifi and xbee.

> What I am trying to achive is this:
>http://mbed.org/blog/entry/HTML5-for-Microcontrollers/

> I do still have a question, how do I do for displaying that data on a
> webpage.

> Regards,

> yOPERO

> On Jan 25, 12:51 pm, Tobias Oberstein<tobias.o...@gmail.com> > > wrote:
>> cool!

>> that was a fast start;)

>> so now you have the basics MCU => JS running ..

>> btw: should you eveer need a native Android app, Autobahn/WS+WAMP is
>> available for that also.

>> ==

>> Now, for the other direction (JS => MCU) .. do you need that also? If
>> so, I can extend the code so you can do that via RPC (part of WAMP).

>> What MCU hardware are you using?

>> And how do you connect that to your PC? I mean: last time I saw a DSUB-9
>> connector on a PC is long ago ... do you use USB?

>> I wanna try myself;)

0 Likes

#16

yOPERO,

to show current values, essentially you need to insert

<div id="temp"></div>

and then in JS in the event handler do:

document.getElementById("temp").innerHTML = event[0];

for graphics, you can use i.e. html5 canvas or other techn. ...

···

==

would you mind sending me the arduino code you use?

some bare bone code would be cool, .. I want to order an Arduino and try myself;)

ps: I will polish up the code a little and include it in Autobahn tests/demo .. only barebone code ... hope this is ok for you.

cheers,
Tobias

Am 25.01.2012 14:29, schrieb yOPERO:

Thanks Tobias, of course I will be publishing here what I do with this
project, I owe you that.

Later on I am going to implement the McuProtocol.controlLed

I have got another question. How do I display on the sser.html page
the humity and temp values that I am currently getting?

cheers

yOPERO

On Jan 25, 1:53 pm, Tobias Oberstein<tobias.o...@gmail.com> > wrote:

here you go ..

sser.pyhttp://pastebin.com/8Z8fG5Af

sser.htmlhttp://pastebin.com/M92qHGw0

needed to refactor the code a little .. if it doesnt make sense to you,
ask ..

start, then open:

http://localhost:2000/sser.html

in browser.

press buttons.

you need to implement your actual control code in

McuProtocol.controlLed

=> should work by self.transport.write .. send to serial

===

regarding Android .. I meant the following:

You have PC<=>MCU running ... then you can connect to PC from any
browser to get your UI.

OR

you can connect from Android native app to PC for alternative UI.

when your PC has a public IP (that is, its on the internet), you can
access the UI (browser and Android)
from anywhere ...

===

about your UI: I'd suggest a so-called "single-page app" approach.

this is: you have only a single html page, and all the interesting stuff
happens via JS.

thanks for explaing USB/serial/MCU btw ...

hope that gets you going ..

would be nice if you keep us up to date about your progress on this list ..

cheers,
Tobias

Am 25.01.2012 13:08, schrieb yOPERO:

About Android of course, nowadays it is kind of easy to connect an
MCU to android via Blueetooth.
For the other direction (JS => MCU) .. I need that also. To make it
simple I am going to put a led to the MCU which is programmed to
switch on when it receives 1 and switch of when receiving a 0. so
please change the code if you have time to.
Yesterday I was working with a PIC but today I have an arduino
arduino.cc it is a ready made unit no need of soldering,etc. you
should give it a try it is very straight forward similar to C++ but
much more easier.
Yes I do connect the Arduino using a USB, in general you can connect a
MCU using usb(serial port) bluetooth(serial port) you have also an
ethernet module you can attached to it(can work as server or client)
finally you have wireless technologies such wifi and xbee.
What I am trying to achive is this:
http://mbed.org/blog/entry/HTML5-for-Microcontrollers/
I do still have a question, how do I do for displaying that data on a
webpage.
Regards,
yOPERO
On Jan 25, 12:51 pm, Tobias Oberstein<tobias.o...@gmail.com> >>> wrote:

cool!
that was a fast start;)
so now you have the basics MCU => JS running ..
btw: should you eveer need a native Android app, Autobahn/WS+WAMP is
available for that also.

Now, for the other direction (JS => MCU) .. do you need that also? If
so, I can extend the code so you can do that via RPC (part of WAMP).
What MCU hardware are you using?
And how do you connect that to your PC? I mean: last time I saw a DSUB-9
connector on a PC is long ago ... do you use USB?
I wanna try myself;)

0 Likes

#17

There you.. the very complicated arduino code:
//////////////////////////////
void setup() {
// initialize the serial communication:
Serial.begin(9600);
}

void loop() {
// Code copied from http://code.google.com/p/arduinoscope/source/browse/trunk/arduino_oscilliscope.pde
Serial.print(analogRead(1));
Serial.print(" ");
Serial.print(analogRead(2));
Serial.println();
delay(1000); // 1Hz data should more than suffice!
}
/////////////////////////////

Here is the reference of the Arduino language: http://arduino.cc/en/Reference/HomePage
and here the playground where you have examples of arduino use:
http://arduino.cc/playground/

Now time to do non-profit marketing, a group of friends and I have
designed a board which works with the Arduino IDE and language, it is
open source.

https://bitbucket.org/fmalpartida/vinciduino/wiki/Home

Check it out it may interest you for the future.

yOPERO

···

On Jan 25, 2:36 pm, Tobias Oberstein <tobias.o...@gmail.com> wrote:

yOPERO,

to show current values, essentially you need to insert

<div id="temp"></div>

and then in JS in the event handler do:

document.getElementById("temp").innerHTML = event[0];

for graphics, you can use i.e. html5 canvas or other techn. ...

==

would you mind sending me the arduino code you use?

some bare bone code would be cool, .. I want to order an Arduino and try
myself;)

ps: I will polish up the code a little and include it in Autobahn
tests/demo .. only barebone code ... hope this is ok for you.

cheers,
Tobias

Am 25.01.2012 14:29, schrieb yOPERO:

> Thanks Tobias, of course I will be publishing here what I do with this
> project, I owe you that.

> Later on I am going to implement the McuProtocol.controlLed

> I have got another question. How do I display on the sser.html page
> the humity and temp values that I am currently getting?

> cheers

> yOPERO

> On Jan 25, 1:53 pm, Tobias Oberstein<tobias.o...@gmail.com> > > wrote:
>> here you go ..

>> sser.pyhttp://pastebin.com/8Z8fG5Af

>> sser.htmlhttp://pastebin.com/M92qHGw0

>> needed to refactor the code a little .. if it doesnt make sense to you,
>> ask ..

>> start, then open:

>>http://localhost:2000/sser.html

>> in browser.

>> press buttons.

>> you need to implement your actual control code in

>> McuProtocol.controlLed

>> => should work by self.transport.write .. send to serial

>> ===

>> regarding Android .. I meant the following:

>> You have PC<=>MCU running ... then you can connect to PC from any
>> browser to get your UI.

>> OR

>> you can connect from Android native app to PC for alternative UI.

>> when your PC has a public IP (that is, its on the internet), you can
>> access the UI (browser and Android)
>> from anywhere ...

>> ===

>> about your UI: I'd suggest a so-called "single-page app" approach.

>> this is: you have only a single html page, and all the interesting stuff
>> happens via JS.

>> thanks for explaing USB/serial/MCU btw ...

>> hope that gets you going ..

>> would be nice if you keep us up to date about your progress on this list ..

>> cheers,
>> Tobias

>> Am 25.01.2012 13:08, schrieb yOPERO:

>>> About Android of course, nowadays it is kind of easy to connect an
>>> MCU to android via Blueetooth.
>>> For the other direction (JS => MCU) .. I need that also. To make it
>>> simple I am going to put a led to the MCU which is programmed to
>>> switch on when it receives 1 and switch of when receiving a 0. so
>>> please change the code if you have time to.
>>> Yesterday I was working with a PIC but today I have an arduino
>>> arduino.cc it is a ready made unit no need of soldering,etc. you
>>> should give it a try it is very straight forward similar to C++ but
>>> much more easier.
>>> Yes I do connect the Arduino using a USB, in general you can connect a
>>> MCU using usb(serial port) bluetooth(serial port) you have also an
>>> ethernet module you can attached to it(can work as server or client)
>>> finally you have wireless technologies such wifi and xbee.
>>> What I am trying to achive is this:
>>>http://mbed.org/blog/entry/HTML5-for-Microcontrollers/
>>> I do still have a question, how do I do for displaying that data on a
>>> webpage.
>>> Regards,
>>> yOPERO
>>> On Jan 25, 12:51 pm, Tobias Oberstein<tobias.o...@gmail.com> > >>> wrote:
>>>> cool!
>>>> that was a fast start;)
>>>> so now you have the basics MCU => JS running ..
>>>> btw: should you eveer need a native Android app, Autobahn/WS+WAMP is
>>>> available for that also.
>>>> ==
>>>> Now, for the other direction (JS => MCU) .. do you need that also? If
>>>> so, I can extend the code so you can do that via RPC (part of WAMP).
>>>> What MCU hardware are you using?
>>>> And how do you connect that to your PC? I mean: last time I saw a DSUB-9
>>>> connector on a PC is long ago ... do you use USB?
>>>> I wanna try myself;)

0 Likes

#18

Hi Tobias

I have been trying real hard to create the lines that would send data
to Arduino using the buttons on index.html,
I am afraid my knowledge in python is very basic and twisted is new to
me.

To be honest I am far from getting there so I hope you can help me out
a bit specially on the overall concepts.

I have my arduino ready to receive data( '6' in this case) when
arduino receives 6 it switchs on the led and sends back the state of
the led.

I have tested it on a serial terminal and works fine.

Also I am able so send the state of the led to the ws and visualize it
on index.html.

I know that when the button on index.html changes its state it is send
back to serial2ws.py.

my doubt is how to capture that state change on the serial2ws.py and
how to send to the serial port the captured data.

Cheers

···

On Jan 25, 2:57 pm, yOPERO <yope...@googlemail.com> wrote:

There you.. the very complicated arduino code:
//////////////////////////////
void setup() {
// initialize the serial communication:
Serial.begin(9600);

}

void loop() {
// Code copied fromhttp://code.google.com/p/arduinoscope/source/browse/trunk/arduino_osc...
Serial.print(analogRead(1));
Serial.print(" ");
Serial.print(analogRead(2));
Serial.println();
delay(1000); // 1Hz data should more than suffice!}

/////////////////////////////

Here is the reference of the Arduino language:http://arduino.cc/en/Reference/HomePage
and here the playground where you have examples of arduino use:http://arduino.cc/playground/

Now time to do non-profit marketing, a group of friends and I have
designed a board which works with the Arduino IDE and language, it is
open source.

https://bitbucket.org/fmalpartida/vinciduino/wiki/Home

Check it out it may interest you for the future.

yOPERO

On Jan 25, 2:36 pm, Tobias Oberstein <tobias.o...@gmail.com> > wrote:

> yOPERO,

> to show current values, essentially you need to insert

> <div id="temp"></div>

> and then in JS in the event handler do:

> document.getElementById("temp").innerHTML = event[0];

> for graphics, you can use i.e. html5 canvas or other techn. ...

> ==

> would you mind sending me the arduino code you use?

> some bare bone code would be cool, .. I want to order an Arduino and try
> myself;)

> ps: I will polish up the code a little and include it in Autobahn
> tests/demo .. only barebone code ... hope this is ok for you.

> cheers,
> Tobias

> Am 25.01.2012 14:29, schrieb yOPERO:

> > Thanks Tobias, of course I will be publishing here what I do with this
> > project, I owe you that.

> > Later on I am going to implement the McuProtocol.controlLed

> > I have got another question. How do I display on the sser.html page
> > the humity and temp values that I am currently getting?

> > cheers

> > yOPERO

> > On Jan 25, 1:53 pm, Tobias Oberstein<tobias.o...@gmail.com> > > > wrote:
> >> here you go ..

> >> sser.pyhttp://pastebin.com/8Z8fG5Af

> >> sser.htmlhttp://pastebin.com/M92qHGw0

> >> needed to refactor the code a little .. if it doesnt make sense to you,
> >> ask ..

> >> start, then open:

> >>http://localhost:2000/sser.html

> >> in browser.

> >> press buttons.

> >> you need to implement your actual control code in

> >> McuProtocol.controlLed

> >> => should work by self.transport.write .. send to serial

> >> ===

> >> regarding Android .. I meant the following:

> >> You have PC<=>MCU running ... then you can connect to PC from any
> >> browser to get your UI.

> >> OR

> >> you can connect from Android native app to PC for alternative UI.

> >> when your PC has a public IP (that is, its on the internet), you can
> >> access the UI (browser and Android)
> >> from anywhere ...

> >> ===

> >> about your UI: I'd suggest a so-called "single-page app" approach.

> >> this is: you have only a single html page, and all the interesting stuff
> >> happens via JS.

> >> thanks for explaing USB/serial/MCU btw ...

> >> hope that gets you going ..

> >> would be nice if you keep us up to date about your progress on this list ..

> >> cheers,
> >> Tobias

> >> Am 25.01.2012 13:08, schrieb yOPERO:

> >>> About Android of course, nowadays it is kind of easy to connect an
> >>> MCU to android via Blueetooth.
> >>> For the other direction (JS => MCU) .. I need that also. To make it
> >>> simple I am going to put a led to the MCU which is programmed to
> >>> switch on when it receives 1 and switch of when receiving a 0. so
> >>> please change the code if you have time to.
> >>> Yesterday I was working with a PIC but today I have an arduino
> >>> arduino.cc it is a ready made unit no need of soldering,etc. you
> >>> should give it a try it is very straight forward similar to C++ but
> >>> much more easier.
> >>> Yes I do connect the Arduino using a USB, in general you can connect a
> >>> MCU using usb(serial port) bluetooth(serial port) you have also an
> >>> ethernet module you can attached to it(can work as server or client)
> >>> finally you have wireless technologies such wifi and xbee.
> >>> What I am trying to achive is this:
> >>>http://mbed.org/blog/entry/HTML5-for-Microcontrollers/
> >>> I do still have a question, how do I do for displaying that data on a
> >>> webpage.
> >>> Regards,
> >>> yOPERO
> >>> On Jan 25, 12:51 pm, Tobias Oberstein<tobias.o...@gmail.com> > > >>> wrote:
> >>>> cool!
> >>>> that was a fast start;)
> >>>> so now you have the basics MCU => JS running ..
> >>>> btw: should you eveer need a native Android app, Autobahn/WS+WAMP is
> >>>> available for that also.
> >>>> ==
> >>>> Now, for the other direction (JS => MCU) .. do you need that also? If
> >>>> so, I can extend the code so you can do that via RPC (part of WAMP).
> >>>> What MCU hardware are you using?
> >>>> And how do you connect that to your PC? I mean: last time I saw a DSUB-9
> >>>> connector on a PC is long ago ... do you use USB?
> >>>> I wanna try myself;)

0 Likes

#19

try insert

self.transport.write('6')

after line

https://github.com/oberstet/Autobahn/blob/master/demo/serial2ws/serial2ws.py#L70

I can't try myself now ... hopefully I get hands on an Arduino this weekend .. when I do,
I extend the example and then I can give you a verified walkthrough ..

···

Am 27.01.2012 14:25, schrieb yOPERO:

Hi Tobias

I have been trying real hard to create the lines that would send data
to Arduino using the buttons on index.html,
I am afraid my knowledge in python is very basic and twisted is new to
me.

To be honest I am far from getting there so I hope you can help me out
a bit specially on the overall concepts.

I have my arduino ready to receive data( '6' in this case) when
arduino receives 6 it switchs on the led and sends back the state of
the led.

I have tested it on a serial terminal and works fine.

Also I am able so send the state of the led to the ws and visualize it
on index.html.

I know that when the button on index.html changes its state it is send
back to serial2ws.py.

my doubt is how to capture that state change on the serial2ws.py and
how to send to the serial port the captured data.

0 Likes

#20

uffff I put the code up side down and it was only adding that line.

I can confirm it works.

thanks Tobias good weekend!

···

On Jan 27, 2:44 pm, Tobias Oberstein <tobias.o...@gmail.com> wrote:

try insert

self.transport.write('6')

after line

https://github.com/oberstet/Autobahn/blob/master/demo/serial2ws/seria...

I can't try myself now ... hopefully I get hands on an Arduino this
weekend .. when I do,
I extend the example and then I can give you a verified walkthrough ..

Am 27.01.2012 14:25, schrieb yOPERO:

> Hi Tobias

> I have been trying real hard to create the lines that would send data
> to Arduino using the buttons on index.html,
> I am afraid my knowledge in python is very basic and twisted is new to
> me.

> To be honest I am far from getting there so I hope you can help me out
> a bit specially on the overall concepts.

> I have my arduino ready to receive data( '6' in this case) when
> arduino receives 6 it switchs on the led and sends back the state of
> the led.

> I have tested it on a serial terminal and works fine.

> Also I am able so send the state of the led to the ws and visualize it
> on index.html.

> I know that when the button on index.html changes its state it is send
> back to serial2ws.py.

> my doubt is how to capture that state change on the serial2ws.py and
> how to send to the serial port the captured data.

0 Likes