Files
Meshify-Firebase/firebase_interface.py
Patrick McDonagh b2461b8595 Use firebase auth
2018-08-10 15:04:26 -05:00

40 lines
1.3 KiB
Python

"""Sample of wrapper for meshify data to firebase."""
import time
from firebase import firebase
BASE_URL = 'https://pocloud-ff2c9.firebaseio.com'
auth = firebase.FirebaseAuthentication('cFjVoqsVX6IRXwhBOqEi9FPrM3249DImRjsRiQM1', 'api@henry-pump.com')
fbdb = firebase.FirebaseApplication(BASE_URL, authentication=auth)
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
}
hist_value = {
'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, hist_value,
connection=None,
params={'print': 'pretty'},
headers={'X_FANCY_HEADER': 'VERY FANCY'})
print(result)