Hello,
I just heard that we can send struct with arduino-lmic library
I actually can prepapre my variable but I cn not have it in byte. I guess I have pain to understand how to have byte when my sensos return int-
First here is how I declare my struct for sending
typedef struct {
byte value;
}Payload;
the arduino-lmic library has a function do_send(). I call my sensor functions and I get the sensor measure stored in int global variable variable. In fact, it’a a struct as well but with two elements and with active and inactive sensor.( Then I have to filter only the active sensor before sending)
struct mesure {
uint16_t id_capteur;
int valeur; // valeur mesurée (adapter le type)
int var_size; // valeur mesurée (adapter le type)
// autre chose de pertinent à mémoriser lors d'une mesure ?
};
const byte tailleHistorique = 11; // Ce chiffre doit correspondre aux nombres de capteurs. Voir capteur mesCapteur[] = {
mesure mesMesures[nbMaxCapteurs][tailleHistorique];
The problem I have it’s how can I send a struct with byte as the doc say
To send data back and forth over The Things Network you’ll need to use bytes
and
Technically, you can send 51 bytes
Here is how I do.
First, I declare globaly where I only store active values and where the index is the ID of the sensor (See below)
typedef struct {
byte value;
}Payload;
Then I in my do_send function
void do_send(osjob_t* j){
// Check if there is not a current TX/RX job running
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Some exemple of function
get_battery()
/*
result of get_battery is store in mesMesures[c_battery][capteur_battery_id].valeur
*/
get_baro();
/*
result of get_baro is store in
mesMesures[c_temperature][capteur_temperature_id].valeur
mesMesures[c_pression][capteur_presion_id].valeur
mesMesures[c_humidity][capteur_humidity_id].valeur
*/
get_luminosity();
/*
result of get_luminosity is store in
mesMesures[c_luminosity][capteur_luminosity_id].valeur
*/
// Now I create a variable type Payload where I only store **the active value**
// Ican have up to 11active sensors and some of them have 3 digit: 33 Degre, 969hKa, 395.
Payload p[nbCapteurActif];
for(int pp = 0; pp < nbMaxCapteurs; pp++)
{
if (mesCapteur[pp].actif)
{
p[mesCapteur[pp].idDuCapteur].value = mesMesures[pp][mesCapteur[pp].idDuCapteur].valeur;
}
}
// Seinding the value. I keep it comment for now
//LMIC_setTxData2(1, p, sizeof(p), 0);
}
All work fine!! Excepted that values are not exact.
For exemple this
Serial.println(F("Verify values to be sent"));
for(int qq=0; qq<nbCapteurActif; qq++)
{
Serial.println(p[qq].value );
}
27
201
53
20
0
43
0
but 201 should be 969
43 should be 429
And all toher should not be byte as 27 should be 32 37.
I still have pain to understand how I can format my data and make it ready to be sent in byte.
It will be really helpfully if you can help me to format Payload p according to
https://www.thethingsnetwork.org/docs/devices/bytes.html#how-to-send-big-numbers
How can I adapt and collect
Payload p[nbCapteurActif];
for(int pp = 0; pp < nbMaxCapteurs; pp++)
{
if (mesCapteur[pp].actif)
{
p[mesCapteur[pp].idDuCapteur].value = mesMesures[pp][mesCapteur[pp].idDuCapteur].valeur;
}
}
// Sending the value. I keep it comment for now
//LMIC_setTxData2(1, p, sizeof(p), 0);
Keeping in mind that
mesCapteur[pp].idDuCapteur
is the ID of the sensor and will let me identify the sensor value in the ‘payload format’
I hope I cleary explain my isue and you can give me tips and hints