Hi,
I'm posting this question into this part of the forum instead of the networking, because the main problem is my poor programming skills. But I'm trying. Little of the background: I bought a house and planning to throw several Arduino Nano + NFR24L01 + 1Wire temp sensors around the premises and single Uno is constantly receiving the data from these nodes. I have already this working between one TX and RX (code below). Next I need to add compatibility for more TXs. After that I have to figure out how to communicate these temperature readings from Uno to Raspberry Pi. Then I need to find some IoT cloud or something to form an online chart. And reason I'm doing this by myself is because already spent all my money into the house and I need to build this temperature system as low cost as possible
If I may ask, it would be great if someone could help me adding the extra TX into this code. I have spent several evenings for exploring similar projects, but they all tend to have some kind of an exception which cant fit in to my project (I cant combine the code into mine). There seems to be several ways to form the addresses. I think my TX doesn't have any address? How do I know which TX is sending? Is there any easy way to add the id or address without building the whole system from a scratch (even it's one of the simpliest right now )
TX
#include <DallasTemperature.h>
#include <OneWire.h>
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float temp1;
const byte slaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
float dataToSend;
unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second
void setup() {
Serial.begin(9600);
Serial.println("SimpleTx Starting");
sensors.begin();
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3,5); // delay, count
radio.openWritingPipe(slaveAddress);
}
void loop() {
currentMillis = millis();
if (currentMillis - prevMillis >= txIntervalMillis) {
send();
prevMillis = millis();
}
}
void send() {
sensors.requestTemperatures();
temp1 = sensors.getTempCByIndex(0);
radio.write(&temp1, sizeof(temp1));
Serial.print(temp1);
delay(10);
RX
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN 9
#define CSN_PIN 10
const byte thisSlaveAddress[5] = {'R','x','A','A','A'};
RF24 radio(CE_PIN, CSN_PIN);
char dataReceived[10];
bool newData = false;
float temp1;
void setup() {
Serial.begin(9600);
Serial.println("SimpleRx Starting");
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.openReadingPipe(1, thisSlaveAddress);
radio.startListening();
}
void loop() {
getData();
}
void getData() {
if ( radio.available() ) {
delay(50);
radio.read(&temp1, sizeof(temp1));
Serial.print("Temp 1: ");
Serial.print(temp1);
Serial.print(" C");
Serial.println(" ");
}
}