Howdy ,
I got stuck with my project. I want to make a network of sensors, consisting of 5 transmitters and a master as receiver.
I manage to send the data from one transmitter to the master, but I fail to send from two transmitters, the second one appears in the serial monitor with 0 values, if I only transmit it, I manage to read it correctly.
Thank you
Transmiter code
#include <Adafruit_AHTX0.h>
#include <SPI.h>
#include <RF24Network.h>
#include "RF24.h"
Adafruit_AHTX0 aht;
RF24 radio(9, 10);
RF24Network network(radio);
const uint16_t this_node = 01;
const uint16_t master00 = 00;
float voltage;
int bat_percentage;
int analogInPin = A0;
int sensorValue;
float calibration = 0.40; // Check Battery voltage using multimeter & add/subtract the value
short int IntervCitire = 1 ; //exprimat in Minute
unsigned long currentMillis = 0;
unsigned long previousMillis_readandsendTemperatura = 0;
typedef struct{
float E;
float F;
float G;
float H;
}
B_t;
B_t duino1;
void setup() {
Serial.begin(115200);
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
radio.begin();
radio.setDataRate(RF24_250KBPS);
network.begin(92, this_node); //(channel, node address)
//radio.setPALevel(RF24_PA_MAX);
if (! aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
Serial.println("AHT10 or AHT20 found");
}
void loop()
{
currentMillis = millis();
if(( currentMillis - previousMillis_readandsendTemperatura ) > ( IntervCitire * 60000 )) {
previousMillis_readandsendTemperatura = currentMillis;
readandsendTemperatura();
}
}
void readandsendTemperatura()
{
//radio.powerUp();
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
duino1.E = temp.temperature;
duino1.F = humidity.relative_humidity;
sensorValue = analogRead(analogInPin);
voltage = (((sensorValue * 3.3) / 1024) * 2 + calibration); //multiply by two as voltage divider network is 100K & 100K Resistor
bat_percentage = mapfloat(voltage, 2.8, 4.2, 0, 100); //2.8V as Battery Cut off Voltage & 4.2V as Maximum Voltage
if (bat_percentage >= 100)
{
bat_percentage = 100;
}
if (bat_percentage <= 0)
{
bat_percentage = 1;
}
duino1.G = voltage;
duino1.H = bat_percentage;
RF24NetworkHeader header(master00); // (Address where the data is going)
bool ok = network.write(header, &duino1, sizeof(duino1)); // Send the data
Serial.print("Temperature: "); Serial.print(duino1.E); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(duino1.F); Serial.println("% rH");
Serial.print("Analog Value = ");
Serial.println(sensorValue);
Serial.print("Output Voltage = ");
Serial.println(voltage);
Serial.print("Battery Percentage = ");
Serial.println(bat_percentage);
//radio.powerDown();
}
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Receiver code
// Fill-in information from your Blynk Template here
#define BLYNK_TEMPLATE_ID "xxxxxx"
#define BLYNK_DEVICE_NAME "xxxxx"
#define BLYNK_FIRMWARE_VERSION "xx"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
// Uncomment your board, or configure a custom board in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#define USE_WEMOS_D1_MINI
#include "BlynkEdgent.h"
#include <SPI.h>
#include <RF24Network.h>
#include <RF24.h>
#include <Wire.h>
BlynkTimer timer;
//float temp1;
#define D3 0 // SI
#define D0 16 // NO I2C Bus SCL (clock)
// Set the pins up
#define CE_PIN D3
#define CSN_PIN D0
RF24 radio(0, 16);
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 00; // Address of our node in Octal format ( 04,031, etc)
const uint16_t node01 = 01; // Address of the other node in Octal format
const uint16_t node02 = 02;
const uint16_t node03 = 03;
const uint16_t node04 = 04;
//BLYNK_CONNECTED() {
// Blynk.syncAll();
//}
typedef struct{
float A;
float B;
float C;
float D;
float E;
float F;
float G;
float H;
}
A_t;
A_t duino1;
void setup()
{
Serial.begin(9600);
radio.begin();
radio.setDataRate(RF24_250KBPS);
network.begin(92, this_node); //(channel, node address)
BlynkEdgent.begin();
//timer.setInterval(6000, checkNetwork);
}
void loop() {
BlynkEdgent.run();
timer.run();
checkNetwork();
}
void checkNetwork()
{ network.update();
while ( network.available() ) { // Is there any incoming data?
RF24NetworkHeader header;
uint16_t msg_size = network.peek(header);
float incomingData;
network.read(header, &duino1, sizeof(duino1)); // Read the incoming data
//network.read(01, &duino2, sizeof(duino2));
if (header.from_node == 03) { // If data comes from Node 02
//network.read(header, &duino1, sizeof(duino1));
Blynk.virtualWrite(2, duino1.A);
Blynk.virtualWrite(8, duino1.B);
Blynk.virtualWrite(6, duino1.C);
Blynk.virtualWrite(7, duino1.D);
Serial.print("duino1.A = ");
Serial.println(duino1.A);
Serial.print("duino1.B = ");
Serial.println(duino1.B);
Serial.print("duino1.C = ");
Serial.println(duino1.C);
Serial.print("duino1.D = ");
Serial.println(duino1.D);
}
if (header.from_node == 01) { // If data comes from Node 012
//network.read(header, &duino2, sizeof(duino2));
Blynk.virtualWrite(1, duino1.E);
Blynk.virtualWrite(3, duino1.F);
Blynk.virtualWrite(4, duino1.G);
Blynk.virtualWrite(5, duino1.H);
Serial.print("duino1.temp1 = ");
Serial.println(duino1.E);
Serial.print("duino1.umid1 = ");
Serial.println(duino1.F);
Serial.print("duino1.volt1 = ");
Serial.println(duino1.G);
Serial.print("duino1.batPercent1 = ");
Serial.println(duino1.H);
}
}
}
The code for the first transmitter is the same as the second, only the part below and the node number are different
typedef struct{
float A;
float B;
float C;
float D;
}
A_t;
A_t duino1;