You can try this script & flow, it should if it is working correctly, give you the data in NR
To note, you have to:
- install paho mqtt client in python on yor RPI if you don't have it already (https://pypi.org/project/paho-mqtt/)
- edit the script and flow if your mqtt broker is running somewhere else, I'm assuming 127.0.0.1
- edilt the mqtt topics in the script and in NR if you want a different naming convention
- always stop the script (abort) correctly, use the command "abort" and send it to the topic as in the flow

[{"id":"65e3a7a6.456798","type":"inject","z":"a4d7c0e0.63723","name":"","topic":"","payload":"abort","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":490,"wires":[["f9adfe3f.f2a3f"]]},{"id":"5d1a1708.13c028","type":"mqtt in","z":"a4d7c0e0.63723","name":"","topic":"loramessage","qos":"2","datatype":"auto","broker":"75eba16c.094f9","x":240,"y":370,"wires":[["a314d60f.a3c5c8"]]},{"id":"f9adfe3f.f2a3f","type":"mqtt out","z":"a4d7c0e0.63723","name":"","topic":"cmnds","qos":"","retain":"","broker":"75eba16c.094f9","x":460,"y":490,"wires":[]},{"id":"a314d60f.a3c5c8","type":"debug","z":"a4d7c0e0.63723","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":370,"wires":[]},{"id":"4a84e79b.10bbf8","type":"comment","z":"a4d7c0e0.63723","name":"Terminate the script correctly","info":"","x":290,"y":450,"wires":[]},{"id":"75eba16c.094f9","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
import time
import paho.mqtt.client as mqtt
from time import sleep
from SX127x.LoRa import *
from SX127x.board_config import BOARD
BOARD.setup()
BOARD.reset()
class mylora(LoRa):
def __init__(self, verbose=False):
super(mylora, self).__init__(verbose)
self.set_mode(MODE.SLEEP)
self.set_dio_mapping([0] * 6)
def on_rx_done(self):
BOARD.led_on()
#print("\nReceived: ")
self.clear_irq_flags(RxDone=1)
payload = self.read_payload(nocheck=True)
data = payload
#data = bytearray( [0x37, 0xFF, 0x0, 0x0, 0x32, 0x39, 0x2E, 0x30, 0x30, 0x0, 0xD9, 0x10] )
tmp = float(str(data).split('\\x')[3])
send_mqtt_message('loramessage', str(tmp))
#print ("Receive: ")
mens=bytes(payload).decode("utf-8",'ignore')
mens=mens[2:-2] #to discard \x00\x00 and \x00 at the end
print(mens)
BOARD.led_off()
def start(self):
self.reset_ptr_rx()
self.set_mode(MODE.RXCONT)
while True:
sleep(.5)
rssi_value = self.get_rssi_value()
status = self.get_modem_status()
sys.stdout.flush()
def send_mqtt_message(topic, msg):
for i in range(5):
try:
result, mid = client.publish(topic, msg, 0)
#print ('result', result)
if result == 0:
break
except:
print ("retrying...")
def on_connect(client, obj, flags, rc):
client.subscribe("cmnds", 0)
def on_subscribe(client, userdata, mid, granted_qos):
print ('Subscribed:', userdata, mid, granted_qos)
print ('Lora script running...')
def on_message(mosq, obj, msg):
global abort
event = msg.payload.decode("utf-8")
print (event)
if event == 'abort':
abort = True
abort = False
client = mqtt.Mosquitto()
client.on_connect = on_connect
client.on_message = on_message
client.on_subscribe = on_subscribe
client.connect("127.0.0.1", 1883, 60)
client.loop_start()
lora = mylora(verbose=False)
lora.set_mode(MODE.STDBY)
lora.set_pa_config(pa_select=1)
assert(lora.get_agc_auto_on() == 1)
try:
print("START")
lora.start()
except KeyboardInterrupt:
sys.stdout.flush()
print("Exit")
abort = True
sys.stderr.write("KeyboardInterrupt\n")
finally:
sys.stdout.flush()
print("Exit")
abort = True
lora.set_mode(MODE.SLEEP)
BOARD.teardown()
while not abort:
time.sleep(1)
client.loop_stop()
client.disconnect()
del client
lora.set_mode(MODE.SLEEP)
BOARD.teardown()
exit(0)