add new command
This commit is contained in:
parent
483a39e30c
commit
012b0d4831
5
.gitignore
vendored
5
.gitignore
vendored
@ -1 +1,6 @@
|
|||||||
/Release/
|
/Release/
|
||||||
|
ConfigGenerator/configuration.cpp
|
||||||
|
ConfigGenerator/configuration.h
|
||||||
|
~*
|
||||||
|
*~
|
||||||
|
|
||||||
|
BIN
.vscode/ipch/4c5e97abbb9a812a/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/4c5e97abbb9a812a/mmap_address.bin
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/4c5e97abbb9a812a/productionMode.ipch
vendored
Normal file
BIN
.vscode/ipch/4c5e97abbb9a812a/productionMode.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/724217c09c04d0aa/PRODUCTIONMODE.ipch
vendored
Normal file
BIN
.vscode/ipch/724217c09c04d0aa/PRODUCTIONMODE.ipch
vendored
Normal file
Binary file not shown.
BIN
.vscode/ipch/724217c09c04d0aa/mmap_address.bin
vendored
Normal file
BIN
.vscode/ipch/724217c09c04d0aa/mmap_address.bin
vendored
Normal file
Binary file not shown.
@ -16,6 +16,7 @@ configItems = [
|
|||||||
{"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32, "default":"geheim123"},
|
{"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32, "default":"geheim123"},
|
||||||
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"RgbLed1"},
|
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"RgbLed1"},
|
||||||
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":8883},
|
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":8883},
|
||||||
|
{"label":"MQTT Topic Color Command", "key":"mqttTopicColorCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/ColorCommand"},
|
||||||
{"label":"MQTT Topic Command", "key":"mqttTopicCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/Command"},
|
{"label":"MQTT Topic Command", "key":"mqttTopicCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/Command"},
|
||||||
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RgbLed1/Debug"},
|
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RgbLed1/Debug"},
|
||||||
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0}
|
{"label":"DebugMode", "key":"debugMode", "type":"I", "default":0}
|
||||||
|
@ -24,6 +24,8 @@
|
|||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
|
|
||||||
|
|
||||||
|
#define MAX_TOKENS 5
|
||||||
|
|
||||||
|
|
||||||
void callback(char* topic, byte* payload, unsigned int length);
|
void callback(char* topic, byte* payload, unsigned int length);
|
||||||
|
|
||||||
@ -70,7 +72,7 @@ void setup_wifi() {
|
|||||||
|
|
||||||
static CRGB evaluationColorWord(char* cmd) {
|
static CRGB evaluationColorWord(char* cmd) {
|
||||||
uint8_t red = 0, green = 0, blue = 0;
|
uint8_t red = 0, green = 0, blue = 0;
|
||||||
if (! strcmp(cmd, "on")) {
|
if ((! strcmp(cmd, "on")) || (! strcmp(cmd, "white")) {
|
||||||
red = 255;
|
red = 255;
|
||||||
green = 255;
|
green = 255;
|
||||||
blue = 255;
|
blue = 255;
|
||||||
@ -129,31 +131,37 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (! strcmp(topic, configBlock.mqttTopicCommand)) {
|
char *inbuf = buffer;
|
||||||
char *inbuf = buffer;
|
char *tk = NULL;
|
||||||
char *tk = NULL;
|
uint8_t tokenCnt = 0;
|
||||||
uint8_t tokenCnt = 0;
|
char *tokens[MAX_TOKENS];
|
||||||
#define MAX_TOKENS 5
|
do {
|
||||||
char *tokens[MAX_TOKENS];
|
if (tokenCnt >= MAX_TOKENS) {
|
||||||
do {
|
break;
|
||||||
tk = strtok(inbuf, " ");
|
}
|
||||||
inbuf = NULL;
|
tk = strtok(inbuf, " ");
|
||||||
tokens[tokenCnt] = tk;
|
inbuf = NULL;
|
||||||
if (tk) {
|
tokens[tokenCnt] = tk;
|
||||||
tokenCnt++;
|
if (tk) {
|
||||||
Serial.print("TokenCnt: ");
|
tokenCnt++;
|
||||||
Serial.print(tokenCnt);
|
Serial.print("TokenCnt: ");
|
||||||
Serial.println();
|
Serial.print(tokenCnt);
|
||||||
}
|
Serial.println();
|
||||||
} while (tk);
|
}
|
||||||
|
} while (tk);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < tokenCnt; i++) {
|
for (uint8_t i = 0; i < tokenCnt; i++) {
|
||||||
Serial.print("Token ");
|
Serial.print("Token ");
|
||||||
Serial.print(i);
|
Serial.print(i);
|
||||||
Serial.print(": ");
|
Serial.print(": ");
|
||||||
Serial.println(tokens[i]);
|
Serial.println(tokens[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (! strcmp(topic, configBlock.mqttTopicCommand)) {
|
||||||
|
int32_t n;
|
||||||
|
|
||||||
|
} else if (! strcmp(topic, configBlock.mqttTopicColorCommand)) {
|
||||||
int32_t n, red, green, blue;
|
int32_t n, red, green, blue;
|
||||||
CRGB colors;
|
CRGB colors;
|
||||||
switch (tokenCnt) {
|
switch (tokenCnt) {
|
||||||
@ -193,10 +201,10 @@ void callback(char* topic, byte* payload, unsigned int length) {
|
|||||||
red = strtol(tokens[1], NULL, 10);
|
red = strtol(tokens[1], NULL, 10);
|
||||||
green = strtol(tokens[2], NULL, 10);
|
green = strtol(tokens[2], NULL, 10);
|
||||||
blue = strtol(tokens[3], NULL, 10);
|
blue = strtol(tokens[3], NULL, 10);
|
||||||
leds[n].r = red;
|
leds[n].r = red;
|
||||||
leds[n].g = green;
|
leds[n].g = green;
|
||||||
leds[n].b = blue;
|
leds[n].b = blue;
|
||||||
FastLED.show();
|
FastLED.show();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -227,6 +235,7 @@ void reconnect() {
|
|||||||
client.publish(configBlock.mqttDebugTopic, "hello world");
|
client.publish(configBlock.mqttDebugTopic, "hello world");
|
||||||
client.publish(configBlock.mqttDebugTopic, WiFi.localIP().toString().c_str());
|
client.publish(configBlock.mqttDebugTopic, WiFi.localIP().toString().c_str());
|
||||||
|
|
||||||
|
client.subscribe(configBlock.mqttTopicColorCommand);
|
||||||
client.subscribe(configBlock.mqttTopicCommand);
|
client.subscribe(configBlock.mqttTopicCommand);
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user