Building clouddata.dustcloud.org

Building clouddata.dustcloud.org

Requirements

Goal

clouddata.dustcloud.org allows a customer to publish sensor data to the Internet less than 5 min after having opened a SmartMesh IP starter kit

This translates into the following requirements:

Architecture

The solution consists of the PublishToWeb SmartMesh SDK program and the clouddata.dustcloud.org server.

PublishToWeb Smartmesh SDK application

This application is part of the default SmartMesh SDK, and runs on the user's computer. It:

  • connects to the SmartMesh IP Manager

  • subscribes to data notifications

  • forwards all the OAP temperature data readings produced by the SmartMesh IP motes to clouddata.dustcloud.org.

clouddata.dusctloud.org server

The clouddata.dusctloud.org server is built on Ubuntu Server. It has the following internal architecture:

  • the iptables firewall filters out all external traffic not going to TCP port 80

  • the NGINX load balancer redirects:

  • the clouddata_server script is part of the SmartMesh SDK. It receives data from the PublishToWeb.py application and inserts it into the database. 

  • the influxdb database efficiently stores time series data. In this example, the database is configured to automatically drop data after 12 hours.

  • the grafana data visualization tools offer a clean dashboard for visualizing the data

Installation Steps

Vagrant setup files for the step-by-step guide below are maintained at https://github.com/dustcloud/clouddata-server.

 

Ubuntu

At the time of writing, we have installed Ubuntu Server 16.04 LTS.

If you are installing the server on a virtual machine using VirtualBox for testing purposes:

  • configure two network adapters:

    • Adapter 1 as "NAT" (this allows your VM to access the web)

    • Adaptor 2 as "Host-only Adapter" (this allows your host OS to access the web server running your VM)

  • after booting your VM, edit /etc/network/interfaces to add the last lines corresponding to the second network interface

    # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface (NAT) auto enp0s3 iface enp0s3 inet dhcp # The secondary network interface (Host-only adapter) auto enp0s8 iface enp0s8 inet dhcp
  • restart the networking services:

    sudo service networking restart

Once installed, log into the server.

Update

sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade

The commands above update your entire OS. This can take 10-15min.

SSH

Install the OpenSSH server:

sudo apt-get install openssh-server

Add your public key to the server:

mkdir .ssh touch .ssh/authorized_keys echo "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIBx8jcskAQwgmw2ZR18K1cyW4NyQDFhLYiva4WLDHyVgxBuo95ndyeYHoc1lk6FpRpV9jdvTCD4rGx8OT28dFyVFvDSiNxbwm/qMHhvY9Vtu7842h0Hkelb5w2DU8Qvp33OQ67frQNKcvnYOP2MQxkfKVRInP/pfzuux0NiErcFxQ== rsa-key-thomas" > .ssh/authorized_keys chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys chown $USER:$USER ~/.ssh -R

Edit /etc/ssh/sshd_config so it contains the following (un-commented) lines:

RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keys

Restart the SSH server:

sudo service ssh restart

influxdb

install database

Install and start InfluxDB automatically:

curl -sL https://repos.influxdata.com/influxdb.key | sudo apt-key add - source /etc/lsb-release echo "deb https://repos.influxdata.com/${DISTRIB_ID,,} ${DISTRIB_CODENAME} stable" | sudo tee /etc/apt/sources.list.d/influxdb.list sudo apt-get update && sudo apt-get install influxdb sudo systemctl start influxdb sudo systemctl enable influxdb

You should see the InfluxDB admin panel at http://192.168.56.101:8083/.

By default, the HTTP API of InfluxDB runs on TCP port 8086.

create database

Use the influx client to create a database "grafana" and associate a retention policy so datapoints are automatically deleted after 12 hours:

user@ubuntu:~$ influx Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring. Connected to http://localhost:8086 version 0.10.0 InfluxDB shell 0.10.0 > CREATE DATABASE grafana > CREATE RETENTION POLICY twelve_h_only ON grafana DURATION 12h REPLICATION 1 DEFAULT > exit user@ubuntu:~$