|
|
|
@ -15,6 +15,9 @@ |
|
|
|
#include <WiFiUdp.h>
|
|
|
|
#include <ArduinoOTA.h>
|
|
|
|
|
|
|
|
// RemoteDebug
|
|
|
|
#include <RemoteDebug.h>
|
|
|
|
|
|
|
|
#include "alarmclock.h"
|
|
|
|
|
|
|
|
void setup() |
|
|
|
@ -28,6 +31,9 @@ void setup() |
|
|
|
// OTA
|
|
|
|
setupOTA(); |
|
|
|
|
|
|
|
// RemoteDebug
|
|
|
|
Debug.begin("alarmclock"); |
|
|
|
|
|
|
|
// LED
|
|
|
|
maxBrightness = LED_MAXBRIGHTNESS_DEFAULT; |
|
|
|
curbrightness = LED_BRIGHTNESS_DEFAULT; |
|
|
|
@ -43,7 +49,7 @@ void setup() |
|
|
|
testConnectMQTT(); |
|
|
|
|
|
|
|
fps = 0; |
|
|
|
Serial.println("Ready"); |
|
|
|
Debug.println("Ready"); |
|
|
|
|
|
|
|
/* MQTT
|
|
|
|
* Il est important de faire un loop avant toute chose, |
|
|
|
@ -56,10 +62,7 @@ void setup() |
|
|
|
client.loop(); |
|
|
|
} |
|
|
|
|
|
|
|
// OTA
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("End of setup"); |
|
|
|
Debug.println("End of setup"); |
|
|
|
} |
|
|
|
|
|
|
|
// OTA
|
|
|
|
@ -96,41 +99,41 @@ void setupOTA() |
|
|
|
// WIFI
|
|
|
|
void setupWifi() |
|
|
|
{ |
|
|
|
Serial.print("Connexion a "); |
|
|
|
Serial.print(WIFI_SSID); |
|
|
|
Debug.print("Connexion a "); |
|
|
|
Debug.print(WIFI_SSID); |
|
|
|
WiFi.mode(WIFI_STA); |
|
|
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); |
|
|
|
|
|
|
|
while (WiFi.status() != WL_CONNECTED) { |
|
|
|
delay(500); |
|
|
|
Serial.print("."); |
|
|
|
Debug.print("."); |
|
|
|
} |
|
|
|
Serial.println(" OK"); |
|
|
|
Serial.print("IP : "); |
|
|
|
Serial.println(WiFi.localIP()); |
|
|
|
Debug.println(" OK"); |
|
|
|
Debug.print("IP : "); |
|
|
|
Debug.println(WiFi.localIP()); |
|
|
|
} |
|
|
|
|
|
|
|
// MQTT
|
|
|
|
void testConnectMQTT() |
|
|
|
{ |
|
|
|
while (!client.connected()) { |
|
|
|
Serial.print("Connexion au serveur MQTT... "); |
|
|
|
Debug.print("Connexion au serveur MQTT... "); |
|
|
|
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) { |
|
|
|
Serial.print("OK\nSend Current State"); |
|
|
|
Debug.print("OK\nSend Current State"); |
|
|
|
mqttSendState(); |
|
|
|
mqttSendBrightnessState(); |
|
|
|
mqttSendColorState(); |
|
|
|
|
|
|
|
Serial.print("OK\nSubscribe"); |
|
|
|
Debug.print("OK\nSubscribe"); |
|
|
|
client.subscribe(MQTT_LED_COMMAND); |
|
|
|
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND); |
|
|
|
client.subscribe(MQTT_LED_COLOR_COMMAND); |
|
|
|
|
|
|
|
Serial.println(" OK"); |
|
|
|
Debug.println(" OK"); |
|
|
|
} else { |
|
|
|
Serial.print("KO, erreur : "); |
|
|
|
Serial.print(client.state()); |
|
|
|
Serial.println(", on attend 5 secondes avant de recommencer"); |
|
|
|
Debug.print("KO, erreur : "); |
|
|
|
Debug.print(client.state()); |
|
|
|
Debug.println(", on attend 5 secondes avant de recommencer"); |
|
|
|
delay(5000); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -148,8 +151,8 @@ 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); |
|
|
|
Debug.print("Received [" + stopic + "] : "); |
|
|
|
Debug.println(msgString); |
|
|
|
|
|
|
|
if (stopic == MQTT_LED_COMMAND) { |
|
|
|
if (msgString == "ON") { |
|
|
|
@ -248,18 +251,18 @@ void ledDisplay() |
|
|
|
FastLED.setBrightness(breath); |
|
|
|
/* Debug
|
|
|
|
EVERY_N_SECONDS(1) { |
|
|
|
Serial.print(breath); |
|
|
|
Serial.print(" | "); |
|
|
|
Serial.print(curbrightness); |
|
|
|
Serial.print("/"); |
|
|
|
Serial.println(maxBrightness); |
|
|
|
Debug.print(breath); |
|
|
|
Debug.print(" | "); |
|
|
|
Debug.print(curbrightness); |
|
|
|
Debug.print("/"); |
|
|
|
Debug.println(maxBrightness); |
|
|
|
} |
|
|
|
*/ |
|
|
|
fps++; |
|
|
|
if (SHOW_FPS) { |
|
|
|
EVERY_N_SECONDS(1) { |
|
|
|
Serial.print("FPS : "); |
|
|
|
Serial.println(fps); |
|
|
|
Debug.print("FPS : "); |
|
|
|
Debug.println(fps); |
|
|
|
fps=0; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -267,20 +270,23 @@ void ledDisplay() |
|
|
|
} |
|
|
|
|
|
|
|
void loop() { |
|
|
|
EVERY_N_SECONDS(10) { |
|
|
|
if (curbrightness <= maxBrightness) { |
|
|
|
curbrightness++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// OTA
|
|
|
|
ArduinoOTA.handle(); |
|
|
|
|
|
|
|
// RemoteDebug
|
|
|
|
Debug.handle(); |
|
|
|
|
|
|
|
// MQTT
|
|
|
|
testConnectMQTT(); |
|
|
|
client.loop(); |
|
|
|
|
|
|
|
// LED
|
|
|
|
EVERY_N_SECONDS(10) { |
|
|
|
if (curbrightness <= maxBrightness) { |
|
|
|
curbrightness++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!ledState) { |
|
|
|
FastLED.delay(1000); |
|
|
|
} else { |
|
|
|
|