new command tested and config mode switch fixed

This commit is contained in:
Wolfgang Hottgenroth 2019-04-10 12:23:25 +02:00
parent a45806aacf
commit 15e33778a7
Signed by: wn
GPG Key ID: B586EAFCDF2F65F4
6 changed files with 144 additions and 96 deletions

View File

@ -184,10 +184,10 @@ environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.DT
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.DTS/value=3600 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.DTS/value=3600
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/operation=replace
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/value=1554657771 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.LOCAL/value=1554895981
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/operation=replace
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/value=1554650571 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.UTC/value=1554888781
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/operation=replace
environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/value=3600 environment/project/io.sloeber.core.toolChain.release.1583508753/A.EXTRA.TIME.ZONE/value=3600
@ -466,10 +466,10 @@ environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.BOARD_NA
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.BOARD_NAME/value=NodeMCU 1.0 (ESP-12E Module) environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.BOARD_NAME/value=NodeMCU 1.0 (ESP-12E Module)
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/operation=replace
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/value=/dev/ttyUSB5 environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.COM_PORT/value=/dev/ttyUSB4
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/operation=replace
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}///// environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.ECLIPSE_LOCATION/value=${eclipse_home}//////////
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/delimiter=\: environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/delimiter=\:
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/operation=replace environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/operation=replace
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/value= environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/value=

View File

@ -34,6 +34,9 @@ void setup() {
Serial.print("Magic: "); Serial.print("Magic: ");
Serial.println(configBlock.magic); Serial.println(configBlock.magic);
Serial.print("ConfigSwitch: ");
Serial.println(digitalRead(CONFIG_SWITCH));
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC)); configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));

View File

@ -36,6 +36,7 @@ void configServeIndex() {
strcpy(configBlock.mqttPass, "geheim123"); strcpy(configBlock.mqttPass, "geheim123");
strcpy(configBlock.mqttClientId, "RgbLed1"); strcpy(configBlock.mqttClientId, "RgbLed1");
configBlock.mqttPort = 8883; configBlock.mqttPort = 8883;
strcpy(configBlock.mqttTopicColorCommand, "IoT/RgbLed1/ColorCommand");
strcpy(configBlock.mqttTopicCommand, "IoT/RgbLed1/Command"); strcpy(configBlock.mqttTopicCommand, "IoT/RgbLed1/Command");
strcpy(configBlock.mqttDebugTopic, "IoT/RgbLed1/Debug"); strcpy(configBlock.mqttDebugTopic, "IoT/RgbLed1/Debug");
configBlock.debugMode = 0; configBlock.debugMode = 0;
@ -193,6 +194,21 @@ void configServeIndex() {
buffer += configBlock.mqttPort; buffer += configBlock.mqttPort;
buffer += "\""; buffer += "\"";
buffer +=
" />"
" </td>"
" </tr>"
" <tr>"
" <td>"
" <label for\"mqttTopicColorCommand\">MQTT Topic Color Command</label>"
" </td><td>"
" <input type=\"text\" name=\"mqttTopicColorCommand\" id=\"mqttTopicColorCommand\" ";
buffer += " size=\"64\" ";
buffer += " value=\"";
buffer += configBlock.mqttTopicColorCommand;
buffer += "\"";
buffer += buffer +=
" />" " />"
" </td>" " </td>"
@ -284,6 +300,8 @@ void configServeGetConfiguration() {
strcpy(configBlock.mqttClientId, arg.c_str()); strcpy(configBlock.mqttClientId, arg.c_str());
arg = webServer.arg("mqttPort"); arg = webServer.arg("mqttPort");
configBlock.mqttPort = atoi(arg.c_str()); configBlock.mqttPort = atoi(arg.c_str());
arg = webServer.arg("mqttTopicColorCommand");
strcpy(configBlock.mqttTopicColorCommand, arg.c_str());
arg = webServer.arg("mqttTopicCommand"); arg = webServer.arg("mqttTopicCommand");
strcpy(configBlock.mqttTopicCommand, arg.c_str()); strcpy(configBlock.mqttTopicCommand, arg.c_str());
arg = webServer.arg("mqttDebugTopic"); arg = webServer.arg("mqttDebugTopic");
@ -350,6 +368,10 @@ void showConfiguration() {
Serial.print(configBlock.mqttPort); Serial.print(configBlock.mqttPort);
Serial.println(">"); Serial.println(">");
Serial.print("mqttTopicColorCommand = <");
Serial.print(configBlock.mqttTopicColorCommand);
Serial.println(">");
Serial.print("mqttTopicCommand = <"); Serial.print("mqttTopicCommand = <");
Serial.print(configBlock.mqttTopicCommand); Serial.print(configBlock.mqttTopicCommand);
Serial.println(">"); Serial.println(">");

View File

@ -9,6 +9,7 @@ typedef struct {
char mqttPass[32]; char mqttPass[32];
char mqttClientId[32]; char mqttClientId[32];
uint32_t mqttPort; uint32_t mqttPort;
char mqttTopicColorCommand[64];
char mqttTopicCommand[64]; char mqttTopicCommand[64];
char mqttDebugTopic[64]; char mqttDebugTopic[64];
uint32_t debugMode; uint32_t debugMode;

View File

@ -12,9 +12,9 @@
#define EEPROM_ADDR 0 #define EEPROM_ADDR 0
#define CONFIG_SWITCH 2 #define CONFIG_SWITCH 4 // Arduino numbering
#define PIXEL_PIN 1 #define PIXEL_PIN 1 // NODEMCU numbering
#define NUM_OF_LEDs 64 #define NUM_OF_LEDs 64
#endif /* DEFINES_H_ */ #endif /* DEFINES_H_ */

View File

@ -72,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")) || (! strcmp(cmd, "white")) { if ((! strcmp(cmd, "on")) || (! strcmp(cmd, "white"))) {
red = 255; red = 255;
green = 255; green = 255;
blue = 255; blue = 255;
@ -159,7 +159,29 @@ void callback(char* topic, byte* payload, unsigned int length) {
if (! strcmp(topic, configBlock.mqttTopicCommand)) { if (! strcmp(topic, configBlock.mqttTopicCommand)) {
int32_t n; int32_t n, b;
CRGB pseudoColors;
switch (tokenCnt) {
case 1:
// set brightness
b = strtol(tokens[0], NULL, 10);
for (uint8_t i = 0; i < NUM_OF_LEDs; i++) {
leds[i].r = b;
leds[i].g = b;
leds[i].b = b;
}
FastLED.show();
break;
case 2:
// set brightness for one LED
n = strtol(tokens[0], NULL, 10);
b = strtol(tokens[1], NULL, 10);
if (n >= 0 && n < NUM_OF_LEDs) {
leds[n] = b;
FastLED.show();
}
break;
}
} else if (! strcmp(topic, configBlock.mqttTopicColorCommand)) { } else if (! strcmp(topic, configBlock.mqttTopicColorCommand)) {
int32_t n, red, green, blue; int32_t n, red, green, blue;