I ended up using a simple test with paho. One published a message to another that acts if the message is hello world. I did this when communicating with mosquitos server and it worked ok, a bit slow but it was communicating.
Now, I opened up my firewall on my server to communicate between the pi and the server both on port 1883. but I keep getting a connection refused error on my server.
Script 1
MQTT Publish Demo
Publish two messages, to two different topics
import paho.mqtt.publish as publish
publish.single("CoreElectronics/test", "Hello", hostname="linode ip")
publish.single("CoreElectronics/topic", "World!", hostname="linode ip")
print("Done")
Script 2
# MQTT Client demo
# Continuously monitor two different MQTT topics for data,
# check if the received data matches two predefined 'commands'
import paho.mqtt.client as mqtt
# The callback for when the client receives a CONNACK response from the server.
def on_connect(client, userdata, flags, rc):
print("Connected with result code "+str(rc))
# Subscribing in on_connect() - if we lose the connection and
# reconnect then subscriptions will be renewed.
client.subscribe("CoreElectronics/test")
client.subscribe("CoreElectronics/topic")
# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
print(msg.topic+" "+str(msg.payload))
if msg.payload == "Hello":
print("Received message #1, do something")
# Do something
if msg.payload == "World!":
print("Received message #2, do something else")
# Do something else
# Create an MQTT client and attach our routines to it.
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("linode server", 1883, 60)
# Process network traffic and dispatch callbacks. This will also handle
# reconnecting. Check the documentation at
#
https://github.com/eclipse/paho.mqtt.python
# for information on how to use other loop*() functions
client.loop_forever()