Hello together,
based on TMRh20'slibrary I have create 3 sketches to start with network- using 1 Master and min. 5 Nodes...
So, first stepp, I have now 1 master and 2 chields... Both chields are receiving datas from Master without any problems. But master is allways receiving datas from 1 node- I have tryed a lot and read documentations but can not find any solution....
maybe you could help me....
master:
#include <SPI.h>
#include "RF24.h"
#include "FastLED.h"
#include <DS3232RTC.h>
#include <Time.h>
#include <Wire.h>
RF24 radio(9,10);
byte addresses[][6] = {"1Pipe","2Pipe","3Pipe","4Pipe","5Pipe","6Pipe",};
long Status[6] = {10,11,12,13,14,15}; // definiere das Verhalten der Lampen
long Sensor[6]; // Fadingzeit, Farbe (CSV), Helligkeit (CSV), Sättigung (CSV), Haltezeit, Adresse Lampe, Pipe
int IRStatus;
int IRRaum; // 01 = Raum 1, 02 = Raum 2, 03 = Raum 3, 04 = Raum 4, 05 = Raum 5, 06 = alle Räume
int Auto = 1; // wenn Auto = 0, dann gelten die manuellen Vorgaben, Wenn Auto = 1, dann gelten die Programmvorgaben
// wenn Auto = 2, starte Pogramm???
// Ordne automatische Programme zu
int i;
#define DATA_PIN 4
#define NUM_LEDS 3
CRGB leds[NUM_LEDS];
void setup()
{
Serial.begin(57600);
Serial.println("Test Zentrale");
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
leds[0] = CRGB::Cyan;
FastLED.show();
delay(200);
leds[1] = CRGB::Cyan;
FastLED.show();
delay(200);
leds[2] = CRGB::Cyan;
FastLED.show();
delay(200);
leds[0] = CRGB::Orange;
FastLED.show();
delay(200);
leds[1] = CRGB::Orange;
FastLED.show();
delay(200);
leds[2] = CRGB::Orange;
FastLED.show();
delay(200);
leds[0] = CRGB::Black;
FastLED.show();
delay(200);
leds[1] = CRGB::Black;
FastLED.show();
delay(200);
leds[2] = CRGB::Black;
FastLED.show();
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus() != timeSet)
Serial.println("Unable to sync with the RTC");
else
Serial.println("RTC has set the system time");
radio.begin();
radio.openWritingPipe(addresses[1]);
radio.openReadingPipe(1,addresses[3]);
radio.startListening();
}
void loop()
{
radio.read( Sensor, sizeof(Sensor) );
unsigned long time = micros();
Serial.println("empfange ");
Serial.print(" PIR: " );
Serial.println(Sensor[0]);
Serial.print(" IR- Code: " );
Serial.println(Sensor[1]);
Serial.print(" IR- Raum " );
Serial.println(Sensor[2]);
Serial.print(" Raum ID " );
Serial.println(Sensor[3]);
Serial.print(" ? " );
Serial.println(Sensor[4]);
Serial.print(" ? " );
Serial.println(Sensor[5]);
Serial.println(" ");
Serial.println(" ");
if (i < 6)
{i++;}
else
{i = 1;}
radio.stopListening();
radio.write( Status, sizeof(Status) );
radio.startListening();
Serial.print("Sende Vorgaben an Lampe ");
Serial.println();
Serial.print("Fadingzeit: ");
Serial.println(Status[0]);
Serial.print("Farbe (CSV): ");
Serial.println(Status[1]);
Serial.print("Helligkeit: ");
Serial.println(Status[2]);
Serial.print("Saettigung ");
Serial.println(Status[3]);
Serial.print("Programm: ");
Serial.println(Status[4]);
Serial.print("Auto? ");
Serial.println(Status[5]);
Serial.println(" ");
Serial.println(" ");
}
Node 1:
#include <SPI.h>
#include "RF24.h"
#include "FastLED.h"
#include "IRremote.h"
RF24 radio(9,10);
byte addresses[][6] = {"1Pipe","2Pipe","3Pipe","4Pipe","5Pipe","6Pipe"};
long Sensor[6];
long Status[6];
long Trigger[6];
int IRStatus;
int IRRaum; // 01 = Raum 1, 02 = Raum 2, 03 = Raum 3, 04 = Raum 4, 05 = Raum 5, 06 = alle Räume
int RaumID = 2;
int receiver = 3;
IRrecv irrecv(receiver);
decode_results results;
int PIR;
int sensorPin = 4;
#define DATA_PIN 2
#define NUM_LEDS 3
CRGB leds[NUM_LEDS];
void setup()
{
Serial.begin(57600);
Serial.print("Test Lampe ");
Serial.println(RaumID);
pinMode(sensorPin, INPUT);
irrecv.enableIRIn();
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
radio.begin();
radio.openWritingPipe(addresses[RaumID]);
radio.openReadingPipe(1,addresses[1]);
radio.startListening();
}
void loop()
{
leds[0] = CRGB::Black;
FastLED.show();
leds[1] = CRGB::Black;
FastLED.show();
leds[2] = CRGB::Black;
FastLED.show();
PIR = digitalRead(sensorPin);
if (PIR == HIGH)
{
leds[1] = CRGB::Green;
FastLED.show();
Serial.println("Bewegung erkannt.");
}
else
{
leds[1] = CRGB::Red;
FastLED.show();
Serial.println("keine Bewegung.");
}
if (irrecv.decode(&results))
{
translateIR();
irrecv.resume();
}
Sensor[0] = PIR;
Sensor[1] = IRStatus;
Sensor[2] = IRRaum;
Sensor[3] = RaumID;
radio.stopListening();
Serial.println("Sende...");
Serial.print(" Bewegung erkannt: ");
Serial.println(Sensor[0]);
Serial.print(" IR- Code ");
Serial.println(Sensor[1]);
Serial.print(" IR- Raum ");
Serial.println(Sensor[2]);
Serial.print(" Raum ID ");
Serial.println(Sensor[3]);
Serial.print(" offen ");
Serial.println(Sensor[4]);
Serial.print(" offen ");
Serial.println(Sensor[5]);
Serial.println(" ");
Serial.println(" ");
if (!radio.write( Sensor, sizeof(Sensor) ))
{
Serial.println("fehlgeschlagen");
leds[0] = CRGB::Red;
FastLED.show();
}
radio.startListening(); // Now, continue listening
unsigned long started_waiting_at = micros(); // Set up a timeout period, get the current microseconds
boolean timeout = false; // Set up a variable to indicate if a response was received or not
while ( ! radio.available() ){ // While nothing is received
if (micros() - started_waiting_at > 20 ){ // If waited longer than 200ms, indicate timeout and exit while loop
timeout = true;
break;
}
}
delay(5);
if ( timeout ){ // Describe the results
Serial.println("Fehlgeschlagen- Antwortzeit abgelaufen...");
leds[1] = CRGB::Red;
FastLED.show();
}
else
{
IRStatus = 0;
radio.read( Status, sizeof(Status) );
Serial.println("empfange Vorgaben: ");
Serial.print("Fadingzeit: ");
Serial.println(Status[0]);
Serial.print(" Farbe (CSV): ");
Serial.println(Status[1]);
Serial.print(" Helligkeit (CSV: )");
Serial.println(Status[2]);
Serial.print(" Saettigung (CSV): ");
Serial.println(Status[3]);
Serial.print(" offen ");
Serial.println(Status[4]);
Serial.print(" offen ");
Serial.println(Status[5]);
Serial.println(" ");
Serial.println(" ");
leds[0] = CRGB::Green;
FastLED.show();
}
delay(10);
}
void translateIR()
{
switch(results.value)
{}
}
Node 2 is the same as Node 1, only "RaumID" is a different one...
I have put some example-values in sketch from master, cause real sketch is realing long- master is receiving Datas from Nodes (lamps with PIR and IR-remote) and is calculating Values for brightness, colour and so on , depending on time, date and weather and so on....