Add files via upload

This commit is contained in:
Deb 2018-02-12 22:43:26 -05:00 committed by GitHub
parent 1a761b7f8f
commit 462607f29a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -460,146 +460,149 @@ void checkForRequests() {
// *************************************************************************** // ***************************************************************************
#ifdef ENABLE_MQTT #ifdef ENABLE_MQTT
void mqtt_callback(char* topic, byte* payload_in, unsigned int length) { void mqtt_callback(char* topic, byte* payload_in, unsigned int length) {
String payload_str = (char*)payload_in;
uint8_t * payload = (uint8_t *)malloc(length + 1); uint8_t * payload = (uint8_t *)malloc(length + 1);
memcpy(payload, payload_in, length); memcpy(payload, payload_in, length);
payload[length] = NULL; payload[length] = NULL;
String payload_str = (char*)payload;
DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload); DBG_OUTPUT_PORT.printf("MQTT: Message arrived [%s]\n", payload);
if ((strcmp(topic,mqtt_ha_state_in.c_str())==0)){ if ((strcmp(topic,mqtt_ha_state_in.c_str())==0)){
if (strcmp(payload_str.c_str(),"true")==0){ if (payload_str=="true" and !(animation_on)){
main_color.red = 255; mode = ALL;
main_color.green = 255; strip.setColor(main_color.red, main_color.green, main_color.blue);
main_color.blue = 255; strip.start();
DBG_OUTPUT_PORT.printf("MQTT: ON\n"); DBG_OUTPUT_PORT.printf("MQTT: ON\n");
mqtt_client.publish(mqtt_ha_state_out.c_str(), String("true").c_str()); mqtt_client.publish(mqtt_ha_state_out.c_str(), String("true").c_str());
} else if (strcmp(payload_str.c_str(),"false")==0){ } else if (payload_str=="false"){
mode = OFF; mode = OFF;
animation_on = false;
strip.start();
DBG_OUTPUT_PORT.printf("MQTT: OFF\n"); DBG_OUTPUT_PORT.printf("MQTT: OFF\n");
mqtt_client.publish(mqtt_ha_state_out.c_str(), String("false").c_str()); mqtt_client.publish(mqtt_ha_state_out.c_str(), String("false").c_str());
} }
} else if (strcmp(topic,mqtt_ha_effect_in.c_str())==0){ } else if (strcmp(topic,mqtt_ha_effect_in.c_str())==0){
uint8_t * effect_mqtt; char * effect_mqtt;
if (strcmp(payload_str.c_str(),"Static")==0){ animation_on = true;
effect_mqtt = (uint8_t *) "/0"; if (payload_str=="Static"){
} else if (strcmp(payload_str.c_str(),"Blink")==0){ effect_mqtt = "/0";
effect_mqtt = (uint8_t *) "/1"; } else if (payload_str=="Blink"){
} else if (strcmp(payload_str.c_str(),"Breath")==0){ effect_mqtt = "/1";
effect_mqtt = (uint8_t *) "/2"; } else if (payload_str=="Breath"){
} else if (strcmp(payload_str.c_str(),"ColorWipe")==0){ effect_mqtt = "/2";
effect_mqtt = (uint8_t *) "/3"; } else if (payload_str=="ColorWipe"){
} else if (strcmp(payload_str.c_str(),"ColorWipeInverse")==0){ effect_mqtt = "/3";
effect_mqtt = (uint8_t *) "/4"; } else if (payload_str=="ColorWipeInverse"){
} else if (strcmp(payload_str.c_str(),"ColorWipeReverse")==0){ effect_mqtt = "/4";
effect_mqtt = (uint8_t *) "/5"; } else if (payload_str=="ColorWipeReverse"){
} else if (strcmp(payload_str.c_str(),"ColorWipeReverseInverse")==0){ effect_mqtt = "/5";
effect_mqtt = (uint8_t *) "/6"; } else if (payload_str=="ColorWipeReverseInverse"){
} else if (strcmp(payload_str.c_str(),"ColorWipeRandom")==0){ effect_mqtt = "/6";
effect_mqtt = (uint8_t *) "/7"; } else if (payload_str=="ColorWipeRandom"){
} else if (strcmp(payload_str.c_str(),"RandomColor")==0){ effect_mqtt = "/7";
effect_mqtt = (uint8_t *) "/8"; } else if (payload_str=="RandomColor"){
} else if (strcmp(payload_str.c_str(),"SingleDynamic")==0){ effect_mqtt = "/8";
effect_mqtt = (uint8_t *) "/9"; } else if (payload_str=="SingleDynamic"){
} else if (strcmp(payload_str.c_str(),"MultiDynamic")==0){ effect_mqtt = "/9";
effect_mqtt = (uint8_t *) "/10"; } else if (payload_str=="MultiDynamic"){
} else if (strcmp(payload_str.c_str(),"Rainbow")==0){ effect_mqtt = "/10";
effect_mqtt = (uint8_t *) "/11"; } else if (payload_str=="Rainbow"){
} else if (strcmp(payload_str.c_str(),"RainbowCycle")==0){ effect_mqtt = "/11";
effect_mqtt = (uint8_t *) "/12"; } else if (payload_str=="RainbowCycle"){
} else if (strcmp(payload_str.c_str(),"Scan")==0){ effect_mqtt = "/12";
effect_mqtt = (uint8_t *) "/13"; } else if (payload_str=="Scan"){
} else if (strcmp(payload_str.c_str(),"DualScan")==0){ effect_mqtt = "/13";
effect_mqtt = (uint8_t *) "/14"; } else if (payload_str=="DualScan"){
} else if (strcmp(payload_str.c_str(),"Fade")==0){ effect_mqtt = "/14";
effect_mqtt = (uint8_t *) "/15"; } else if (payload_str=="Fade"){
} else if (strcmp(payload_str.c_str(),"TheaterChase")==0){ effect_mqtt = "/15";
effect_mqtt = (uint8_t *) "/16"; } else if (payload_str=="TheaterChase"){
} else if (strcmp(payload_str.c_str(),"TheaterChaseRainbow")==0){ effect_mqtt = "/16";
effect_mqtt = (uint8_t *) "/17"; } else if (payload_str=="TheaterChaseRainbow"){
} else if (strcmp(payload_str.c_str(),"RunningLights")==0){ effect_mqtt = "/17";
effect_mqtt = (uint8_t *) "/18"; } else if (payload_str=="RunningLights"){
} else if (strcmp(payload_str.c_str(),"Twinkle")==0){ effect_mqtt = "/18";
effect_mqtt = (uint8_t *) "/19"; } else if (payload_str=="Twinkle"){
} else if (strcmp(payload_str.c_str(),"TwinkleRandom")==0){ effect_mqtt = "/19";
effect_mqtt = (uint8_t *) "/20"; } else if (payload_str=="TwinkleRandom"){
} else if (strcmp(payload_str.c_str(),"TwinkleFade")==0){ effect_mqtt = "/20";
effect_mqtt = (uint8_t *) "/21"; } else if (payload_str=="TwinkleFade"){
} else if (strcmp(payload_str.c_str(),"TwinkleFadeRandom")==0){ effect_mqtt = "/21";
effect_mqtt = (uint8_t *) "/22"; } else if (payload_str=="TwinkleFadeRandom"){
} else if (strcmp(payload_str.c_str(),"Sparkle")==0){ effect_mqtt = "/22";
effect_mqtt = (uint8_t *) "/23"; } else if (payload_str=="Sparkle"){
} else if (strcmp(payload_str.c_str(),"FlashSparkle")==0){ effect_mqtt = "/23";
effect_mqtt = (uint8_t *) "/24"; } else if (payload_str=="FlashSparkle"){
} else if (strcmp(payload_str.c_str(),"HyperSparkle")==0){ effect_mqtt = "/24";
effect_mqtt = (uint8_t *) "/25"; } else if (payload_str=="HyperSparkle"){
} else if (strcmp(payload_str.c_str(),"Strobe")==0){ effect_mqtt = "/25";
effect_mqtt = (uint8_t *) "/26"; } else if (payload_str=="Strobe"){
} else if (strcmp(payload_str.c_str(),"StrobeRainbow")==0){ effect_mqtt = "/26";
effect_mqtt = (uint8_t *) "/27"; } else if (payload_str=="StrobeRainbow"){
} else if (strcmp(payload_str.c_str(),"MultiStrobe")==0){ effect_mqtt = "/27";
effect_mqtt = (uint8_t *) "/28"; } else if (payload_str=="MultiStrobe"){
} else if (strcmp(payload_str.c_str(),"BlinkRainbow")==0){ effect_mqtt = "/28";
effect_mqtt = (uint8_t *) "/29"; } else if (payload_str=="BlinkRainbow"){
} else if (strcmp(payload_str.c_str(),"ChaseWhite")==0){ effect_mqtt = "/29";
effect_mqtt = (uint8_t *) "/30"; } else if (payload_str=="ChaseWhite"){
} else if (strcmp(payload_str.c_str(),"ChaseColor")==0){ effect_mqtt = "/30";
effect_mqtt = (uint8_t *) "/31"; } else if (payload_str=="ChaseColor"){
} else if (strcmp(payload_str.c_str(),"ChaseRandom")==0){ effect_mqtt = "/31";
effect_mqtt = (uint8_t *) "/32"; } else if (payload_str=="ChaseRandom"){
} else if (strcmp(payload_str.c_str(),"ChaseRainbow")==0){ effect_mqtt = "/32";
effect_mqtt = (uint8_t *) "/33"; } else if (payload_str=="ChaseRainbow"){
} else if (strcmp(payload_str.c_str(),"ChaseFlash")==0){ effect_mqtt = "/33";
effect_mqtt = (uint8_t *) "/34"; } else if (payload_str=="ChaseFlash"){
} else if (strcmp(payload_str.c_str(),"ChaseFlashRandom")==0){ effect_mqtt = "/34";
effect_mqtt = (uint8_t *) "/35"; } else if (payload_str=="ChaseFlashRandom"){
} else if (strcmp(payload_str.c_str(),"ChaseRainbowWhite")==0){ effect_mqtt = "/35";
effect_mqtt = (uint8_t *) "/36"; } else if (payload_str=="ChaseRainbowWhite"){
} else if (strcmp(payload_str.c_str(),"ChaseBlackout")==0){ effect_mqtt = "/36";
effect_mqtt = (uint8_t *) "/37"; } else if (payload_str=="ChaseBlackout"){
} else if (strcmp(payload_str.c_str(),"ChaseBlackoutRainbow")==0){ effect_mqtt = "/37";
effect_mqtt = (uint8_t *) "/38"; } else if (payload_str=="ChaseBlackoutRainbow"){
} else if (strcmp(payload_str.c_str(),"ColorSweepRandom")==0){ effect_mqtt = "/38";
effect_mqtt = (uint8_t *) "/39"; } else if (payload_str=="ColorSweepRandom"){
} else if (strcmp(payload_str.c_str(),"RunningColor")==0){ effect_mqtt = "/39";
effect_mqtt = (uint8_t *) "/40"; } else if (payload_str=="RunningColor"){
} else if (strcmp(payload_str.c_str(),"RunningRedBlue")==0){ effect_mqtt = "/40";
effect_mqtt = (uint8_t *) "/41"; } else if (payload_str=="RunningRedBlue"){
} else if (strcmp(payload_str.c_str(),"RunningRandom")==0){ effect_mqtt = "/41";
effect_mqtt = (uint8_t *) "/42"; } else if (payload_str=="RunningRandom"){
} else if (strcmp(payload_str.c_str(),"LarsonScanner")==0){ effect_mqtt = "/42";
effect_mqtt = (uint8_t *) "/43"; } else if (payload_str=="LarsonScanner"){
} else if (strcmp(payload_str.c_str(),"Comet")==0){ effect_mqtt = "/43";
effect_mqtt = (uint8_t *) "/44"; } else if (payload_str=="Comet"){
} else if (strcmp(payload_str.c_str(),"Fireworks")==0){ effect_mqtt = "/44";
effect_mqtt = (uint8_t *) "/45"; } else if (payload_str=="Fireworks"){
} else if (strcmp(payload_str.c_str(),"FireworksRandom")==0){ effect_mqtt = "/45";
effect_mqtt = (uint8_t *) "/46"; } else if (payload_str=="FireworksRandom"){
} else if (strcmp(payload_str.c_str(),"MerryChristmas")==0){ effect_mqtt = "/46";
effect_mqtt = (uint8_t *) "/47"; } else if (payload_str=="MerryChristmas"){
} else if (strcmp(payload_str.c_str(),"FireFlicker")==0){ effect_mqtt = "/47";
effect_mqtt = (uint8_t *) "/48"; } else if (payload_str=="FireFlicker"){
} else if (strcmp(payload_str.c_str(),"FireFlickerSoft")==0){ effect_mqtt = "/48";
effect_mqtt = (uint8_t *) "/49"; } else if (payload_str=="FireFlickerSoft"){
} else if (strcmp(payload_str.c_str(),"FireFlickerIntense")==0){ effect_mqtt = "/49";
effect_mqtt = (uint8_t *) "/50"; } else if (payload_str=="FireFlickerIntense"){
} else if (strcmp(payload_str.c_str(),"CircusCombustus")==0){ effect_mqtt = "/50";
effect_mqtt = (uint8_t *) "/51"; } else if (payload_str=="CircusCombustus"){
} else if (strcmp(payload_str.c_str(),"Halloween")==0){ effect_mqtt = "/51";
effect_mqtt = (uint8_t *) "/52"; } else if (payload_str=="Halloween"){
} else if (strcmp(payload_str.c_str(),"BicolorChase")==0){ effect_mqtt = "/52";
effect_mqtt = (uint8_t *) "/53"; } else if (payload_str=="BicolorChase"){
} else if (strcmp(payload_str.c_str(),"TricolorChase")==0){ effect_mqtt = "/53";
effect_mqtt = (uint8_t *) "/54"; } else if (payload_str=="TricolorChase"){
} else if (strcmp(payload_str.c_str(),"ICU")==0){ effect_mqtt = "/54";
effect_mqtt = (uint8_t *) "/55"; } else if (payload_str=="ICU"){
effect_mqtt = "/55";
} }
handleSetWS2812FXMode(effect_mqtt); handleSetWS2812FXMode((uint8_t *)effect_mqtt);
DBG_OUTPUT_PORT.printf("MQTT: Set WS2812 mode [%s]\n", payload); DBG_OUTPUT_PORT.printf("MQTT: Set WS2812 mode [%s]\n", effect_mqtt);
mqtt_client.publish(mqtt_ha_effect_out.c_str(), String((char *)payload).c_str()); mqtt_client.publish(mqtt_ha_effect_out.c_str(), (char*)payload);
} else if ((strcmp(topic,mqtt_ha_brightness_in.c_str())==0)){ } else if (strcmp(topic,mqtt_ha_brightness_in.c_str())==0){
uint8_t b = (uint8_t) strtol((const char *) &payload[0], NULL, 10); uint8_t b = (uint8_t) strtol((const char *) &payload[0], NULL, 10);
brightness = constrain(b, 0, 255); brightness = constrain(b, 0, 255);
strip.setBrightness(brightness); strip.setBrightness(brightness);
@ -616,12 +619,14 @@ void mqtt_callback(char* topic, byte* payload_in, unsigned int length) {
main_color.red = constrain(rm, 0, 255); main_color.red = constrain(rm, 0, 255);
main_color.green = constrain(gm, 0, 255); main_color.green = constrain(gm, 0, 255);
main_color.blue = constrain(bm, 0, 255); main_color.blue = constrain(bm, 0, 255);
strip.setColor(main_color.red, main_color.green, main_color.blue);
strip.start();
mqtt_client.publish(mqtt_ha_rgb_out.c_str(), String((char *)payload).c_str()); mqtt_client.publish(mqtt_ha_rgb_out.c_str(), String((char *)payload).c_str());
} else if (strcmp(topic,mqtt_ha_speed.c_str())==0){ } else if (strcmp(topic,mqtt_ha_speed.c_str())==0){
uint8_t d = (uint8_t) strtol((const char *) &payload[0], NULL, 10); uint8_t d = (uint8_t) strtol((const char *) &payload[0], NULL, 10);
ws2812fx_speed = constrain(d, 0, 255); ws2812fx_speed = constrain(d, 0, 255);
strip.setSpeed(convertSpeed(ws2812fx_speed)); strip.setSpeed(convertSpeed(ws2812fx_speed));
} else { } else if (strcmp(topic,(char *)mqtt_intopic)==0){
// # ==> Set main color // # ==> Set main color
if (payload[0] == '#') { if (payload[0] == '#') {
@ -687,9 +692,9 @@ void mqtt_callback(char* topic, byte* payload_in, unsigned int length) {
if (payload[0] == '$') { if (payload[0] == '$') {
DBG_OUTPUT_PORT.printf("MQTT: Get status info.\n"); DBG_OUTPUT_PORT.printf("MQTT: Get status info.\n");
//String json_str = listStatusJSON(); //String json_str = listStatusJSON();
char* json_str = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; //char* json_str = "";
DBG_OUTPUT_PORT.println("MQTT: Out: "+String(json_str)); DBG_OUTPUT_PORT.println("MQTT: Out: "+String(listStatusJSON()));
mqtt_client.publish(mqtt_outtopic, json_str); mqtt_client.publish(mqtt_outtopic, listStatusJSON());
} }
// ~ ==> Get WS2812 modes. // ~ ==> Get WS2812 modes.