Created
May 26, 2020 20:52
-
-
Save chadtsigler/c43cd9639a61b4df287cda04d5670b76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import paho.mqtt.client as paho | |
import time | |
import os | |
from virtru_sdk import Client, LogLevel, Policy, EncryptStringParams | |
virtru_owner="<VIRTRU PROVIDED>" | |
virtru_appid="<VIRTRU PROVIDED>" | |
virtru_share=["user1@example.com","user2@demo.com"] | |
mqtt_broker="<IP/HOST of MQTT Broker>" | |
def encrypt_string(clear_text): | |
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") | |
policy = Policy() | |
policy.share_with_users(virtru_share) | |
policy.expire_in_days(10) | |
string_params = EncryptStringParams(clear_text) | |
string_params.set_policy(policy) | |
(policy_id, tdf_data) = vclient.encrypt_string(encrypt_string_params=string_params) | |
return tdf_data | |
def measure_temp(): | |
temp = os.popen("vcgencmd measure_temp").readline() | |
return (temp.replace("temp=","")).replace("'C",'').strip() | |
#return "0" | |
client = paho.Client() | |
client.connect(mqtt_broker, 1883) | |
client.loop_start() | |
while True: | |
temperature = measure_temp() | |
ticks = str(time.time()) | |
print(f"{ticks} Temp: {temperature}") | |
enc_temp = encrypt_string(str(f"{ticks} {temperature}")) | |
(rc, mid) = client.publish("sensor/temperature", enc_temp, qos=1) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment