HTML5 for Microcontrollers!


HTML5 already holds some pretty exciting prospects for web application developers, but there is no reason why it should stop there. If you can get microcontrollers to start talking the same language too, the opportunities for the Internet of Things enabled by HTML5 could be amazing!

This project shows an early glimpse of how you can build Internet of Things sensors with mbed that can be quickly deployed using just a smartphone, and transmit their real-time sensor data to a server that can be visualised on different clients, all using these new HTML5 web standards:

You can see immediately from the demo just how natural the deployment and interaction feel, and why HTML5 could be a key enabler in the Internet of Things.

The hardware

The mbed Microcontroller reads it's attached sensors and sends the real-time data to a server over Wifi using HTML5 Websockets. In our case, the messages are simple JSON messages to a simple websockets server hub.

This example uses the new mbed Cortex-M0 beta to make battery-powered prototypes of sensors communicating via wifi:

/media/uploads/simon/sensor-prototype.png

Of course, the same concept works over any transport, such as using the mbed NXP LPC1768 built-in Ethernet to make wired websockets connections.

Viewing the data stream on a web page

The real time data from any sensor can be viewed on any client using HTML5 Canvas just by subscribing to the stream:

/media/uploads/simon/sensor-prototype-demo.png

This is just an example - the clients for this data can range from simple viewers such as this that just display the data they see, to complex databases, filters and triggers; anything that can listen on a websocket connection.

The code

As an overview, here is the main C/C++ code running on the mbed microcontroller that makes it all work:

Import program

00001 #include "mbed.h"
00002 #include "Wifly.h"
00003 #include "Websocket.h"
00004 
00005 DigitalOut l1(LED1);
00006 
00007 //Here, we create an instance, with pins 9 and 10 connecting to the
00008 //WiFly's TX and RX pins, and pin 21 to RESET. We are connecting to the
00009 //"mbed" network, password "password", and we are using WPA.
00010 Wifly wifly(p9, p10, p21, "mbed", "password", true);
00011 
00012 //Here, we create a Websocket instance in 'rw' (read-write) mode
00013 //on the 'samux' channel
00014 Websocket ws("ws://sockets.mbed.org/ws/samux/rw", &wifly);
00015 
00016 
00017 int main() {
00018     char recv[40];
00019 
00020     while (1) {
00021 
00022         //we connect the network
00023         while (!wifly.join()) {
00024             wifly.reset();
00025         }
00026 
00027         //we connect to the websocket server
00028         while (!ws.connect());
00029 
00030         while (1) {
00031             wait(0.5);
00032 
00033             //Send Hello world
00034             ws.send("Hello World! over Wifi");
00035 
00036             // if a message is available, print it
00037             if (ws.read(recv)) {
00038                 // show that we receive messages
00039                 l1 = !l1;
00040             }
00041         }
00042     }
00043 }

Hopefully that gives a good feel for how quickly these prototypes can be put together.

The technology is coming, so it is now just up to you to create the killer apps! For all the dirty details of how to build it to get you on your way, see:

19 comments on HTML5 for Microcontrollers!:

25 Oct 2011

Release date please? :-D

25 Oct 2011

For non-native english audiance, the background music is quite disturbing. Please don't follow the trend ;-) On the other hand: Good video!

25 Oct 2011

Can this technique be used to upload data into a database for storage as well as the live feed demonstrated? I'm looking to upload 100 or so bytes every second, is this doable?

25 Oct 2011

I'm loving that you guys are exploring this concept of The Internet of Things in your MBed platform, for years that I've been trying to get the 2 worlds together (web technology + microcontrollers) but without success, mostly due to the lack of support from the microcontrollers Company with their limited TCP/IP Stacks and libraries for the Web friendly protocols!

Also been testing the integration of microcontrollers with Linux Embedded Boards, trying an easy way to communicate with both, not always easy to get SPI or I2C protocol running on the Embedded board (when you have some custom Linux Distro may be complicated, doing Kernel Space drivers to get the protocols running may be an hard challenge).

So, looking forward to start making some test with the MBed! Actually, I'm currently making some demos with this, I'll be presenting the MBed board and The Internet of Things concept to a local group of friends next month ;), my way of showing my gratitude to the MBed community!

Well, also have a quick question (not having the time to test this now, but could be useful for my demo), have anyone tested the max speed of data transfer over the WebSocket protocol? Similar to the previous question of Tom, would like to get the feeling of what could be achieved with this approach!

My future goal would be to have several sensor broadcasting live data via MBed->WebSockets to a Linux Embedded platfform running an webapp (this app would collect and distribute data and also save it to local database for later reporting).

Keep up the good work ;)

25 Oct 2011

Well, but it appears to be calling `wifly.reset();` without even going to sleep even for second! Hey, you are not even trying to save any power AND using a 802.11 network your battery will die very very quickly, it's not the way to go.

25 Oct 2011

Hi,

Love the concept but could you please re post the video without the backing music please? I really can't hear a word that is being said and it really is quite distracting.

If you don't/can't replace the video with one that has no backing music could you post one and copy the link in the thread please?

Cheers

Simon

25 Oct 2011

This is great stuff...

I'm just a little cautious as there are many reported IP issues on mBed currently that cause lock ups and crashes. Especially apparent when implementing a webserver on mBed or larger packets, 1500 MTU . The consensus seemed to be that the stacks or buffer usage was still flawed and needing attention to fix .

Several mBed people, maybe even yourself Simon were working on this but everything has gone quiet . What is the state of play re these issues ?

K

25 Oct 2011

I also have toyed with using HTML5 technologies with the mBed (including web sockets), see the hack I put together here: http://mbed.org/users/nandgate/notebook/websockets/, I also presented on this at my HTML-5 meet up (http://www.meetup.com/HTML5-Denver-Users-Group/) and folks were very receptive and interested in how to connect and build the "Internet of things".

25 Oct 2011

I agree with opinion # 6. For non english speaker,it is tough enough trying just to catch the accent without the music. I wish the author would provide the version without the background music. Thanks.

25 Oct 2011

@tom sure, this data could be put in to a database; we just didn't to keep the demo simple

@ilya yeah, there is certainly things you could do to save power. We just kept it simple to show the concept, but could certainly be improved. The use of wifi definitely shouldn't be dismissed to quickly; it works really well, and even without power optimisation might enable practical applications. But with lower data rates and some low power optimisation, it could be useful for even more. I have some scales that send my weight to the Internet every time I step on it; I haven't changed the batteries yet!

@kevin yeah, we can look at the Mtu thing

@others yeah, I can republish without music ;) will have to wait till I'm back in the uk next week as it is on a different laptop. I'm afraid making videos isn't my strongest skill! Will try and get better!

Hope you find it interesting and inspiring!

Simon

25 Oct 2011

Did you plan to provide WebSocket feature build in ? It's may be the better way to push data out with low bandwith, easy to write and high speed...

25 Oct 2011

From another non-english speaker : yes, this video is beyond understanding, please keep this kind of background for your saturday night fever, we've got ears, not samplers.

25 Oct 2011

A very practical solution for rapid deployment. Too bad the video background music that makes it virtually inaudible for those who do not speak English as their mother tongue.

25 Oct 2011

Hi Miguel, Herve,

Yep, will try and republish without the music :) I'll try and get better at making these videos and considering other languages!

There is a writeup here which should help clarify anything you missed: http://mbed.org/cookbook/IOT

Glad you found it useful,

Simon

25 Oct 2011

Can you make your videos without the background music - I find it very distracting and can't hear what the presenter is trying to say.

30 Oct 2011

Video now uploaded without music! Sorry for my production mistake, but hopefully it is better now.

30 Oct 2011

What type of WIFI board is it ?

I have looked on WWW.coolcomponents.com and sparkfun

And there are a few to choose from, Is there only one that will work straight away, Or will they all work ?

Cheers

Ceri

31 Oct 2011

The WIFI board used is from sparkfun: http://www.sparkfun.com/products/10050

31 Oct 2011

Thank you for redoing the video, can understand it really easily now! It always amazes me with the mbed that once you add a couple of libraries the code that makes up the main application really isn't that much

Cheers

Simon

You need to log in to post a discussion