first commit
This commit is contained in:
43
examples/ask/ask_receiver/ask_receiver.ino
Normal file
43
examples/ask/ask_receiver/ask_receiver.ino
Normal file
@@ -0,0 +1,43 @@
|
||||
// ask_receiver.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Simple example of how to use RadioHead to receive messages
|
||||
// with a simple ASK transmitter in a very simple way.
|
||||
// Implements a simplex (one-way) receiver with an Rx-B1 module
|
||||
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
|
||||
|
||||
#include <RH_ASK.h>
|
||||
#ifdef RH_HAVE_HARDWARE_SPI
|
||||
#include <SPI.h> // Not actually used but needed to compile
|
||||
#endif
|
||||
|
||||
RH_ASK driver;
|
||||
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
|
||||
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
|
||||
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
|
||||
|
||||
void setup()
|
||||
{
|
||||
#ifdef RH_HAVE_SERIAL
|
||||
Serial.begin(9600); // Debugging only
|
||||
#endif
|
||||
if (!driver.init())
|
||||
#ifdef RH_HAVE_SERIAL
|
||||
Serial.println("init failed");
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
|
||||
uint8_t buflen = sizeof(buf);
|
||||
|
||||
if (driver.recv(buf, &buflen)) // Non-blocking
|
||||
{
|
||||
int i;
|
||||
|
||||
// Message with a good checksum received, dump it.
|
||||
driver.printBuffer("Got:", buf, buflen);
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
// ask_reliable_datagram_client.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, reliable messaging client
|
||||
// with the RHReliableDatagram class, using the RH_ASK driver to control a ASK radio.
|
||||
// It is designed to work with the other example ask_reliable_datagram_server
|
||||
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_ASK.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_ASK driver;
|
||||
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
|
||||
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
}
|
||||
|
||||
uint8_t data[] = "Hello World!";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.println("Sending to ask_reliable_datagram_server");
|
||||
|
||||
// Send a message to manager_server
|
||||
if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
|
||||
{
|
||||
// Now wait for a reply from the server
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
|
||||
{
|
||||
Serial.print("got reply from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("No reply, is ask_reliable_datagram_server running?");
|
||||
}
|
||||
}
|
||||
else
|
||||
Serial.println("sendtoWait failed");
|
||||
delay(500);
|
||||
}
|
||||
|
@@ -0,0 +1,54 @@
|
||||
// ask_reliable_datagram_server.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Example sketch showing how to create a simple addressed, reliable messaging server
|
||||
// with the RHReliableDatagram class, using the RH_ASK driver to control a ASK radio.
|
||||
// It is designed to work with the other example ask_reliable_datagram_client
|
||||
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
|
||||
|
||||
#include <RHReliableDatagram.h>
|
||||
#include <RH_ASK.h>
|
||||
#include <SPI.h>
|
||||
|
||||
#define CLIENT_ADDRESS 1
|
||||
#define SERVER_ADDRESS 2
|
||||
|
||||
// Singleton instance of the radio driver
|
||||
RH_ASK driver;
|
||||
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
|
||||
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
|
||||
|
||||
// Class to manage message delivery and receipt, using the driver declared above
|
||||
RHReliableDatagram manager(driver, SERVER_ADDRESS);
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
if (!manager.init())
|
||||
Serial.println("init failed");
|
||||
}
|
||||
|
||||
uint8_t data[] = "And hello back to you";
|
||||
// Dont put this on the stack:
|
||||
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (manager.available())
|
||||
{
|
||||
// Wait for a message addressed to us from the client
|
||||
uint8_t len = sizeof(buf);
|
||||
uint8_t from;
|
||||
if (manager.recvfromAck(buf, &len, &from))
|
||||
{
|
||||
Serial.print("got request from : 0x");
|
||||
Serial.print(from, HEX);
|
||||
Serial.print(": ");
|
||||
Serial.println((char*)buf);
|
||||
|
||||
// Send a reply back to the originator client
|
||||
if (!manager.sendtoWait(data, sizeof(data), from))
|
||||
Serial.println("sendtoWait failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
examples/ask/ask_transmitter/ask_transmitter.ino
Normal file
38
examples/ask/ask_transmitter/ask_transmitter.ino
Normal file
@@ -0,0 +1,38 @@
|
||||
// ask_transmitter.pde
|
||||
// -*- mode: C++ -*-
|
||||
// Simple example of how to use RadioHead to transmit messages
|
||||
// with a simple ASK transmitter in a very simple way.
|
||||
// Implements a simplex (one-way) transmitter with an TX-C1 module
|
||||
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
|
||||
|
||||
#include <RH_ASK.h>
|
||||
#ifdef RH_HAVE_HARDWARE_SPI
|
||||
#include <SPI.h> // Not actually used but needed to compile
|
||||
#endif
|
||||
|
||||
RH_ASK driver;
|
||||
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
|
||||
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
|
||||
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
|
||||
|
||||
void setup()
|
||||
{
|
||||
#ifdef RH_HAVE_SERIAL
|
||||
Serial.begin(9600); // Debugging only
|
||||
#endif
|
||||
if (!driver.init())
|
||||
#ifdef RH_HAVE_SERIAL
|
||||
Serial.println("init failed");
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
const char *msg = "hello";
|
||||
|
||||
driver.send((uint8_t *)msg, strlen(msg));
|
||||
driver.waitPacketSent();
|
||||
delay(200);
|
||||
}
|
Reference in New Issue
Block a user