Files
Meshify-Firebase/firebase_interface.py
Patrick McDonagh f89cd46e96 Initial Commit
2018-05-22 13:11:58 -05:00

33 lines
1.1 KiB
Python

"""Sample of wrapper for meshify data to firebase."""
import time
from firebase import firebase
BASE_URL = 'https://pocloud-ff2c9.firebaseio.com'
fbdb = firebase.FirebaseApplication(BASE_URL, None)
def set_firebase_channel(deviceId, device_type, channel, value, timestamp):
"""Sets the value of a firebase channel."""
if timestamp == 0:
timestamp = time.time()
channel_value = {
'name': channel,
'value': value,
'timestamp': timestamp
}
channels_url = "/devices/{}/{}/channels/{}".format(deviceId, device_type, channel)
chan_result = fbdb.patch(channels_url, channel_value,
connection=None,
params={'print': 'pretty'},
headers={'X_FANCY_HEADER': 'VERY FANCY'})
print(chan_result)
history_url = "/devices/{}/{}/history/{}".format(deviceId, device_type, channel)
result = fbdb.post(history_url, channel_value,
connection=None,
params={'print': 'pretty'},
headers={'X_FANCY_HEADER': 'VERY FANCY'})
print(result)