Twitter

by acls us

IoT Electric Imp monitoring with Zabbix and Grafana

ImpThe Electric Imp range of IoT devices offer a simple means to interface with a number of different physical data collection devices and connect back to a central controlling Server Platform via built-in WiFi. Code can be written and deployed from the central Server Platform that controls how the collected data is made available. In the following example I have used the built-in light level sensor data and exposed it via a simple web interface on the Server Platform. This data is collected and stored by a Zabbix Server and presented via a Grafana Dashboard.

Imp Network

The Electric Imp itself is packaged in an SD Card like enclosure which can be plugged into a number of different SD Card type sockets to give connectivity to power and physical interfaces. The Electric Imp has a light level sensor inside the SD Card type package that is used to read configuration instructions from a Smart Phone App (BlinkUp) to setup the WiFi parameters and can be used as a Light Sensor at run-time. Once configured and connected to a WiFi Network with Internet connectivity, the Electric Imp connects to the central Imp Cloud from which it will download any updates and Device code created for the device. The Imp Cloud will also have Agent code that runs on the Imp Cloud and controls communication between the Imp Cloud and the device.

The Imp Device code used simply registers a function to be called when and Agent message of type "queryLight" arrives. When the function is called by the arrival of the message it reads the hardware lightlevel and sends that back to the Agent.

 Imp Device Code

The Imp Agent code used is a little more complicated but all it does is to get triggered when a http get request arrives (the URL to use for the specific device is shown in the Development environment on Imp Cloud), sends a message to the device and passes the reply back as the http response. There is also code to handle timeouts communicating with the device. If there is any error communicating, a zero value is returned on the http response.

Imp Agent Code

At the Zabbix Server, the local Zabbix Agent is used to send the https request to the Imp Cloud on the specific URL for the device and extract the Light Level data by using a "web.page.regexp" item (xxxxxxxxxxx replaced with the specific value from the Development Environment);

web.page.regexp[agent.electricimp.com,xxxxxxxxxx/?queryLight,80,"([0-9]+)$"]

The data is then held on the Zabbix Server and used by a Grafana Dashboard to show a graph of the level and a status panel which shows red if there is a problem communicating with the device.

Dashboard

 

Part two here.

FreePBX/Asterisk on an Amazon Ubuntu Lightsail instance

I needed to install Asterisk 13.10, FreePBX 14.0 on Ubuntu 16.04 LTS in an Amazon Lightsail instance. I based the installation process on a set of installation notes on the FreePBX site but this was based on Ubuntu 14.04 LTS on bare metal. Ubuntu 16.04 needed a few changes to the procedure which was further complicated by the Amazon Lightsail customised image. So the following takes into account these requirements. Its not been fully tested yet but does install and run. The Lightsail instances was 2GB RAM 40GB Disk and a static IP. After each login, I use sudo to get the system into root mode. There will be people out there that tut tut at me for that!

Step 1 - Added a swap file and get Ubuntu up to date.

sudo -i
fallocate -l 4g /swap
chmod 600 /swap
mkswap /swap
swapon /swap
echo '/swap swap swap 0 0' | tee -a /etc/fstab
apt update
apt upgrade -y
(keep the local menu.lst for grub, prompts twice)
reboot

Step 2 - Install a bunch of pre-requisites. This includes PHP 5.6 which FreePBX 13 needs (module updates will not work with PHP 7 installed) hense the use of an external repository.

sudo -i
add-apt-repository ppa:ondrej/php
apt update
apt-get install -y build-essential apache2 mysql-server mysql-client\
bison flex php5.6 php5.6-curl php5.6-cli php5.6-mysql php-pear php5.6-gd php5.6-mbstring php5.6-xml sox\
libncurses5-dev libssl-dev libmysqlclient-dev mpg123 libxml2-dev libnewt-dev sqlite3\
libsqlite3-dev pkg-config automake libtool autoconf unixodbc-dev uuid uuid-dev\
libasound2-dev libogg-dev libvorbis-dev libcurl4-openssl-dev libical-dev libneon27-dev libsrtp0-dev\
libspandsp-dev libiksemel3 libapache2-mod-php5.6 exim4

(you will prompted three times for a MySQL root password, leave it blank and tab to “ok” and press enter)

cat >> /etc/mysql/conf.d/mysqld.cnf << EOF
[mysqld]
sql_mode = "NO_ENGINE_SUBSTITUTION"
EOF
service mysql restart

(The above sets the MySQL mode to be compatible with previous MySQL versions, not STRICT)

Step 3 - Install some more required packages with versions that are not in the standard Ubuntu repository. nodejs 6 and a version of libmyodbc that works.

curl -sL https://deb.nodesource.com/setup_6.x -o nodesource_setup.sh
bash nodesource_setup.sh
apt-get install -y nodejs
wget https://dev.mysql.com/get/Downloads/Connector-ODBC/5.3/mysql-connector-odbc-5.3.10-linux-ubuntu17.04-x86-64bit.tar.gz
gunzip mysql-connector-odbc-5.3.10-linux-ubuntu17.04-x86-64bit.tar.gz
tar xvf mysql-connector-odbc-5.3.10-linux-ubuntu17.04-x86-64bit.tar
cd mysql-connector-odbc-5.3.10-linux-ubuntu17.04-x86-64bit
cp bin/* /usr/local/bin
cp lib/* /usr/local/lib
myodbc-installer -a -d -n "MySQL ODBC 5.3 Driver" -t "Driver=/usr/local/lib/libmyodbc5a.so"
reboot

Step 4 - Asterisk (with some config file adjustments) and FreePBX.

sudo -i
apt install asterisk -y
service asterisk stop
chown asterisk. /var/run/asterisk
chown -R asterisk. /etc/asterisk
chown -R asterisk. /var/{lib,log,spool}/asterisk
chown -R asterisk. /usr/lib/asterisk
sed -i 's/(!)//' /etc/asterisk/asterisk.conf
sed -i 's/\(^upload_max_filesize = \).*/\1256M/' /etc/php/5.6/cli/php.ini
sed -i 's/\(^memory_limit = \).*/\1256M/' /etc/php/5.6/cli/php.ini
a2enmod rewrite
rm -rf /var/www/html
cp /etc/apache2/apache2.conf /etc/apache2/apache2.conf_orig
sed -i 's/^\(User\|Group\).*/\1 asterisk/' /etc/apache2/apache2.conf
sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
service apache2 restart
cat >> /etc/odbc.ini << EOF
[MySQL-asteriskcdrdb]
Description=MySQL connection to 'asteriskcdrdb' database
driver=MySQL
server=localhost
database=asteriskcdrdb
Port=3306
Socket=/var/run/mysqld/mysqld.sock
option=3
EOF
wget http://mirror.freepbx.org/modules/packages/freepbx/freepbx-14.0-latest.tgz
tar vxfz freepbx-14.0-latest.tgz
cd freepbx
./start_asterisk start
./install -n
reboot

Using Zabbix and Grafana to BitCoin BlockChain Stats

BlockChainI wanted to get a few BitCoin BlockChain Stats to show on a Grafana Dashboard without having to install and run a whole bunch of code. Luckily blockchain.info provide a simple REST web interface for this.

The next step was to get the data needed from blockchain.info. A simple PHP script was used to get this data, format it and use the Zabbix Sender (zabbix_sender) to post it into a Zabbix Server. I organised the Zabbix data using a single Zabbix host with a few Zabbix items (which must be created as "Zabbix trapper" item type) to hold the data. The PHP script is run on a Zabbix Server (just for convenience really) under cron every 60 seconds.

Finally I created a simple Grafana Dashboard using "Single Value" panels to show the data.

Blockchain