commit
e0f99c548f
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,2 +1,6 @@
|
|||||||
.vscode/*
|
.vscode/*
|
||||||
mqttfastledmenu.h
|
arduino/mqttfastledmenu/mqttfastledmenu.h
|
||||||
|
arduino/.pioenvs
|
||||||
|
arduino/.piolibdeps
|
||||||
|
arduino/.clang_complete
|
||||||
|
arduino/.gcc-flags.json
|
||||||
|
|||||||
@ -6,23 +6,22 @@ inocode:
|
|||||||
INSTBOARD: "esp8266:esp8266"
|
INSTBOARD: "esp8266:esp8266"
|
||||||
BOARD: "${INSTBOARD}:nodemcuv2"
|
BOARD: "${INSTBOARD}:nodemcuv2"
|
||||||
before_script:
|
before_script:
|
||||||
- apt update >/dev/null
|
|
||||||
- cd /
|
- cd /
|
||||||
- wget --quiet "https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz" -O "arduino-nightly-linux64.tar.xz"
|
- wget --quiet "https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz" -O "arduino-nightly-linux64.tar.xz"
|
||||||
- tar axf "arduino-nightly-linux64.tar.xz"
|
- tar axf "arduino-nightly-linux64.tar.xz"
|
||||||
- /arduino-nightly/arduino --pref "boardsmanager.additional.urls=${ESPURL}"
|
- /arduino-nightly/arduino --pref "boardsmanager.additional.urls=${ESPURL}"
|
||||||
- /arduino-nightly/arduino --install-boards "${INSTBOARD}"
|
- /arduino-nightly/arduino --install-boards "${INSTBOARD}"
|
||||||
script:
|
script:
|
||||||
- cd "${CI_PROJECT_DIR}"
|
- cd "${CI_PROJECT_DIR}/arduino/${CI_PROJECT_NAME}"
|
||||||
- cp "mqttfastledmenu.example.h" "mqttfastledmenu.h"
|
- cp "${CI_PROJECT_NAME}.example.h" "${CI_PROJECT_NAME}.h"
|
||||||
- /arduino-nightly/arduino --install-library "FastLED"
|
- /arduino-nightly/arduino --install-library "FastLED"
|
||||||
- /arduino-nightly/arduino --install-library "PubSubClient"
|
- /arduino-nightly/arduino --install-library "PubSubClient"
|
||||||
- /arduino-nightly/arduino --pref "${MEMORY}" --board "${BOARD}" --verify "mqttfastledmenu.ino"
|
- /arduino-nightly/arduino --pref "${MEMORY}" --board "${BOARD}" --verify "${CI_PROJECT_NAME}.ino"
|
||||||
|
|
||||||
yaml:
|
yaml:
|
||||||
image: "python:alpine"
|
image: "python:alpine"
|
||||||
before_script:
|
before_script:
|
||||||
- pip install "PyYAML"
|
- pip install "PyYAML"
|
||||||
script:
|
script:
|
||||||
- cd "${CI_PROJECT_DIR}"
|
- cd "${CI_PROJECT_DIR}/home-assistant"
|
||||||
- python -c "from yaml import load, Loader; load(open('ha_configuration.yml'), Loader=Loader)"
|
- python -c "from yaml import load, Loader; load(open('ha_configuration.yml'), Loader=Loader)"
|
||||||
@ -2,7 +2,7 @@ Introduction
|
|||||||
============
|
============
|
||||||
|
|
||||||
Le but est d'avoir un selecteur d'effet, choix de la vitesse et de la couleur.
|
Le but est d'avoir un selecteur d'effet, choix de la vitesse et de la couleur.
|
||||||
Un exemple de configuration pour home-assistant se trouve dans [ha_configuration.yml](ha\_configuration.yml).
|
Un exemple de configuration pour home-assistant se trouve dans [ha_configuration.yml](home-assistant/ha\_configuration.yml).
|
||||||
|
|
||||||
Matériel
|
Matériel
|
||||||
========
|
========
|
||||||
@ -17,5 +17,5 @@ Matériel
|
|||||||
Médias
|
Médias
|
||||||
======
|
======
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "mqttfastledmenu.h"
|
#include "mqttfastledmenu.h"
|
||||||
|
|
||||||
#include <FastLED.h>
|
#include <FastLED.h>
|
||||||
@ -31,16 +33,14 @@ void setup()
|
|||||||
client.setServer(MQTT_SERVER, MQTT_PORT);
|
client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||||
client.setCallback(callbackMQTT);
|
client.setCallback(callbackMQTT);
|
||||||
testConnectMQTT();
|
testConnectMQTT();
|
||||||
client.subscribe(MQTT_LED_COMMAND);
|
// TODO : ne marche pas comme je le désire :
|
||||||
client.subscribe(MQTT_LED_EFFECT_COMMAND);
|
// au boot il prends les params par défaut, j'aimerais ceux de home assistant
|
||||||
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
|
|
||||||
client.subscribe(MQTT_LED_SPEED_COMMAND);
|
|
||||||
client.subscribe(MQTT_LED_COLOR_COMMAND);
|
|
||||||
|
|
||||||
// LED
|
// LED
|
||||||
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
|
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
|
||||||
ledBlackAll();
|
ledBlackAll();
|
||||||
FastLED.setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
|
Serial.println("Ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
// WIFI
|
// WIFI
|
||||||
@ -55,8 +55,7 @@ void setupWifi()
|
|||||||
delay(500);
|
delay(500);
|
||||||
Serial.print(".");
|
Serial.print(".");
|
||||||
}
|
}
|
||||||
|
Serial.println(" OK");
|
||||||
Serial.println();
|
|
||||||
Serial.print("IP : ");
|
Serial.print("IP : ");
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
@ -67,12 +66,13 @@ void testConnectMQTT()
|
|||||||
while (!client.connected()) {
|
while (!client.connected()) {
|
||||||
Serial.print("Connexion au serveur MQTT... ");
|
Serial.print("Connexion au serveur MQTT... ");
|
||||||
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
|
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
|
||||||
Serial.println("OK");
|
Serial.print("OK\nSubscribe");
|
||||||
client.subscribe(MQTT_LED_COMMAND);
|
client.subscribe(MQTT_LED_COMMAND);
|
||||||
client.subscribe(MQTT_LED_EFFECT_COMMAND);
|
client.subscribe(MQTT_LED_EFFECT_COMMAND);
|
||||||
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
|
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
|
||||||
client.subscribe(MQTT_LED_SPEED_COMMAND);
|
client.subscribe(MQTT_LED_SPEED_COMMAND);
|
||||||
client.subscribe(MQTT_LED_COLOR_COMMAND);
|
client.subscribe(MQTT_LED_COLOR_COMMAND);
|
||||||
|
Serial.println(" OK");
|
||||||
} else {
|
} else {
|
||||||
Serial.print("KO, erreur : ");
|
Serial.print("KO, erreur : ");
|
||||||
Serial.print(client.state());
|
Serial.print(client.state());
|
||||||
@ -103,7 +103,8 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
|
|||||||
client.publish(MQTT_LED_STATE, message_buff, true);
|
client.publish(MQTT_LED_STATE, message_buff, true);
|
||||||
} else {
|
} else {
|
||||||
ledState = false;
|
ledState = false;
|
||||||
client.publish(MQTT_LED_STATE, message_buff, true);
|
ledBlackAll();
|
||||||
|
client.publish(MQTT_LED_STATE, message_buff, false);
|
||||||
}
|
}
|
||||||
} else if (stopic == MQTT_LED_EFFECT_COMMAND) {
|
} else if (stopic == MQTT_LED_EFFECT_COMMAND) {
|
||||||
// Si on ne repasse pas tout à noir, cela peut faire des effets surprenants
|
// Si on ne repasse pas tout à noir, cela peut faire des effets surprenants
|
||||||
@ -116,7 +117,12 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
|
|||||||
FastLED.setBrightness(brightness);
|
FastLED.setBrightness(brightness);
|
||||||
client.publish(MQTT_LED_BRIGHTNESS_STATE, message_buff, true);
|
client.publish(MQTT_LED_BRIGHTNESS_STATE, message_buff, true);
|
||||||
} else if (stopic == MQTT_LED_COLOR_COMMAND) {
|
} else if (stopic == MQTT_LED_COLOR_COMMAND) {
|
||||||
color = msgString.toInt();
|
// Sample : 134,168,255
|
||||||
|
int red = msgString.substring(0, msgString.indexOf(',')).toInt();
|
||||||
|
int green = msgString.substring(msgString.indexOf(',') + 1, msgString.lastIndexOf(',')).toInt();
|
||||||
|
int blue = msgString.substring(msgString.lastIndexOf(',') + 1).toInt();
|
||||||
|
|
||||||
|
color=((red <<16)|(green <<8)|blue);
|
||||||
client.publish(MQTT_LED_COLOR_STATE, message_buff, true);
|
client.publish(MQTT_LED_COLOR_STATE, message_buff, true);
|
||||||
} else if (stopic == MQTT_LED_SPEED_COMMAND) {
|
} else if (stopic == MQTT_LED_SPEED_COMMAND) {
|
||||||
speed = msgString.toInt();
|
speed = msgString.toInt();
|
||||||
@ -129,38 +135,34 @@ void ledBlackAll()
|
|||||||
{
|
{
|
||||||
FastLED.clear();
|
FastLED.clear();
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
FastLED.delay(1000 / speed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ledCylon()
|
void ledCylon()
|
||||||
{
|
{
|
||||||
// Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante
|
// Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante
|
||||||
// TODO : trop d'attente entre les clients.loop !!!!
|
|
||||||
for(int i = 0; i < LED_NUM; i++) {
|
for(int i = 0; i < LED_NUM; i++) {
|
||||||
if ((i % 10) == 0) {
|
EVERY_N_SECONDS(1) {
|
||||||
client.loop();
|
client.loop();
|
||||||
if (ledEffect != LED_EFFECT_CYLON) {
|
if (ledEffect != LED_EFFECT_CYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leds[i] = color;
|
leds[i] = color;
|
||||||
FastLED.show();
|
|
||||||
FastLED.delay(1000 / speed);
|
FastLED.delay(1000 / speed);
|
||||||
leds[i] = CRGB::Black;
|
leds[i] = CRGB::Black;
|
||||||
FastLED.show();
|
|
||||||
FastLED.delay(1000 / speed);
|
FastLED.delay(1000 / speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = LED_NUM - 1; i > 0; i--) {
|
for(int i = LED_NUM - 1; i > 0; i--) {
|
||||||
if ((i % 10) == 0) {
|
EVERY_N_SECONDS(1) {
|
||||||
client.loop();
|
client.loop();
|
||||||
if (ledEffect != LED_EFFECT_CYLON) {
|
if (ledEffect != LED_EFFECT_CYLON) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
leds[i] = color;
|
leds[i] = color;
|
||||||
FastLED.show();
|
|
||||||
FastLED.delay(1000 / speed);
|
FastLED.delay(1000 / speed);
|
||||||
leds[i] = CRGB::Black;
|
leds[i] = CRGB::Black;
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
@ -178,15 +180,12 @@ void ledError()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FastLED.show();
|
|
||||||
FastLED.delay(1000 / speed);
|
FastLED.delay(1000 / speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : ne doit pas rester à terme, ça ne sert à rien de garder une fonction comme ça
|
void ledFullColor()
|
||||||
void ledFullRed()
|
|
||||||
{
|
{
|
||||||
fill_solid(leds, LED_NUM, color);
|
fill_solid(leds, LED_NUM, color);
|
||||||
FastLED.show();
|
|
||||||
FastLED.delay(1000 / speed);
|
FastLED.delay(1000 / speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,29 +194,16 @@ void loop() {
|
|||||||
testConnectMQTT();
|
testConnectMQTT();
|
||||||
client.loop();
|
client.loop();
|
||||||
|
|
||||||
// TODO : à retirer je pense
|
|
||||||
//EVERY_N_SECONDS(180) {
|
|
||||||
// Serial.print("MQTT Subscribe refresh");
|
|
||||||
// client.subscribe(MQTT_LED_EFFECT_COMMAND);
|
|
||||||
// client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
|
|
||||||
// client.subscribe(MQTT_LED_COLOR_COMMAND);
|
|
||||||
// client.subscribe(MQTT_LED_SPEED_COMMAND);
|
|
||||||
// Serial.println(" done");
|
|
||||||
//}
|
|
||||||
|
|
||||||
// LED
|
// LED
|
||||||
if (!ledState) {
|
if (!ledState) {
|
||||||
ledBlackAll();
|
|
||||||
FastLED.delay(1000);
|
FastLED.delay(1000);
|
||||||
} else {
|
} else {
|
||||||
if (ledEffect == LED_EFFECT_CYLON) {
|
if (ledEffect == LED_EFFECT_CYLON) {
|
||||||
ledCylon();
|
ledCylon();
|
||||||
} else if (ledEffect == LED_EFFECT_FULLRED) {
|
} else if (ledEffect == LED_EFFECT_FULLRED) {
|
||||||
ledFullRed();
|
ledFullColor();
|
||||||
} else {
|
} else {
|
||||||
ledError();
|
ledError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : regrouper input et select en un seul group, l'input enverrait directement Off et les effets ne seraient que effets
|
|
||||||
@ -23,8 +23,8 @@
|
|||||||
#define MQTT_USER "XXX"
|
#define MQTT_USER "XXX"
|
||||||
#define MQTT_PASS "XXX"
|
#define MQTT_PASS "XXX"
|
||||||
|
|
||||||
#define MQTT_LED_STATE "strip1/switch"
|
#define MQTT_LED_COMMAND "strip1/switch"
|
||||||
#define MQTT_LED_COMMAND "strip1/status"
|
#define MQTT_LED_STATE "strip1/status"
|
||||||
#define MQTT_LED_EFFECT_COMMAND "strip1/effect/switch"
|
#define MQTT_LED_EFFECT_COMMAND "strip1/effect/switch"
|
||||||
#define MQTT_LED_EFFECT_STATE "strip1/effect/status"
|
#define MQTT_LED_EFFECT_STATE "strip1/effect/status"
|
||||||
#define MQTT_LED_BRIGHTNESS_COMMAND "strip1/brightness/switch"
|
#define MQTT_LED_BRIGHTNESS_COMMAND "strip1/brightness/switch"
|
||||||
@ -38,3 +38,11 @@
|
|||||||
// TODO : essayer, devrait limiter le flikering
|
// TODO : essayer, devrait limiter le flikering
|
||||||
//#define FASTLED_ALLOW_INTERRUPTS 0
|
//#define FASTLED_ALLOW_INTERRUPTS 0
|
||||||
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
|
#define FASTLED_ESP8266_NODEMCU_PIN_ORDER
|
||||||
|
|
||||||
|
void setupWifi();
|
||||||
|
void testConnectMQTT();
|
||||||
|
void callbackMQTT(char* topic, byte* payload, unsigned int length);
|
||||||
|
void ledBlackAll();
|
||||||
|
void ledCylon();
|
||||||
|
void ledError();
|
||||||
|
void ledFullColor();
|
||||||
0
arduino/mqttfastledmenu/mqttfastledmenu.ino
Normal file
0
arduino/mqttfastledmenu/mqttfastledmenu.ino
Normal file
18
arduino/platformio.ini
Normal file
18
arduino/platformio.ini
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; http://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:nodemcuv2]
|
||||||
|
platform=espressif8266
|
||||||
|
board=nodemcuv2
|
||||||
|
framework=arduino
|
||||||
|
|
||||||
|
[platformio]
|
||||||
|
src_dir=mqttfastledmenu
|
||||||
|
lib_dir=/home/jcabillot/Arduino/libraries
|
||||||
@ -17,40 +17,40 @@ input_slider:
|
|||||||
strip1_animation_speed:
|
strip1_animation_speed:
|
||||||
name: "Strip1 Animation Speed"
|
name: "Strip1 Animation Speed"
|
||||||
initial: 120
|
initial: 120
|
||||||
min: 10
|
min: 0
|
||||||
max: 150
|
max: 150
|
||||||
step: 10
|
step: 10
|
||||||
|
|
||||||
light:
|
light:
|
||||||
platform: "mqtt"
|
platform: "mqtt"
|
||||||
name: "Test ESP"
|
name: "Test ESP"
|
||||||
command_topic: "strip1/switch"
|
command_topic: "strip1/switch"
|
||||||
state_topic: "strip1/status"
|
state_topic: "strip1/status"
|
||||||
rgb_state_topic: "strip1/color/switch"
|
rgb_command_topic: "strip1/color/switch"
|
||||||
rgb_command_topic: "strip1/color/status"
|
rgb_state_topic: "strip1/color/status"
|
||||||
brightness_state_topic: "strip1/brightness/switch"
|
brightness_command_topic: "strip1/brightness/switch"
|
||||||
brightness_command_topic: "strip1/brightness/status"
|
brightness_state_topic: "strip1/brightness/status"
|
||||||
|
|
||||||
automation:
|
automation:
|
||||||
- alias: "Strip1 Effect"
|
- alias: "Strip1 Effect"
|
||||||
hide_entity: False
|
hide_entity: True
|
||||||
trigger:
|
trigger:
|
||||||
- platform: "state"
|
- platform: "state"
|
||||||
entity_id: "input_select.strip1_effect"
|
entity_id: "input_select.strip1_effect"
|
||||||
action:
|
action:
|
||||||
- service: "mqtt.publish"
|
- service: "mqtt.publish"
|
||||||
data_template:
|
data_template:
|
||||||
topic: "strip1/effect/switch"
|
topic: "strip1/effect/switch"
|
||||||
payload: '{{ trigger.to_state.state | string }}'
|
payload: '{{ trigger.to_state.state | string }}'
|
||||||
retain: True
|
retain: True
|
||||||
- alias: "Strip1 Animation Speed"
|
- alias: "Strip1 Animation Speed"
|
||||||
hide_entity: False
|
hide_entity: True
|
||||||
trigger:
|
trigger:
|
||||||
- platform: "state"
|
- platform: "state"
|
||||||
entity_id: "input_slider.strip1_animation_speed"
|
entity_id: "input_slider.strip1_animation_speed"
|
||||||
action:
|
action:
|
||||||
- service: "mqtt.publish"
|
- service: "mqtt.publish"
|
||||||
data_template:
|
data_template:
|
||||||
topic: "strip1/speed/switch"
|
topic: "strip1/speed/switch"
|
||||||
payload: '{{ trigger.to_state.state | int }}'
|
payload: '{{ trigger.to_state.state | int }}'
|
||||||
retain: True
|
retain: True
|
||||||
|
Before Width: | Height: | Size: 154 KiB After Width: | Height: | Size: 154 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 238 KiB After Width: | Height: | Size: 238 KiB |
Loading…
x
Reference in New Issue
Block a user