Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
39 lines (32 sloc) 1.01 KB
import yaml
import json
import time
import requests
import paho.mqtt.client as mqtt
Structure of bttn_client.yaml:
'api_key': ' API KEY'
'bttn_id': ' ID'
'sleep_time': 10
* The sleep time defines the polling frequency in seconds
* The api_key and the bttn_id can be found in the web interface
configFile = file('bttn_client.yaml', 'r')
config = yaml.load(configFile)
#Connect to mqtt client on localhost
client = mqtt.Client()
prev_timestamp = time.time()
while 1:
resp = requests.get(""+config['bttn_id']+"/feed?limit=1&after="+str(prev_timestamp), headers={'X-Api-Key':config['api_key']})
print resp_json['address'][0]
print resp_json['events']
if resp_json['events']:
mqtt_payload='{"UniqueIdentifier":"' + resp_json['address'][0] + '"}'
client.publish("/opentrigger/signals/trigger", mqtt_payload)
prev_timestamp = time.time()