This commit is contained in:
Julien Cabillot
2017-04-20 11:13:06 +02:00
committed by Cabillot Julien
parent 8304d15938
commit dbfb7120d5
2 changed files with 51 additions and 3 deletions
+49 -3
View File
@@ -87,10 +87,15 @@ void testConnectMQTT()
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
Serial.print("OK\nSubscribe");
client.subscribe(MQTT_LED_COMMAND);
mqttSendState();
client.subscribe(MQTT_LED_EFFECT_COMMAND);
//mqttSendEffectState();
client.subscribe(MQTT_LED_BRIGHTNESS_COMMAND);
mqttSendBrightnessState();
client.subscribe(MQTT_LED_SPEED_COMMAND);
//mqttSendSpeedState();
client.subscribe(MQTT_LED_COLOR_COMMAND);
//mqttSendColorState();
Serial.println(" OK");
} else {
Serial.print("KO, erreur : ");
@@ -119,12 +124,11 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
if (stopic == MQTT_LED_COMMAND) {
if (msgString == "ON") {
ledState = true;
client.publish(MQTT_LED_STATE, message_buff, true);
} else {
ledState = false;
ledBlackAll();
client.publish(MQTT_LED_STATE, message_buff, true);
}
mqttSendState();
} else if (stopic == MQTT_LED_EFFECT_COMMAND) {
// Si on ne repasse pas tout à noir, cela peut faire des effets surprenants
ledBlackAll();
@@ -148,6 +152,48 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
}
}
void mqttSendState()
{
if (ledState) {
client.publish(MQTT_LED_STATE, "ON", true);
} else {
client.publish(MQTT_LED_STATE, "OFF", true);
}
}
void mqttSendEffectState()
{
char buff[ledEffect.length() + 1];
ledEffect.toCharArray(buff, ledEffect.length() + 1);
client.publish(MQTT_LED_EFFECT_STATE, buff, true);
}
void mqttSendBrightnessState()
{
char buff[4];
itoa(brightness, buff, 10);
client.publish(MQTT_LED_BRIGHTNESS_STATE, buff, true);
}
void mqttSendSpeedState()
{
char buff[4];
itoa(speed, buff, 10);
client.publish(MQTT_LED_SPEED_STATE, buff, true);
}
void mqttSendColorState()
{
/*
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);
TODO: client.publish(MQTT_LED_COLOR_STATE, message_buff, true);
avec color
*/
}
// LED
/**
* Coupe tout le strip de led.
@@ -170,7 +216,7 @@ void ledCylon()
if (ledEffect != LED_EFFECT_CYLON) {
return;
}
if ((i - 3) >= 0) {
leds[i - 3] = CRGB::Black;
}