A shortcut to embedded SmartMesh networks

In the emerging world of Internet-of-Things, wireless low-power mesh networks are more relevant than ever. Data Respons has gained valuable experience with one particular technology after employing it in a large industrial instrumentation project, namely Linear Technology’s SmartMesh IP. As a specialist on embedded solutions, Data Respons recently became an official Linear SmartMesh partner, after developing the QuickStart Library: A software library that greatly reduce development time for embedded applications of SmartMesh IP.

Mesh-to-the-edge

SmartMesh IP is a wireless technology pioneered by the Linear Technology owned company Dust Networks. A descendant of ultra-low power and ultra-high reliability protocols such as WirelessHART, the SmartMesh IP protocol is based on the 6LoWPAN and 802.15.4e standards. It features a time slotted, channel hopping mesh network where every node knows exactly when to listen, talk or sleep, resulting in a very power efficient and collision-free packet exchange. Every device in the mesh network has the same routing capabilities, often referred to as “mesh-to-the-edge”, as it provides redundant routing to the edge of the network. This allows for a self-forming and self-healing network that constantly adapts to changes in topology, while maintaining an extremely high data reliability, even in harsh frequency environments.

Motes and manager

A SmartMesh IP network consists of one or several wireless nodes, known as motes, which collect and relay data, and a network manager. The manager has two fundamental functions: Firstly, it is an access point (AP) that acts as a gateway between the mesh network and the monitoring or control network. Secondly, it runs the network application software that continuously makes decisions on how to build and maintain the mesh network.

Figure 1: SmartMesh IP network with an Embedded Manager

The Embedded Manager is a self-contained solution where both the AP function and the network management algorithms runs on a single chip. This setup however, illustrated in Figure 1, is limited for smaller networks, as the single AP has a hardware constraint of 100 motes and a throughput of 36.4 packets per second. The customer software communicates with the manager directly through a serial Application Programming Interface (API).

Figure 2: SmartMesh IP network with a Vritual Manager

A second, new alternative is the Virtual Manager, where the network application runs on an x86 virtual machine, while only the AP functionality remains on-chip. The AP, together with a bridge SW on a locally connected MCU or PC, then constitutes an AP gateway that connects remotely to the virtual manager. This connection can be serial, Ethernet, wifi or even cellular, as long as it can support the maximum throughput of 40 packets per second from the AP. In this setup, illustrated in Figure 2, the customer application interacts with the virtual manager through an HTTP-based API. Adding multiple aps can scale the network to support thousands of motes, as well as increase the available throughput, reduce latency or achieve redundancy.

Figure 3: Master or Slave – The two modes of a SmartMesh IP mote.

Master and slave

The typical use for a mesh network is to publish sensor data from each node to a centralized application for processing, storage and/or visualization. As illustrated in Figure 3, a smartmesh IP mote can operate in two different modes. Running in a master mode, the on-board ARM Cortex-M3 processor can access sensors and other I/O directly, where it runs an application that terminates commands and controls network joining. An On-Chip Software Development Kit (SDK) allows a user to write applications directly on the mote, on top of the smartmesh IP network protocol stack. Alternatively, the mote can run as a slave to a connected device, expecting the master device to terminate commands and control network joining via a serial API. This puts more complexity in the hands of the user, but is often the most viable option in an embedded solution, as a custom MCU adds more flexibility.

C library

Since both the smartmesh mote and embedded manager has a similar serial API that the typical embedded application has to interact with, Linear provides a complete implementation of both in the smartmesh C Library. This library abstracts commands into simple function calls, handling serial formatting and framing for the high-level data link control (HDLC) protocol used in all serial communication with smartmesh devices. The library also makes sure to match sent commands with ensuing replies, passing them back through a callback function. Notifications received from the smartmesh device are also parsed and correctly acknowledged, before they too are passed back “up” through a callback function. Still, implementing the API itself is not necessarily the hardest part. On the manager-side there is little to no required intervention, as it will autonomously start creating a network upon power-up – The connected customer software simply need subscribe to the desired notifications, while commands and interactions are stateless, and thus reasonably straightforward. By contrast, on the mote-side a software designer has to be aware of mote states and corresponding behavior, as well as the correct sequence of configurations and commands to join a network. Linear found that this knowledge barrier sometimes prevented potential customers from embedding smartmesh IP in their applications, which is why the need for a simpler starting point emerged.

Quickstart library

The quickstart Library (QSL) developed by Data Respons abstracts the mote interface one step further: A finite state machine (FSM) schedules the necessary sequence of commands depending on the current state, events and replies from the mote, leaving only a minimal and intuitive API for the user. For example, the steps necessary to configure the mote, set up sockets, initialize a search for and join a network, as well as request a certain bandwidth, are all hidden in a simple call to connect. Downstream user payloads are also handled by storing them in a circular inbox buffer with a configurable size, where calls to read will pop the oldest message in the inbox, if any. Send queues a payload for transmission to the manager, while is Connected is a simple way to check if the mote is still connected (this way the user application can determine if a failed send is the result of not being connected or an actual transmission failure). Lastly, init should be called once upon startup, and will simply initialize the data structures and establish the serial connection to the mote. Except for read, which returns the number of bytes read, the API only returns simple Booleans to let the user application know if an attempt was successful, avoiding the need to interpret any response codes. Furthermore, send and connect has a configurable timeout such that the user application can be sure that their call will return within a set limit. While send only makes one attempt at queueing a packet, connect keeps trying to join a network until successful or the configured timeout occurs.

Figure 4: The QuickStart Library structure.

Platform independent

Designed to be highly portable, the QSL (and the underlying C Library) is written in C without any hardware-specific code, allowing its use “as-is” in any C-based platform. Platform dependent functions only have their prototypes implemented, leaving their definition to the user. For instance, a developer has to define how to feed the watchdog (if any) or how individual bytes are written to or read from the serial port. Figure 4 illustrates the library structure, where the hardware specific categories that need definitions are listed to the left (watchdog and lock for concurrency is optional).

To further help developers get started, complete sample code is provided for a set of commonly used platforms: Raspberry Pi, Atmel SAM C21 and STM32, as well as a generic example for the ARM mbed operating system. Sample code for these platforms also include implementations of the necessary prototypes.

Rapid mesh network prototyping

QSL is accompanied by a detailed guide, with step-by-step instructions on how to get started with the typical case of data publishing from an external MCU. The guide also explains how to get a demo up and running with the sample code provided for the supported platforms. It also includes guidance on existing tools that can visualize data arriving on the manager-side, as well as transmit data downstream to motes. This allows a developer to integrate a prototype mesh network with their embedded system within only a few hours. As the name entails, the QSL is primarily meant to help developers get started with embedding smartmesh IP in their applications. The library is not an exhaustive API for the smartmesh IP mote, although its interface is adequate for most simple applications, as it provides functionality for data transmission and configuration of the most important network settings. Furthermore, by extending its functionality or simply by using it as a thorough how-to, the QSL can reduce development time for advanced applications that require more features from the underlying mote interface.

Note:
On March 10th, 2017 Linear Technology Corporation officially became part of Analog Devices. Inc