Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to integrate modules and smart meters with LoRa node-to-gateway communication

By Ayush Jain August 30, 2023

LoRa (long-range) technology ensures reliable long-range communication between a node and gateway, providing long-term, low-power use for devices This article provides an explanation of LoRa node-to-gateway communication while introducing a node equipped with two buttons to control the flags. These buttons enable users to turn on or off specific actions associated with each button and update the status on the gateway.

From home automation to industrial monitoring, this enhanced LoRa communication setup presents several possibilities for Internet-of-things (IoT) deployments.

This tutorial will cover the hardware setup, protocol selection, and gateway configuration, facilitating real-time data transmission and visualization.

A block diagram of LoRa node-to-gateway communication.

Abstract
Here’s what we’ll cover…

1. How to upload LoRa code for the LoRa E5 Mini-Board
2. Circuit diagram to connect a ST-Link and the buttons to the LoRa E5 Mini-Board
3. How to set-up an end node in the gateway
4. The program flow or algorithm with an explanation

Requirements

1. Make sure the LoRa gateway is already installed as shown in this article
2. STM32Cube IDE must be installed on your PC
3. The LoRa E5 Mini-Board by Seed Studio
4. The original ST-Link V2 programmer
5. A tactile switch and some basic soldering knowledge

Compiling the code

1. Download the code and extract it

Download the code and extract it from the folder.

2. Open the folder and double-click on “.project”

Open the project file in the STM32Cube IDE.

3. The project will be listed in the ‘Project Explorer’ tab on the left of the STM32CUBE IDE. Select the project and click on the hammer Icon on the top bar to compile the code.

Compiling the code in the STM32CUBE IDE.

4. After compiling the code, there should be zero errors as shown in image below. If there’s an error message, go through the steps again to ensure success.

Successful compilation with zero errors.

Uploading the code

1. Locating a genuine ST-Link V2 is necessary for the proper flashing of the LoRa code, as clone ST-Link variants are often not compatible. This means it’s essential to recognize the original ST-Link. One reliable method for identification involves examining the hardware components.    

Upon close analysis, a genuine ST-Link V2 has an STM chip, indicating authenticity. The clones are typically imported from China and look slightly different. 

This project requires a smooth “flashing process,” which occurs reliably with a genuine ST-Link with the STM chip (see image below). Knowing the difference will ensure compatibility and proper programming.

An original ST-Link V2.

2. Connect five wires to the LoRa E5 Mini Board as indicated in the below image, including 3V3, SWDIO, SWCLK, RST, and GND.

The ST-Link connection between the ST-Link V2 and the LoRa-E5.

3. Go back to the STM32 Cube IDE and click on the ‘Play; button as shown below to upload the code.

Uploading the code with the ‘Play’ button in the STM32 Cube IDE.

4. You should receive the message, “Download verified successfully.”

The “Download verified successfully“ message you must receive before moving forward.

Connecting the buttons
Connect the two tactile switches as shown in this circuit diagram:

The circuit diagram for the tactile switches.

The connection between the tactile button and LoRa-5E.

Adding a device to the gateway

1. If there is no device profile, add one. If you already have one, this same profile can be used for multiple nodes.

2. To add a profile, open ChirpStack and go to the ‘Device profiles.’

The ‘Device profiles’ on the Chirpstack dashboard.

3. Click on ‘Add device profile.’

The ‘Add device profile’ button.

4. Fill out the general information, and click ‘Submit.’

LoRa’s general profile information to fill out.

5. Turn off the OTAA because the device will run in ABP mode. Fill out the RX3 data rate details and frequency.

The join (OTAA/ABP) in LoRa’s general profile window… select ABP.

6. Turn on the Class-C mode as shown below.

Enable the Class C in LoRa’s general profile.

7.  Add ‘Applications’ next, which contain all of the devices.

LoRa’s ‘Application’ window.

8. Click on ‘Add applications.’

Click LoRa’s ‘Add application.’

9. Fill the details of Application as given below in image.

Fill in the ‘Application’ form.

10. Click on the application that was just created and then click on the ‘Add device’ button. This process must be done anytime a new device is added.

Click on ‘Add device.’

11. Start to fill in the details as shown below. You’ll need to find the Device EUI, which is what we’ll cover in the next step.

Device window with the missing Device EUI information.

Finding EUI and KEYs

1. To find the Device EUI and the Keys, connect the device to a PC via USB cable.

USB connection between the device and a PC.

2. Open any Serial Terminal (we’re using Arduino), and select the device port. Open the Serial Terminal with a baud rate of 115200. Press the ‘Reset’ button to see the Keys.

Arduino’s Serial Terminal window… used to find the Keys.

The EUI and Keys information.

3. Copy the Device EUI from the Serial Terminal and paste it in ChirpStack Add the device section as shown in the image below.

The Device EUI data.

4. Go to the ‘Activation’ section and fill out device’s address, AppSkey, and Network S key, which you can get from the Serial Terminal.

The ‘Activation’ of the device.

Receiving data

1. To receive data, go to the event section where there is incoming data every 10 seconds.

The events of the device incoming every 10 seconds.

2. The data is in a hexadecimal format. It sends the battery level, as well as the Button1 and Button2 status, in hexadecimal.

The hexadecimal data format.

3. When Button1 is pressed, the Button1 flag will be HIGH in the data that follows (just click it once with your mouse without holding it down).

This is LoRa-5 connected with tactical buttons when the Button1 is clicked.

When Button1 is pressed, the flag will be HIGH.

4. When Button2 is pressed the Button2 flag will be HIGH in the data that follows.

This is LoRa-5 connected with tactical buttons when Button2 is clicked.

When Button2 is pressed, the flag will be HIGH.

5. When both buttons are pressed, the flag will be zero.

When both buttons are clicked, the flag will be zero.

Code algorithm

The algorithm.

Code explanation

1. The LoRa-based STM32 code is slightly different from typical codes. The main.c file starts the process to run lora_app.c as main file. So, open the lora_app.c that contains the code.

The lora_app.c as main file.

2. There is a lot happening in the code, but let’s review what’s relevant to this tutorial. The condition below begin a timer, which calls the OnTxTimerEvent function that sends data to the gateway. The default time is 10 seconds, which can be changed by initializing the TxPeriodicity in milliseconds. The below image removes the APP_TX_DUTYCYCLE and places the time delay required in milliseconds.

Explains the OnTxTimerEvent function to send data on the LoRa gateway.

This function handles all of the interruption that occurs from the interrupt pins. There is a 100-millisecond delay for debouncing purposes.

The SendTxData function containing a buffer to send data to the LoRa.

Integrating smart meters
Smart meters with pulse sensors can be seamlessly integrated into the above code. The pulse sensors generate pulses whenever a meter reading increases, acting like the button interrupts in this tutorial. By configuring a microcontroller (MCU) to recognize these pulses as interrupts, a user can effectively track meter readings in real-time.

Whenever a pulse is received by the interrupt pin, the MCU will increment the meter reading and store it as a variable. The code can then be programmed to send these readings to the gateway at regular intervals, such as every 10 seconds. The transmission frequency can be adjusted to suit specific application requirements.

This integration enhances the functionality of smart meters, enabling accurate and automated tracking of energy consumption. With real-time readings, utilities can efficiently monitor usage, identify patterns, and optimize energy distribution. The versatile code can be adjusted for different pulse sensor setups, so it can work with many smart meter designs.

 

 

You may also like:


  • Understanding LoRa architecture: nodes, gateways, and servers

  • How LoRa enables long-range communication

  • How communication works between two LoRa end-node devices

  • What is Chirpstack?

  • What is LoRa and LoRaWAN?

  • What are LoRa gateways and what types are available?

  • How does LoRa modulation enable long-range communication?

Filed Under: Tutorials
Tagged With: communication, gateway, lora, lorae5, meters, node, smartmeters
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Power Efficiency
Discover proven strategies for power conversion, wide bandgap devices, and motor control — balancing performance, cost, and sustainability across industrial, automotive, and IoT systems.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions.

  • PCB layout impact on RF path impedance
  • rechargeable battery and simple alkaline battery in one single product
  • Persistent Shoot-Through vin=vout in Synchronous Buck Converter – Physical Phenomenon Issue
  • Methods for Calculating SNR and SFDR in a CUI for Use in Machine Learning
  • Ensuring Reliable Backups in Azure

RSS Electro-Tech-Online.com Discussions

  • WTB: "The Theory Of Servicing AM, FM, And FM Receivers" by Clarence R. Green and Robert M. Bourque
  • Converting 1vac to 24vac
  • AC Input Relay Device Required
  • MLT-8530 Buzzer on ESP32: Why Is the Sound Output Lower Than Expected?
  • Scope Clock CRT Z-Axis - Grid bias positive?

Featured – Real Time Hardware Filter Design

  • Practical implementation of bandpass and band reject filters
  • Practical application of hardware filters with real-life examples
  • A filter design example
  • Types of filter responses
  • What are the two types of hardware filters?
  • What are hardware filters and their types?

Recent Articles

  • GigaDevices introduces 32-bit MCUs with integrated DSP and FPU support
  • Grinn introduces 8-core SBC supporting AI-ready embedded development
  • EPC’s 100 kHz BLDC inverter supports high-efficiency motion control
  • Melexis announces 5 W smart driver to supports sensorless FOC operation
  • STMicroelectronics’ motion sensor simplifies industrial IoT system design

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Sensor Series
      • 3D Printing
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
  • Guest Post Guidelines
  • Advertise
  • Subscribe