Merge branch 'dev' into 'master'

Dev

See merge request !2
This commit is contained in:
Julien Cabillot 2017-03-09 21:06:55 +01:00
commit e0f99c548f
12 changed files with 100 additions and 85 deletions

6
.gitignore vendored
View File

@ -1,2 +1,6 @@
.vscode/*
mqttfastledmenu.h
arduino/mqttfastledmenu/mqttfastledmenu.h
arduino/.pioenvs
arduino/.piolibdeps
arduino/.clang_complete
arduino/.gcc-flags.json

View File

@ -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}"
- python -c "from yaml import load, Loader; load(open('ha_configuration.yml'), Loader=Loader)"
- cd "${CI_PROJECT_DIR}/home-assistant"
- python -c "from yaml import load, Loader; load(open('ha_configuration.yml'), Loader=Loader)"

View File

@ -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
======
![Fritzing BreadBoard](mqttfastledmenu_bb.png)
![IRL](irl1.jpg)
![Fritzing BreadBoard](medias/mqttfastledmenu_bb.png)
![IRL](medias/irl1.jpg)

View File

@ -1,3 +1,5 @@
#include <Arduino.h>
#include "mqttfastledmenu.h"
#include <FastLED.h>
@ -20,27 +22,25 @@ char message_buff[100];
PubSubClient client(espClient);
void setup()
{
{
Serial.begin(SERIAL_SPEED);
Serial.println("\nresetting");
// WIFI
setupWifi();
// MQTT
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
@ -50,13 +50,12 @@ void setupWifi()
Serial.print(WIFI_SSID);
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
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());
@ -93,7 +93,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
}
message_buff[i] = '\0';
String msgString = String(message_buff);
Serial.print("Received [" + stopic + "] : ");
Serial.println(msgString);
@ -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,39 +135,35 @@ 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) {
client.loop();
if (ledEffect != LED_EFFECT_CYLON) {
return;
}
EVERY_N_SECONDS(1) {
client.loop();
if (ledEffect != LED_EFFECT_CYLON) {
return;
}
}
leds[i] = color;
FastLED.show();
FastLED.delay(1000 / speed);
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) {
client.loop();
if (ledEffect != LED_EFFECT_CYLON) {
return;
}
EVERY_N_SECONDS(1) {
client.loop();
if (ledEffect != LED_EFFECT_CYLON) {
return;
}
}
leds[i] = color;
FastLED.show();
FastLED.delay(1000 / speed);
FastLED.delay(1000 / speed);
leds[i] = CRGB::Black;
FastLED.show();
}
@ -178,46 +180,30 @@ 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 ledFullRed()
void ledFullColor()
{
fill_solid(leds, LED_NUM, color);
FastLED.show();
FastLED.delay(1000 / speed);
FastLED.delay(1000 / speed);
}
void loop() {
// MQTT
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);
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

View File

@ -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();

18
arduino/platformio.ini Normal file
View 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

View File

@ -17,40 +17,40 @@ input_slider:
strip1_animation_speed:
name: "Strip1 Animation Speed"
initial: 120
min: 10
max: 150
step: 10
min: 0
max: 150
step: 10
light:
platform: "mqtt"
name: "Test ESP"
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"
- platform: "state"
entity_id: "input_select.strip1_effect"
action:
- service: "mqtt.publish"
data_template:
topic: "strip1/effect/switch"
topic: "strip1/effect/switch"
payload: '{{ trigger.to_state.state | string }}'
retain: True
retain: True
- alias: "Strip1 Animation Speed"
hide_entity: False
hide_entity: True
trigger:
- platform: "state"
- platform: "state"
entity_id: "input_slider.strip1_animation_speed"
action:
- service: "mqtt.publish"
data_template:
topic: "strip1/speed/switch"
topic: "strip1/speed/switch"
payload: '{{ trigger.to_state.state | int }}'
retain: True
retain: True

View File

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 154 KiB

View File

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

Before

Width:  |  Height:  |  Size: 238 KiB

After

Width:  |  Height:  |  Size: 238 KiB