Hi all,
My first post here, been testing stuff with Arduino for a couple of weeks now. The idea is to build a network of sensors in the house.
So, the hardware and the sketches i’m working on.
The UNO, which is the base who’s recieving data.
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Wire.h>
RF24 radio(5,6);
RF24Network network(radio);
const uint16_t this_node = 00;
const uint16_t other_node = 01;
struct payload_t
{
/*unsigned long temp1;
unsigned long temp2;
*/
float temp1;
float temp2;
};
void setup(void)
{
Serial.begin(9600);
Serial.println("RF24 Network Rx-DS18B20");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 88, /*node address*/ this_node);
}
void loop(void)
{
network.update();
while ( network.available())
{
RF24NetworkHeader header;
payload_t payload;
network.read(header,&payload,sizeof(payload));
Serial.print("Temp1= ");
Serial.print(payload.temp1);
Serial.println(" C");
Serial.print("Temp2= ");
Serial.print(payload.temp2);
Serial.println(" C");
}}
One of the TX is a NANO with this sketch
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#define ONE_WIRE_BUS 4
int numbers[6];///16
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress Sonda0 = { 0x28, 0xFF, 0x32, 0xD0, 0x4C, 0x04, 0x00, 0xFF };
RF24 radio(9,10);
RF24Network network(radio);
const uint16_t this_node = 01;
const uint16_t other_node = 00;
const unsigned long interval = 2000; //ms
unsigned long last_sent;
unsigned long packets_sent;
struct payload_t
{
//unsigned long temp1;
float temp1;
};
void setup()
{
Serial.begin(9600);
sensors.begin();
sensors.setResolution(Sonda0, 12);
Serial.println("RF24 Network Tx-DS18B20");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 88, /*node address*/ this_node);
}
void loop(void) {
sensors.requestTemperatures();
delay(5000);
Serial.print("DS18B20 = ");
Serial.print(" ");
Serial.print(sensors.getTempC(Sonda0));
Serial.println(" C");
float sizeofpayload;
network.update();
unsigned long now = millis();
if ( now - last_sent >= interval )
{
last_sent = now;
float sens1 = (sensors.getTempC(Sonda0));
float temp1 = {sens1};
payload_t payload = {sens1};
RF24NetworkHeader header(/*to node*/ other_node);
bool ok1 = network.write(header,&payload,sizeof(payload));
}
}
And the final and last is a ProMini with this sketch
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#define ONE_WIRE_BUS 2
int numbers[6];///16
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress Sonda0 = { 0x28, 0xFF, 0xF9, 0x36, 0x4B, 0x04, 0x00, 0x97 };
RF24 radio(9,10);
RF24Network network(radio);
const uint16_t this_node = 01;
const uint16_t other_node = 00;
const unsigned long interval = 2000; //ms
unsigned long last_sent;
unsigned long packets_sent;
struct payload_t
{
//unsigned long temp2;
float temp2;
};
void setup()
{
Serial.begin(9600);
sensors.begin();
sensors.setResolution(Sonda0, 12);
Serial.println("RF24 Network Tx-DS18B20");
SPI.begin();
radio.begin();
network.begin(/*channel*/ 88, /*node address*/ this_node);
}
void loop(void) {
sensors.requestTemperatures();
delay(5000);
Serial.print("DS18B20 = ");
Serial.print(" ");
Serial.print(sensors.getTempC(Sonda0));
Serial.println(" C");
float sizeofpayload;
network.update();
unsigned long now = millis();
if ( now - last_sent >= interval )
{
last_sent = now;
float sens0 = (sensors.getTempC(Sonda0));
float temp2 = {sens0};
payload_t payload = {sens0};
RF24NetworkHeader header(/*to node*/ other_node);
bool ok1 = network.write(header,&payload,sizeof(payload));
}
}
Both the Nano and the ProMini is each equipt with a DS18B20 and sending readings fine to the Uno. However I want to separate the readings so the Nano is Temp1 and the ProMini is Temp2.
How to go about this?
The result i get is:
Temp1= 27.06 C
Temp2= 0.00 C
Temp1= 26.25 C
Temp2= 0.00 C
Temp1= 27.06 C
Temp2= 0.00 C
Temp1= 26.25 C
Temp2= 0.00 C
Temp1= 27.06 C
Temp2= 0.00 C
Temp1= 26.25 C
Temp2= 0.00 C
anyone?