add new command

This commit is contained in:
Wolfgang Hottgenroth 2019-04-10 11:15:12 +02:00
parent 483a39e30c
commit 012b0d4831
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
7 changed files with 43 additions and 28 deletions

5
.gitignore vendored
View File

@ -1 +1,6 @@
/Release/ /Release/
ConfigGenerator/configuration.cpp
ConfigGenerator/configuration.h
~*
*~

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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}

View File

@ -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,13 +131,14 @@ 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;
#define MAX_TOKENS 5
char *tokens[MAX_TOKENS]; char *tokens[MAX_TOKENS];
do { do {
if (tokenCnt >= MAX_TOKENS) {
break;
}
tk = strtok(inbuf, " "); tk = strtok(inbuf, " ");
inbuf = NULL; inbuf = NULL;
tokens[tokenCnt] = tk; tokens[tokenCnt] = tk;
@ -154,6 +157,11 @@ void callback(char* topic, byte* payload, unsigned int length) {
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) {
@ -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