WIP
This commit is contained in:
parent
bcf24560e9
commit
b5d3578c22
@ -17,11 +17,6 @@ void setup()
|
||||
// WIFI
|
||||
setupWifi();
|
||||
|
||||
// MQTT
|
||||
client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||
client.setCallback(callbackMQTT);
|
||||
testConnectMQTT();
|
||||
|
||||
// LED
|
||||
brightness = LED_BRIGHTNESS_DEFAULT;
|
||||
color = LED_COLOR_DEFAULT;
|
||||
@ -29,6 +24,7 @@ void setup()
|
||||
ledEffect = LED_EFFECT_ERROR;
|
||||
ledState = false;
|
||||
|
||||
// LED
|
||||
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
|
||||
ledBlackAll();
|
||||
FastLED.setBrightness(brightness);
|
||||
@ -37,6 +33,12 @@ void setup()
|
||||
currentPalette = RainbowColors_p;
|
||||
currentBlending = LINEARBLEND;
|
||||
//////////////////////////////// ColorPalette ///////////////////////////////
|
||||
|
||||
// MQTT
|
||||
client.setServer(MQTT_SERVER, MQTT_PORT);
|
||||
client.setCallback(callbackMQTT);
|
||||
testConnectMQTT();
|
||||
|
||||
Serial.println("Ready");
|
||||
|
||||
/* MQTT
|
||||
@ -76,17 +78,20 @@ void testConnectMQTT()
|
||||
while (!client.connected()) {
|
||||
Serial.print("Connexion au serveur MQTT... ");
|
||||
if (client.connect("ESP8266Client", MQTT_USER, MQTT_PASS)) {
|
||||
Serial.print("OK\nSend Current State");
|
||||
mqttSendState();
|
||||
mqttSendSpeedState();
|
||||
mqttSendBrightnessState();
|
||||
mqttSendEffectState();
|
||||
mqttSendColorState();
|
||||
|
||||
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 : ");
|
||||
@ -124,11 +129,11 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
|
||||
// Si on ne repasse pas tout à noir, cela peut faire des effets surprenants
|
||||
ledBlackAll();
|
||||
ledEffect = msgString;
|
||||
client.publish(MQTT_LED_EFFECT_STATE, message_buff, true);
|
||||
mqttSendEffectState();
|
||||
} else if (stopic == MQTT_LED_BRIGHTNESS_COMMAND) {
|
||||
brightness = msgString.toInt();
|
||||
FastLED.setBrightness(brightness);
|
||||
client.publish(MQTT_LED_BRIGHTNESS_STATE, message_buff, true);
|
||||
mqttSendBrightnessState();
|
||||
} else if (stopic == MQTT_LED_COLOR_COMMAND) {
|
||||
// Sample : 134,168,255
|
||||
int red = msgString.substring(0, msgString.indexOf(',')).toInt();
|
||||
@ -136,20 +141,16 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
|
||||
int blue = msgString.substring(msgString.lastIndexOf(',') + 1).toInt();
|
||||
|
||||
color=((red <<16)|(green <<8)|blue);
|
||||
client.publish(MQTT_LED_COLOR_STATE, message_buff, true);
|
||||
mqttSendColorState();
|
||||
} else if (stopic == MQTT_LED_SPEED_COMMAND) {
|
||||
speed = msgString.toInt();
|
||||
client.publish(MQTT_LED_SPEED_STATE, message_buff, true);
|
||||
mqttSendSpeedState();
|
||||
}
|
||||
}
|
||||
|
||||
void mqttSendState()
|
||||
{
|
||||
if (ledState) {
|
||||
client.publish(MQTT_LED_STATE, "ON", true);
|
||||
} else {
|
||||
client.publish(MQTT_LED_STATE, "OFF", true);
|
||||
}
|
||||
client.publish(MQTT_LED_STATE, (ledState) ? "ON": "OFF", true);
|
||||
}
|
||||
|
||||
void mqttSendEffectState()
|
||||
@ -175,14 +176,13 @@ void mqttSendSpeedState()
|
||||
|
||||
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
|
||||
*/
|
||||
int red = color>>16 & 0xFF;
|
||||
int green = color>>8 & 0xFF;
|
||||
int blue = color & 0xFF;
|
||||
char buff[12];
|
||||
|
||||
sprintf(buff, "%i,%i,%i\0", red, green, blue);
|
||||
client.publish(MQTT_LED_COLOR_STATE, buff, true);
|
||||
}
|
||||
|
||||
// LED
|
||||
@ -237,10 +237,10 @@ void ledCylon()
|
||||
}
|
||||
|
||||
// Il faut nettoyer certaines cases avant la prochaine loop
|
||||
if ((LED_NUM - 2) >= 0) {
|
||||
leds[LED_NUM - 2] = color;
|
||||
leds[LED_NUM - 2].fadeLightBy(220);
|
||||
}
|
||||
if ((LED_NUM - 2) >= 0) {
|
||||
leds[LED_NUM - 2] = color;
|
||||
leds[LED_NUM - 2].fadeLightBy(220);
|
||||
}
|
||||
if ((LED_NUM - 1) >= 0 ) {
|
||||
leds[LED_NUM - 1] = CRGB::Black;
|
||||
}
|
||||
@ -316,8 +316,8 @@ void ledFullColor()
|
||||
// 0.36787944 ?? censé correspondre au minimum
|
||||
// 108.4 ?? censé correspondre au maximum
|
||||
int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4;
|
||||
Serial.print(breath);
|
||||
Serial.println(" / 255");
|
||||
//Serial.print(breath);
|
||||
//Serial.println(" / 255");
|
||||
FastLED.setBrightness(breath);
|
||||
FastLED.delay(100 / speed);
|
||||
}
|
||||
|
||||
@ -54,6 +54,11 @@ PubSubClient client(espClient);
|
||||
void setupWifi();
|
||||
void testConnectMQTT();
|
||||
void callbackMQTT(char* topic, byte* payload, unsigned int length);
|
||||
void mqttSendState();
|
||||
void mqttSendEffectState();
|
||||
void mqttSendBrightnessState();
|
||||
void mqttSendSpeedState();
|
||||
void mqttSendColorState();
|
||||
void ledBlackAll();
|
||||
void ledCylon();
|
||||
void ledError();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user