Hello, I have a Wisgate Edge Lite 2 LoRa gateway (RAK7268CV2) and I can send messages to the gateway from my Arduino. But I want to know how to use python as shown in the link here Use the MQTT Broker Like a Pro + Examples | RAKwireless Documentation Center
I want to access my sensor data from my python program but I am having difficulties.
On my PC I am connected to the hotspo of the LoRa Gateway (its IP address is 192.168.230.1), on the Gateway I can see my application ID is 1, I can see my device EUI. When I go to the configuration page on the Gateway, on the Built-In network server I can see that the Gateway Backend MQTT Broker Address is 127.0.0.1 and the port is 1883.
But when I put these details into the python example here Use the MQTT Broker Like a Pro + Examples | RAKwireless Documentation Center
I get an error saying ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it.
My code is:
import json
import base64
import paho.mqtt.client as mqtt
from datetime import datetime
mqtt_ip = '127.0.0.1'
mqtt_port = 1883
mqtt_rx_topic = 'application/1/device/a8610a3439307f10/rx'
# Type the IP of your server
mqtt_ip = '127.0.0.1'
mqtt_port = 1883
# Type your username and password. If the private MQTT server does not require username and password, commend the lines
# mqtt_username = 'username'
# mqtt_password = 'password'
# Replace the "id" with the id of your application and "eui" with your device eui
#mqtt_rx_topic = 'application/c1f1563eaa48956c962b60324c03f68a/device/a8610a3439307f10/rx'
mqtt_rx_topic = 'application/1/device/a8610a3439307f10/rx'
# After subscribing to the node's data, send the "Hello RAKwireless" string to the node
def on_print_rak_node_info(payload):
json_str = payload.decode()
try:
json_rx = json.loads(json_str)
on_print_node_rx_info(json_rx)
dev_eui = json_rx['devEUI']
app_id = json_rx['applicationID']
# Industrial gateway default tx topic
tx_topic = 'application/%s/device/%s/tx' % (app_id, dev_eui)
str_hello = "Hello RAKwireless"
tx_msg = '{"confirmed":true,"fPort":10,"data":"%s" }' % str(base64.b64encode(str_hello.encode("utf-8")).encode("utf-8"))
mqttc.publish(tx_topic, tx_msg, qos=0, retain=False)
print('Send \'Hello RAKwireless\' to node %s' % dev_eui)
except Exception as e:
raise e
finally:
pass
mqttc = mqtt.Client()
mqttc.on_message = on_message
# Connect to mqtt broker, the heartbeat time is 60s
mqttc.connect(mqtt_ip, mqtt_port, 60)
mqttc.subscribe(mqtt_rx_topic, 0)
mqttc.loop_forever()