Skip to content

Instantly share code, notes, and snippets.

@zvakanaka
Created November 13, 2021 05:25
Show Gist options
  • Save zvakanaka/066a2d4348691cf4789e940850174b4b to your computer and use it in GitHub Desktop.
Save zvakanaka/066a2d4348691cf4789e940850174b4b to your computer and use it in GitHub Desktop.
#include <Arduino.h>
// same version as dronebot 433 video
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK rf_driver;
void setup() {
rf_driver.init();
Serial.begin(9600);
}
void loop() {
if (Serial.available()) { // check for incoming serial data
String command = Serial.readString(); // read command from serial port
if (command.indexOf("open") > -1) {
Serial.println("Sending 'open'");
String commandStr = "{\"command\": \"open\"}";
static char *msg = commandStr.c_str();
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
} else if (command.indexOf("shut") > -1) {
Serial.println("Sending 'shut'");
String commandStr = "{\"command\": \"shut\"}";
static char *msg = commandStr.c_str();
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
} else {
Serial.print("Received unknown serial command:");
Serial.println(command);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment