Sending sensor data over RFM95

Started by sharkhat, February 09, 2017, 04:40:40 PM

sharkhat

I was wondering if there are any example codes that use the moteino RFM95 LoRa and send sensor data (like temperature/humidity/pressure ala..MBP280)to the server?  I have the simple client and server code running, but I am using strings and converting those to char arrays to send data.  I am looking for more elegant examples.

I am also looking for code examples that can pass a message down the line of several moteinos all the way to a moteino that is connected to a gateway.

Thanks

luisgcu

#1
Quote from: sharkhat on February 09, 2017, 04:40:40 PM
I was wondering if there are any example codes that use the moteino RFM95 LoRa and send sensor data (like temperature/humidity/pressure ala..MBP280)to the server?  I have the simple client and server code running, but I am using strings and converting those to char arrays to send data.  I am looking for more elegant examples.

I am also looking for code examples that can pass a message down the line of several moteinos all the way to a moteino that is connected to a gateway.

Thanks

hello I had some hard times learning how to do that.
I think  don't have  very clear example.. but I can share you some pieces of codes  that may be good start point for you.

//sender
#include <RHReliableDatagram.h>
#include <RH_RF95.h>

struct EnvioData {           create a data structure with the data that you want to send 
   int            Mot_curr;     motor load (amps) (emon lib)
   int            ACL_volt;      Line voltage
 double      somedata;  
};
  
  EnvioData   Paiload_enviar;     see the bellow declaration you can't miss that

uint8_t*enviar_paiload=0;       i think this is no needed, i just did it initialize the structure 

setup{
initialize the I/o, the radio etc.
enviar_paiload =(uint8_t*)(&Paiload_enviar);      this is important don't miss that part..
}

void loop (){
code to check if I/O changed  if there is any change  then assign the  variable  that holds your I/O to the  variable in the structure that we created before
 an example how to assig a value or IO to the structure variables
Paiload_enviar.Mot_curr   = analogRead(A0);  
Paiload_enviar. ACL_volt  =  any int value;
Paiload_enviar.somedata = 123456789;
 the next is to send data when you want 
if (manager.sendtoWait(enviar_paiload, sizeof(Paiload_enviar), SERVER_ADDRESS))      
    
          {
              
           Serial.println("Mensaje sent OK :: Delay:= ");
         
            Blink(Data_Act, 60, 3); //blink LED 3 times,
          }
                else
                {    
                 Serial.println("Mensaje has  failed");
                 Blink(Data_Act, 30, 2); //blink LED 3 times, 40ms between blinks
               
                }

//end send data
}


//receiver side

#include <RHReliableDatagram.h>
#include <RH_RF95.h>
RH_RF95 driver;                           //
RHReliableDatagram manager(driver, MY_ADDRESS);

// create a similar structure to hold the data  to  receive
struct RecivoData  {
   int            Mot_curr;     // motor load (amps) (emon lib)
   int            ACL_volt;     // Line voltage
 double      somedata;    };
  
 RecivoData  Paiload_recibir;              //    do not forget this part
Setup {
Recibir_paiload            =(uint8_t*)(&Paiload_recibir);    // do not forget this part
}


void loop{

if (manager.available())
    {    
      uint8_t len = sizeof(RecivoData);   //l
      uint8_t from;
         if (manager.recvfromAck(Recibir_paiload, &len, &from))  
            {
             Serial.println("recibiendo...");
             
            
              Serial.print(Paiload_recibir.Mot_curr);
              Serial.print(", ");
             
              Serial.print(Paiload_recibir.ACL_volt);
              Serial.print(", ");
              Serial.println(Paiload_recibir.somedata);
            
                
              } 
            }

}


//
..Knowing other is wisdom,
knowing yourself is Enlightenment..

xtalintegrated

#2
hello.. I use the conversion of string to char array to send values..
I use this..
String data = "(id:'" + ssenText + "',m:'" + messageText + "')"; //send message
        int str_length=data.length()+1; //additional 1 for the null
        char char_array[str_length];
        data.toCharArray(char_array,str_length); //converted to char_array
        rf95.send((uint8_t *)char_array, sizeof(char_array));
        rf95.waitPacketSent();

where ssenText, messageText are Strings.. if you have float, integer, its better to convert it via (String) integerVar .. thank you