Use Lua To Address M2M Development Challenges

Oct. 16, 2012
Lua is a scripting language that provides a flexible M2M development and deployment environment for deeply embedded applications.
The development of machine-to-machine (M2M) embedded solutions presents some specific challenges, compared to other embedded applications:
  • Embedded devices operate in the field, often distributed over large geographical areas.
  • There is no human operator to troubleshoot or maintain them.
  • They come in potentially large fleets that must be managed collectively and effectively.
  • Communications happen largely over wireless networks.
  • They integrate many different fields of expertise: hardware, embedded software, networking, wireless, collaboration with telecom operators, server-side software, and user interfaces. While none of these fields are beyond the reach of a competent R&D department, very few departments master all of these skills simultaneously.

Moreover, and contrary to what many would guess, only 5% of the typical costs of an M2M project go to hardware, according to an Analysys Mason Report.1 Also, 17% is spent on communication fees, and a staggering 78% is spent on application design and provisioning.

Given how much of the total cost they represent, R&D teams must be equipped with all the productivity tools they can afford. Investing in tools is generally more important than saving a couple of CPU cycles on the hardware, although this approach runs contrary to the habits of many embedded development shops.

Language And Tools

Lua offers powerful expressiveness, ease of learning, embeddability, and easy co-habitation with C.2 Like its close siblings Python and Ruby, it saves a lot of development and maintenance time—or allows designers to keep larger applications under control—by removing large classes of programming errors and saving a lot of boilerplate low-level code, which provides advanced and reliable data structures and offers effective control over concurrency matters.

Proper tools have also become a must. A good integration development environment (IDE) enhances the mastering of today’s extensive libraries, through integrated documentation, smart auto-completion, templates, and code analysis tools. It also allows better control of embedded devices through simulation, local or distant debugging (bugs only occurring in the field are a common nightmare of M2M maintenance), and interactive exploration of live devices.

There is a strong demand for tools enabling the creation and deployment of an M2M solution without a dedicated development team. Some tools permit you to quickly sketch a monitoring and reporting application, provided the appropriate drivers are available and the business logic remains very simple and standard.

Such tools are very valuable. They let people take the first step toward M2M empowerment of their business. But if the solution proves valuable, it’s likely to grow in complexity, and soon enough it will become a very specialized application maintained by developers.

Rapid prototyping tools must not impede this transition. Any generated application must be readable, modifiable, and extensible for developers, and those developers must not be limited by the constraints of the prototyping tool. If you don’t plan in advance for this evolution, you’re painting yourself into a corner.

Embedded Libraries

Dedicated libraries must support the most obvious M2M activities, including data acquisition and actuator control: general-purpose I/O (GPIO), analog-to-digital converters (ADCs) and digital-to-analog converters (DACs), controller area networks (CANs), I2C, or ZigBee, for example. Increasingly, media from the PC world, such as Ethernet or USB, is finding its way into embedded systems.

A recurring issue with embedded I/O is that hardware providers tend to create custom protocols over serial for every other peripheral. Since there only are so many ways to dialog on a serial line, a proper “serial framework” library can save a lot of boilerplate code and standardize the implementation of those protocols.

Embedded systems are often distributed locally across several CPUs, sensors, and actuators. (For instance, consider a home automation and alarm system.) In such systems, remote sensors and actuators are handled by very minimalist micro-controllers and report raw data to the smart gateway, which will filter, sample, consolidate, and report that data with more sophistication. As such, the gateway needs to understand a standard, simple protocol easily implemented on smaller controllers.

Finally, many M2M applications can be seen as monitoring systems. They sample data, consolidate and report some of it, use some other data as triggering events, and optionally drive some actuators according to local or network-induced triggers. A comprehensive M2M library should provide a monitoring library, which will help in architecting the whole application in a standard way and save a lot of generic boilerplate code.

Over-The-Air Updates

However well planned and debugged a solution might be, if it is kept alive for long enough, some changes will require updating the embedded software. This is challenging because of wireless network constraints. Also, large fleets of devices must be handled concurrently. And without a human operator to troubleshoot failed updates, the process must be extremely robust. To sum up, updating M2M software over the air is best left to specialists. Embedded update systems as well as update campaign management servers must be offered as turn-key, robust solutions to non-specialist developers.


Different estimates predict between 2 billion and 50 billion M2M devices in 2020.3, 4 Therefore, wireless communications will remain a challenge for M2M applications in the foreseeable future. Optimizing the way data is exchanged and handling the retries and fallback systems will remain specialized skills and will require adaptation along the application’s lifecycle.

A specialized agent must handle communication policies, then, which must be easily updated remotely and open to future improvements such as operator-controlled load shedding. The most effective way to do so is to associate data exchanges with specific policies (e.g.,  “urgent,” “regular,” “when-idle…”). These policies’ behavior can be controlled through declarative data, pushed and updated from a central server like any other data exchanged from the server to the devices.

One Solution

Having acquired these insights through years of M2M expertise, Sierra Wireless has developed AirVantage M2M Cloud, tailored to address these requirements. The ALEOS Application Framework provides a way to handle smart interactions between devices and the Cloud, a rich set of embedded libraries, and a state-of-the-art development environment.

Sierra Wireless also provides ready-to-use hardware devices for faster and cheaper solution design and deployment.

The development framework is based on Lua, a modern, embedded-friendly and very quickly learned language.5 It has been proposed as a new open-source project, Mihini, under the umbrella of the M2M Industry Working Group imitative, and it will be available in early 2013.

Our Eclipse-based IDE offers all the features one can expect—project management, supply chain management (SCM) integration, content assist, integrated documentation, interactive execution and debugging on remote target hardware, generation of software update campaign packages—all as an open-source, commercially friendly solution (

It comes with a set of dedicated M2M libraries to address the recurring issues faced by solution designers. An autonomous embedded agent takes care of the most sensitive issues such as update over-the-air or communication management, which can be controlled completely from the AirVantage Cloud.


  1. The total cost of ownership for embedded mobile devices,” Lee Sanders, Ian Streule, and Gilles Monniaux.
  2. Accelerate Embedded Development With Lua,” Fabien Fleutot.
  3. Imagine An M2M World With 2.1 Billion Connected Things,” Steve Hilton.
  4. More Than 50 Billion Connected Devices."
  5. Lua in the Gaming Industry Roundtable Report."
About the Author

Fabien Fleutot

Fabien Fleutot is a technical expert at Sierra Wireless. He is an expert in embedded systems and programming languages semantics, as well as an active member of the Lua community. He has more than 12 years of experience with embedded, distributed, and networked systems, both in academia and in the industry, including five years at Sierra Wireless designing better ways to create and deploy M2M solutions.

Sponsored Recommendations


To join the conversation, and become an exclusive member of Electronic Design, create an account today!