Sufian Kaki Aslam
Published © GPL3+

LoRa-E5 <> The Things Network <> MQTT

Monitor and Control your LoRa-E5 powered IoT devices using any Arduino / ESP board using the Things Network!

IntermediateProtip3 hours5,594
LoRa-E5 <> The Things Network <> MQTT

Things used in this project

Hardware components

Seeed Studio Grove LoRa E5
You may use any E5 based module, either the development kit or LoRs E5 Mini will also work as long as you interface the UART of the microcontroller to the E5 module.
×1
ESP32
Espressif ESP32
I used an ESP32 Dev Module, but I have tested it with M5Core2 AWS as well and it works just fine. You could try it with Arduino Uno / Nano etc as well since all you will need is only a UART enabled board programmable using Arduino IDE
×1
RAK2245 RPi HAT Edition WisLink LPWAN Concentrator
RAKwireless RAK2245 RPi HAT Edition WisLink LPWAN Concentrator
I used this to setup my LoRaWAN gateway. If you have any other LoRaWAN gateway setup already, you won't need this!
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
The RAK2245 is just an R Pi hat so I had to use it with an R Pi. RAK2245 suggests using R Pi 3, but I tried it with R Pi 4 and R Pi 2 and it worked fine on both. So I have settled with R Pi 2 just so that I can use my idle hardware :D
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Things Stack
The Things Industries The Things Stack
Cool Term

Story

Read more

Schematics

ESP32+LoRa-E5

You basically any microcontroller that supports UART along with a LoRa-E5 module and the connection given in this image holds good

Code

Python program

Python
This program allows you to send and receive messages from the LoRa device. Download the paho-mqtt library by executing pip install paho-mqtt
import paho.mqtt.client as mqtt
import json
import base64
from time import sleep

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("v3/test-app-868@ttn/devices/eui-70b3d57ed004d84c/up")

def on_message(client, userdata, msg):
    messg = json.loads(msg.payload)
    print('Received: ' + str(messg['uplink_message']['decoded_payload']))

client = mqtt.Client()
client.username_pw_set("test-app-868@ttn", "NNSXS.IG5UN5CKVNA7IWCQBLS5XXCEGRKNKBEDIJT...")
client.on_connect = on_connect
client.on_message = on_message

client.connect("eu1.cloud.thethings.network", 1883, 60)
client.loop_start()

try:
    while True:
        topic = "v3/test-app-868@ttn/devices/eui-70b3d57ed004d84c/down/push"
        js = {'name': 'Sufian', 'id': 'sufiankaki'}
        str_js = json.dumps(js)

        x = {}
        x["f_port"] = 1
        x["frm_payload"] = base64.b64encode(str.encode(str_js)).decode()
        x["priority"] = "NORMAL"
        
        message = {}
        message["downlinks"] = []
        message["downlinks"].append(x)

        client.publish(topic, json.dumps(message))
        print('Published: ' + json.dumps(message))
        sleep(5)
except KeyboardInterrupt:
    client.loop_stop()
    print("Stopped the client!")

Firmware for ESP32 Dev Module

Credits

Sufian Kaki Aslam

Sufian Kaki Aslam

5 projects • 8 followers
Aspiring Technologist!
Thanks to Seeed Studio.

Comments