Tuesday, August 27, 2013

Internet of Things with help of ARM

Today, ARM Ltd announced they have acquired Sensinode Oy, a Finnish company providing software technology for Internet of Things (IoT). In the press release, ARM says they will make the technology available to developers through the ARM mbed project, to enable easy creation of IoT applications.

Sensinode is most known for the Nanostack implementation of the 6LoWPAN standard. They are also known for their active contribution to standardization at IoT scheme. At Espotel, I have been involved as the project manager in a customer product development project where Nanostack was applied in a wireless sensor network for industrial automation application. 

The mbed development platform is intended for fast creation of products based on ARM microcontrollers. It consists of software and hardware development tools (SDK, HDK), online IDE and support of the community. At the moment, there are 11 COTS MCU boards readily available from different vendors, ranging from Cortex-M0 to M4 core.

The mbed Compiler is a C/C++ IDE provided as a web app, thus most operating systems and browsers are supported as the host environment. Unlike with the BeagleBone C9, your mbed projects are stored in the cloud, not in the development platform itself. The IDE provides version control by default, but also rises some security concerns. For hobbyist and experimentation, that's maybe not a problem, if the code is intended to be published anyway.

Try it by yourself

 

I did some quick exercise with the mbed and a Freescale Freedom board KL25Z with Cortex-M0 core. In less time than what it takes to write this posting, I got my first code up and running in the target. There are just a few steps to follow, according to the instructions.
  1. Connect the board via USB cable meanwhile pressing the reset button. The device gets mounted as a USB mass storage in bootloader update mode.
  2. Update bootloader by drag-and-drop the image, then reset the device
  3. Open the IDE by clicking mbed icon at the device flash
  4. Write your code, compile, and save the binary to the device flash 
  5. Reset the device, and you're running you new code !
Steps 1 and 2 needs to be done only once, to enable mbed on your target.

FRDM-KL25Z blinking blue and green LED.
After my experiment, I'm really fascinated by the concept of mbed. Together with the proven wireless internet connectivity provided by Sensinode, I believe what ARM promises, the IoT is one step closer.

Monday, August 26, 2013

Embedded Conference Scandinavia 2013

Embedded Conference Scandinavia in Stockholm is the leading event in Nordic countries focusing on embedded technology. The conference has grown year by year, and this is the 8th time it is organized. This year the event is moved to Kista from Stockholmsmässa where it was organized earlier. For the first time, the conference is organized jointly with M2M Summit Scandinavia, which is a branch of the M2M Summit in Germany, organized by M2M Alliance.

My presentation proposal to the conference was accepted, and I got time slot 13:30-14:00 at central demo square, on Wednesday the 6th of November. The topic is "Embedded connectivity with HTML5". This is the 4th time I'm having talk at ECS. Last time I discussed about implementing embedded user interfaces with help of HTML5.

Espotel will have a booth at the conference, and you're welcome to meet us at any time within the two days event.

ECS'13, 5th-6th of November, Kista Stockholm

Friday, August 16, 2013

SiLabs + Energy Micro

Today, I met SiLabs people, who presented their new MCU portfolio. As you may know, Silicon Labs accuired Energy Micro. The deal was closed just only 6 weeks ago. Energy Micro was founded by a Norwegian Geir Førre, who also founded Chipcon, which was sold to Texas Instruments. What a success of serial entrepreneur! I had once a chance to listen to Geir in Stockholm, and I have to admit that he is a wise guy.

I was more or less aware of what EM has made with the silicon, but I didn't knew their development tools offering. Simplicity Studio provides quite nice tools for energy profiling and optimization. Competitors are narrowing the gab in MCU energy consumption figures, but according to my understanding, they don't provide similar level of development software support for energy optimization. So, from my perspective, that's the #1 competitive advantage that SiLabs has in EMF over competitors.

SiLabs promises to launch an EFR family of integrated MCU+RF next year. That will contain EMF core + radio of some sort. Only preliminary numbers are provided for RF characteristics yet. However, SiLabs has good reputation in discrete radios, at least in Sub-GHz RF chips, which are extensively used by my company in customer design. Thus I expect something competitive to approach market.

Wednesday, August 14, 2013

WebSocket experimentation with BeagleBone



I really like the concept of BeagleBone and Cloud9 IDE. I have my board connected directly to my local intranet with Ethernet cable, so I can access the IDE and my saved project, and continue working at any PC in my household, no matter whether it’s the ChromeBook, my company Windows Ultrabook, or my wife's MacBook. The very same user experience available with zero-installation needed. And my project is secured, as it is stored locally at the mass memory of the board itself. No one can access it from outside of my intranet. Of course, in case of professional software development, version control, collaboration, backups, etc. needs to be considered separately.

The default Ångström Linux image installed on BeagleBone, does not have the WebSocket Javascript library socket.io installed by default. At GitHub BoneScript Socket.IO page there are instructions how to install socket.io.  The whole project was initially committed only two weeks ago. There is also a nice, but rather complex example of using WebSocket to remote control LEDs, which needs to be externally attached to the BeagleBone board. NB! Some hardware hacking required.

I wrote a canonical code example demonstrating how to control an onboard LED at BeagleBone. So, no hardware hacking is needed to test the code.  JavaScript uses JSON (JavaScript Object Notation) to exchange data. In this example, very simple JSON messages are delivered over the WebSocket connection to control and confirm the LED state. BoneScript functions are used for hardware access.

JSON messages in this example have the following simple syntax:

{"name":"led","args":["on"]}

The demo consists of two files located in sockserv folder. Socketserver.js, which is the Node.JS executed at BeagleBone, and socketclient.html which is the web page delivered to web browser upon request, containing HTML and JavaScript code for communication with the Beagle. The architecture equals to the scenario #1, presented in my previous posting.

 Let’s take a closer look at few key functions.

Server side
This is how the "web server" is implemented. Whenever a client is connected and sends any GET command, the static socketclient.html file is read from local the flash disk at beagle, and send to the browser.

function httpserver (req, res) {
  fs.readFile('sockserv/socketclient.html',
  function (err, data) {
    if (err) {
      res.writeHead(500);
      return res.end('Error loading index.html');
    } 
    res.writeHead(200);
    res.end(data);
  });
}
When WebSocket connection is established, and some data received, the following callback will parse the message, whether the LED should be switched ON or OFF. As an acknowledgement, the same message is transmitted back to the client.

io.sockets.on('connection', function (socket) {
  socket.on('led', function (data) {
    console.log(data);
    if (data == 'on'){
        b.digitalWrite(led, b.HIGH);
        socket.emit('led', 'on');
    }else{
        b.digitalWrite(led, b.LOW);
        socket.emit('led', 'off');
    }
  });
});

Client side
At the socketclient.html page, there is one button to toggle the state of the LED. When the button is clicked, this function transmits JSON message over WebSocket to server.
     
function toggleLed(){
    if ( document.getElementById("ledButton").value == "Switch On" ) {
        socket.emit('led', 'on');
    } else {
        socket.emit('led', 'off');
    }      
}
If acknowledgement is received, it it processed by this callback function, which changes the state of the button, confirming successful operation to user. If you see the label of the button changed, you know the message has travelled back and forth.


socket.on('led', function (data) {
    console.log(data);
    if (data == 'on'){
        document.getElementById("ledButton").value= "Switch Off";
    } else {
        document.getElementById("ledButton").value= "Switch On";
    }
});
There is one flaw in beauty in this code. Once the page is loaded, the button is not initially synchronized with the actual state of the physical LED. Only after clicking the button for the first time, the UI and the LED are in sync. I made this decision by purpose, as I want to keep the example as simple as possible. 

 
Web UI of the demo.


Disclaimer: I’m not a professional JavaScript programmer, actual this was my first Node.JS code written ever, and only few times tried JavaScript before. Thus, the code may not be optimal, and something I may have understood wrong. I warmly welcome any feedback to correct faults, and to make it pedagogically more correct. Well, it just looks like working OK.

WebSocket connectivity for Embedded



WebSocket is not only for web pages, but is good for embedded M2M connectivity as well.

WebSocket is often called as the TCP socket of the Web. And that’s pretty much correct. WebSocket provides full-duplex communication channel in between WS client and WS server. Roles of client and server are relevant only when establishing connection, when communicating it’s irrelevant, as both sides can transmit independently, just like in traditional TCP/IP sockets. 

What’s the added value of WebSocket over conventional TCP socket then?  It’s the browser integration. With WebSocket, browser can open a socket connection easily as instructed by JavaScript code. Opening traditional TCP socket at client side is not trivial at all. Secondly, WebSocket supports TSL/SSL security by nature, no separate security function needs to be implemented.

What makes WebSocket good for Embedded M2M? Well, first of all, it’s standardized, free, and open. It reduces your code size, in case of having both human interface and machine interface, as the same communication module can be utilized for purposes. Most importantly, it gives new freedom in constellation of functionality.

In the old school web architecture, specific application logic was only accessible to client through web server. This means the server must be capable enough to handle that kind of communication, and provide an interface of some sort for application logic integration. Generally speaking, in order to run such a capable web server, a proper CPU w/MMU and a real operating system is needed. We’re talking about something like Espotel Jhumar platform or similar, a device with ARM9 CPU running Linux.
Traditional web architecture.

Thanks to WebSocket, web server and application logic can be totally separated from each other. No need for any interfacing, and they can be located in separate hardware even. In this scenario, web server only needs to provide static HTML/JavaScript code when requested, which makes server implementation super lightweight. One can implement such a server from scratch in matter of hours, with minimal memory footprint.  By instructions given in JavaScript code, the client can then establish WebSocket connection directly to application logic only, for application specific data exchange. 

Our engineers have demonstrated running web server and an application logic with WebSocket support in a Cortex-M0 MCU. I have done that same by myself with Arduino platform. That’s the proof of simplicity. Even the most low-end hardware can do Internet-of-Things, with help of HTML5 technology. If strong authentication and security is needed, then HW requirement is upgradedup  to Cortex-M4 or higher, depending on availability of cryptographic subsystem.

I have recognized 4 different scenarios how to distribute web server and application logic, illustrated in the picture below. 
Different WebSocket architecture options


  1. Integrated - Both server and application logic resides in the same hardware. Stand-alone all-in-one solution.
  2. Pre-loaded – HTML/JS code is pre-loaded in client side, sort of Apps approach. Most lightweight.
  3. Cloud wed – Web service is located in cloud, and data is exchanged directly with embedded device. Easy deployment of new UI features.
  4. Cloud hub – All traffic is routed through cloud. Access through firewalls, and in case of mobile and non-static IP end-points.