Skip to content

Instantly share code, notes, and snippets.

@chadtsigler
Created May 26, 2020 20:46
Show Gist options
  • Save chadtsigler/55b99d5e59600d566a1db6bceeb0c104 to your computer and use it in GitHub Desktop.
Save chadtsigler/55b99d5e59600d566a1db6bceeb0c104 to your computer and use it in GitHub Desktop.
MQTT Python Subscriber using the Virtru SDK
import paho.mqtt.client as paho
from virtru_sdk import LogLevel, Client
virtru_owner="<VIRTRU PROVIDED>"
virtru_appid="<VIRTRU PROVIDED>"
mqtt_broker="<IP/HOST of MQTT Broker>"
def on_subscribe(client, userdata, mid, granted_qos):
print("Subscribed: "+str(mid)+" "+str(granted_qos))
def on_message(client, userdata, msg):
clear_msg = decrypt_string(msg.payload)
print(msg.topic+" "+str(msg.qos)+" "+str(clear_msg))
def decrypt_string(encrypted_string):
vclient = Client(owner=virtru_owner,
app_id=virtru_appid)
vclient.set_eas_url("https://api.virtru.com/accounts")
vclient.set_kas_url("https://api.virtru.com/kas")
vclient.set_acm_url("https://api.virtru.com/acm")
return vclient.decrypt_string(encrypted_string)
client = paho.Client()
client.on_subscribe = on_subscribe
client.on_message = on_message
client.connect(mqtt_broker, 1883)
client.subscribe("sensor/#", qos=1)
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment