new command tested and config mode switch fixed
This commit is contained in:
parent
a45806aacf
commit
15e33778a7
@ -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.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/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/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/operation=replace
|
||||
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.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/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/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/operation=replace
|
||||
environment/project/io.sloeber.core.toolChain.release.1583508753/JANTJE.EXTRA.ALL/value=
|
||||
|
@ -34,6 +34,9 @@ void setup() {
|
||||
|
||||
Serial.print("Magic: ");
|
||||
Serial.println(configBlock.magic);
|
||||
Serial.print("ConfigSwitch: ");
|
||||
Serial.println(digitalRead(CONFIG_SWITCH));
|
||||
|
||||
|
||||
configMode = ((LOW == digitalRead(CONFIG_SWITCH)) || (configBlock.magic != MAGIC));
|
||||
|
||||
|
@ -36,6 +36,7 @@ void configServeIndex() {
|
||||
strcpy(configBlock.mqttPass, "geheim123");
|
||||
strcpy(configBlock.mqttClientId, "RgbLed1");
|
||||
configBlock.mqttPort = 8883;
|
||||
strcpy(configBlock.mqttTopicColorCommand, "IoT/RgbLed1/ColorCommand");
|
||||
strcpy(configBlock.mqttTopicCommand, "IoT/RgbLed1/Command");
|
||||
strcpy(configBlock.mqttDebugTopic, "IoT/RgbLed1/Debug");
|
||||
configBlock.debugMode = 0;
|
||||
@ -193,6 +194,21 @@ void configServeIndex() {
|
||||
buffer += configBlock.mqttPort;
|
||||
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 +=
|
||||
" />"
|
||||
" </td>"
|
||||
@ -284,6 +300,8 @@ void configServeGetConfiguration() {
|
||||
strcpy(configBlock.mqttClientId, arg.c_str());
|
||||
arg = webServer.arg("mqttPort");
|
||||
configBlock.mqttPort = atoi(arg.c_str());
|
||||
arg = webServer.arg("mqttTopicColorCommand");
|
||||
strcpy(configBlock.mqttTopicColorCommand, arg.c_str());
|
||||
arg = webServer.arg("mqttTopicCommand");
|
||||
strcpy(configBlock.mqttTopicCommand, arg.c_str());
|
||||
arg = webServer.arg("mqttDebugTopic");
|
||||
@ -350,6 +368,10 @@ void showConfiguration() {
|
||||
Serial.print(configBlock.mqttPort);
|
||||
Serial.println(">");
|
||||
|
||||
Serial.print("mqttTopicColorCommand = <");
|
||||
Serial.print(configBlock.mqttTopicColorCommand);
|
||||
Serial.println(">");
|
||||
|
||||
Serial.print("mqttTopicCommand = <");
|
||||
Serial.print(configBlock.mqttTopicCommand);
|
||||
Serial.println(">");
|
||||
|
@ -9,6 +9,7 @@ typedef struct {
|
||||
char mqttPass[32];
|
||||
char mqttClientId[32];
|
||||
uint32_t mqttPort;
|
||||
char mqttTopicColorCommand[64];
|
||||
char mqttTopicCommand[64];
|
||||
char mqttDebugTopic[64];
|
||||
uint32_t debugMode;
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
#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
|
||||
|
||||
#endif /* DEFINES_H_ */
|
||||
|
@ -72,7 +72,7 @@ void setup_wifi() {
|
||||
|
||||
static CRGB evaluationColorWord(char* cmd) {
|
||||
uint8_t red = 0, green = 0, blue = 0;
|
||||
if ((! strcmp(cmd, "on")) || (! strcmp(cmd, "white")) {
|
||||
if ((! strcmp(cmd, "on")) || (! strcmp(cmd, "white"))) {
|
||||
red = 255;
|
||||
green = 255;
|
||||
blue = 255;
|
||||
@ -112,106 +112,128 @@ static CRGB evaluationColorWord(char* cmd) {
|
||||
|
||||
|
||||
void callback(char* topic, byte* payload, unsigned int length) {
|
||||
const uint8_t BUFSIZE = 128;
|
||||
if ((length + 1) >= BUFSIZE) { // 1 for terminating NUL
|
||||
const uint8_t BUFSIZE = 128;
|
||||
if ((length + 1) >= BUFSIZE) { // 1 for terminating NUL
|
||||
#ifdef DEBUG
|
||||
Serial.println("Received message too long, ignore it");
|
||||
Serial.println("Received message too long, ignore it");
|
||||
#endif
|
||||
} else {
|
||||
char buffer[BUFSIZE];
|
||||
memcpy(buffer, payload, length);
|
||||
*(buffer + length) = 0;
|
||||
} else {
|
||||
char buffer[BUFSIZE];
|
||||
memcpy(buffer, payload, length);
|
||||
*(buffer + length) = 0;
|
||||
#ifdef DEBUG
|
||||
Serial.print("Received message: ");
|
||||
Serial.print(length);
|
||||
Serial.print(" ");
|
||||
Serial.print(topic);
|
||||
Serial.print(" ");
|
||||
Serial.println(buffer);
|
||||
Serial.print("Received message: ");
|
||||
Serial.print(length);
|
||||
Serial.print(" ");
|
||||
Serial.print(topic);
|
||||
Serial.print(" ");
|
||||
Serial.println(buffer);
|
||||
#endif
|
||||
|
||||
|
||||
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);
|
||||
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;
|
||||
|
||||
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)) {
|
||||
int32_t n, red, green, blue;
|
||||
CRGB colors;
|
||||
switch (tokenCnt) {
|
||||
case 1:
|
||||
// on, off, color word for all LEDs
|
||||
colors = evaluationColorWord(tokens[0]);
|
||||
for (uint8_t i = 0; i < NUM_OF_LEDs; i++) {
|
||||
leds[i] = colors;
|
||||
}
|
||||
FastLED.show();
|
||||
break;
|
||||
case 2:
|
||||
// token0 = LED number, token1 = color
|
||||
n = strtol(tokens[0], NULL, 10);
|
||||
if (n >= 0 && n < NUM_OF_LEDs) {
|
||||
colors = evaluationColorWord(tokens[1]);
|
||||
leds[n] = colors;
|
||||
FastLED.show();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// token0 = red, token1 = green, token2 = blue
|
||||
red = strtol(tokens[0], NULL, 10);
|
||||
green = strtol(tokens[1], NULL, 10);
|
||||
blue = strtol(tokens[2], NULL, 10);
|
||||
for (uint8_t i = 0; i < NUM_OF_LEDs; i++) {
|
||||
leds[i].r = red;
|
||||
leds[i].g = green;
|
||||
leds[i].b = blue;
|
||||
}
|
||||
FastLED.show();
|
||||
break;
|
||||
case 4:
|
||||
// token0 = LED number, token1 = red, token2 = green, token3 = blue
|
||||
n = strtol(tokens[0], NULL, 10);
|
||||
if (n >= 0 && n < NUM_OF_LEDs) {
|
||||
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();
|
||||
}
|
||||
break;
|
||||
}
|
||||
int32_t n, red, green, blue;
|
||||
CRGB colors;
|
||||
switch (tokenCnt) {
|
||||
case 1:
|
||||
// on, off, color word for all LEDs
|
||||
colors = evaluationColorWord(tokens[0]);
|
||||
for (uint8_t i = 0; i < NUM_OF_LEDs; i++) {
|
||||
leds[i] = colors;
|
||||
}
|
||||
FastLED.show();
|
||||
break;
|
||||
case 2:
|
||||
// token0 = LED number, token1 = color
|
||||
n = strtol(tokens[0], NULL, 10);
|
||||
if (n >= 0 && n < NUM_OF_LEDs) {
|
||||
colors = evaluationColorWord(tokens[1]);
|
||||
leds[n] = colors;
|
||||
FastLED.show();
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
// token0 = red, token1 = green, token2 = blue
|
||||
red = strtol(tokens[0], NULL, 10);
|
||||
green = strtol(tokens[1], NULL, 10);
|
||||
blue = strtol(tokens[2], NULL, 10);
|
||||
for (uint8_t i = 0; i < NUM_OF_LEDs; i++) {
|
||||
leds[i].r = red;
|
||||
leds[i].g = green;
|
||||
leds[i].b = blue;
|
||||
}
|
||||
FastLED.show();
|
||||
break;
|
||||
case 4:
|
||||
// token0 = LED number, token1 = red, token2 = green, token3 = blue
|
||||
n = strtol(tokens[0], NULL, 10);
|
||||
if (n >= 0 && n < NUM_OF_LEDs) {
|
||||
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();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -265,7 +287,7 @@ void setupProduction() {
|
||||
setup_wifi();
|
||||
client.setServer(configBlock.mqttBroker, configBlock.mqttPort);
|
||||
|
||||
FastLED.addLeds<NEOPIXEL, PIXEL_PIN>(leds, NUM_OF_LEDs);
|
||||
FastLED.addLeds<NEOPIXEL, PIXEL_PIN>(leds, NUM_OF_LEDs);
|
||||
}
|
||||
|
||||
|
||||
@ -320,7 +342,7 @@ void loop() {
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user