Wednesday, August 14, 2013

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.

No comments:

Post a Comment