Need help for Lora Transmission point to point

Hi everybody,

I need help for my school project to transmit in Lora point to point.

I found code examples on the provider’s site of my Lora devices.

In the program, they send the text “hello world” but I want to send a variable and my teacher and I don’t understand how to do… :confused:

I post here the link of the website of my lora devices : http://wiki.seeedstudio.com/Grove_LoRa_Radio/
and here the two progralms for the clien (transmitter) and server (receiver)

CLIENT :

// rf95_client.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing client
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95 if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf95_server
// Tested with Anarduino MiniWirelessLoRa

#include <SoftwareSerial.h>
#include <RH_RF95.h>


// Singleton instance of the radio driver
SoftwareSerial ss(5, 6);
RH_RF95 rf95(ss);


void setup() 
{
    Serial.begin(115200);
    Serial.println("RF95 client test.");

    if (!rf95.init())
    {
        Serial.println("init failed");
        while(1);
    }

    // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

    // The default transmitter power is 13dBm, using PA_BOOST.
    // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
    // you can set transmitter powers from 5 to 23 dBm:
    //rf95.setTxPower(13, false);
    
    rf95.setFrequency(434.0);
}

void loop()
{
    Serial.println("Sending to rf95_server");
    // Send a message to rf95_server
    uint8_t data[] = "Hello World!";
    rf95.send(data, sizeof(data));
   
    rf95.waitPacketSent();
    
    // Now wait for a reply
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if(rf95.waitAvailableTimeout(3000))
    {
        // Should be a reply message for us now   
        if(rf95.recv(buf, &len))
        {
            Serial.print("got reply: ");
            Serial.println((char*)buf);
        }
        else
        {
            Serial.println("recv failed");
        }
    }
    else
    {
        Serial.println("No reply, is rf95_server running?");
    }
    
    delay(1000);
}

SERVER :

// rf95_server.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple messageing server
// with the RH_RF95 class. RH_RF95 class does not provide for addressing or
// reliability, so you should only use RH_RF95  if you do not need the higher
// level messaging abilities.
// It is designed to work with the other example rf95_client
// Tested with Anarduino MiniWirelessLoRa



#include <SoftwareSerial.h>
#include <RH_RF95.h>


// Singleton instance of the radio driver
SoftwareSerial ss(5, 6);
RH_RF95 rf95(ss);

int led = 13;


void setup() 
{
    Serial.begin(115200);
    Serial.println("RF95 server test.");
    
    pinMode(led, OUTPUT); 
    
    if(!rf95.init())
    {
        Serial.println("init failed");
        while(1);
    } 
    // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

    // The default transmitter power is 13dBm, using PA_BOOST.
    // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
    // you can set transmitter powers from 5 to 23 dBm:
    //rf95.setTxPower(13, false);
    
    rf95.setFrequency(434.0);
}

void loop()
{
  if(rf95.available())
  {
    // Should be a message for us now   
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if(rf95.recv(buf, &len))
    {
        digitalWrite(led, HIGH);
        
        Serial.print("got request: ");
        Serial.println((char*)buf);
        
        // Send a reply
        uint8_t data[] = "And hello back to you";
        rf95.send(data, sizeof(data));
        rf95.waitPacketSent();
        Serial.println("Sent a reply");
        
        digitalWrite(led, LOW);
    }
    else
    {
        Serial.println("recv failed");
    }
  }
}

If you can help me it will be really helpful for me !! :smiley:

Ask if something you don’t understand or if I don’t explain well what I want…

Thanks for help :wink:

but I want to send a variable and my teacher and I don't understand how to do

Plain and simple. You can't. A variable is a memory location. You can't cut out that memory location, and physically send it anywhere.

You could send the VALUE stored in the variable.

Converting any type variable to a string is possible. If the variable is an int, itoa() is the proper function. If the variable is a float, dtostrf() is the proper function. If the variable is a char, or array of chars, no conversion is needed.

You know how to send a string, so you should be good to go.

Yes that what I want, I want to send a value store in a variable but I don't understand how to do that...

Let me see if I can help, ymmv, T's and C's apply :wink:

As PaulS says, itoa() converts an integer to a string.

So first, run this:

void setup()
{
  Serial.begin(9600);
  char myBuffer[12];
  int myInt = 5432;
  Serial.println(itoa(myInt, myBuffer, 10));

} //setup

void loop()
{
} //loop

It gives this, which is the "string version" of the integer:

5432

I set up a string 12 characters in length, then makes an int of value 5432.

Then itoa takes that int ie myInt, of base 10, and sticks it into the prepared empty string ie myBuffer. (edit: And I think, that myBuffer is the return value of itoa, so it's what the Serial.print() "sees" as its thing to print.)

So I further think, in your case this:

uint8_t data[] = "Hello World!";
    rf95.send(data, sizeof(data));

... becomes:

uint8_t data[12]; // or whatever to allow longest number
int myVar=5432;
    rf95.send(itoa(myVar, data, 10), sizeof(data));

I reckon that essentially replaces "data" which was Hello world in your rf95.send() , with a new data which is the integer myVar converted to a string, still called data.

That's my theory, anyway...

I wondered how to be sure that the 5432 printed in previous post was the string and not the original integer.

This prints out the individual digits, which proves that.

void setup()
{
  Serial.begin(9600);
  char myBuffer[12];
  int myInt = 5432;
  Serial.println(itoa(myInt, myBuffer, 10));
  Serial.println(myBuffer[0]);
  Serial.println(myBuffer[1]);
  Serial.println(myBuffer[2]);
  Serial.println(myBuffer[3]);

} //setup

void loop()
{
} //loop
5432
5
4
3
2

Gweno:
Yes that what I want, I want to send a value store in a variable but I don’t understand how to do that…

Replace the “hello world” string that you send out by the string created from your value, and presto: you’re transmitting that value.

neiklot:
I wondered how to be sure that the 5432 printed in previous post was the string and not the original integer.

This prints out the individual digits, which proves that.

void setup()

{
  Serial.begin(9600);
  char myBuffer[12];
  int myInt = 5432;
  Serial.println(itoa(myInt, myBuffer, 10));
  Serial.println(myBuffer[0]);
  Serial.println(myBuffer[1]);
  Serial.println(myBuffer[2]);
  Serial.println(myBuffer[3]);

} //setup

Thank you ! I will test it very soon :wink:

void loop()
{
} //loop






5432
5
4
3
2

Ok what was that... you just randomly commented in the middle of quoting my whole post back :wink:

oh sorry... :smiley: I made a wrong manipulation ::slight_smile: