# Programming for IoT

## Summary


Programming for IoT is usually a polyglot (multiple languages) effort since the Internet-of-Things (IoT) is a system of inter-related computing devices that are provided with unique identifiers and the ability to transfer data over a network. The choice of programming-language depends on the capability and purpose of the device. IoT encompasses a variety of devices including edge devices, gateways, and cloud servers.

## Discussion

### What are the popular languages for IOT?

The most popular languages in IoT are **Java, C, C++, Python, Javascript, Node.js, Assembler, PHP, C#, Lua, R, Go, Ruby, Swift and Rust** in descending order of popularity. This is from a 2017 online survey co-sponsored by Eclipse IoT Working Group, IEEE IoT, AGILE IoT and IoT Council in which 713 individuals participated.  

Other languages include **Parasail, Microsoft P, Eclipse Mita, Kotlin, Dart, MicroPython, and B#**. 


### Which languages are suitable for edge devices, gateways and cloud computing?

 

    + **Edge Devices** - These are constrained-resource embedded systems. For very small devices (higher constraints), **Assembly and C** are the languages of choice. A better processor and more computing power on the device enables one to use **C, Python, Node.js, Java**. The focus is to minimize instruction count, and maximize execution speed and resource management.
    + **Gateways** - Gateways manage communication and do analysis of data from many devices through several different buses. More languages can be run on these devices because of their increased computing power, including **C, C++, Java, Python, and Node.js**.
    + **Cloud** - With the nearly unlimited computing capability that's available, frameworks like **Apache Hadoop** and **HiveQL** can compute and process large IOT datasets. Statistical computing and visualization can be done using languages like **R** or **Julia.**

### What are the approaches used in IoT application development?

    + **Node-Centric Programming** - Every aspect is programmed by the developer like communication between nodes, collection and analysis of sensor data, issuing commands to actuator nodes. Interaction between devices is explicitly encoded.
    + **Database approach** - Every node is considered part of a database and the developer can issue queries to sensor nodes. Focus is on collection, aggregation and sending of data to the base station.
    + **Macro programming** - Abstractions are provided to specify high-level communication.
    + **Model-driven development** - Application development complexity is reduced by increasing the level of abstraction and by describing the system using different system views. The vertical separation of concerns (SOC) reduces app development complexity by separating platform-independent model (PIM) and platform-specific model (PSM). The horizontal separation of concerns separates different aspects of a system.

### What are the features to consider when evaluating IoT programming frameworks?

The following features are relevant:

    + **Scalability** - Programming frameworks that support diverse programming patterns that are able to perform load-balancing dynamically.
    + **Concurrency** - Real-time communication between millions of devices and applications mean millions of concurrent connections. Thread locking is not efficient in such situations.
    + **Coordination** - Programming language support for explicitly (control driven) or implicitly (data driven) orchestrating the role of computing elements.
    + **Heterogeneity** - Programming framework gives guidance on how computations are mapped to the computing elements.
    + **Fault tolerance** - Applications should be able to gracefully go from online to offline state as networks partition and heal their connections.
    + **Light footprint** - In terms of runtime overhead and in terms of programming effort the framework should be light.
    + **Support for latency and sensitivity** - In geographically distributed applications, pushing all computations to the cloud is not ideal. The programming framework has to handle these requirements dynamically.

### What programming paradigms are suitable for IoT?

A programming paradigm is a way to classify the programming language based on its execution model. It should be kept in mind that a particular language can below to more than one paradigm. The following programming paradigms are suited for IoT:

    + **Functional** - Functional programming helps solve the challenges of scalability and concurrency. Its preference for immutability, function composition, avoiding side-effects, less code, etc. avoid several IoT pitfalls.
    + **Dataflow** - Dataflow programming emphasizes the movement of data. It models programs as a series of connections. Explicitly defined inputs and outputs connect operations. An operation runs as soon as all of its inputs become valid. Dataflow languages are inherently parallel and can work well in large decentralized systems.
    + **Event-Driven** - Event-driven programming (events triggered by sensors, connectivity, or time) is well suited to IoT where devices spend most of their time in power-saving modes, wake up due to some event, process data, send it out, and go back to sleep.

### Are there any specific requirements that the languages should satisfy to be used for IoT?

Developers can consider the following:

    + Languages that support Functional, Dataflow, or Event-driven programming.
    + Interpreted languages (Python) are slower than compiled ones (C/C++/Rust/Go).
    + Type safety, memory management, no null pointer exceptions. Languages such as C and C++ use explicit pointers to reference memory. Incorrect pointer calculations can lead to buffer overruns and memory access violations.
    + Availability of GPIO libraries.
    + Libraries that support IoT protocols like Advanced Message Queuing Protocol (AMQP), Constrained Application Protocol (CoAP), Extensible Messaging and Presence Protocol (XMPP), OASIS MQTT, or Very Simple Control Protocol (VSCP).

### Within languages, are there any specific variants, modules or libraries that enables IOT?

    + In Python, "mraa" and "paho-mqtt" are useful for IoT. . MicroPython can be used on constrained devices.
    + Java first appeared in the 1990s for a resource-tight embedded environment, requiring minimum computing power. Many of the Oracle Java ME Embedded APIs are targeted at the needs of embedded systems.
    + Eclipse Mita is a new programming language designed to feel like modern programming languages in the vein of TypeScript, Kotlin, and Go. It helps scale from prototypes to commercial IoT deployments by transpiling to C code.

### Could you share some best practices for IoT developers?

Choose a programming framework that promotes design reuse, implementation reuse and validation reuse in order to enhance software extensibility, flexibility and portability. To make distributed IoT microservices resilient, developers should be able to specify precise sequence of execution steps to be taken by compiled code, regardless of the order in which asynchronous event messages are processed. 


### Could you list IDEs, debuggers and tools for IoT programming?

IDEs and tools for IoT are many and we list some of them below: 

    + **Eclipse IOT project (Kura)** - This is a Java-based development framework for IoT applications.
    + **Arduino IDE** - This IDE includes support for the C and C++ programming languages for programmable microcontrollers. It's a complete package with many examples and pre-loaded libraries.
    + **Raspbian** - This IDE comes with many packages and examples created specifically for the Raspberry Pi boards.
    + **OpenSCADA** - This project is a part of Eclipse IOT Industry Working Group along with Eclipse SCADA (Supervisory Control and Data Acquisition). It provides several libraries, interface apps, and configuration tools.
    + **PlatformIO** - This is a cross-platform IDE that supports over 400 embedded boards, and several development platforms and frameworks.
    + **Macchina.io** - This is a toolkit for building embedded applications for IoT using POCO C++ libraries and the V8 JavaScript engine. The core is implemented in C++. JavaScript is used for application development. It enables dynamically extensible modular applications using the plug-in and services model similar to OSGi in Java.


## Milestones

Nov  
2005

International Telecommunications Union publishes the 7th in its series of reports on the Internet, titled “The Internet of Things.” 

Oct  
2013

IBM releases version 0.2.0 of **Node Red**, a visual wiring tool for IoT. In 2016, IBM contributes Node-RED as an open source JS Foundation project.

Nov  
2013

Damien George launches **MicroPython**, a software implementation of the Python 3 programming language, written in C, that's optimized to run on a microcontroller. 

Oct  
2015

Lars Bak and Kasper Lund of Google announce the **Fletch** project for the **Dart** programming language to optimise it for Internet of Things (IoT) devices.  

2016

Microsoft open sources **P**, a language designed for asynchronous event-driven programming, which it considers vital for the cloud, artificial intelligence and IoT.  

Mar  
2017

Team **KinomaJS** starts **Moddable**, a new company building tools for developers to create open IoT products using standard JavaScript on low cost microcontrollers. KinomaJS is a JS application framework optimised for IoT. KinomaJS was previously supported by Marvell Semiconductor.  

May  
2017

Google makes **Kotlin** (JetBrains), a statically typed programming language for JVM, a first class language for Android Apps and its Android Things IoT Platform. 

Mar  
2018

Eclipse announces **Mita**, a language that aims to remove the entry barrier to embedded IoT development. Mita is transpiled to C code. It combines imperative programming with model-driven configuration.

Mar  
2018

The Linux Foundation announces **ACRN**, an open source reference hypervisor project designed for IoT device development.