PM2M Docker

1) Installer Docker sur votre machine

2) Installer les clients Mosquitto pour souscrire et publier sur les sujets (ie topics)

sudo apt install -y mosquitto-clients mosquitto_sub -h test.mosquitto.org -t "iot_pm2m/1718/groupe1/#" -v mosquitto_pub -h test.mosquitto.org -t "iot_pm2m/1718/groupe1/fridge123" -v -m "temp=20.0;hum=10;open=true"

Lancer le client Web MQTT HiveMQ.

3) Lancer les containers Docker suivant


 * 1) NodeRED app for collect sensors data

name_to_ipaddress{ ifconfig | grep "inet " |awk '{ if ( $1 == "inet" ) { print $2 } else if ( $2 == "Link" ) { printf "%s:" ,$1 } }' | grep -v "127.0.0.1" | head -1 }

NODERED_WEB_PORT=1880 NODERED_ADMIN_PASSWORD="MUST_BE_CHANGED"
 * 1) Note : Password can be crypt and set into settings.js with node-red-admin hash-pw

GF_PORT=3600 GF_PASSWORD="MUST_BE_CHANGED"

MQTT_BROKER_1=mqtt01 MQTT_BROKER_2=mqtt02 MQTT_BROKER_1=test.mosquitto.org MQTT_BROKER_2=test.mosquitto.org LOCAL_HOST=$(name_to_ipaddress localhost) echo $LOCAL_HOST


 * 1) Clean
 * 1) Clean

docker rm -f influxdb_for_iot docker rm -f mongodb_for_iot docker rm -f nodered_for_iot docker rm -f grafana_for_iot docker rm -f chronograf_for_iot

rm -fr influxdb mongo grafana chronograf rm -f lib/flows/*

mkdir influxdb docker pull influxdb docker run -d --name influxdb_for_iot \ -p 8086:8086 \ -p 8083:8083 \ -v influxdb:/var/lib/influxdb \ influxdb
 * 1) Influx DB
 * 1) Influx DB

docker run -d --name mongodb_for_iot \ -p 27017:27017 \ mongo
 * 1) MongoDB
 * 1) MongoDB

docker pull nodered/node-red-docker
 * 1) Influx DB
 * 1) Influx DB

LOCALDIR=$(pwd) docker run -d --name nodered_for_iot \ -v $LOCALDIR:/data \ -p $NODERED_WEB_PORT:1880 \ --add-host=influxdb-1:$LOCAL_HOST \ --add-host=mongodb-1:$LOCAL_HOST \ -e FLOWS=lora.flow.json \ -e NODE_OPTIONS="--max_old_space_size=128" \ nodered/node-red-docker

npm install node-red-contrib-influxdb npm install node-red-node-mongodb npm install node-red-contrib-pubnub npm install node-red-contrib-ifttt npm install node-red-contrib-kafka-node npm install node-red-contrib-web-worldmap

npm install -g node-red-admin node-red-admin target http://localhost:$PORT node-red-admin list node-red-admin install node-red-contrib-influxdb


 * 1) Grafana
 * 1) Grafana

docker run -d --name grafana_for_iot \ -p $GF_PORT:3000 \ --add-host=influxdb-1:$LOCAL_HOST \ -e "GF_SECURITY_ADMIN_PASSWORD=$GF_PASSWORD" \ grafana/grafana


 * 1) Chronograf
 * 1) Chronograf

mkdir chronograf docker run -d --name chronograf_for_iot \ -p 18888:8888 \ --add-host=influxdb-1:$LOCAL_HOST \ -v chronograf:/var/lib/chronograf \ chronograf

docker logs --follow nodered_for_iot tail -f logfile.txt
 * 1) Logs
 * 1) Logs


 * 1) Stop then Start
 * 1) Stop then Start

docker stop influxdb_for_iot docker stop mongodb_for_iot docker stop nodered_for_iot docker stop grafana_for_iot docker stop chronograf_for_iot

docker start influxdb_for_iot docker start mongodb_for_iot docker start nodered_for_iot docker start grafana_for_iot docker start chronograf_for_iot

Bonus track : Developing IoT Mashups with Docker, MQTT, Node-RED, InfluxDB, Grafana