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