Core Electronics Forum

Lora Communication

Hi dears, I’m trying to make communication between 2 Nodes and a Gateway using arduino, So I have 3 (sx1278,433Mhz) Lora module and 3 Arduino uno. cause I’m not in a coverage area for a existent gateways, So I need to set up my own gateway. I suppose using Class A. the question is:
Can I consider 2 of them as Nodes and last one as Gateway? if yes; so does anyone have same example code or link for that?

1 Like

Hey hosein,

Doing some reading, I’ve found that gateways are generally used to bridge LoRa with the internet through WiFi or similar, is that what you’re trying to achieve? (FYI a bit more info on your project would be awesome to get some context)

Generally gateways use an ESP32 or Raspberry Pi combined with a LoRa modem.

Keen to find out more about your project!
-James

1 Like

Hi Hosein,

Which LoRa module did you have? That will be one of the main factors here, as long as it’s a transceiver you should be fine for your setup.

The libraries used could also be dependent on the breakouts you are using.

These ones here that Core stock communicate via UART which uses the inbuilt serial library: LoRa Radio Module - 433MHz (Pair) Australia

Liam.

1 Like

Hi @Liam120347 . thanks for your answer. I using this (https://cutt.ly/zbDX8K4).I would like to use (Lora.h) library and I’m searching for some example algorithm to be used in coding gateway and nodes cause I want to implement class A and B in my device. I’m even coding now to implementation but I want to have some example codes nearby myself to get help from them.

1 Like

Hey Hosien,

Have you had a look over on the GitHub repo for the library? They have some examples on there that can get the ball rolling: GitHub - sandeepmistry/arduino-LoRa: An Arduino library for sending and receiving data using LoRa radios.
I’m keen to see how your project goes!

Liam.

3 Likes

Hi dear @Liam120347 . yeah I exactly use that library and I read whole the library but there are some codes which I don’t know how to use it. see this picture from Library:


for example what is the ARDUINO_SAMD_MKRWAN1300?? i know that is just kind of Arduino board but Can I use its functions in Arduino Uno?

The two function declarations that you have marked are the declarations for the functions to be executed on the Receive and TXDone events.

The third line you have marked is telling the compiler to only include that code if the device it is compiling for is not ARDUINO_SAMD_MKRWAN1300. There is no difference in functionality between the devices, just a difference in the way that the functionality is implemented, so the compiler has to know which way to do it. The end result is the same for all devices.

1 Like

Sorry my friend. I could not understand what you mean. do you mean that if I have Arduino Uno can use that function or not?

If the library is compatible with the UNO then presumably you can use it with the UNO. That it also supports other Arduino variations doesn’t matter.

You use that part of the library by first registering your callback function:

  // register the receive callback
  LoRa.onReceive(onReceive);

and then providing the function to handle the callback:

void onReceive(int packetSize) {
  // Read the packet and process it
  ...
}

There should be no need to be concerned with the internal workings of the library.

2 Likes

thanks a lot @Jeff105671

I have another question:
Is it necessary to use LoRa.onReceive(onReceive) and LoRa.onTxDone(onTxDone) function before receiving?? what do these functions actually do? I know just onReceive function Diagnose the received packet at first but the exact question is what is different between using just Lora.Receive(); and using LoRa.onReceive(onReceive);LoRa.onTxDone(onTxDone);LoRa_rxMode();?? see this pictures:

just Receive:
11

another one:
22

what exactly this onReceive and ontxdone do?
hope you understand what I mean.

Questions about the detail of using the library are best asked at the official site for that library.

onReceive is a callback (hence the need to register it) that will be called when the receive occurs. The code in that function then processes the received data. Similarly, onTxDone is a callback that will be called when a transmission completes, so you can do whatever needs to be done at that time.

Whether you use one or both depends on what you are trying to do and how you have constructed your application. For instance, if communication must be asynchronous then you will use them, if it isn’t, then you don’t need them (but you could still use them).

1 Like