You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
689 B
32 lines
689 B
4 years ago
|
from counterfit_connection import CounterFitConnection
|
||
|
CounterFitConnection.init('127.0.0.1', 5000)
|
||
|
|
||
|
import time
|
||
|
from counterfit_shims_seeed_python_dht import DHT
|
||
|
import paho.mqtt.client as mqtt
|
||
|
import json
|
||
|
|
||
|
sensor = DHT("11", 5)
|
||
|
|
||
|
id = '<ID>'
|
||
|
|
||
|
client_telemetry_topic = id + '/telemetry'
|
||
|
client_name = id + 'temperature_sensor_client'
|
||
|
|
||
|
mqtt_client = mqtt.Client(client_name)
|
||
|
mqtt_client.connect('test.mosquitto.org')
|
||
|
|
||
|
mqtt_client.loop_start()
|
||
|
|
||
|
print("MQTT connected!")
|
||
|
|
||
|
while True:
|
||
|
_, temp = sensor.read()
|
||
|
telemetry = json.dumps({'temperature' : temp})
|
||
|
|
||
|
print("Sending telemetry ", telemetry)
|
||
|
|
||
|
mqtt_client.publish(client_telemetry_topic, telemetry)
|
||
|
|
||
|
time.sleep(10 * 60)
|