Building clouddata.dustcloud.org
- 1 Requirements
- 2 Architecture
- 3 Installation Steps
- 3.1 Ubuntu
- 3.2 influxdb
- 3.2.1 install database
- 3.2.2 create database
- 3.3 grafana
- 3.3.1 install
- 3.3.2 change admin username and password
- 3.3.3 connect to database
- 3.3.4 create dashboard
- 3.3.5 enable anonymous access
- 3.3.6 set as default dashboard
- 3.4 clouddata_server script
- 3.4.1 install Python
- 3.4.2 install clouddata_server script
- 3.4.3 run at startup
- 3.5 NGINX
- 3.5.1 installation
- 3.5.2 configuration
- 3.6 iptables
- 3.6.1 configure
- 3.6.2 verify
- 3.6.3 run at boot
- 4 Testing
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:
clouddata.dustcloud.org must be able to receive sensor data, and store data as timelines for 12 hours.
clouddata.dustcloud.org must offer a web interface to visualize the data.
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:
HTTP requests to http://clouddata.dustcloud.org/api/v1 to the
clouddata_serverscript running on TCP port 8080HTTP requests to http://clouddata.dustcloud.org/ to the grafana frontend running on TCP port 3000
the
clouddata_serverscript 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/interfacesto 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 dhcprestart 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-upgradeThe commands above update your entire OS. This can take 10-15min.
SSH
Install the OpenSSH server:
sudo apt-get install openssh-serverAdd 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 -REdit /etc/ssh/sshd_config so it contains the following (un-commented) lines:
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keysRestart the SSH server:
sudo service ssh restartinfluxdb
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 influxdbYou 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:~$