Hi all ive modified the reliable client sketch for nrf24 radis but have a problem that it wont compile due to being unable to determine data lenght and im no sure what it is ive done wrong. Ive included the code below.
im using arduino 1.0.6
// nrf24_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_NRF24 driver to control a NRF24 radio.
// It is designed to work with the other example nrf24_reliable_datagram_server
// Tested on Uno with Sparkfun WRL-00691 NRF24L01 module
// Tested on Teensy with Sparkfun WRL-00691 NRF24L01 module
// Tested on Anarduino Mini (http://www.anarduino.com/mini/) with RFM73 module
// Tested on Arduino Mega with Sparkfun WRL-00691 NRF25L01 module
#include <Narcoleptic.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>
#define CLIENT_ADDRESS 2
#define SERVER_ADDRESS 1
#define ONE_WIRE_BUS 7
#define temps sensors.getTempCByIndex(0);
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Singleton instance of the radio driver
RH_NRF24 driver;
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, CLIENT_ADDRESS);
//#########################//
//Data Structure to be sent//
//#########################//
typedef struct {
byte nodeID; // nodeID
int temp; // Temperature reading
}
Payload;
Payload ttx;
//#########################//
//Data Structure to be sent//
//#########################//
void setup()
{
Serial.begin(9600);
sensors.begin(); // start one wire
if (!manager.init()) // check rf working
Serial.println("init failed"); // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
}
uint8_t data[] = ttx;
// Dont put this on the stack:
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];
void loop()
{
ttx.nodeID = CLIENT_ADDRESS;
sensors.requestTemperatures(); // Get the temperature
Serial.println(sensors.getTempCByIndex(0));
ttx.temp=(sensors.getTempCByIndex(0)*100); // Read sensor and convert to integer, reversed at receiving end
Serial.println("Sending to nrf24_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 nrf24_reliable_datagram_server running?");
}
}
else
Serial.println("sendtoWait failed");
delay(500);
Narcoleptic.delay(60000); // enter low power mode for 60 seconds, valid range 16-32000 ms with standard Narcoleptic lib
// change variable for delay from int to unsigned int in Narcoleptic.cpp and Narcoleptic.h
// to extend range up to 65000 ms
}