influxDB vs PostgreSQL
- https://portavita.github.io/2018-07-31-blog_influxdb_vs_postgresql
- https://db-engines.com/en/system/InfluxDB%3BPostgreSQL
Install https://github.com/docker/docker-install
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sh get-docker.sh
add user docker group https://docs.docker.com/install/linux/linux-postinstall/
$ ...
Create image
// cria docker img a partir do arquivo ./Dockerfile
$ docker build -t iot/dockernode .
Install https://docs.docker.com/compose/install/
substitua 1.25.4 pela versao desejada
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
Commands
docker-compose up
docker-compose stop
//update service XXX
docker-compose build XXX
Uninstall $ sudo rm /usr/local/bin/docker-compose
Grafana
PostgresSQL
docker
PostgreSQL
node-postgres
https://www.postgresqltutorial.com/
$ sudo docker pull postgres
$ docker run --name iot-postgres -v ./postgres/datadir:/var/lib/postgresql/data -e POSTGRES_PASSWORD=iotdatabase -e POSTGRES_DB=db_iot -d postgres
$ echo "iotdatabase" | docker secret create db_pass -
$ docker ... POSTGRES_PASSWORD_FILE=/run/secrets/db_pass -d postgres
https://www.npmjs.com/package/mqtt
$ npm install -y
$ touch index.js
$ touch Dockerfile
$ touch .dockerignore
package.json
"scripts": {
"start": "node index.js"
}
create img
$ docker build -t iot/dockernode .
run
$ docker run -p 3000:3000 -d iot/dockernode
Install
$ npm install nodemon
Update package.json
"scripts": {
"start": "nodemon index.js"
}
run
$ docker run -p 3000:3000 -v /home/luiz/git/iot-docker/:/usr/app -d iot/dockernode
Add file docker-compose.yml
run
$ docker-compose up
- https://medium.com/@alifabdullah/using-mqtt-protocol-with-node-js-f0eb8065b5b6
- https://medium.com/@czarantoniodesouza/experimentando-a-node-mcu-com-nodejs-e-mqtt-798bc5666d2f
docker hub
$ docker pull eclipse-mosquitto
run
$ docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto
Tutorial
MQTT explore
MQTTBox - https://chrome.google.com/webstore/detail/mqttbox/kaajoficamnjijhkeomgfljpicifbkaf/
- mqtt://0.0.0.0:1883
- client_id : users : password
Create container with docker-compose
localhost:27017
mongoDB shell
Create user for verneMQ to access the database
use devices
db.createUser({ user: 'vernemq', pwd: 'vernemq', roles: [{role : 'readWrite', db: 'devices'}]})
Users vernemq:
client_id : users : password
DEADBEEF : device : pwddev
wemos-nodemcu-v3 : device : pwddev
unused : commander : pwdcmd
- To cipher key to save in database
$ htpasswd -bnBC 10 "" "pwddev" | tr -d ':\n' | sed 's/$2y/$2a/'
$ htpasswd -bnBC 10 "" "pwdcmd" | tr -d ':\n' | sed 's/$2y/$2a/'
- Create users to access vernemq in mongoDB
/* Device */
use devices
db.getCollection("vmq_acl_auth").insert({
"mountpoint" : "",
"client_id" : "wemos-nodemcu-v3",
"username" : "device",
"passhash" : "$2a$10$ozvotzM5e2LsXjhVMTzYPOkS.h83eXEGItRnXTRkSSBm3AAkn0VAW",
"publish_acl" : [
{
"pattern" : "devices/%c/state/#"
}
],
"subscribe_acl" : [
{
"pattern" : "devices/%c/commands/#"
}
]
})
/* User to send commands */
use devices
db.getCollection("vmq_acl_auth").insert({
"mountpoint" : "",
"client_id" : "unused",
"username" : "commander",
"passhash" : "$2a$10$o57uY5AJSZ2Y/wf.9o//6erHjYIvAn6ilrbcpRAa0ZSd0gsSNba96",
"publish_acl" : [
{
"pattern" : "devices/+/commands/#"
}
],
"subscribe_acl" : [
{
"pattern" : "devices/+/state/#"
}
]
})
Tutorials
Distancia
LAN
WAN
Energia
Custo
Camada fisica
TCP/IP
socket
WebSocket
MQTT
Serializacao
Json
xml
protocolo buffer
protocolo mDNS (para para ser encontrada na rede local)
Backend Dados tempo real nSQL Serie Temporal FireBase??? Inlfux Associacao (SQL, pra usuarios e etc) Postgres Deploy Containers CI/CD Cloud
Mensageria
Escalabilidade
Vertical
Horizontal
Alerta e eventos
Autenticacao e autorizacao
jwt
envio-nuvem->dispositivo
recebimento-Dispositivo=>nuvem
Web page
react
Dashboard
grafana
IO
Atuadores
Sensores
GPIO
Protocolos
I2C
SPI
Serial Uart
CAN
Hardware
Microcontrolador
FrameWork
Arquitetura
Configuracao
iD
setup Inicial
Provisionamento
Atualizacao
reset de Fabrica
Design Final
case
PCB
Componentes
Montagem
Larga escala
Distancia
Energia
Custo
Camada fisica
IP
TCP
sockt
webSocket
MQTT
nao IP
Bluetooth
Zigbee
LoRa
Serializacao
Json
xml
protocolo buffer
Dados
tempo real
Serie Temporal
Associacao
Deploy
Containers
CI/CD
Cloud
IaaS
PaaS
...
Mensageria
Escalabilidade
Vertical
Horizontal
Alerta e eventos
Autenticacao e autorizacao
envio-nuvem->dispositivo
recebimento-Dispositivo=>nuvem
Web
Aplicativos
Administracao e Backoffice
Visualizacao
relatorios
dashboard
Comportamento de usuario
preenchimento de falhas
predicao