Created
November 13, 2021 05:25
-
-
Save zvakanaka/066a2d4348691cf4789e940850174b4b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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