Compare commits
9 Commits
b78344743d
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22326398a5 | ||
|
|
78f085915d | ||
|
|
0af54b04b8 | ||
|
|
15fd42805e | ||
|
|
600e110e21 | ||
|
|
47a28dd476 | ||
|
|
a80c5b7be8 | ||
|
|
a2e969b51d | ||
|
|
ca90119874 |
@@ -1,5 +1,5 @@
|
||||
# MQTT Lampe ADN #
|
||||
Programme ESP8266 permettant de faire réagire une double colonne de leds (leds strip) en fonction d'un message MQTT envoyé par un brocker.
|
||||
 Programme ESP8266 permettant de faire réagire une double colonne de leds (leds strip) en fonction d'un message MQTT envoyé par un brocker.
|
||||
|
||||
Le nombre de leds est paramétrable.
|
||||
|
||||
@@ -29,13 +29,6 @@ Les messages MQTT interprétés doivent être dans les topics:
|
||||
|
||||
|
||||
|
||||
# Mise à jour OTA #
|
||||
TODO
|
||||
|
||||
Bien que cela soit possible il n'est pas nécessaire de brancher l'ESP8266 sur un port USB pour le mettre à jour, une simple connexion wifi suffi.
|
||||
La mise à jour se fait un uploadant le firmware compilé dans l'ESP via son URL OTA.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
illustrations/20220529153304_IMG_0890.JPG
Normal file
BIN
illustrations/20220529153304_IMG_0890.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
BIN
illustrations/20220529_174155.jpg
Normal file
BIN
illustrations/20220529_174155.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 136 KiB |
BIN
illustrations/lampAllumee.JPG
Normal file
BIN
illustrations/lampAllumee.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.6 KiB |
BIN
illustrations/schéma 2.png
Normal file
BIN
illustrations/schéma 2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
BIN
illustrations/schéma 3.png
Normal file
BIN
illustrations/schéma 3.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
BIN
illustrations/shéma 1.png
Normal file
BIN
illustrations/shéma 1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 34 KiB |
@@ -12,7 +12,7 @@
|
||||
platform = espressif8266
|
||||
board = nodemcuv2
|
||||
monitor_speed = 115200
|
||||
upload_port = COM11
|
||||
upload_port = COM13
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoPixel@^1.10.4
|
||||
|
||||
33
src/main.cpp
33
src/main.cpp
@@ -10,12 +10,12 @@
|
||||
// lumiere/color/lampeADN (R,V,B) : Changement de couleur des LEDS.
|
||||
// lumiere/brightness/lampeADN value : luminosité [0-255]
|
||||
// lumiere/animation/lampeADN value : ID de l'animation [0-6]
|
||||
// lumiere/allume/lampeADN value : Allummage des leds du bas vers le haut (en %) 0= aucune, 100 =) toutes
|
||||
// lumiere/allume/lampeADN value : Allummage des leds du bas vers le haut (en %) 0= aucune, 100= toutes
|
||||
// ---------------------------------------------------------------------------------------
|
||||
#include <Arduino.h>
|
||||
//#define ModeDebug
|
||||
|
||||
const String firmwareActualVersion = "1.0.0";
|
||||
const String firmwareActualVersion = "1.1.1";
|
||||
|
||||
#ifdef ModeDebug
|
||||
#define DEBUG(message) \
|
||||
@@ -49,7 +49,6 @@ int LED_COUNT = 66;
|
||||
|
||||
|
||||
// LEDS
|
||||
boolean g_BOO_AnimationSeconde = true;
|
||||
#include "my_leds.h"
|
||||
|
||||
|
||||
@@ -104,8 +103,6 @@ void setup() {
|
||||
strip.show(); // Turn OFF all pixels ASAP
|
||||
strip.setBrightness(255);
|
||||
LED_Animation(5);
|
||||
g_BOO_AnimationSeconde = true;
|
||||
|
||||
DEBUG("************************** Tout est initialise");
|
||||
}
|
||||
|
||||
@@ -120,10 +117,6 @@ void setup() {
|
||||
unsigned long lastRecu = 0;
|
||||
int numled = 0;
|
||||
void loop() {
|
||||
// On écoute le serveur OTA
|
||||
// OTA_doUpdate();
|
||||
|
||||
|
||||
// Test si la connection Wifi existe toujours ...................................
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
// Si on est déconnecté on tente de se reconnecter automatiquement avec les anciens settings.
|
||||
@@ -145,28 +138,6 @@ void loop() {
|
||||
|
||||
|
||||
|
||||
|
||||
// Animation des LEDS toutes les secondes .........................................
|
||||
if (millis() - lastRecu > 1000 ) {
|
||||
lastRecu = millis();
|
||||
|
||||
// Allumage d'une led
|
||||
if ( g_BOO_AnimationSeconde ) {
|
||||
if ( numled >= LED_COUNT /2 ) {
|
||||
LED_AllumeBaton( numled -1, 0,0,0 ); // Noir
|
||||
LED_AllumeBaton( numled -2, 0,0,0 ); // Noir
|
||||
numled = 0;
|
||||
}
|
||||
LED_AllumeBaton( numled, 255,0,100 ); // Rouge
|
||||
LED_AllumeBaton( numled -1, 50,0,70 ); // Noir
|
||||
LED_AllumeBaton( numled -2, 0,0,0 ); // Noir
|
||||
|
||||
numled++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Traitement des Messages MQTT ...................................................
|
||||
// Tout est fait dans MQTT_callback()
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// MQTT client
|
||||
#include <PubSubClient.h>
|
||||
#define MQTT_broker "192.168.0.11"
|
||||
#define MQTT_broker "192.168.100.11"
|
||||
#define MQTT_port 1883
|
||||
#define MQTT_user ""
|
||||
#define MQTT_password ""
|
||||
@@ -14,6 +14,7 @@ char topic_lumiere_color[8 + 6 + DEVICEID_SIZE];
|
||||
char topic_lumiere_bright[8 + 11 + DEVICEID_SIZE];
|
||||
char topic_lumiere_anim[8 + 10 + DEVICEID_SIZE];
|
||||
char topic_lumiere_rempli[8 + 7 + DEVICEID_SIZE];
|
||||
char topic_lumiere_allume_barres[8 + 7 + 7 + DEVICEID_SIZE];
|
||||
|
||||
|
||||
|
||||
@@ -62,9 +63,9 @@ void MQTT_connect() {
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// Déclenche les actions à la réception d'un message MQTT.
|
||||
// lumiere/portal [ON|OFF] : Allumage de la barre de LEDS.
|
||||
// lumiere/portal/color [#RRVVBB] : Changement de couleur des LEDS.
|
||||
// lumiere/portal/animation [1/2/3/4/5] : Animation des LEDS.
|
||||
// lumiere/lampeADN [ON|OFF] : Allumage de la barre de LEDS.
|
||||
// lumiere/lampeADN/color [#RRVVBB] : Changement de couleur des LEDS.
|
||||
// lumiere/lampeADN/animation [1/2/3/4/5] : Animation des LEDS.
|
||||
//
|
||||
void MQTT_callback(char* topic, byte* payload, unsigned int length) {
|
||||
|
||||
@@ -87,16 +88,12 @@ void MQTT_callback(char* topic, byte* payload, unsigned int length) {
|
||||
|
||||
if ( String( message ) == "ON") {
|
||||
DEBUG("Allumage les leds");
|
||||
c.B = 255;
|
||||
LED_changeCouleur( c, 10 );
|
||||
|
||||
} else if ( String( message ) == "OFF") {
|
||||
DEBUG("Extinction des leds");
|
||||
LED_changeCouleur( c, 10 );
|
||||
LED_changeCouleurInverse( c, 1 );
|
||||
}
|
||||
|
||||
g_BOO_AnimationSeconde = false;
|
||||
|
||||
|
||||
// .....................................................................................
|
||||
} else if ( strcmp( topic, topic_lumiere_color) == 0) {
|
||||
@@ -140,6 +137,19 @@ void MQTT_callback(char* topic, byte* payload, unsigned int length) {
|
||||
DEBUG("Detection du topics :" + String( topic_lumiere_rempli ));
|
||||
DEBUG("Lancement du remplissage à :" + String( message ));
|
||||
LED_Remplissage(String( message ).toInt());
|
||||
|
||||
|
||||
// .....................................................................................
|
||||
} else if ( strcmp( topic, topic_lumiere_allume_barres) ==0 ) {
|
||||
DEBUG("Detection du topics :" + String( topic_lumiere_allume_barres ));
|
||||
DEBUG("Lancement du remplissage des " + String( message ) + " barres");
|
||||
Couleur color;
|
||||
color.R = 255;
|
||||
color.V = 255;
|
||||
color.B = 255;
|
||||
for(int i = 0; i < String( message ).toInt(); i++){
|
||||
LED_AllumeBaton(i, color );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,4 +179,5 @@ void MQTT_setup(){
|
||||
sprintf( topic_lumiere_bright, "lumiere/brightness/%s", DeviceID);
|
||||
sprintf( topic_lumiere_anim, "lumiere/animation/%s", DeviceID);
|
||||
sprintf( topic_lumiere_rempli, "lumiere/allume/%s", DeviceID);
|
||||
sprintf( topic_lumiere_allume_barres, "lumiere/allume/%s/barres", DeviceID);
|
||||
}
|
||||
@@ -33,6 +33,9 @@ void LED_AllumeBaton(unsigned int num, Couleur color){
|
||||
|
||||
// ALLUMAGE LEDS DESCENDENTE
|
||||
strip.setPixelColor(LED_COUNT-1 - num, strip.Color( color.R, color.V, color.B ));
|
||||
|
||||
// MISE À JOUR DU LED STRIP
|
||||
strip.show();
|
||||
}
|
||||
void LED_AllumeBaton(unsigned int num, unsigned int R, unsigned int V, unsigned int B){
|
||||
// ALLUMAGE LEDS MONTANTE
|
||||
@@ -60,13 +63,28 @@ void LED_colorWipe(uint32_t color, int wait) {
|
||||
|
||||
|
||||
/** --------------------------------------------------------------------------------------
|
||||
* @brief Change toute la lampe avec la oculeur passée en paramètre.
|
||||
* @brief Change toute la lampe avec la couleur passée en paramètre en partant du bas
|
||||
*
|
||||
* @param color la couleur RVB
|
||||
* @param wait intger avec le delay
|
||||
*/
|
||||
void LED_changeCouleur(Couleur color, int wait){
|
||||
for( int i =0; i<= LED_COUNT; i++){
|
||||
for( int i =0; i<= LED_COUNT/2; i++){
|
||||
LED_AllumeBaton(i, color);
|
||||
strip.show(); // Update strip to match
|
||||
delay(wait); // Pause for a moment
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** --------------------------------------------------------------------------------------
|
||||
* @brief Change toute la lampe avec la couleur passée en paramètre en partant du haut.
|
||||
*
|
||||
* @param color la couleur RVB
|
||||
* @param wait intger avec le delay
|
||||
*/
|
||||
void LED_changeCouleurInverse(Couleur color, int wait){
|
||||
for( int i = LED_COUNT/2; i >= 0; i--){
|
||||
LED_AllumeBaton(i, color);
|
||||
strip.show(); // Update strip to match
|
||||
delay(wait); // Pause for a moment
|
||||
@@ -251,16 +269,10 @@ void theaterChaseRainbow(uint8_t wait) {
|
||||
*/
|
||||
void LED_Remplissage(unsigned int value){
|
||||
|
||||
// ON PASSE TOUTES LES LEDS EN NOIR
|
||||
for (int i = 0; i < LED_COUNT; i++) {
|
||||
strip.setPixelColor(i, strip.Color(0,0,0)); // Noir
|
||||
}
|
||||
strip.show();
|
||||
|
||||
|
||||
// ALLUMAGE DES LEDS
|
||||
Couleur color;
|
||||
for (int i = 0; i <= (int) ((LED_COUNT/2) * value / 100); i++) {
|
||||
int max = (int) ((LED_COUNT/2) * value / 100);
|
||||
for (int i = 0; i <= max; i++) {
|
||||
// DEFINITION DE LA COULEUR
|
||||
int value = 255 - i * 255/(LED_COUNT/2);
|
||||
color.R = 255 - value;
|
||||
@@ -270,10 +282,16 @@ void LED_Remplissage(unsigned int value){
|
||||
|
||||
// ALLUMAGE DU BATON DE LEDS
|
||||
LED_AllumeBaton(i, color );
|
||||
|
||||
// MISE À JOUR DU LED STRIP
|
||||
strip.show();
|
||||
}
|
||||
|
||||
// ON PASSE TOUTES LES LEDS EN NOIR
|
||||
color.R = 0;
|
||||
color.V = 0;
|
||||
color.B = 0;
|
||||
for (int i = max +1; i < LED_COUNT / 2 ; i++) {
|
||||
LED_AllumeBaton(i, color );
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -284,7 +302,6 @@ void LED_Remplissage(unsigned int value){
|
||||
// [1..9]
|
||||
//
|
||||
void LED_Animation(int num) {
|
||||
g_BOO_AnimationSeconde = false;
|
||||
DEBUG(num);
|
||||
switch ( num ) {
|
||||
case 0:
|
||||
@@ -305,9 +322,6 @@ void LED_Animation(int num) {
|
||||
case 5:
|
||||
rainbowCycle(10);
|
||||
break;
|
||||
case 6:
|
||||
g_BOO_AnimationSeconde = true;
|
||||
break;
|
||||
default:
|
||||
DEBUG("Animation inconnue ->" + String(num) );
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user