Merge branch 'otaremdeb' into 'master'

Otaremdeb

See merge request !6
This commit is contained in:
Julien Cabillot 2017-05-28 11:33:58 +02:00
commit 60f87a5df2
6 changed files with 96 additions and 22 deletions

1
.gitignore vendored
View File

@ -6,3 +6,4 @@ lib/*
.piolibdeps .piolibdeps
.clang_complete .clang_complete
.gcc-flags.json .gcc-flags.json
platformio.ini

View File

@ -32,6 +32,6 @@ Avancement
Le projet est actuellement fonctionnel. Le projet est actuellement fonctionnel.
Il reste des tweaks à faire pour que les effets marchent comme je le désire mais ça fonctionne. Il reste des tweaks à faire pour que les effets marchent comme je le désire mais ça fonctionne.
TODO: changer le mqtt light par un mqtt_json, cela permettrais d'avoir un truc un peu "normal". Il existe de nombreux exemples sur le net pour esp qu'il devrait être très simple d'intégrer. TODO: changer le mqtt light par un mqtt_json, cela permettrais d'avoir un truc un peu "normal". Il existe de nombreux exemples sur le net pour esp qu'il devrait être très simple d'intégrer.
TODO: Utiliser ArduinoOTA pour gérer les mises à jours sans fil.
TODO: passer sur mqtt_json : l'envoi de l'état ne prends qu'un appel tout comme la réception, bien plus rapide TODO: passer sur mqtt_json : l'envoi de l'état ne prends qu'un appel tout comme la réception, bien plus rapide
TODO: gitlab-ci : on peut checker la syntax en lancant un docker home-assistant !!! TODO: gitlab-ci : on peut checker la syntax en lancant un docker home-assistant !!!
TODO: utiliser https://home-assistant.io/docs/configuration/secrets/

View File

@ -1,12 +1,25 @@
#include <Arduino.h> #include <Arduino.h>
// LED
// 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
#include <FastLED.h> #include <FastLED.h>
// WIFI
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
// MQTT
#include <PubSubClient.h> #include <PubSubClient.h>
// OTA
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
// RemoteDebug
#include <RemoteDebug.h>
#include "mqttfastledmenu.h" #include "mqttfastledmenu.h"
// LED // LED
@ -33,6 +46,12 @@ void setup()
// WIFI // WIFI
setupWifi(); setupWifi();
// OTA
setupOTA();
// RemoteDebug
Debug.begin("chamber");
// LED // LED
/* /*
brightness = LED_BRIGHTNESS_DEFAULT; brightness = LED_BRIGHTNESS_DEFAULT;
@ -56,7 +75,7 @@ void setup()
client.setCallback(callbackMQTT); client.setCallback(callbackMQTT);
testConnectMQTT(); testConnectMQTT();
Serial.println("Ready"); Debug.println("Ready");
/* MQTT /* MQTT
* Il est important de faire un loop avant toute chose, * Il est important de faire un loop avant toute chose,
@ -69,7 +88,47 @@ void setup()
client.loop(); client.loop();
} }
Serial.println("End of setup"); Debug.println("End of setup");
}
// OTA
void setupOTA()
{
ArduinoOTA.setHostname("mqttfastledmenu"); // on donne une petit nom a notre module
ArduinoOTA.setPassword(OTA_PASSWORD);
ArduinoOTA.onStart([]() {
Debug.println("OTA Starting");
Serial.println("OTA Starting");
});
ArduinoOTA.onEnd([]() {
Debug.println("\nOTA End");
Serial.println("\nOTA End");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Debug.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("OTA Error[%u]: ", error);
Debug.printf("OTA Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
Debug.println("Auth Failed");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
Debug.println("Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
Debug.println("Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
Debug.println("Receive Failed");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
Debug.println("End Failed");
}
});
ArduinoOTA.begin();
} }
// WIFI // WIFI
@ -93,27 +152,27 @@ void setupWifi()
void testConnectMQTT() void testConnectMQTT()
{ {
while (!client.connected()) { while (!client.connected()) {
Serial.print("Connexion au serveur MQTT... "); Debug.print("Connexion au serveur MQTT... ");
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) { if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
Serial.print("OK\nSend Current State"); Debug.print("OK\nSend Current State");
mqttSendState(); mqttSendState();
mqttSendSpeedState(); mqttSendSpeedState();
mqttSendBrightnessState(); mqttSendBrightnessState();
mqttSendEffectState(); mqttSendEffectState();
mqttSendColorState(); mqttSendColorState();
Serial.print("OK\nSubscribe"); Debug.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"); Debug.println(" OK");
} else { } else {
Serial.print("KO, erreur : "); Debug.print("KO, erreur : ");
Serial.print(client.state()); Debug.print(client.state());
Serial.println(", on attend 5 secondes avant de recommencer"); Debug.println(", on attend 5 secondes avant de recommencer");
delay(5000); delay(5000);
} }
} }
@ -131,8 +190,8 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
message_buff[i] = '\0'; message_buff[i] = '\0';
String msgString = String(message_buff); String msgString = String(message_buff);
Serial.print("Received [" + stopic + "] : "); Debug.print("Received [" + stopic + "] : ");
Serial.println(msgString); Debug.println(msgString);
if (stopic == MQTT_LED_COMMAND) { if (stopic == MQTT_LED_COMMAND) {
if (msgString == "ON") { if (msgString == "ON") {
@ -322,7 +381,7 @@ void ledError()
* Pour éviter un éclairage basique, on applique un breath qui permet * Pour éviter un éclairage basique, on applique un breath qui permet
* de faire respirer la couleur (brightness). * de faire respirer la couleur (brightness).
*/ */
void ledFullColor() void ledBreathing()
{ {
// Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
@ -508,6 +567,12 @@ void fire()
//////////////////////// FastLED-3.1.5/examples/Fire202 /////////////////////// //////////////////////// FastLED-3.1.5/examples/Fire202 ///////////////////////
void loop() { void loop() {
// OTA
ArduinoOTA.handle();
// RemoteDebug
Debug.handle();
// MQTT // MQTT
testConnectMQTT(); testConnectMQTT();
client.loop(); client.loop();
@ -518,9 +583,8 @@ void loop() {
} 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_BREATHING) {
//TODO : degager ce nom : LED_EFFECT_FULLRED ledBreathing();
ledFullColor();
} else if (ledEffect == LED_EFFECT_COLORPATTERN) { } else if (ledEffect == LED_EFFECT_COLORPATTERN) {
ledColorPattern(); ledColorPattern();
} else if (ledEffect == LED_EFFECT_COLORTEMP) { } else if (ledEffect == LED_EFFECT_COLORTEMP) {

View File

@ -1,8 +1,14 @@
#define SERIAL_SPEED 115200 #define SERIAL_SPEED 115200
// OTA
#define OTA_PASSWORD "n87z21Tx5%P%EX&*"
// DebugRemote
RemoteDebug Debug;
// LED // LED
#define LED_NUM 300 #define LED_NUM 300
#define LED_PIN 5 // = D1 #define LED_PIN 5 // = D5
#define LED_CHIPSET WS2812B #define LED_CHIPSET WS2812B
#define LED_COLOR_ORDER GRB #define LED_COLOR_ORDER GRB
#define LED_BRIGHTNESS_DEFAULT 96 #define LED_BRIGHTNESS_DEFAULT 96
@ -13,7 +19,7 @@
#define LED_EFFECT_COLORPATTERN "colorp" #define LED_EFFECT_COLORPATTERN "colorp"
#define LED_EFFECT_COLORTEMP "colort" #define LED_EFFECT_COLORTEMP "colort"
#define LED_EFFECT_FIRE "fire" #define LED_EFFECT_FIRE "fire"
#define LED_EFFECT_FULLRED "full" #define LED_EFFECT_BREATHING "breathing"
#define LED_EFFECT_ERROR "error" #define LED_EFFECT_ERROR "error"
// WIFI // WIFI
@ -38,6 +44,7 @@
#define MQTT_LED_COLOR_STATE "strip1/color/status" #define MQTT_LED_COLOR_STATE "strip1/color/status"
void setupOTA();
void setupWifi(); void setupWifi();
void testConnectMQTT(); void testConnectMQTT();
void callbackMQTT(char* topic, byte* payload, unsigned int length); void callbackMQTT(char* topic, byte* payload, unsigned int length);
@ -49,7 +56,7 @@ void mqttSendColorState();
void ledBlackAll(); void ledBlackAll();
void ledCylon(); void ledCylon();
void ledError(); void ledError();
void ledFullColor(); void ledBreathing();
///////////////////////////////// ColorPalette ///////////////////////////////// ColorPalette
// This example shows several ways to set up and use 'palettes' of colors // This example shows several ways to set up and use 'palettes' of colors
// with FastLED. // with FastLED.

View File

@ -7,7 +7,7 @@
- "colorp" - "colorp"
- "colort" - "colort"
- "fire" - "fire"
- "full" - "breathing"
- "error" - "error"
command_topic: "strip1/switch" command_topic: "strip1/switch"
state_topic: "strip1/status" state_topic: "strip1/status"

View File

@ -12,6 +12,8 @@
platform=espressif8266 platform=espressif8266
board=nodemcuv2 board=nodemcuv2
framework=arduino framework=arduino
upload_port=<IP>
upload_flags=--auth="<PASS>"
[platformio] [platformio]
src_dir=arduino/mqttfastledmenu src_dir=arduino/mqttfastledmenu