switch to optiboot and add support for multiple commands
This commit is contained in:
parent
217a0b4bc6
commit
8b2cbecae3
9
gateway/README.md
Normal file
9
gateway/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# A gateway for 433 MHz devices
|
||||
It uses [rc_switch](https://github.com/sui77/rc-switch) library for controlling wall sockets.
|
||||
|
||||
It also supports receiving commands from the same protocol.
|
||||
|
||||
It acts as a serial gateway and it is connected to a Raspberry Pi running Home assistant.
|
||||
|
||||
It uses an Arduino Pro Mini 5v 16 Mhz.
|
||||
The original bootloader has been replaced with Optiboot using this tutorial: https://andreasrohner.at/posts/Electronics/How-to-make-the-Watchdog-Timer-work-on-an-Arduino-Pro-Mini-by-replacing-the-bootloader/
|
||||
@ -8,12 +8,14 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:pro16MHzatmega328]
|
||||
[env:uno]
|
||||
platform = atmelavr
|
||||
board = pro16MHzatmega328
|
||||
board = uno
|
||||
board_build.mcu = atmega328p
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
sui77/rc-switch@^2.6.3
|
||||
bblanchon/ArduinoJson@6.16.1
|
||||
adafruit/Adafruit Unified Sensor@^1.1.4
|
||||
adafruit/DHT sensor library@1.3.10
|
||||
upload_port = /dev/ttyUSB0
|
||||
|
||||
@ -22,8 +22,9 @@ void readCommand();
|
||||
void readDht(JsonDocument& jsonDoc);
|
||||
|
||||
void setup() {
|
||||
digitalWrite(RESET_PIN, HIGH);
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
pinMode(RESET_PIN, INPUT_PULLUP);
|
||||
pinMode(RESET_PIN, OUTPUT);
|
||||
|
||||
mySwitch.enableReceive(digitalPinToInterrupt(RECEIVE_PIN));
|
||||
mySwitch.enableTransmit(SEND_PIN);
|
||||
@ -70,16 +71,12 @@ void readRcSwitch(JsonDocument& jsonDoc) {
|
||||
}
|
||||
}
|
||||
|
||||
void readCommand() {
|
||||
if (Serial.available() > 0) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
if (cmd == "reset") {
|
||||
pinMode(RESET_PIN, OUTPUT);
|
||||
digitalWrite(RESET_PIN, LOW);
|
||||
}
|
||||
StaticJsonDocument<256> jsonDoc;
|
||||
DeserializationError err = deserializeJson(jsonDoc, cmd);
|
||||
if (err == DeserializationError::Ok) {
|
||||
void runJsonCommand(String cmd) {
|
||||
StaticJsonDocument<256> jsonArray;
|
||||
DeserializationError err = deserializeJson(jsonArray, cmd);
|
||||
if (err == DeserializationError::Ok) {
|
||||
JsonArray array = jsonArray.as<JsonArray>();
|
||||
for(JsonVariant jsonDoc : array) {
|
||||
if (jsonDoc.containsKey("rcSwitch")) {
|
||||
JsonObject rcSwitch = jsonDoc["rcSwitch"];
|
||||
unsigned int protocol = rcSwitch["protocol"];
|
||||
@ -95,14 +92,32 @@ void readCommand() {
|
||||
} else {
|
||||
mySwitch.setProtocol(protocol);
|
||||
mySwitch.send(rcSwitch["value"]);
|
||||
// Serial.println((const char*)rcSwitch["value"]);
|
||||
}
|
||||
} else {
|
||||
Serial.println(err.c_str());
|
||||
}
|
||||
} else {
|
||||
Serial.println(err.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void readCommand() {
|
||||
if (Serial.available() > 0) {
|
||||
String cmd = Serial.readStringUntil('\n');
|
||||
if (cmd == "reset") {
|
||||
Serial.println("resetting...");
|
||||
delay(200);
|
||||
digitalWrite(RESET_PIN, LOW);
|
||||
}
|
||||
if (cmd.endsWith(",")) {
|
||||
cmd = cmd.substring(0, cmd.lastIndexOf(','));
|
||||
}
|
||||
cmd = "[" + cmd + "]";
|
||||
// Serial.println(cmd);
|
||||
runJsonCommand(cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void readDht(JsonDocument& jsonDoc) {
|
||||
unsigned long currentTime = millis();
|
||||
if ((currentTime - lastReadTime) > readInterval) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user