Ajout de remotedebug (OK)

This commit is contained in:
Julien Cabillot 2017-04-24 20:59:12 +02:00 committed by Cabillot Julien
parent a6cef0c9f6
commit d1841f75b4
2 changed files with 42 additions and 33 deletions

View File

@ -15,6 +15,9 @@
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
// RemoteDebug
#include <RemoteDebug.h>
#include "alarmclock.h" #include "alarmclock.h"
void setup() void setup()
@ -28,6 +31,9 @@ void setup()
// OTA // OTA
setupOTA(); setupOTA();
// RemoteDebug
Debug.begin("alarmclock");
// LED // LED
maxBrightness = LED_MAXBRIGHTNESS_DEFAULT; maxBrightness = LED_MAXBRIGHTNESS_DEFAULT;
curbrightness = LED_BRIGHTNESS_DEFAULT; curbrightness = LED_BRIGHTNESS_DEFAULT;
@ -43,7 +49,7 @@ void setup()
testConnectMQTT(); testConnectMQTT();
fps = 0; fps = 0;
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,
@ -56,10 +62,7 @@ void setup()
client.loop(); client.loop();
} }
// OTA Debug.println("End of setup");
Serial.println("End of setup");
} }
// OTA // OTA
@ -96,41 +99,41 @@ void setupOTA()
// WIFI // WIFI
void setupWifi() void setupWifi()
{ {
Serial.print("Connexion a "); Debug.print("Connexion a ");
Serial.print(WIFI_SSID); Debug.print(WIFI_SSID);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) { while (WiFi.status() != WL_CONNECTED) {
delay(500); delay(500);
Serial.print("."); Debug.print(".");
} }
Serial.println(" OK"); Debug.println(" OK");
Serial.print("IP : "); Debug.print("IP : ");
Serial.println(WiFi.localIP()); Debug.println(WiFi.localIP());
} }
// MQTT // MQTT
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();
mqttSendBrightnessState(); mqttSendBrightnessState();
mqttSendColorState(); mqttSendColorState();
Serial.print("OK\nSubscribe"); Debug.print("OK\nSubscribe");
client.subscribe(MQTT_LED_COMMAND); client.subscribe(MQTT_LED_COMMAND);
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND); client.subscribe(MQTT_LED_BRIGHTNESS_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);
} }
} }
@ -148,8 +151,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") {
@ -248,18 +251,18 @@ void ledDisplay()
FastLED.setBrightness(breath); FastLED.setBrightness(breath);
/* Debug /* Debug
EVERY_N_SECONDS(1) { EVERY_N_SECONDS(1) {
Serial.print(breath); Debug.print(breath);
Serial.print(" | "); Debug.print(" | ");
Serial.print(curbrightness); Debug.print(curbrightness);
Serial.print("/"); Debug.print("/");
Serial.println(maxBrightness); Debug.println(maxBrightness);
} }
*/ */
fps++; fps++;
if (SHOW_FPS) { if (SHOW_FPS) {
EVERY_N_SECONDS(1) { EVERY_N_SECONDS(1) {
Serial.print("FPS : "); Debug.print("FPS : ");
Serial.println(fps); Debug.println(fps);
fps=0; fps=0;
} }
} }
@ -267,20 +270,23 @@ void ledDisplay()
} }
void loop() { void loop() {
EVERY_N_SECONDS(10) {
if (curbrightness <= maxBrightness) {
curbrightness++;
}
}
// OTA // OTA
ArduinoOTA.handle(); ArduinoOTA.handle();
// RemoteDebug
Debug.handle();
// MQTT // MQTT
testConnectMQTT(); testConnectMQTT();
client.loop(); client.loop();
// LED // LED
EVERY_N_SECONDS(10) {
if (curbrightness <= maxBrightness) {
curbrightness++;
}
}
if (!ledState) { if (!ledState) {
FastLED.delay(1000); FastLED.delay(1000);
} else { } else {

View File

@ -6,6 +6,9 @@ int fps;
// OTA // OTA
#define OTA_PASSWORD "XXX" #define OTA_PASSWORD "XXX"
// DebugRemote
RemoteDebug Debug;
// LED // LED
#define LED_NUM 30 #define LED_NUM 30
#define LED_PIN 5 // = D1 #define LED_PIN 5 // = D1