====== MQTT (mosquitto) ======
Fait :
- [x] Comparatif
- [x] MQTT sur Raspberry Pi
- [x] MQTT sur Arduino
- [x] Relay + Capteur courant
- [x] MQTT et Node-Red
- [X] MQTT & InfluxDB
- [X] MQTT & Java
country=fr
update_config=1
ctrl_interface=/var/run/wpa_supplicant
network={
scan_ssid=1
ssid="LE2P"
psk="XXXXXX"
}
Remarque :
- //[Optionnel]// **Fixer l'adresse IP de la machine** si besoin pour le wifi
- Faire ''%%sudo nano /etc/dhcpcd.conf%%'' et mettre ceci
interface wlan0
static ip_address=192.168.1.2/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1
*
* Au besoin désactiver le ipV6 en éditant le faisant ''%%sudo nano /etc/sysctl.d/local.conf%%'' et en mettant la ligne suivante ''%%net.ipv6.conf.all.disable_ipv6=1%%''
* Faire ensuite ''%%sudo ifconfig wlan0 down && sudo ifconfig wlan0 up%%''
* **Configurer raspberry** avec ''%%sudo raspi-config%%''
* Changer les options de localisations (FR etc.)
* ''%%sudo apt-get update && sudo apt-get upgrade%%''
* ''%%sudo apt-get install ntpdate%%''
* **Changer le mot de passe** par défaut : ''%%passwd%%''
* **Mettre à jour la date du Raspberry** :
* Faire ''%%sudo apt-get install ntp%%''
* //Editer le fichier ''%%sudo nano /etc/ntp.conf%%'' et dans les pools rajouter ntp.univ.run// (uniquement dans le cas d'un serveur interne à L'université de la Réunion)
* //[Optionnel]// **Créer un username différent** :
* Faire ''%%sudo adduser house001%%'' et entrer le mot de passante
* Faire ''%%sudo adduser house001 sudo%%'' pour l'ajouter au groupe sudo
* Au besoin, supprimer l'utilisateur pi en faisant ''%%sudo deluser
-remove-home pi%%'' ou encore le désactiver en faisant ''%%sudo passwd
--lock pi%%''
* //[Optionnel]// **Pour plus de sécurité, il est possible ensuite** (tuto sur [[https://www.raspberrypi.org/documentation/configuration/security.md|ce site]]) :
* Interdire l'accès root en SSH
* Obliger le mot de passe pour les ''%%sudo%%''
* Forcer l'utilisation de clés SSH
* Installer un firewall (''%%ufw%%'' ou ''%%iptables%%'')
* Installer ''%%fail2ban%%''
==== Raspberry Pi : Installation du broker ====
L'installation se fait comme suit :
Dans ''%%/etc/mosquitto/mosquitto.conf%%'', rajouter les lignes
allow_anonymous false
password_file /etc/mosquitto/passwd
Ensuite il faut faire :
/***************************************************
Adafruit MQTT Library WINC1500 Modified by Yassine
Demo written by Limor Fried/Ladyada for Adafruit Industries.
Modified by Yassine Gangat for LE²P.
MIT license, all text above must be included in any redistribution
****************************************************/
#include
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include
//
---------------------------- GROVE LCD Lib
-------------------------
//#include // i2c LIB to use LCD
#include "rgb_lcd.h" // lcd LIB
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
const char ssid[] = SECRET_SSID; // your network SSID (name)
const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
// int keyIndex = 0; // your network key Index number (needed only for WEP)
/************************* Broker Setup **********************************/
#define SERVER "192.168.2.2"
#define SERVERPORT 1883
#define USERNAME "user"
#define PWD "apqm"
/******************************* Global State ****************************/
//Set up the wifi client & Adafruit MQTT Client
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PWD);
#define halt(s) { Serial.println(F( s )); while(1); }
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/
Adafruit_MQTT_Publish numbers = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/numbers");
// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffmsg = Adafruit_MQTT_Subscribe(&mqtt, USERNAME "/feeds/onoff");
/*************************** Sketch Code ************************************/
//
--------------------------- Variables & others
--------------------------------
rgb_lcd lcd;
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
void setup() {
//
------------------------- Initialization Serial
------------------------------
while (!Serial); // wait for serial port to connect. Needed for native USB port only
Serial.begin(9600);
Serial.println(F("Adafruit MQTT Library WINC1500 Modified by Yassine"));
//
---------------------- Initialization Wifi WINC1500
--------------------------
// Initialise the Client
Serial.print(F("\nInit the WiFi module..."));
// check for the presence of the breakout
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(F("WINC1500 not present"));
// don't continue:
while (true);
}
Serial.println(F("ATWINC OK!"));
//
------------------------------ Physical part
----------------------------------
Serial.println(F("LCD Init"));
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
#if 1
lcd.createChar(0, heart);
#endif
lcd.setCursor(0, 0);
lcd.print(F("Made with "));
lcd.write((unsigned char)0);
lcd.setCursor(0, 1);
lcd.print(F(" by Yassine"));
//
--------------------------- Variables & others
--------------------------------
mqtt.subscribe(&onoffmsg);
}
uint32_t x = 0;
void loop() {
//
------------------------------ MQTT Connection
--------------------------------
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected).
MQTT_connect();
lcd.setRGB(255,165,0);
//
------------------------------ Subscription
-----------------------------------
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &onoffmsg) {
Serial.print(F("Got: "));
Serial.println((char *)onoffmsg.lastread);
if (0 == strcmp((char *)onoffmsg.lastread, "OFF")) {
lcd.setRGB(255,0,0);
lcd.setCursor(0, 1);
lcd.print(F("Received OFF "));
}
if (0 == strcmp((char *)onoffmsg.lastread, "ON")) {
lcd.setRGB(0,255,0);
lcd.setCursor(0, 1);
lcd.print(F("Received ON "));
}
}
}
//
------------------------------ Publication
----------------------------------
Serial.print(F("\nSending "));
Serial.print(x);
lcd.setCursor(0, 1);
lcd.print(F("Sending "));
lcd.setCursor(8, 1);
lcd.print(x);
if (! numbers.publish(x++)) {
Serial.println(F("...Failed"));
} else {
Serial.println(F("...OK!"));
}
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(F("Attempting to connect to SSID: "));
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
uint8_t timeout = 10;
while (timeout && (WiFi.status() != WL_CONNECTED)) {
timeout--;
delay(1000);
}
}
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print(F("Connecting to MQTT... "));
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println(ret);
Serial.println(F("Retrying MQTT connection in 5 seconds..."));
mqtt.disconnect();
delay(5000); // wait 5 seconds
}
Serial.println(F("MQTT Connected!"));
}
Remarques sur ce code :
- Le ''%%USERNAME%%'' et ''%%PWD%%'' sont ceux qui ont été définis dans les **mosquitto_passwd** (voir précédemment).
- Le mot de passe du wifi est stocké dans ''%%arduino_secrets.h%%'' (mais celui du broker, volontairement)
- Dès que la mémoire dynamique (vive) est utilisée à plus de 80%, il y a des soucis de connexion au wifi comme au MQTT.
- La solution la plus rapide pour diminuer ce nombre a été de remplacer ''%%Serial.println("Text")%%'' par ''%%Serial.println(F("Text"))%%''. Cela fonctionne aussi pour les ''%%lcd.print%%''.
- Une autre solution est de mettre ''%%const%%'' partout où cela est possible !
- Une solution plus complexe, mais envisageable à la fin est d'utiliser ''%%PROGMEM%%''.
- Sachant que les ''%%Serial.println%%'' utilisent beaucoup cette SRAM, il est possible :
- de le supprimer lorsque tout fonctionne
- d'utiliser ce genre d'astuce
#define DEBUG //que l'on commente avant de téléverser
puis dans le code...
#ifdef DEBUG
Serial.prinlln(F("Affichage\n"));
#endif
Plus d'informations sur la fonction ''%%F()%%'' et sur la gestion de mémoire sont disponibles :
- En français sur [[https://www.carnetdumaker.net/articles/reduire-lempreinte-memoire-dun-programme-arduino-avec-progmem/|ce site]] et [[https://zestedesavoir.com/tutoriels/374/gestion-de-la-memoire-sur-arduino/|ce site]].
- En anglais sur [[https://learn.adafruit.com/memories-of-an-arduino/optimizing-sram|ce site]] et [[https://forum.arduino.cc/index.php?topic=79436.0|ce forum]].
Le fichier ''%%arduino_secrets.h%%'' contient le code suivant :
#define SECRET_SSID "NOM-POINT-D-ACCES"
#define SECRET_PASS "MDP-WIFI"
===== Application =====
==== Test préliminaire ====
Pour la suite du test, nous avons fait le montage suivant sur le Arduino :
- Nous avons branché un [[https://www.elecfreaks.com/wiki/index.php?title=Octopus_Current_Sensor|Octopus Current Sensor]] en plaçant le signal reçu sur le PIN A0. Sur ce relai, nous avons branché une LED (et une résistance ainsi qu'un potentiomètre).
{{http://www.robitshop.com/octopus-current-sensor-10267-42-B.jpg| Octopus Current Sensor}}
* Nous avons utilisé un [[http://www.mantech.co.za/Datasheets/Products/IDUINO-ME114.pdf|4 Channel 12vdc Relay Module IDUINO Board]] en branchant le Relay sur le PIN 7
{{https://www.jaycar.com.au/medias/sys_master/images/9105856659486/arduino-compatible-4-channel-12v-relay-moduleImageMain-515.jpg|4 Channel 12vdc Relay Module Board}}
// Initialise the Arduino data pins for INPUT/OUTPUT
const int analogInPin = A0;
const int RELAY1 = 7;
void setup() {
pinMode(RELAY1, OUTPUT);
Serial.begin(9600);
Serial.println("Setup");
}
void loop() {
digitalWrite(RELAY1, LOW); // Turns ON Relays 1
Serial.println("---------------------- OFF
----------------------");
delay(5000);
mesure(analogInPin);
delay(5000);
digitalWrite(RELAY1, HIGH); // Turns Relay Off
Serial.println("---------------------- ON
-----------------------");
delay(2000);
mesure(analogInPin);
delay(2000);
Serial.println("=================================================");
}
void mesure(int analogPin) {
float sensorValue = 0; // value read from the pot
// read the analog in value:
sensorValue = analogRead(analogPin);
// map it to the range of the analog out:
Serial.print("sensor = ");
Serial.println(sensorValue);
sensorValue = ((sensorValue
- 506) * 5 / 1024 / 0.066);
// print the results to the serial monitor:
Serial.print("Converted = ");
Serial.println(sensorValue);
Serial.print("Mapped = ");
Serial.println(map(sensorValue, 0, 1023, 0, 255));
}
==== Modification ====
Ensuite nous avons modifié le code original de notre Arduino (voir [[#arduino-code|Arduino : Code]]) pour que :
- Le relai s'actionne lorsque la valeur lut sur le flux ''%%user/feeds/onoff%%'' est **ON** et s'éteint lorsque la valeur est **OFF**.
- Le capteur permet de mesurer le courant que nous ferons varier avec un potentiomètre. L'Arduino renverra cette valeur sur le broker MQTT.
Nous avons donc le code suivant :
/***************************************************
Adafruit MQTT Library WINC1500 Modified by Yassine
Demo written by Limor Fried/Ladyada for Adafruit Industries.
Modified by Yassine Gangat for LE²P.
MIT license, all text above must be included in any redistribution
****************************************************/
#include
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include
//
---------------------------- GROVE LCD Lib
-------------------------
//#include // i2c LIB to use LCD
#include "rgb_lcd.h" // lcd LIB
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
const char ssid[] = SECRET_SSID; // your network SSID (name)
const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
// int keyIndex = 0; // your network key Index number (needed only for WEP)
// Initialise the Arduino data pins for INPUT/OUTPUT
const int analogInPin = A0;
const int RELAY2 = 8;
const int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
/************************* Broker Setup **********************************/
#define SERVER "192.168.2.2"
#define SERVERPORT 1883
#define USERNAME "user"
#define PWD "apqm"
/******************************* Global State ****************************/
//Set up the wifi client & Adafruit MQTT Client
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PWD);
#define halt(s) { Serial.println(F( s )); while(1); }
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/
Adafruit_MQTT_Publish numbers = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/numbers");
// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffmsg = Adafruit_MQTT_Subscribe(&mqtt, USERNAME "/feeds/onoff");
/*************************** Sketch Code ************************************/
//
--------------------------- Variables & others
--------------------------------
rgb_lcd lcd;
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
void setup() {
//
------------------------- Initialization Serial
------------------------------
while (!Serial); // wait for serial port to connect. Needed for native USB port only
Serial.begin(9600);
Serial.println(F("Adafruit MQTT Library WINC1500 Modified by Yassine"));
//
---------------------- Initialization Wifi WINC1500
--------------------------
// Initialise the Client
Serial.print(F("\nInit the WiFi module..."));
// check for the presence of the breakout
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(F("WINC1500 not present"));
// don't continue:
while (true);
}
Serial.println(F("ATWINC OK!"));
//
------------------------------ Physical part
----------------------------------
Serial.println(F("LCD Init"));
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
#if 1
lcd.createChar(0, heart);
#endif
lcd.setCursor(0, 0);
lcd.print(F("Made with "));
lcd.write((unsigned char)0);
lcd.setCursor(0, 1);
lcd.print(F(" by Yassine"));
pinMode(RELAY2, OUTPUT);
//
--------------------------- Variables & others
--------------------------------
mqtt.subscribe(&onoffmsg);
}
// uint32_t x = 0;
void loop() {
//
------------------------------ MQTT Connection
--------------------------------
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected).
MQTT_connect();
lcd.setRGB(255,165,0);
//
------------------------------ Subscription
-----------------------------------
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &onoffmsg) {
Serial.print(F("Got: "));
Serial.println((char *)onoffmsg.lastread);
if (0 == strcmp((char *)onoffmsg.lastread, "OFF")) {
lcd.setRGB(255,0,0);
lcd.setCursor(0, 1);
lcd.print(F("Received OFF "));
digitalWrite(RELAY2, LOW); // Turns OFF Relays 1
}
if (0 == strcmp((char *)onoffmsg.lastread, "ON")) {
lcd.setRGB(0,255,0);
lcd.setCursor(0, 1);
lcd.print(F("Received ON "));
digitalWrite(RELAY2, HIGH); // Turns ON Relays 1
}
}
}
//
------------------------------ Publication
----------------------------------
Serial.print(F("\nSending "));
Serial.print(mesure(analogInPin));
lcd.setCursor(0, 1);
lcd.print(F("Sending "));
lcd.setCursor(8, 1);
lcd.print(mesure(analogInPin));
if (! numbers.publish((uint32_t) mesure(analogInPin))) {
Serial.println(F("...Failed"));
} else {
Serial.println(F("...OK!"));
}
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(F("Attempting to connect to SSID: "));
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
uint8_t timeout = 10;
while (timeout && (WiFi.status() != WL_CONNECTED)) {
timeout--;
delay(1000);
}
}
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print(F("Connecting to MQTT... "));
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println(ret);
Serial.println(F("Retrying MQTT connection in 5 seconds..."));
mqtt.disconnect();
delay(5000); // wait 5 seconds
}
Serial.println(F("MQTT Connected!"));
}
double mesure(int analogPin) {
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
RawValue = analogRead(analogPin);
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
Amps = ((Voltage
- ACSoffset) / mVperAmp);
/*Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3);
// the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3);
// the '3' after voltage allows you to display 3 digits after decimal point
delay(2500); */
return(Voltage);
}
Remarque :
- on est toujours confronté au problème de mémoire dynamique. Dans les logs de téléversement de Arduino, si dans la phrase ''%%Les variables globales utilisent 1614 octets (78%) de mémoire dynamique%%'', la mémoire utilisée arrive ou dépasse **80%** la connexion au wifi devient impossible...
====== Bonus(es) ======
===== Accès à MQTT depuis l'extérieur =====
Il est possible d'accéder au broker depuis l'extérieur en suivant une partie du tuto suivant : [[http://devotics.fr/installez-home-assistant/|Tuto IpDynamique]]
===== MQTT et Node-RED =====
Node-RED est un outil puissant pour construire des applications de l'Internet des Objets (IoT) en mettant l'accent sur la simplification de la programmation qui se fait grâce à des blocs de code prédéfinis, appelés « nodes » ''%%pour%%'' effectuer des tâches. Il utilise une approche de programmation visuelle qui permet aux développeurs de connecter les blocs de code ensemble. Les nœuds connectés, généralement une combinaison de nœuds d'entrée, de nœuds de traitement et de nœuds de sortie, lorsqu'ils sont câblés ensemble, constituent un « flow ». [[http://silanus.fr/sin/?p=984|Tuto Node-RED]]
La vocation de cette solution est de permettre de lier aisément des sources de données à des composants de traitement, locaux ou distants, et de créer des chaines de valeurs en quelques clics.
Node-RED est compatible avec MQTT : [[https://bentek.fr/mosquitto-node-red-raspberry-pi/|Tuto MQTT Node-RED]]
==== Installation Node-RED ====
Sur le raspberry-pi, allez dans le menu : **"Menu
-> Preferences
-> Recommended Software"**. Node-RED en fait partie depuis 2018.
Si déjà installé, il est possible (voire préférable) de faire un ''%%sudo apt-get upgrade%%''. D'autres options d'installation sont disponibles sur [[https://nodered.org/docs/hardware/raspberrypi|le site officiel]].
Node-RED peut fonctionner tel quel, cependant, pour pouvoir rajouter des modules, il faut avoir ''%%npm%%'' en faisant ''%%sudo apt-get install npm%%'' et en mettant à jour ''%%sudo npm i npm
-g%%''. (sinon, l'option //"Manage Palette"// sera absente)
Une autre possibilité est de lancer la commande suivante, qui permet de faire tout ce qu'il y a à faire : ''%%bash <(curl
-sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)%%''
{{https://wiki.mchobby.be/images/8/8d/Rasp-Node-RED-install-node-01.png| script}}
==== Démarrage ====
Pour démarrer Node-RED dans **"Menu
-> Programmation
-> Node-RED"**. On peut également démarrer depuis le Terminal avec la commande ''%%sudo node-red-start%%''.
Remarque :
- Pour permettre d'auto-start de node-red, il faut faire ''%%sudo systemctl enable nodered.service%%''
- On accéde à Node-RED avec http:%%//%%localhost:1880/ ou encore http:%%//%%adresse-Ip-Du-Rpi:1880/
{{https://dennisschultz.files.wordpress.com/2015/06/node-red-startup.png| Ecran de démarrage}}
==== Module Dashboard ====
=== Installation du module ===
Pour contrôler nos objets MQTT, nous allons utiliser le module Dashboard. Pour cela:
- Aller dans le menu de Node-RED en haut à droite
- Cliquer sur //"Manage Palette"//
- Dans l'onglet install, chercher et installer node-red-dashboard
=== Configuration du module ===
* Aller dans le menu de Node-RED en haut à droite
* Cliquer sur //"View
-> Dashboard"//
* Cliquer sur **+tab** pour rajouter un écran, dans lequel on mette ensuite 2 groupes avec **+group** Note : On accéde à Node-RED avec http:%%//%%localhost:1880/ui (après avoir déployé le flux)
=== Création de Nodes ===
Une fois les nodes créés et liés, en cliquant sur **"deploy"** en haut à droite, on permet la mise en fonction de ces nodes.
== Nodes MQTT ==
* Faire un drag & drop d'un node MQTT **A** en input
* Le configurer :
* Configurer le serveur la première fois
* Configurer le topic %%//%%"user/feeds/numbers"%%//%%
* Faire un drag & drop d'un node MQTT **B** en output
* Le configurer :
* Résutiliser le même serveur
* Configurer le topic %%//%%"user/feeds/onff"%%//%%
== Nodes Dashboard ==
* Faire un drag & drop d'un node switch (input du dashboard)
* Le connecter avec l'entrée du node **B**
* Le configurer
* Mettre **ON** pour %%//%%"On Payload"%%//%% (sous forme de string)
* Mettre **OFF** pour %%//%%"Off Payload"%%//%% (sous forme de string)
* Faire un drag & drop d'un node text (output du dashboard)
* Le connecter avec la sortie du node **A**
* Le configurer (on peut laisser ce qu'il y a par défaut)
* Faire un drag & drop d'un node chart (output du dashboard)
* Le connecter avec la sortie du node **A**
* Le configurer (on peut laisser ce qu'il y a par défaut)
== Pour test: ==
Pour aller plus rapidement, il est possible de faire directement un import du code json du flow au lieu de créer les nodes précédents :
[
{
"id": "798f513a.e8a04",
"type": "tab",
"label": "Mon 1er flow",
"disabled": false,
"info": "Flow de test pour :\n- Récupérer une donnée MQTT et afficher\n- Envoyer une valeur par MQTT"
},
{
"id": "57a9ca2c.283154",
"type": "ui_base",
"theme": {
"name": "theme-dark",
"lightTheme": {
"default": "#0094CE",
"baseColor": "#0094CE",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"edited": true,
"reset": false
},
"darkTheme": {
"default": "#097479",
"baseColor": "#097479",
"baseFont": "Verdana,Verdana,Geneva,sans-serif",
"edited": true,
"reset": false
},
"customTheme": {
"name": "Untitled Theme 1",
"default": "#4B7930",
"baseColor": "#4B7930",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"reset": false
},
"themeState": {
"base-color": {
"default": "#097479",
"value": "#097479",
"edited": false
},
"page-titlebar-backgroundColor": {
"value": "#097479",
"edited": false
},
"page-backgroundColor": {
"value": "#111111",
"edited": false
},
"page-sidebar-backgroundColor": {
"value": "#000000",
"edited": false
},
"group-textColor": {
"value": "#0eb8c0",
"edited": false
},
"group-borderColor": {
"value": "#555555",
"edited": false
},
"group-backgroundColor": {
"value": "#333333",
"edited": false
},
"widget-textColor": {
"value": "#eeeeee",
"edited": false
},
"widget-backgroundColor": {
"value": "#097479",
"edited": false
},
"widget-borderColor": {
"value": "#333333",
"edited": false
},
"base-font": {
"value": "Verdana,Verdana,Geneva,sans-serif"
}
}
},
"site": {
"name": "Node-RED Dashboard",
"hideToolbar": "false",
"allowSwipe": "false",
"allowTempTheme": "true",
"dateFormat": "DD/MM/YYYY",
"sizes": {
"sx": 48,
"sy": 48,
"gx": 6,
"gy": 6,
"cx": 6,
"cy": 6,
"px": 0,
"py": 0
}
}
},
{
"id": "106a0892.4df7b7",
"type": "ui_tab",
"z": "",
"name": "Ecran principale",
"icon": "dashboard",
"order": 1
},
{
"id": "8e831ec7.d81eb",
"type": "ui_group",
"z": "",
"name": "Flux reçus",
"tab": "106a0892.4df7b7",
"order": 1,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "279e1ad8.ebeae6",
"type": "ui_group",
"z": "",
"name": "Envoie infos",
"tab": "106a0892.4df7b7",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "f460a0.8fc35f6",
"type": "mqtt-broker",
"z": "",
"name": "Mon Broker",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "503ea954.5b97c8",
"type": "ui_switch",
"z": "798f513a.e8a04",
"name": "ON/OFF switch",
"label": "ON/OFF switch",
"group": "279e1ad8.ebeae6",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "switch",
"style": "",
"onvalue": "ON",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "OFF",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 225,
"y": 265,
"wires": [
[
"8495340b.8c7758"
]
]
},
{
"id": "e98fe402.458458",
"type": "ui_text",
"z": "798f513a.e8a04",
"group": "8e831ec7.d81eb",
"order": 0,
"width": 0,
"height": 0,
"name": "Valeur actuelle",
"label": "Valeur Actuelle",
"format": "{{msg.payload}}",
"layout": "row-spread",
"x": 220,
"y": 323,
"wires": []
},
{
"id": "9878823e.bbfaa",
"type": "mqtt in",
"z": "798f513a.e8a04",
"name": "Lecture user/feeds/numbers",
"topic": "user/feeds/numbers",
"qos": "2",
"broker": "f460a0.8fc35f6",
"x": 144,
"y": 455,
"wires": [
[
"e98fe402.458458",
"a63e7897.d1d608"
]
]
},
{
"id": "8495340b.8c7758",
"type": "mqtt out",
"z": "798f513a.e8a04",
"name": "Envoie vers user/feeds/onoff",
"topic": "user/feeds/onoff",
"qos": "",
"retain": "",
"broker": "f460a0.8fc35f6",
"x": 392,
"y": 175,
"wires": []
},
{
"id": "a63e7897.d1d608",
"type": "ui_chart",
"z": "798f513a.e8a04",
"name": "Valeur du courant",
"group": "8e831ec7.d81eb",
"order": 0,
"width": 0,
"height": 0,
"label": "Valeur du courant",
"chartType": "line",
"legend": "true",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": true,
"ymin": "",
"ymax": "",
"removeOlder": 1,
"removeOlderPoints": "",
"removeOlderUnit": "3600",
"cutout": 0,
"useOneColor": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"x": 339,
"y": 548,
"wires": [
[],
[]
]
}
]
===== MQTT et InfluxDB =====
En partant du principe que InfluxDB a été installé (voir [[https://gist.github.com/gyassine/27dd5bc1ff84bc3e98f6d0ec5cb549f4|mon tuto]]), la configuration de telegraf se fait comme suit :
[[inputs.mqtt_consumer]]
## MQTT broker URLs to be used. The format should be scheme://host:port,
## schema can be tcp, ssl, or ws.
servers = ["tcp://10.243.4.250:1883"]
## MQTT QoS, must be 0, 1, or 2
qos = 0
## Connection timeout for initial connection in seconds
connection_timeout = "30s"
## Topics to subscribe to
topics = [
"CtrlLoad/#",
"NetwEmul/#",
"SolarPan/#",
]
# if true, messages that can't be delivered while the subscriber is offline
# will be delivered when it comes back (such as on service restart).
# NOTE: if true, client_id MUST be set
persistent_session = false
# If empty, a random client ID will be generated.
client_id = ""
## username and password to connect MQTT server.
username = "Admin"
password = "apqm"
## Optional SSL Config
# ssl_ca = "/etc/telegraf/ca.pem"
# ssl_cert = "/etc/telegraf/cert.pem"
# ssl_key = "/etc/telegraf/key.pem"
## Use SSL but skip chain & host verification
# insecure_skip_verify = false
## Data format to consume.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_INPUT.md
data_format = "value"
data_type= "integer"
Les valeurs sont ensuite stocké avec les tag appropriés (par exemple ''%%CtrlLoad/feeds/numbers%%'') dans ''%%telegraf.mqtt_consumer.topic%%''.
//Exemple local de dashboard : http:%%//%%10.82.64.147/chronograf/sources/1/dashboards/3//
===== MQTT et Java =====
L'implémentation de MQTT sous java est simple. Il suffit d'utiliser la [[https://www.eclipse.org/paho/clients/java/|libraire]] ''%%org.eclipse.paho%%'' avec **GRADLE** ''%%compile("org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0")%%'' ou **MAVEN**
org.eclipse.paho
org.eclipse.paho.client.mqttv3
1.1.0
On utilisera les variables suivantes :
String topic = "MQTT Examples";
String content = "Message from MqttPublishSample";
int qos = 2;
String broker = "tcp://10.243.4.250:1883";
La création de la connexion au broker se fait comme suit :
MqttClient client = new MqttClient(broker, MqttClient.generateClientId());
On peut rajouter des options de connexions comme suit :
MqttConnectOptions options = new MqttConnectOptions();
options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setConnectionTimeout(10);
puis on se connecte avec :
client.connect(options); // enlever options si aucune option configurée
Pour publier un message, il suffit de faire :
System.out.println("Publishing message: "+content);
MqttMessage message = new MqttMessage(content.getBytes());
message.setQos(qos);
client.publish(topic, message);
Pour souscrire à un topic, il faut créer une classe qui reçoit et traite les messages :
// Latch used for synchronizing b/w threads
final CountDownLatch latch = new CountDownLatch(1);
// Topic filter the client will subscribe to
final String subTopic = "T/GettingStarted/pubsub";
// Callback
- Anonymous inner-class for receiving messages
mqttClient.setCallback(new MqttCallback() {
public void messageArrived(String topic, MqttMessage message) throws Exception {
// Called when a message arrives from the server that
// matches any subscription made by the client
String time = new Timestamp(System.currentTimeMillis()).toString();
System.out.println("\nReceived a Message!" +
"\n\tTime: " + time +
"\n\tTopic: " + topic +
"\n\tMessage: " + new String(message.getPayload()) +
"\n\tQoS: " + message.getQos() + "\n");
latch.countDown(); // unblock main thread
}
public void connectionLost(Throwable cause) {
System.out.println("Connection to Solace messaging lost!" + cause.getMessage());
latch.countDown();
}
public void deliveryComplete(IMqttDeliveryToken token) {
}
});
// Subscribe client to the topic filter and a QoS level of 0
System.out.println("Subscribing client to topic: " + subTopic);
mqttClient.subscribe(subTopic, 0);
System.out.println("Subscribed");
// Wait for the message to be received
try {
latch.await(); // block here until message received, and latch will flip
} catch (InterruptedException e) {
System.out.println("I was awoken while waiting");
}
Un [[https://github.com/SolaceSamples/solace-samples-mqtt/blob/master/src/main/java/com/solace/samples/TopicPublisher.java|publisher]] et [[https://github.com/SolaceSamples/solace-samples-mqtt/blob/master/src/main/java/com/solace/samples/TopicSubscriber.java|subscriber]] complet est disponible sur GitHub.
//Source : https:%%//%%dev.solace.com/samples/solace-samples-mqtt/publish-subscribe///
====== Code final ======
===== Arduino =====
/***************************************************
Adafruit MQTT Library WINC1500 Modified by Yassine
Demo written by Limor Fried/Ladyada for Adafruit Industries.
Modified by Yassine Gangat for LE²P.
MIT license, all text above must be included in any redistribution
****************************************************/
#include
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include
//
---------------------------- GROVE LCD Lib
-------------------------
//#include // i2c LIB to use LCD
#include "rgb_lcd.h" // lcd LIB
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
const char ssid[] = SECRET_SSID; // your network SSID (name)
const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
// int keyIndex = 0; // your network key Index number (needed only for WEP)
// Initialise the Arduino data pins for INPUT/OUTPUT
const int analogInPin = A0;
const int RELAY2 = 8;
const int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
/************************* Broker Setup **********************************/
#define SERVER "192.168.2.2"
#define SERVERPORT 1883
#define USERNAME "SolarPan" // NetwEmul
- CtrlLoad
- SolarPan
#define PWD "apqm"
/******************************* Global State ****************************/
//Set up the wifi client & Adafruit MQTT Client
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, SERVER, SERVERPORT, USERNAME, PWD);
#define halt(s) { Serial.println(F( s )); while(1); }
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: /feeds/
Adafruit_MQTT_Publish numbers = Adafruit_MQTT_Publish(&mqtt, USERNAME "/feeds/numbers");
// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffmsg = Adafruit_MQTT_Subscribe(&mqtt, USERNAME "/feeds/onoff");
/*************************** Sketch Code ************************************/
//
--------------------------- Variables & others
--------------------------------
rgb_lcd lcd;
byte heart[8] = {
0b00000,
0b01010,
0b11111,
0b11111,
0b11111,
0b01110,
0b00100,
0b00000
};
void setup() {
//
------------------------- Initialization Serial
------------------------------
while (!Serial); // wait for serial port to connect. Needed for native USB port only
Serial.begin(9600);
// Serial.println(F("Adafruit MQTT Library WINC1500 Modified by Yassine"));
//
---------------------- Initialization Wifi WINC1500
--------------------------
// Initialise the Client
// Serial.print(F("\nInit the WiFi module..."));
// check for the presence of the breakout
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(F("WINC1500 not present"));
// don't continue:
while (true);
}
// Serial.println(F("ATWINC OK!"));
//
------------------------------ Physical part
----------------------------------
// Serial.println(F("LCD Init"));
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
#if 1
lcd.createChar(0, heart);
#endif
lcd.setCursor(0, 0);
lcd.print(F("Made with "));
lcd.write((unsigned char)0);
lcd.setCursor(0, 1);
lcd.print(F(" by Yassine"));
pinMode(RELAY2, OUTPUT);
//
--------------------------- Variables & others
--------------------------------
mqtt.subscribe(&onoffmsg);
}
// uint32_t x = 0;
void loop() {
//
------------------------------ MQTT Connection
--------------------------------
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected).
MQTT_connect();
// lcd.setRGB(255,165,0);
//
------------------------------ Subscription
-----------------------------------
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(5000))) {
if (subscription == &onoffmsg) {
Serial.print(F("Got: "));
Serial.println((char *)onoffmsg.lastread);
if (0 == strcmp((char *)onoffmsg.lastread, "OFF")) {
lcd.setRGB(255, 0, 0);
lcd.setCursor(0, 1);
lcd.print(F("Closing "));
lcd.print(F(USERNAME));
digitalWrite(RELAY2, LOW); // Turns OFF Relays 1
}
if (0 == strcmp((char *)onoffmsg.lastread, "ON")) {
lcd.setRGB(0, 255, 0);
lcd.setCursor(0, 1);
lcd.print(F("Opening "));
lcd.print(F(USERNAME));
digitalWrite(RELAY2, HIGH); // Turns ON Relays 1
}
}
}
//
------------------------------ Publication
----------------------------------
int32_t val = mesureSimple(analogInPin);
if (val < 0) {
lcd.setRGB(245, 130, 49);
} else {
lcd.setRGB(0, 0, 117);
}
// int32_t val = mesure(analogInPin) * 100;
Serial.print(F("\nSending "));
Serial.print(val);
lcd.setCursor(0, 1);
lcd.print(F(" "));
lcd.setCursor(0, 1);
lcd.print(F(USERNAME));
lcd.setCursor(9, 1);
lcd.print(val);
// Si on met double au lieu de int32_t, plantage !!!
if (! numbers.publish(val)) {
Serial.println(F("...Failed"));
} else {
Serial.println(F("...OK!"));
}
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(F("Attempting to connect to SSID: "));
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
uint8_t timeout = 10;
while (timeout && (WiFi.status() != WL_CONNECTED)) {
timeout--;
delay(1000);
}
}
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print(F("Connecting to MQTT... "));
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
Serial.println(ret);
Serial.println(F("Retrying MQTT connection in 5 seconds..."));
mqtt.disconnect();
delay(5000); // wait 5 seconds
}
Serial.println(F("MQTT Connected!"));
}
double mesure(int analogPin) {
const int ACSoffset = 2500;
double Amps = 0;
/*double Voltage = 0;
int RawValue= 0;
RawValue = analogRead(analogPin);
/*Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
Amps = ((Voltage
- ACSoffset) / mVperAmp);*/
Amps = (((analogRead(analogPin) / 1024.0) * 5000
- ACSoffset) / mVperAmp);
/*Serial.print("Raw Value = " ); // shows pre-scaled value
Serial.print(RawValue);
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3);
// the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3);
// the '3' after voltage allows you to display 3 digits after decimal point
delay(2500); */
return (Amps);
}
int mesureSimple(int analogPin) {
int Valeur = analogRead(analogPin);
return (Valeur);
}
===== Node-RED =====
[
{
"id": "798f513a.e8a04",
"type": "tab",
"label": "Mon 1er flow",
"disabled": false,
"info": "Flow de test pour :\n- Récupérer une donnée MQTT et afficher\n- Envoyer une valeur par MQTT"
},
{
"id": "57a9ca2c.283154",
"type": "ui_base",
"theme": {
"name": "theme-dark",
"lightTheme": {
"default": "#0094CE",
"baseColor": "#0094CE",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"edited": true,
"reset": false
},
"darkTheme": {
"default": "#097479",
"baseColor": "#097479",
"baseFont": "Verdana,Verdana,Geneva,sans-serif",
"edited": true,
"reset": false
},
"customTheme": {
"name": "Untitled Theme 1",
"default": "#4B7930",
"baseColor": "#4B7930",
"baseFont": "-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen-Sans,Ubuntu,Cantarell,Helvetica Neue,sans-serif",
"reset": false
},
"themeState": {
"base-color": {
"default": "#097479",
"value": "#097479",
"edited": false
},
"page-titlebar-backgroundColor": {
"value": "#097479",
"edited": false
},
"page-backgroundColor": {
"value": "#111111",
"edited": false
},
"page-sidebar-backgroundColor": {
"value": "#000000",
"edited": false
},
"group-textColor": {
"value": "#0eb8c0",
"edited": false
},
"group-borderColor": {
"value": "#555555",
"edited": false
},
"group-backgroundColor": {
"value": "#333333",
"edited": false
},
"widget-textColor": {
"value": "#eeeeee",
"edited": false
},
"widget-backgroundColor": {
"value": "#097479",
"edited": false
},
"widget-borderColor": {
"value": "#333333",
"edited": false
},
"base-font": {
"value": "Verdana,Verdana,Geneva,sans-serif"
}
}
},
"site": {
"name": "Node-RED Dashboard",
"hideToolbar": "false",
"allowSwipe": "false",
"allowTempTheme": "true",
"dateFormat": "DD/MM/YYYY",
"sizes": {
"sx": 48,
"sy": 48,
"gx": 6,
"gy": 6,
"cx": 6,
"cy": 6,
"px": 0,
"py": 0
}
}
},
{
"id": "106a0892.4df7b7",
"type": "ui_tab",
"z": "",
"name": "Ecran principale",
"icon": "dashboard",
"order": 1
},
{
"id": "8e831ec7.d81eb",
"type": "ui_group",
"z": "",
"name": "Flux reçus",
"tab": "106a0892.4df7b7",
"order": 1,
"disp": true,
"width": "17",
"collapse": false
},
{
"id": "279e1ad8.ebeae6",
"type": "ui_group",
"z": "",
"name": "Envoie infos",
"tab": "106a0892.4df7b7",
"order": 2,
"disp": true,
"width": "6",
"collapse": false
},
{
"id": "f460a0.8fc35f6",
"type": "mqtt-broker",
"z": "",
"name": "Mon Broker",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
},
{
"id": "503ea954.5b97c8",
"type": "ui_switch",
"z": "798f513a.e8a04",
"name": "NetwEmul ON/OFF switch",
"label": "NetwEmul ON/OFF switch",
"group": "279e1ad8.ebeae6",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "switch",
"style": "",
"onvalue": "ON",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "OFF",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 188,
"y": 176,
"wires": [
[
"8495340b.8c7758"
]
]
},
{
"id": "e98fe402.458458",
"type": "ui_text",
"z": "798f513a.e8a04",
"group": "8e831ec7.d81eb",
"order": 0,
"width": 0,
"height": 0,
"name": "Valeur actuelle",
"label": "Valeur Actuelle",
"format": "{{msg.payload}}",
"layout": "row-spread",
"x": 480,
"y": 443,
"wires": []
},
{
"id": "9878823e.bbfaa",
"type": "mqtt in",
"z": "798f513a.e8a04",
"name": "Lecture de SolarPan",
"topic": "SolarPan/feeds/numbers",
"qos": "2",
"broker": "f460a0.8fc35f6",
"x": 151,
"y": 479,
"wires": [
[
"e98fe402.458458",
"a63e7897.d1d608"
]
]
},
{
"id": "8495340b.8c7758",
"type": "mqtt out",
"z": "798f513a.e8a04",
"name": "Envoie vers NetwEmul/feeds/onoff",
"topic": "NetwEmul/feeds/onoff",
"qos": "",
"retain": "",
"broker": "f460a0.8fc35f6",
"x": 502,
"y": 178,
"wires": []
},
{
"id": "a63e7897.d1d608",
"type": "ui_chart",
"z": "798f513a.e8a04",
"name": "Ensoleillement",
"group": "8e831ec7.d81eb",
"order": 0,
"width": 0,
"height": 0,
"label": "Ensoleillement",
"chartType": "line",
"legend": "true",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": "1",
"removeOlderPoints": "",
"removeOlderUnit": "60",
"cutout": 0,
"useOneColor": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"x": 472,
"y": 506,
"wires": [
[],
[]
]
},
{
"id": "c447fb5f.ce5208",
"type": "ui_switch",
"z": "798f513a.e8a04",
"name": "CtrlLoad ON/OFF switch",
"label": "CtrlLoad ON/OFF switch",
"group": "279e1ad8.ebeae6",
"order": 0,
"width": 0,
"height": 0,
"passthru": true,
"decouple": "false",
"topic": "switch",
"style": "",
"onvalue": "ON",
"onvalueType": "str",
"onicon": "",
"oncolor": "",
"offvalue": "OFF",
"offvalueType": "str",
"officon": "",
"offcolor": "",
"x": 178,
"y": 243,
"wires": [
[
"4096fa94.514d14"
]
]
},
{
"id": "4096fa94.514d14",
"type": "mqtt out",
"z": "798f513a.e8a04",
"name": "Envoie vers CtrlLoad/feeds/onoff",
"topic": "CtrlLoad/feeds/onoff",
"qos": "",
"retain": "",
"broker": "f460a0.8fc35f6",
"x": 502,
"y": 245,
"wires": []
},
{
"id": "33ce16a5.0352ca",
"type": "mqtt in",
"z": "798f513a.e8a04",
"name": "Lecture de NetwEmul",
"topic": "NetwEmul/feeds/numbers",
"qos": "2",
"broker": "f460a0.8fc35f6",
"x": 159,
"y": 552,
"wires": [
[
"f185a9c5.e05d98"
]
]
},
{
"id": "6020fc0e.f19df4",
"type": "mqtt in",
"z": "798f513a.e8a04",
"name": "Lecture de CtrlLoad",
"topic": "CtrlLoad/feeds/numbers",
"qos": "2",
"broker": "f460a0.8fc35f6",
"x": 148,
"y": 624,
"wires": [
[
"f185a9c5.e05d98"
]
]
},
{
"id": "f185a9c5.e05d98",
"type": "ui_chart",
"z": "798f513a.e8a04",
"name": "Valeur du courant",
"group": "8e831ec7.d81eb",
"order": 0,
"width": 0,
"height": 0,
"label": "Valeur du courant",
"chartType": "line",
"legend": "true",
"xformat": "HH:mm:ss",
"interpolate": "linear",
"nodata": "",
"dot": false,
"ymin": "",
"ymax": "",
"removeOlder": "1",
"removeOlderPoints": "",
"removeOlderUnit": "60",
"cutout": 0,
"useOneColor": false,
"colors": [
"#1f77b4",
"#aec7e8",
"#ff7f0e",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5"
],
"useOldStyle": false,
"x": 486,
"y": 599,
"wires": [
[],
[]
]
}
]