• March

    8

    2016
  • 2157
  • 0

Building Micoservices based IoT with Enduro/X middleware platform

Overview

Microservices based systems in nowadays gains popularity as the same with Internet of Things (IoT) concept. The microservices based architecture allows to build efficient and scalable appliances. In this tutorial we will build temperature logging appliance based on Raspberry Pi (RPI), Dallas semiconductor DS18B20 sensors, Enduro/X Application Server for Go and MariaDB database. There will be two temperature sensors connected to the appliance and both will be logged to database with. Each sensor will be assigned tag, which is record in database. This small project is named “frog”.

The Sensor

The hardware wiring is following:

connect-multiple-ds18b2-i2c-sensors-raspberry-pi

DS18B20 Temperature sensor wiring (source: http://www.reuk.co.uk/OtherImages/connect-multiple-ds18b2-i2c-sensors-raspberry-pi.jpg

Sensor driver

The operating system used for Raspberry Pi is Rasbian (https://www.raspberrypi.org/downloads/raspbian/). To get sensors working, the boot parameters of Rasbian linux boot parameters must be changed (info source):

add the following line to the bottom :

After this reboot the RPI. When system is booted back, sensors should be available at:

exds_temp_sensors

The Golang compiler

When sensors are ready for work, Google Go compiler is installed (according to: Info source). In short:

Building the Enduro/X

Enduro/X is built according to Building Guide, but instead of “user1″ user “pi” is used. In short:

Designing the appliance

The system consists of several client processes which reads the sensor files and do posts to server process which writes that data to database. The concept can be seen here:

exds_components_1

For each sensor there is own “client” process (name of the executable) running. And there is Enduro/X service “TEMPLOG” advertised by “server” (name of executable) process.

Creating the “templog” application structure

The appliance

This section describes the application.

Project directory structure

Build environment & go packages

The build environment we defined in source file “~/templog/set”:

This basically sets the GOPATH variable and loads the runtime environment (to conf/setndrx to be defined later). Before continue to develop the appliance, load the environment with following command:

Defining the UBF IPC buffer

The UBF buffer is used for “client” process which reads the sensors and call the server process for data logging. Buffer should contain data about the sensor (inside or outside), this basically is “tag”, string format. And buffer shall contain information about temperature reading done (in Celsius) with floating point.
Contents for “~/templog/src/ubftab”, file named after the project name “frog.fd”:

Makefile for the field definitions (~/templog/src/ubftab/Makefile):

Installing the dependencies

The client process

The client process will read the temperature sensor device file (command line parameter ‘-device’), also client process shall have one parameter by setting it’s tag (‘-tag’ param) and sleep time parameter, identifying the temperature read interval (‘-sleep’ param).

Client process in file “~/templog/src/client/client.go” is define as follows:

Makefile for client process is following (~/templog/src/client/Makefile):

The server process

The server process is defined as following (~/templog/src/server/server.go):

Makefile for server process is following (~/templog/src/server/Makefile):

Appliance configuration

Enduro/X application configuration typically consists of following configuration files:
1. “setndrx” – environment variables for Enduro/X
2. “ndrxconfig.xml” – application configuration
3. “debug.conf” – debug configuration

Environment variables for Enduro/X – setndrx

The file contents for for environment file is following: (~/templog/conf/setndrx)

Application configuration – ndrxconfig.xml

Application configuration consists of the:
– Starting up two “server” processes with MariaDB connection string “frog:frog1@/frog”.
– Starting Client Process Monitor (cpmsrv) XATMI server
– Starting two client processes which each reads it’s own temperature sensor device.

File: (~/templog/conf/ndrxconfig.xml)

Debug configuration – debug.conf

File: (~/templog/conf/debug.conf)

Testing

Before start the application, you will need to load new environment which includes contents from “setndrx”, that could be done with command written before:

Now start the Enduro/X application server:

To see that client processes are running, use “pc” (print clients) command:

from the above listing can be seen that “INSIDE” and “OUTSIDE” sensors reader processes are working ok.

To check that temperature is reading ok (and having reading for last 4 days), I use following select:

Conclusions

The project is good basis for adding new sensors and processing them in different ways. Enduro/X allows to create a cluster via ‘tpbridge’ process, thus Raspberry pi can be easily interconnected with desktop or server machines.

The full project files can be downloaded here: templog.tar.gz

LEAVE A COMMENT

You comment will be published within 24 hours.

Cancel reply
This site uses cookies to enhance your experience. By continuing to the site you accept their use. More info in our cookies policy.     ACCEPT

Phone:
+371 28379007

Kalnciema 116 str., Riga, Latvia

About Us

Company is founded in 2011 with passion in Web project and E-commerce. In addition company have interest in real time systems. Which in fusion gives company ability to deliver to customers wide range of solutions.

Our Services
  • Web Design
  • Web CMS Implementation
  • E-commerce Development
  • SEO Implementation & Monitoring
  • Graphic Design
  • User Training
  • SLA & Maintenance
Products
  • Enduro/X Middlware platform
© Copyright 2015 ATR Baltic, SIA