Sorting for Correct Message
hello,
i making rf24network tmrh20's library. have 3 grandchild nodes sending values 1 child node stores values, takes own reading, , sends of values master node. when start , @ serial monitor on master node, picks values child node, grandchildren inconsistently picked up. main suspect lack of proper sorting child node. here code:
it might not efficient all-around code, original got job done 1 grandchild node, , didn't have problem modifying 2 grandchildren (maybe luck?). adding third one, starting become inconsistent.
a couple solutions think might work don't know how use them properly:
- name id's , have variable reads id , figures out message there
-have each message send values @ end of string child node can sort from
- have each 1 different header type , peek header type , sort there
i think header work best, documentation on little thin, don't know if that's can used for. 1 other thing nodes reasonable distance away each other , readings time-sensitive, not want child node send grandchildren. let me know think. in advance.
i making rf24network tmrh20's library. have 3 grandchild nodes sending values 1 child node stores values, takes own reading, , sends of values master node. when start , @ serial monitor on master node, picks values child node, grandchildren inconsistently picked up. main suspect lack of proper sorting child node. here code:
code: [select]
#include <spi.h>
#include "rf24.h"
#include "rf24network.h"
#include <onewire.h>
#include <dallastemperature.h>
#define one_wire_bus 2
onewire onewire(one_wire_bus);
dallastemperature sensors(&onewire);
rf24 radio (7, 8);
rf24network network(radio);
const uint16_t node01 = 01;
const uint16_t node00 = 00;
const uint16_t node011 = 011;
const uint16_t node021 = 021;
const uint16_t node031 = 031;
const unsigned long interval = 2000;
unsigned long last_got;
int m11;
int t11;
int id011;
int m21;
int t21;
int id021;
int m31;
int t31;
int id031;
struct payload_01 {
float moisture01;
float temp01;
int m011;
int t011;
int m021;
int t021;
int m031;
int t031;
int id01;
};
struct payload_011 {
float moisture011;
float temp011;
int id011;
};
struct payload_021 {
float moisture021;
float temp021;
int id021;
};
struct payload_031 {
float moisture031;
float temp031;
int id031;
};
void setup()
{
serial.begin(9600);
delay(1000);
radio.begin();
spi.begin();
sensors.begin();
network.begin(01);
delay(1000);
}
void loop()
{
network.update();
unsigned long = millis();
rf24networkheader header011;
network.peek(header011);
payload_011 payload011;
network.read(header011, &payload011, sizeof(payload011));
id011 = payload011.id011;
if (id011 == 11)
{ m11 = payload011.moisture011;
t11 = payload011.temp011;
payload011.id011 = 0;
}
rf24networkheader header021;
network.peek(header021);
payload_021 payload021;
network.read(header021, &payload021, sizeof(payload021));
id021 = payload021.id021;
if (id021 == 21)
{ m21 = payload021.moisture021;
t21 = payload021.temp021;
payload021.id021 = 0;
}
rf24networkheader header031;
network.peek(header031);
payload_031 payload031;
network.read(header031, &payload031, sizeof(payload031));
id031 = payload031.id031;
if (id031 == 31)
{ m31 = payload031.moisture031;
t31 = payload031.temp031;
payload031.id031 = 0;
}
delay(100);
payload_01 payload01;
if (now - last_got >= interval)
{ sensors.requesttemperatures();
payload01.moisture01 = analogread(a0);
payload01.temp01 = sensors.gettempfbyindex(0);
payload01.m011 = m11;
payload01.t011 = t11;
payload01.m021 = m21;
payload01.t021 = t21;
payload01.m031 = m31;
payload01.t031 = t31;
payload01.id01 = 1;
rf24networkheader header01(node00);
network.write(header01, &payload01, sizeof(payload01));
payload01.m011 = 0;
payload01.t011 = 0;
m11 = 0;
t11 = 0;
m21 = 0;
t21 = 0;
m31 = 0;
t31 = 0;
last_got = now;
}
}
it might not efficient all-around code, original got job done 1 grandchild node, , didn't have problem modifying 2 grandchildren (maybe luck?). adding third one, starting become inconsistent.
a couple solutions think might work don't know how use them properly:
- name id's , have variable reads id , figures out message there
-have each message send values @ end of string child node can sort from
- have each 1 different header type , peek header type , sort there
i think header work best, documentation on little thin, don't know if that's can used for. 1 other thing nodes reasonable distance away each other , readings time-sensitive, not want child node send grandchildren. let me know think. in advance.
three instances of struct containing 2 floats , 1 int makes sense. 3 identical structs different member names, , 1 instance of each not.
meaningless names, m011, not tell anything.
you need learn arrays.
meaningless names, m011, not tell anything.
you need learn arrays.
Arduino Forum > Using Arduino > Programming Questions > Sorting for Correct Message
arduino
Comments
Post a Comment