Hello Everyone,
My goal is to send/receive a set of (2) integers (1-12) using an RF95W Lora module. At this point I want to verify that I can send/receive the values and I've run into troubles with Radioheads wonderful library. I've verified that my modules work by using the reliable datagram example projects. I'm using arduino DUE's for both sending and receiving.
I'm getting a Invalid cast error and I'm looking for some direction. The point of this basic sketch is to verify the data transmission before building the rest of the features into the project. Radiohead suggests using "htons" to convert to a network type protocol, but I"m heaving trouble using it.
Any suggestions
Thank You,
Mark
#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
#define RFM95_CS 30 //SPI channel select or slave select pin for
#define RFM95_INT 32 //SPI interupt pin for data "ready" function
#define RFM95_RST 28 //Reset pin for initial reset of module
#define RFM95_FREQ 915.0 //Frequency Set function 915 MHz
//Radio Driver
RH_RF95 rf95(RFM95_CS, RFM95_INT); // (SlaveSelectPin, interrupt pin) Use standard SPI connections on Due Header
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(rf95, SERVER_ADDRESS);
// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB
struct dataStruct {
uint16_t cue;
uint16_t slat;
} CSDat;
//byte buf[sizeof(CSDat)] = {0};
void setup()
{
CSDat.cue = 10;
CSDat.slat = 20;
Serial.begin(9600);
while (!Serial) ; // Wait for serial port to be available
pinMode(RFM95_RST, OUTPUT);
digitalWrite(RFM95_RST, HIGH); //initialize reset pin
// manual reset module
digitalWrite(RFM95_RST, LOW);
delay(10);
digitalWrite(RFM95_RST, HIGH);
delay(10);
//initialize RFM95 radio
if (!rf95.init()) {
Serial.println("RFM95 radio init failed");
while (1);
}
Serial.println("RFM95 radio init OK!");
//Set frequency 915 MHz
if (!rf95.setFrequency(RFM95_FREQ)) {
Serial.println("setFrequency failed");
}
if (!manager.init())
Serial.println("init failed");
// Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
// The default transmitter power is 13dBm, using PA_BOOST.
// If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
// you can set transmitter powers from 5 to 23 dBm:
rf95.setTxPower(23, false); //Set transmitter power, 23 dBm and false (no RFO pins)
// You can optionally require this module to wait until Channel Activity
// Detection shows no activity on the channel before transmitting by setting
// the CAD timeout to non-zero:
// driver.setCADTimeout(10000);
}
//uint8_t data[] = "And hello back to you";
// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
void loop()
{
dataStruct data;
data.cue = htons(10);
data.slat = htons(20);
Serial.println(data.cue);
Serial.println(data.slat);
delay(1000);
uint8_t len = sizeof(buf);
uint8_t from;
// Send a reply back to the originator client
if (!manager.sendtoWait((uint8_t*)data, sizeof(data), from))
Serial.println("sendtoWait failed");
}