commit
e0f99c548f
6
.gitignore
vendored
6
.gitignore
vendored
@ -1,2 +1,6 @@
|
||||
.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"
|
||||
BOARD: "${INSTBOARD}:nodemcuv2"
|
||||
before_script:
|
||||
- apt update >/dev/null
|
||||
- cd /
|
||||
- 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"
|
||||
- /arduino-nightly/arduino --pref "boardsmanager.additional.urls=${ESPURL}"
|
||||
- /arduino-nightly/arduino --install-boards "${INSTBOARD}"
|
||||
script:
|
||||
- cd "${CI_PROJECT_DIR}"
|
||||
- cp "mqttfastledmenu.example.h" "mqttfastledmenu.h"
|
||||
- cd "${CI_PROJECT_DIR}/arduino/${CI_PROJECT_NAME}"
|
||||
- cp "${CI_PROJECT_NAME}.example.h" "${CI_PROJECT_NAME}.h"
|
||||
- /arduino-nightly/arduino --install-library "FastLED"
|
||||
- /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:
|
||||
image: "python:alpine"
|
||||
before_script:
|
||||
- pip install "PyYAML"
|
||||
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)"
|
||||
@ -2,7 +2,7 @@ Introduction
|
||||
============
|
||||
|
||||
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
|
||||
========
|
||||
@ -17,5 +17,5 @@ Matériel
|
||||
Médias
|
||||
======
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "mqttfastledmenu.h"
|
||||
|
||||
#include <FastLED.h>
|
||||
@ -31,16 +33,14 @@ void setup()
|
||||
client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||
client.setCallback(callbackMQTT);
|
||||
testConnectMQTT();
|
||||
client.subscribe(MQTT_LED_COMMAND);
|
||||
client.subscribe(MQTT_LED_EFFECT_COMMAND);
|
||||
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
|
||||
client.subscribe(MQTT_LED_SPEED_COMMAND);
|
||||
client.subscribe(MQTT_LED_COLOR_COMMAND);
|
||||
// TODO : ne marche pas comme je le désire :
|
||||
// au boot il prends les params par défaut, j'aimerais ceux de home assistant
|
||||
|
||||
// LED
|
||||
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
|
||||
ledBlackAll();
|
||||
FastLED.setBrightness(brightness);
|
||||
Serial.println("Ready");
|
||||
}
|
||||
|
||||
// WIFI
|
||||
@ -55,8 +55,7 @@ void setupWifi()
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
Serial.println(" OK");
|
||||
Serial.print("IP : ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
@ -67,12 +66,13 @@ void testConnectMQTT()
|
||||
while (!client.connected()) {
|
||||
Serial.print("Connexion au serveur MQTT... ");
|
||||
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
|
||||
Serial.println("OK");
|
||||
Serial.print("OK\nSubscribe");
|
||||
client.subscribe(MQTT_LED_COMMAND);
|
||||
client.subscribe(MQTT_LED_EFFECT_COMMAND);
|
||||
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
|
||||
client.subscribe(MQTT_LED_SPEED_COMMAND);
|
||||
client.subscribe(MQTT_LED_COLOR_COMMAND);
|
||||
Serial.println(" OK");
|
||||
} else {
|
||||
Serial.print("KO, erreur : ");
|
||||
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);
|
||||
} else {
|
||||
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) {
|
||||
// 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);
|
||||
client.publish(MQTT_LED_BRIGHTNESS_STATE, message_buff, true);
|
||||
} 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);
|
||||
} else if (stopic == MQTT_LED_SPEED_COMMAND) {
|
||||
speed = msgString.toInt();
|
||||
@ -129,15 +135,13 @@ void ledBlackAll()
|
||||
{
|
||||
FastLED.clear();
|
||||
FastLED.show();
|
||||
FastLED.delay(1000 / speed);
|
||||
}
|
||||
|
||||
void ledCylon()
|
||||
{
|
||||
// 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++) {
|
||||
if ((i % 10) == 0) {
|
||||
EVERY_N_SECONDS(1) {
|
||||
client.loop();
|
||||
if (ledEffect != LED_EFFECT_CYLON) {
|
||||
return;
|
||||
@ -145,14 +149,13 @@ void ledCylon()
|
||||
}
|
||||
|
||||
leds[i] = color;
|
||||
FastLED.show();
|
||||
FastLED.delay(1000 / speed);
|
||||
leds[i] = CRGB::Black;
|
||||
FastLED.show();
|
||||
FastLED.delay(1000 / speed);
|
||||
}
|
||||
|
||||
for(int i = LED_NUM - 1; i > 0; i--) {
|
||||
if ((i % 10) == 0) {
|
||||
EVERY_N_SECONDS(1) {
|
||||
client.loop();
|
||||
if (ledEffect != LED_EFFECT_CYLON) {
|
||||
return;
|
||||
@ -160,7 +163,6 @@ void ledCylon()
|
||||
}
|
||||
|
||||
leds[i] = color;
|
||||
FastLED.show();
|
||||
FastLED.delay(1000 / speed);
|
||||
leds[i] = CRGB::Black;
|
||||
FastLED.show();
|
||||
@ -178,15 +180,12 @@ void ledError()
|
||||
}
|
||||
}
|
||||
|
||||
FastLED.show();
|
||||
FastLED.delay(1000 / speed);
|
||||
}
|
||||
|
||||
// TODO : ne doit pas rester à terme, ça ne sert à rien de garder une fonction comme ça
|
||||
void ledFullRed()
|
||||
void ledFullColor()
|
||||
{
|
||||
fill_solid(leds, LED_NUM, color);
|
||||
FastLED.show();
|
||||
FastLED.delay(1000 / speed);
|
||||
}
|
||||
|
||||
@ -195,29 +194,16 @@ void loop() {
|
||||
testConnectMQTT();
|
||||
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
|
||||
if (!ledState) {
|
||||
ledBlackAll();
|
||||
FastLED.delay(1000);
|
||||
} else {
|
||||
if (ledEffect == LED_EFFECT_CYLON) {
|
||||
ledCylon();
|
||||
} else if (ledEffect == LED_EFFECT_FULLRED) {
|
||||
ledFullRed();
|
||||
ledFullColor();
|
||||
} else {
|
||||
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_PASS "XXX"
|
||||
|
||||
#define MQTT_LED_STATE "strip1/switch"
|
||||
#define MQTT_LED_COMMAND "strip1/status"
|
||||
#define MQTT_LED_COMMAND "strip1/switch"
|
||||
#define MQTT_LED_STATE "strip1/status"
|
||||
#define MQTT_LED_EFFECT_COMMAND "strip1/effect/switch"
|
||||
#define MQTT_LED_EFFECT_STATE "strip1/effect/status"
|
||||
#define MQTT_LED_BRIGHTNESS_COMMAND "strip1/brightness/switch"
|
||||
@ -38,3 +38,11 @@
|
||||
// TODO : essayer, devrait limiter le flikering
|
||||
//#define FASTLED_ALLOW_INTERRUPTS 0
|
||||
#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,7 +17,7 @@ input_slider:
|
||||
strip1_animation_speed:
|
||||
name: "Strip1 Animation Speed"
|
||||
initial: 120
|
||||
min: 10
|
||||
min: 0
|
||||
max: 150
|
||||
step: 10
|
||||
|
||||
@ -26,14 +26,14 @@ light:
|
||||
name: "Test ESP"
|
||||
command_topic: "strip1/switch"
|
||||
state_topic: "strip1/status"
|
||||
rgb_state_topic: "strip1/color/switch"
|
||||
rgb_command_topic: "strip1/color/status"
|
||||
brightness_state_topic: "strip1/brightness/switch"
|
||||
brightness_command_topic: "strip1/brightness/status"
|
||||
rgb_command_topic: "strip1/color/switch"
|
||||
rgb_state_topic: "strip1/color/status"
|
||||
brightness_command_topic: "strip1/brightness/switch"
|
||||
brightness_state_topic: "strip1/brightness/status"
|
||||
|
||||
automation:
|
||||
- alias: "Strip1 Effect"
|
||||
hide_entity: False
|
||||
hide_entity: True
|
||||
trigger:
|
||||
- platform: "state"
|
||||
entity_id: "input_select.strip1_effect"
|
||||
@ -44,7 +44,7 @@ automation:
|
||||
payload: '{{ trigger.to_state.state | string }}'
|
||||
retain: True
|
||||
- alias: "Strip1 Animation Speed"
|
||||
hide_entity: False
|
||||
hide_entity: True
|
||||
trigger:
|
||||
- platform: "state"
|
||||
entity_id: "input_slider.strip1_animation_speed"
|
||||
|
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