bonjour a tous
me revoilà avec un code qui fonctionne en m inspirant de tous vos différents conseils.
Vous me pardonnerez l’état brouillon du code mais je cherche a le fignoler et a le rendre plus efficace.
voici le 3 codes
1 récepteur et 2 transmetteurs.
recepteur:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Servo.h>
#define led 2
RF24 radio(7, 8); // nRF24L01 (CE,CSN)
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;
void setup() {
Serial.begin(115200);
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
Serial.println("demarrage");
}
void loop() {
network.update();
//===== Receiving =====//
while ( network.available() ) { // Is there any incoming data?
RF24NetworkHeader header;
network.peek(header);
Serial.print("Received packet #");
Serial.println();
delay(1000);
Serial.print("From ");
Serial.println(header.from_node,OCT);
Serial.print("Header Type: ");
Serial.println((char)header.type);
// Serial.println(header.from_node);
unsigned long incomingData1;
if(header.from_node ){
network.read(header, &incomingData1, sizeof(incomingData1)); // Read the incoming data
Serial.println(incomingData1);
delay(1000);}
}
}
transmetteur 1:
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#define button 2
#define led 3
RF24 radio(7, 8); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 03; // Address of this node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
void setup() {
Serial.begin(115200);
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
}
void loop() {
network.update();
//===== Sending =====//
// Servo control at Node 01
unsigned long potValue = 1000;
Serial.println(potValue);
RF24NetworkHeader header1(master00); // (Address where the data is going)
bool ok = network.write(header1, &potValue, sizeof(potValue));} // Send the data
/* LED Control at Node 012
unsigned long buttonState = digitalRead(button);
RF24NetworkHeader header4(node012); // (Address where the data is going)
bool ok3 = network.write(header4, &buttonState, sizeof(buttonState)); // Send the data
// LEDs control at Node 022
unsigned long pot2Value = analogRead(A1);
RF24NetworkHeader header3(node022); // (Address where the data is going)
bool ok2 = network.write(header3, &pot2Value, sizeof(pot2Value)); // Send the data
}*/
transmetteur 2 :
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#define button 2
#define led 3
RF24 radio(7, 8); // nRF24L01 (CE,CSN)
RF24Network network(radio); // Include the radio in the network
const uint16_t this_node = 02; // Address of this node in Octal format ( 04,031, etc)
const uint16_t master00 = 00; // Address of the other node in Octal format
void setup() {
Serial.begin(115200);
SPI.begin();
radio.begin();
network.begin(90, this_node); //(channel, node address)
radio.setDataRate(RF24_2MBPS);
}
void loop() {
network.update();
//===== Receiving =====//
while ( network.available() ) {
RF24NetworkHeader header2;
unsigned long incomingData;
network.read(header2, &incomingData, sizeof(incomingData));
Serial.println(header2.from_node);
delay(1000);}// Read the incoming data
//Serial.println(incomingData); // PWM output to LED 01 (dimming)
//===== Sending =====//
// Servo control at Node 01
unsigned long potValue = analogRead(A0);
Serial.println(potValue);
RF24NetworkHeader header2(master00); // (Address where the data is going)
bool ok = network.write(header2, &potValue, sizeof(potValue));delay(100);} // Send the data
; // Send the data
}*/
j'ai vu dans un exemple trouver sur le net une "commande" que souhaiterai utiliser mais j'avoue ne pas comprendre comment, voici cette ligne qui m'intrigue:
if (header.from_node == 0) { // If data comes from Node 02
dans l'exemple que j'exploite, cette commande est utiliser pour différencier les données arrivant de tel ou tel carte.
ce que je ne comprend pas c'est que "==0" correspond a l'adresse du "node 02" et l'autre ligne c'est
if (header.from_node == 10) { // If data comes from Node 012
quel est le rapport entre ces 2 valeurs et comment les définir, comment savoir quelle valeur correspond a
l'adresse du node.
quelque chose m’échappe mais quoi......
y'a t il une conversion a faire j'avoue ne pas y arriver.
par contre pour recevoir toutes les donnes arrivant des autres nodes pas de soucis je reçois tout, mais j 'aimerai les différencié voila pourquoi je m'en remets a vous.
bien cordialement