gateway: execute array but echo each executed command #2
@ -15,9 +15,6 @@ steps:
|
|||||||
- pio run -e pro-mini
|
- pio run -e pro-mini
|
||||||
- echo -n 'reset' > /dev/ttyUSB0; sleep 1s; avrdude -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:.pio/build/pro-mini/firmware.hex:i -v
|
- echo -n 'reset' > /dev/ttyUSB0; sleep 1s; avrdude -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:.pio/build/pro-mini/firmware.hex:i -v
|
||||||
- service ser2net start
|
- service ser2net start
|
||||||
when:
|
|
||||||
target:
|
|
||||||
- production
|
|
||||||
|
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
|
|||||||
@ -33,8 +33,8 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
StaticJsonDocument<200> jsonDoc;
|
|
||||||
readCommand();
|
readCommand();
|
||||||
|
StaticJsonDocument<200> jsonDoc;
|
||||||
readRcSwitch(jsonDoc);
|
readRcSwitch(jsonDoc);
|
||||||
Dht::read(jsonDoc);
|
Dht::read(jsonDoc);
|
||||||
if (!jsonDoc.isNull()) {
|
if (!jsonDoc.isNull()) {
|
||||||
@ -105,34 +105,38 @@ void blink() {
|
|||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void runJsonCommand(String cmd) {
|
void runRcSwitchCommand(JsonVariant jsonDoc) {
|
||||||
StaticJsonDocument<256> jsonArray;
|
JsonObject rcSwitch = jsonDoc["rcSwitch"];
|
||||||
|
unsigned int protocol = rcSwitch["protocol"];
|
||||||
|
if (protocol == 1) {
|
||||||
|
mySwitch.setProtocol(protocol);
|
||||||
|
char* group = rcSwitch["group"];
|
||||||
|
int channel = rcSwitch["channel"];
|
||||||
|
rcSwitch["state"] ? mySwitch.switchOn(group, channel) : mySwitch.switchOff(group, channel);
|
||||||
|
} else {
|
||||||
|
mySwitch.setProtocol(protocol);
|
||||||
|
mySwitch.send(rcSwitch["value"]);
|
||||||
|
}
|
||||||
|
serializeJson(jsonDoc, Serial);
|
||||||
|
Serial.println();
|
||||||
|
// blink();
|
||||||
|
}
|
||||||
|
|
||||||
|
void runJsonCommands(const char* cmd) {
|
||||||
|
String origCmd = String(cmd);
|
||||||
|
StaticJsonDocument<512> jsonArray;
|
||||||
DeserializationError err = deserializeJson(jsonArray, cmd);
|
DeserializationError err = deserializeJson(jsonArray, cmd);
|
||||||
if (err == DeserializationError::Ok) {
|
if (err == DeserializationError::Ok) {
|
||||||
JsonArray array = jsonArray.as<JsonArray>();
|
JsonArray array = jsonArray.as<JsonArray>();
|
||||||
for (JsonVariant jsonDoc : array) {
|
for (JsonVariant jsonDoc : array) {
|
||||||
if (jsonDoc.containsKey("rcSwitch")) {
|
if (jsonDoc.containsKey("rcSwitch")) {
|
||||||
JsonObject rcSwitch = jsonDoc["rcSwitch"];
|
runRcSwitchCommand(jsonDoc);
|
||||||
unsigned int protocol = rcSwitch["protocol"];
|
|
||||||
if (protocol == 1) {
|
|
||||||
mySwitch.setProtocol(protocol);
|
|
||||||
char* group = rcSwitch["group"];
|
|
||||||
int channel = rcSwitch["channel"];
|
|
||||||
if (rcSwitch["state"]) {
|
|
||||||
mySwitch.switchOn(group, channel);
|
|
||||||
} else {
|
|
||||||
mySwitch.switchOff(group, channel);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mySwitch.setProtocol(protocol);
|
|
||||||
mySwitch.send(rcSwitch["value"]);
|
|
||||||
// Serial.println((const char*)rcSwitch["value"]);
|
|
||||||
}
|
|
||||||
blink();
|
|
||||||
} else {
|
|
||||||
Serial.println(err.c_str());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Serial.print(err.c_str());
|
||||||
|
Serial.print(": ");
|
||||||
|
Serial.println(origCmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,7 +153,6 @@ void readCommand() {
|
|||||||
cmd = cmd.substring(0, cmd.lastIndexOf(','));
|
cmd = cmd.substring(0, cmd.lastIndexOf(','));
|
||||||
}
|
}
|
||||||
cmd = "[" + cmd + "]";
|
cmd = "[" + cmd + "]";
|
||||||
Serial.println(cmd);
|
runJsonCommands(cmd.c_str());
|
||||||
runJsonCommand(cmd);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user