Archive

Posts Tagged ‘C/C++’

Top Programming Languages & Operating Systems for the Internet of Things

May 19th, 2017 3 comments

The Eclipse foundation has recently done its IoT Developer Survey answered by 713 developers, where they asked  IoT programming languages, cloud platforms, IoT operating systems, messaging protocols (MQTT, HTTP), IoT hardware architectures and more.  The results have now been published. So let’s have a look at some of the slides, especially with regards to programming languages and operating systems bearing in mind that IoT is a general terms that may apply to sensors, gateways and the cloud, so the survey correctly separated languages for different segments of the IoT ecosystem.

Click to Enlarge

C and C++ are still the preferred languages for constrained devices, and developers are normally using more than one language as the total is well over 100%.

Click to Enlarge

IoT gateways are more powerful and resourceful (memory/storage) hardware, so it’s no surprise higher level languages like Java and Python join C and C++, with Java being the most used language with 40.8% of respondents.

Click to Enlarge

When it comes to the cloud with virtually unlimited resources, and no need to interface with hardware in most cases, higher level languages like Java, JavaScript, Node.js, and Python take the lead.

Click to Enlarge

When it comes to operating systems in constrained IoT devices, Linux takes the lead with 44.1%, in front of bare metal (27.6%) and FreeRTOS (15.0 %). Windows is also there in fourth place probably with a mix of Windows IoT core, Windows Embedded, and WinCE.

Click to Enlarge

Linux is the king of IoT gateways with 66.9% of respondent using it far ahead of Windows in second place with 20.5%. They have no chart for the cloud, probably because users just don’t run their own Cloud servers, but relies on providers. They did ask specifically about the Linux distributions used for IoT projects, and the results are a bit surprising with Raspbian taking the lead with 45.5%, with Ubuntu Core following closely at 44.4%.

Click to Enlarge

Maybe Raspbian has been used during the prototyping phase or for evaluation, as most developers (84%) have been using cheap development boards like Arduino, BeagleBone or Raspberry Pi. 20% also claim to have deployed such boards in IoT solutions.

Click to Enlarge

That’s only a few slides of the survey results, and you’ll find more details about Intel/ARM hardware share, messaging & industrial protocols, cloud solutions, wireless connectivity, and more in the slides below.

Via Ubuntu Insights

How to Write ESP8266 Firmware from Scratch (using ESP Bare Metal SDK and C Language)

October 7th, 2016 9 comments

CNXSoft: This is a guest post by Alexander Alashkin, software engineer in Cesanta, working on Mongoose Embedded Web Server.

Espressif’s ESP8266 had quite an evolution. Some may even call it controversial. It all started with ESP8266 being a WiFi module with a basic UART interface. But later it became clear that it’s powerful enough for embedded system. It’s essentially a module that can be used for running full-fledged applications.

esp8266-bare-metal-sdk

Espressif realized this as well and released an SDK. As first versions go, it was full of bugs but since has become significantly better. Another SDK was released which offered FreeRTOS ported to ESP. Here, I want to talk about the non-OS version. Of course, there are third-party firmwares which offer support for script language to simplify development (just Google for these), but ESP8266 is still a microchip (emphasis on MICRO) and using script language might be overkill. So what we are going to come back to is the ESP SDK and bare C. You’ll be surprised, it’s easier than it looks!

First steps

To develop firmware you’ll need:

  1. ESP8266 connected to your computer via USB.
    There are a lot of articles how to connect an ESP to a computer. You will need several Dupont cables and a UART-to-USB adapter. If you have a Arduino board you can use it as UART-to-USB. Google “connect esp8266 to computer” – there are a lot of articles about this.
  1. SDK.  I suggest using this one: https://github.com/pfalcon/esp-open-sdk

Download it and follow its readme to build. There is nothing extraordinary in this process, all you need is to install prerequisites and invoke “make”.

In general, this SDK is intended for *nix systems, but there is a port for Windows as well.

In short, to start development you should have an ESP device available as /dev/ttyUSB0 (/dev/ttyACM0 if you use Arduino or COMn in Windows) and the SDK installed in a certain path.

main()

In C int main() is an entry point to a program. But, in the case of ESP the entry point is void user_init(). This function must be used only for initialization, not for long-running logic.

Here an example:

Note, that all we do in user_init is calling the system_init_done_cb API function. This function accepts one parameter, which is a pointer to function which will be called once all system modules will be properly initialized. You can put your initialization code in user_init too, but you can face problems with some system function (like WiFi), just because appropriate modules aren’t initialized yet. Thus, it is better to use system_init_done_cb and perform initialization in the callback function.

Beware of the dog

ESP8266 has a watchdog functionality. And there is NO documented API to control it (there is some undocumented stuff, but out of scope for this tutorial). Its timeout is 1 second.

What does that mean? It means, that you have to return the control flow to system every second, otherwise the device will be rebooted. This code leads to the device reboot:

In general, watchdog is not evil, it helps if the program hangs. And, 1 second is not so small as it sounds. Just keep this fact in mind.

Doing something

Taking what we learned about the watchdog into account, we face an obvious question: where can I run my tasks?

The simplest answer is in timers. The timer API is very simple in ESP.

If the last parameter of the os_time_arm function is 0, the timer callback will be invoked only once. If it’s 1, it will be called repeatedly until the os_timer_disarm is called.

And, finally, we have a place to put our code: The start_timer_cb function.

Our task here is to make an LED blink. Some ESP boards have an LED attached to GPIO16, if your board doesn’t have it, you can attach an LED to any free GPIO.

As you remember start_timer_cb is a timer callback function, and it is called every 5 seconds. On first call on variable is 0 and we set GPIO16 to high – as result LED will be turned on. On second call we set GPIO16 to low – and LED is turned off. And so on and so on.

Building the project

Now it is time to build our project. Let’s say, we have only one source file – main.c. I cannot recommend using makefiles which are used for building examples. They are too complicated and a bit weird. So, I’d suggest to write your own (simple!) makefile.

Here are steps:

  1. Compile main.c to main.o.
    Use xtensa-lx106-elf-gcc compiler which is a part of esp-open-sdk.
  2. Link project.
    Linker to use – the same xtensa-lx106-elf-gcc. Libraries to link with are: c gcc hal m pp phy net80211 wpa main

Also, you need to supply the linker script (.ld file). Choose one from esp-open-sdk that matches the flash size of your device. After this step you’ll have .elf file.

  1. Convert .elf file to .bin

For this, use esptool.py script from esp-open-sdk. Run it like this:

If everything is ok, you should have 3 files in <output dir> with names like 0x00000.bin, 0x11000.bin 0x66000.bin.

Flashing

The final step is to put our firmware onto the device. For this we will use the esptool again, but now we should use write_flash option. Like this:

You should use real filenames from the previous step. And, if everything is still OK, the LED attached to the device will start to blink every 5 seconds.

Next steps

Writing the firmware for any device is a huge topic. Working with ESP8266 is no exception. So, the purpose of this article is only to highlight the direction. There are a lot of different APIs in the ESP8266 SDK: WiFi, GPIO, TCP/UDP and more. Make sure to check out the documentation fully here. It’s also good to check out the examples by firmware providers and esp-open-sdk. If you want to start with an example, check out this one which goes through running Mongoose Embedded Web Server on ESP8266.

Top 10 Programming Languages in 2016 for Embedded Software Development

July 27th, 2016 6 comments

IEEE Spectrum has published a list of the top programming languages in 2016 for Web, Mobile, Enterprise, and Embedded sectors with rankings created by weighting and combining 12 metrics from 10 sources. So I thought it would be fun to have a look at the top 10 of languages used for embedded software, and the results are:

Top_10_Embedded_Programming_Languages_2016As expected, C and C++ are at the top, but I’m quite surprised that “Arduino” is now considered a programming language, as it is simply based on C/C++.  When I worked as an embedded software engineer a few years ago, I personally used C, and Assembly, and to a lesser extend C++ and VHDL. I only recently started to play with Arduino code, and while I’ve heard of most other languages in the list, it’s the first time I’ve ever seen Ladder Logic, probably because it’s designed to program PLCs in industrial control applications.

The methodology used is interesting, as the company did not survey actual engineers or developers, but instead used data from technical, social and job search websites, such as Github, Twitter, or CareerBuilder, to generate the rankings.

The Eclipse Foundation Releases Open Source Smart Home & IoT Gateway Frameworks, MQTT & oneM2M Implementations

June 17th, 2016 3 comments

The Eclipse Internet of Things (IoT) Working Group has released – or soon will be releasing – four open source projects for the Internet of Things with Eclipse SmartHome 0.8 framework, Eclipse Kura 2.0 IoT gateway framework, Eclipse Paho 1.2 MQTT & MQTT-SN clients, and Eclipse OM2M 1.0 implementation of oneM2M standard.

Eclipse_IoTEclipse SmartHome 0.8

Eclipse SmartHome is a framework for smart home solutions that runs on embedded devices, including Raspberry Pi, BeagleBone Black or Intel Edison development boards.

The latest SmartHome 0.8 release includes a new REST API and corresponding “Paper UI” administration interface, support for new devices including Sonos speakers, LIFX bulbs, Belkin WeMo devices, digitalSTROM systems, EnOcean devices (via a new OSGi EnOcean Base Driver) and others, as well as a new rule engine supporting templates for beginners, JavaScript for automation rules and graphical rule editors.

You can find more details on Eclipse SmartHome page, and/or download SmartHome 0.8, and optionally SmartHome Designer for Linux, Mac OS X, or Windows.

Eclipse Kura 2.0

Eclipse Kura is a framework for building IoT gateways with the latest Kura 2.0 release to bring a new responsive user interface (UI), support for multiple cloud connections to Eurotech Everyware Cloud, Amazon AWS IoT, Microsoft Azure IoT and IBM IoT Foundation, new tools and code samples to ease the creation of Kura applications, and tighter integration with Apache Camel.

Eclipse Kura 2.0 will be available later in June. You can find more details, including instructions to use it on BeagleBone Black and Raspberry Pi boards on Eclipse Kura page. Kura is also found on commercial M2M and IoT gateways such Eurotech ReliaGATE 15-10.

Eclipse Paho 1.2

Paho MQTT Clients Features Comparison (Click to Enlarge)

Paho MQTT Clients Features Comparison (Click to Enlarge)

Paho provides an open-source client implementations of the MQTT and MQTT-SN messaging protocols in Java, Python, JavaScript, C, .Net, Android and Embedded C/C++ client libraries. Paho 1.2 release adds automatic reconnect & offline buffering functionality for the C, Java and Android Clients, webSocket support for the Java and Python Clients, and a new Go Client for Windows, Mac OS X, Linux and FreeBSD.

Visit Eclipse Paho page for more details about the implementations and to download the latest 1.2 version.

Eclipse OM2M 1.0

Eclipse OM2M is an open source implementation of the oneM2M standard, and the version 1.0 includes the following features:

  • Modular platform architecture, based on OSGi making it highly extensible
  • Lightweight REST API exposed through multiple communication bindings including HTTP and CoAP protocols and supporting various content formats such as XML and JSON.
  • Flexible data storage based on an abstract persistence layer supporting embedded & server databases, in-memory mode, SQL & NoSQL models.
  • Implementation of  Dedicated Common Service Entity (CSE) for Infrastructure node (IN), Middle Node (MN), and Application Service Node (ASN), and Common Service Function (CSF) including: Registration, Application and Service Management, Discovery, Data Management and Repository, Subscription and Notification, Group Management, Security, etc.
oneM2M Functional Architecture with AE (Application Entity), CSE and NSE

oneM2M Functional Architecture with AE (Application Entity), CSE and NSE

Version 1.0 release will be available later this month, you can find out more on Eclipse OM2M page.

The foundation has also issued a proposal for Eclipse Kapua open source project aimed to create a modular integration platform for IoT devices and smart sensors.

You can also check out other open source IoT projects on Eclipse IoT microsite.

ELLO 2M is a DIY Computer with a Keyboard, a 7″ Touchscreen Display and a Prototyping Area (Crowdfunding)

May 28th, 2016 11 comments

The traditional way to play with electronics is to get a board (e.g. Arduino), a breadboard to wire components & sensors to the board, and a computer for programming.  ELLO 2M combines all that into a single piece of hardware with a 7″ touchscreen display, a Microchip PIC32 micro-controller board, a solderless prototyping area made of PGA sockets, and a keyboard.

ELLO_2MELLO 2M hardware specifications:

  • MCU – Microchip PIC32MX470 32-bit micro-controller @ 120 MHz with 128kB RAM (512kB RAM in the ELLO 2M “hacker” versions)
  • Extra System Memory – Optional on-board serial non-volatile data RAM
  • Storage – 3x micro-SD cards (one permanently built-in and two for removable storage); internal serial FRAM
  • Display – 7″ LCD touch-screen panel with 800×480 pixel resolution
  • Audio – Small speaker and buzzer
  • Keyboard – Replaceable QWERTY keyboard
  • Connectivity – 2.4GHz RF communication module with simple communication protocol
  • Expansion – Expansion receptacle, electronic prototyping space with up to 1156 holes
  • Misc – Real-time clock
  • Battery – 4,500mAh battery for up to 12 hours of continuous operation (more in power-saving mode)
  • Dimensions – six stacked circuit boards with 6.4mm total height without socket

ELLO_M2_BASIC_Game

ELLO 2M uses BASIC, which incidentally is the first programming language I first learned many years ago, but C language programming is also possible. More precisely ELLO runs MMBasic implementation released under a Creative Commons License. The project is also open source hardware with all design files released on github.

Konstantin Dimitrov, the project developer, has taken to CrowdSupply to raise funds for mass production. A $65 pledge will get you the six bare PCBs (shown in the video above), so that you can purchase and solder the components yourself, but most people may want an assembled version with price starting at $180 for Ello 2M Developer which does not include the prototyping area, and you’d need to pledge $240 to get Ello 2M Geek with the built-in prototyping board.  You can also request your own custom keyboard panel-out for $550. Shipping is included in the prices, and delivery is scheduled for September 2016.

Via Liliputing and Geek

GNU Complexity Command Line Tool Measures Complexity of C Code

March 1st, 2016 4 comments

GNU complexity is a command line tool that computes a complexity measure of C source code, similar to pmccabe, but with a different method of calculating results with short functions scoring lower than pmccabe and highly nested functionality can score considerably higher. It can be useful to locate suspicious areas in unfamiliar code, get an idea of the efforts required to either understand the code or test it, or self-assess your own code.

Bruce Korb, the maintainer, has just released version 1.5 with some bug fixes, so I’ve given it a quick try.

We’ll need to get the code, build and install it first:

The user’s manual provides some insights and an example, which I’ve used against a directory in Linux source code:

The resulting table shows six information per line: the computed score, the number of lines between the opening and closing curly braces (ln-ct), the number of non-comment, non-blank lines found there (nc-lns), the name of the source file, the line number of the opening curly brace, and the name of the procedure. The higher the score the more complex is the procedure, and thres parameter is used to remove the lowest complexity function from the list. The ranking goes as follows:

  • ‘0-9’ – Easily maintained code.
  • ‘10-19’ – Maintained with little trouble.
  • ‘20-29’ – Maintained with some effort.
  • ‘30-39’ – Difficult to maintain code.
  • ‘40-49’ – Hard to maintain code.
  • ‘50-99’ – Unmaintainable code.
  • ‘100-199’ – Crazy making difficult code.
  • ‘200+’ – I only wish I were kidding.

Have fun.

Marvell EZ-Connect MW302 IoT Starter Kit Supports AWS IoT Cloud Services

October 9th, 2015 6 comments

Amazon has just launched AWS (Amazon Web Services) IoT (Beta), a cloud platform that lets connected devices securely interact with cloud applications and other IoT devices. As pasrt of the announcement, they also released AWS IoT SDK that comes in three flavors:

  • Embedded C SDK for C-based platforms such as Linux, RTOS, with variants for OpenSSL and mbed TLS.
  • JavaScript SDK in Node.js
  • Arduino Yún SDK.

Ten started kits are currently officially supported by AWT IoT, many of them being existing platforms such as LinkIt One, BeagleBone Green, Intel Edison, or TI LaunchPad CC3200,  with several of these kits including SeeedStudio’s Grove modules.

Marvell MW302 IoT Starter Kit (Click to Enlarge)

Marvell MW302 IoT Starter Kit (Click to Enlarge)

One of the kits that’s completely new, at least to me, is Marvell EZ-Connect MW302 IoT Starter Kit which include a mini USB to USB cable, and Marvell 88MW302 development board with the following (preliminary) specifications:

  • SoC – Marvell EZ-Connect MW302 ARM Cortex-M4 WiSoC with 512KB SRAM
  • Storage – No info
  • Connectivity – 2.4Ghz b/g/n Wi-Fi (built-in MW302 MCU
  • USB – 1x micro USB OTG,
  • Debugging – 1x mini USB for UART console and JTAG, 1x 10-pin JTAG connector
  • Expansion headers – 2x 32-pin header with access to SPI, I2C, UART, I2S, PWM, ADC, DAC, as well as power signals and GND.
  • Misc – Reset key, four buttons, various jumpers, two LEDs
  • Power Supply – 5V DC via power jack
  • Dimensions – N/A
Marvell 88MW302 Board (Click to Enlarge)

Marvell AB-88MW30X V2.0 Board (Click to Enlarge)

Information about Marvell MW302 SoC is limited to the product page, and more details require an NDA. Documentation for the kit is slightly better, with the SDK soon to be released on Github, and a getting started guide explains how to use AWS IoT dash with the board to monitor key presses, blink LEDs, and trigger actions with AWS IoT to AWS Lambda feature, which appears similar to what TI Connected LaunchPad does with Exosite cloud platform.

MW302 IoT Starter Kit is listed on Amazon for $49.90, but currently out of stock.

LimiFrog is a Bluetooth 4.1 Wearables Devkit Based on STM32L4 with Lots of Sensors (Crowdfunding)

September 4th, 2015 3 comments

LimitFrog is a tiny board powered by STMicro STM32-L4 microcontroller with Bluetooth 4.1 connectivity, plenty of sensors, and that can run code bare metal as well as RiOT real-time operating system.

LimifrogLimiFrog specifications:

  • MCU – STMicro STM32-L4 ARM Cortex M4 micro-controller @ 80 MHz with DSP, 512KB flash, 128KB RAM
  • External storage – 8MB serial flash for data that supports FAT32 file system
  • Display – 160×128 RGB565 OLED display
  • Connectivity – Bluetooth 4.1 (Panasonic PAN1740)
  • Sensors (Follow this link for datasheets of most components)
    • Pressure, altitude & temperature (LPS25H)
    • 3-axis accelerometer, 3-axis gyroscope (LSM6DS3)
    • 3-axis magnetometer (LIS3MDL)
    • Ambient light, proximity and distance (VL6180X)
    • Ambient sound (SPU0414H5H)
  • USB – micro USB port for power and programming
  • Expansions – 11-pin (through holes) providing access to SPI, I2C, CAN, PWM, GPIOs, ADC, DAC, Analog out, and power signals (3V out GND)
  • Battery – 500 mAh (hours to weeks of battery life depending on application)
  • Dimensions – N/A (but small)

Limifrog_block_diagramThe “basic” version does not come with sensors, Bluetooth 4.1, nor OLED display, so these are optional, and three more versions are offered “Sense”, “Sense’m comm” and “Full Monty” if you want more features.

LimiFrog can currently be programmed in C/C++, and MicroPython support is in the works. The libraries include a USB stack, a FAT file system, and graphics support. As mentioned in the introduction, programs can run bare metal, or using RiOT real-time operating system.

Software Architecture

Software Architecture

The company also provided a code sample in C if you want to check what the API looks like.

The project has launched on Kickstarter, and rewards start at 39 Euros for the “basic” version of the board with a LiPo battery, software packages, 3D printer files for the case, and up to 99 Euros for the “full monty” including Bluetooth 4.1, the OLED display, and all sensors. Delivery is scheduled for January 2016, and shipping costs between 8 and 12 Euros depending on the chosen rewards. More information may also be found on Limifrog.io.