Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
I want to connect raspberry pi to thingworx via mqtt. I am using Mosquitto broker and Paho mqtt as a client on raspberry pi to send data to thingworx. But i am not able to see the message on thingworx can anyone help. The steps I followed are given below.
Raspberry Pi
Steps for Thingworx
Thanks in advance.
Hi,
Did you manage to solve this issue?
I did this a while ago have a look here and let me know if this helps.
The full link to the thread is at the bottom.
Hi,
I have managed to get this working using MQTT, After reading quite a bit of documentation and the sites that you provided I'm 99% happy with the results.
This is what I did to get it working.
# MQTT Publish Demo
# Publish two messages, to two different topics
import paho.mqtt.publish as publish
#client.connect("192.168.2.207", 1883, 60)
#publish.single("CoreElectronics/test", "Hello", hostname="test.mosquitto.org")
publish.single("Thingworx/Name", "Hello", hostname="192.168.2.207")
#publish.single("CoreElectronics/topic", "World!", hostname="test.mosquitto.org")
publish.single("Thingworx/Topic", "World!", hostname="192.168.2.207")
print("Done")
# 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
from sense_hat import SenseHat
sense = SenseHat()
# 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("Thingworx/Name")
cleint.subscribe("Thingworx/Topic")
client.subscribe("Thingworx/Color")
#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))
#sense.show_message(msg.payload) # placing this here will print all the messages on the sence hat screen which is not optimal
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
if msg.payload =="red":
print("Recieved a message from the PI to ")
# Do Something here like print a message to the the sense hat screen
sense.show_message(msg.payload) # This is a better place to do something like set the screen to red/blue/clear etc.
# 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("test.mosquitto.org", 1883, 60)
client.connect("192.168.2.207", 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()
Now that that was working I can connect my thingworx server and test the theory.
Create a new thing and use the MQTT template.
Create 3 properties called Name Topic and Screen_Color
In configuration the Name must be the same as the property and the value that you want it to be set to must be the full path to the topic.
For example Name: Screen_Color Topic Thingworx/Color