anthill / pheromon

Deploy, administrate and harvest data from a swarm of sensors
MIT License
7 stars 6 forks source link

Pheromon

Overview

Pheromon is a open innovation project to deploy, administrate and harvest data from a swarm of sensors. It has been developed in the scope of project 6element dedicated to waste optimisation, and is now in production on the projet vamos.

Use our open API, you can have a look at the dedicated wiki.

Image Alt

Pheromon communicates with sensors over TCP using MQTT protocol. The MQTT broker dispatches the messages depending on the publish/subscribe status of various clients on various subjects. For example, a meteorological sensor will publish on the topics rain and temperature while a sensor measuring peoples fluxes will publish on wifidevices and bluetoothdevices. Meanwhile, the admin interface can publish to all sensors on the all topic, or to one particular sensor on mySensorId topic.

All the messages are persisted in a database that can be queried by a API able to answer queries like "give me all mesaurements of sensor X since Y".

Clients

Two clients are available for now.

The Dashboard is useful to visualize the measurements on a map. Dashboard

You can also administrate your sensors with the Admin. Admin

More on those clients later.

Quick start :

git clone git@github.com:anthill/pheromon.git
cd pheromon
npm install

In dev

Use this for development.

npm run dev

Use npm run stop-dev to stop.

In prod

Use this for production.

npm run prod // launch the service

Database

node database/management/init-db.js
node database/management/backup.js > backups/test.sql

or restore an previous db with

node database/management/restore.js backups/test.sql

you can also use a gziped file (comming from the automated backup for example).

MQTT

MQTT is the communication protocol between the server and the sensors.

Elements

The communication protocol is composed of 3 elements:

Available Topics up to now:

From sensor to maestro:

From maestro to sensor:

Initialization sequence

We don't want sensors to have a manually hard-coded id (for deployment's simplicity) so we use mac addresses of devices:

Sequence

Status update sequence

Each time the sensor's status changes, a message is sent to the maestro to update the DB and react accordingly depending on the situation. Status can be of 3 types:

Sequence

Measurement push sequence

By default, sensor has measurement capabilities (for wifi and bluetooth). Every n minutes, sensor send measurements to kerrigan server to be recorded in DB.

Sequence

Command sending sequence

You can send commands to the sensors.

Sequence

Unitary tests

You can run Pheromon tests in a dedicated docker.

You can use

npm run test

Prepare the server and docker for the updater

sudo useradd -m sensorSSH;
sudo passwd sensorSSH;
su sensorSSH -c 'ssh-keygen -t rsa -b 4096';
sudo usermod -G docker sensorSSH;
AllowTcpForwarding yes
GatewayPorts yes
sudo usermod -s /usr/sbin/nologin sensorSSH;

add "ip": ... in pheromon secret.json where kerrigan is the name of the host in .ssh/config

PRIVATE files

There are 2 PRIVATE files:

server_ip is used in api/maestro.js.

html_token is used in api/api.js and api/routes.js.

cmd_token is used in api/maestro.js and api/clients/Admin/src/main.js.

Licence MIT

Contribute :