from firebase_streaming import Firebase

# Sample callback function
def p(x):
    print x

# Firebase object
fb = Firebase('https://myfirebase.firebaseio.com/')

# Add listener to colors child with no callback
no_callback = fb.child("colors").listener()

# Or use a custom callback
custom_callback = fb.child("shapes").listener(p)

# Start and stop the stream using the following
custom_callack.start()
raw_input("ENTER to stop...")
custom_callback.stop()
Ejemplo n.º 2
0
                first                       = False
    
            else:
                if target_temperature_c_prev != target_temperature_c or hvac_state_prev != hvac_state or away_state_prev != away_state:
                    if hvac_state == "off":
                        msg_str_set = "{\"ac_cmd\":0,"
                    elif hvac_state == "cooling":
                        msg_str_set = "{\"ac_cmd\":1,"
    
                    msg_str_set = msg_str_set + "\"ac_temp\":" + str(int(target_temperature_c)) + ",\"ac_flow\":1,\"away\":" + away_state + "}"
    
                    publish(msg_str_set)
    
                is_online_prev              = is_online
                hvac_state_prev             = hvac_state
                target_temperature_c_prev   = target_temperature_c
                away_state_prev             = away_state

# Firebase object
fb = Firebase('https://developer-api.nest.com/')

# Or use a custom callback
custom_callback = fb.child(child_path).listener(p)

try:
    custom_callback.start()

except KeyboardInterrupt:
    custom_callback.stop()
    sys.exit(1)
Ejemplo n.º 3
0
# RUN WITH PYTHON 3.7
import json
from time import sleep
from firebase_streaming import Firebase
from smbus2 import SMBus, SMBusWrapper
import RPi.GPIO as GPIO
# don't forget the last /
fb = Firebase("https://ecal-mit-hub.firebaseio.com/")

# HUB NAME HAS TO MATCH ONLINE NAME
HUB_NAME = "HUB ECAL"
I2CS = {}
ADDRESSES = {}
ARDUINO_I2C = {}
HUBS = {}
bus = SMBus(1)

# INFO LEDS
GPIO.setmode(GPIO.BCM)
LED_1 = 18
LED_2 = 16
GPIO.setup(LED_1, GPIO.OUT)
GPIO.setup(LED_2, GPIO.OUT)
GPIO.output(LED_1, GPIO.HIGH)
GPIO.output(LED_2, GPIO.LOW)


def verifyHubAndSendMessage(hub, id, message):
    global HUBS
    # print(HUBS)
    # print(hub,id,message)
Ejemplo n.º 4
0
from time import sleep
from firebase_streaming import Firebase
from smbus2 import SMBus, SMBusWrapper
import RPi.GPIO as GPIO 
import argparse
import urllib.request
external_ip = urllib.request.urlopen('https://ident.me').read().decode('utf8')
print("Your IP : "+external_ip)

parser = argparse.ArgumentParser()
parser.add_argument('--id', help='firebase id (string)')
parser.add_argument('--name', help='hub name')
args = parser.parse_args()

# don't forget the last /
fb = Firebase("https://{0}.firebaseio.com/".format(args.id))

# HUB NAME HAS TO MATCH ONLINE NAME
HUB_NAME = "{0}".format(args.name)
I2CS = {}
ADDRESSES = {}
ARDUINO_I2C = {}
HUBS = {}
bus=SMBus(1)

# INFO LEDS
GPIO.setmode(GPIO.BCM)
LED_1 = 18
LED_2 = 16
GPIO.setup(LED_1, GPIO.OUT)
GPIO.setup(LED_2, GPIO.OUT)
Ejemplo n.º 5
0
first_setTargetHeatingCoolingState = True
first_setTargetTemperature = True
ts = time.time()
FanSpeed = 0

target_temperature_c_prev = 0

client = mqtt.Client(client_id=mqtt_clientid)
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(mqtt_user, mqtt_pass)
client.tls_set(mqtt_ca, tls_version=ssl.PROTOCOL_TLSv1)
client.connect(mqtt_cn, 8883, 60)
client.loop_start()

# Firebase object
fb = Firebase('https://developer-api.nest.com/')

# Or use a custom callback
custom_callback = fb.child(streaming_path).listener(p)
homeaway_set = fb.child(homeaway_path)
thermostat_set = fb.child(thermostat_path)

try:
    custom_callback.start()

except KeyboardInterrupt:
    custom_callback.stop()
    sys.exit(1)

c
Ejemplo n.º 6
0
first_setTargetHeatingCoolingState = True
first_setTargetTemperature = True
ts = time.time()
FanSpeed = 0

target_temperature_c_prev = 0

client = mqtt.Client(client_id=mqtt_clientid)
client.on_connect = on_connect
client.on_message = on_message
client.username_pw_set(mqtt_user, mqtt_pass)
client.tls_set(mqtt_ca, tls_version=ssl.PROTOCOL_TLSv1)
client.connect(mqtt_cn, 8883, 60)
client.loop_start()

# Firebase object
fb = Firebase('https://developer-api.nest.com/')

# Or use a custom callback
custom_callback = fb.child(streaming_path).listener(p)
homeaway_set   = fb.child(homeaway_path)
thermostat_set = fb.child(thermostat_path)

try:
    custom_callback.start()

except KeyboardInterrupt:
    custom_callback.stop()
    sys.exit(1)

c
Ejemplo n.º 7
0
import json
import RPi.GPIO as GPIO
from time import sleep
from smbus2 import SMBus, SMBusWrapper
from firebase_streaming import Firebase
fb = Firebase("https://esptest-73b9b.firebaseio.com/")

GPIO.setmode(GPIO.BCM)
LED_1 = 18
LED_2 = 16
GPIO.setup(LED_1, GPIO.OUT)
GPIO.setup(LED_2, GPIO.OUT)
GPIO.output(LED_1, GPIO.HIGH)
GPIO.output(LED_2, GPIO.LOW)

addr1 = 0x8
addr2 = 0x9
addr3 = 0x10
addr4 = 0x11
bus = SMBus(1)
numb = 1
print("start")


def light_toggle(_val):
    GPIO.output(LED_2, GPIO.HIGH)
    print("hello git hub 012", _val)
    data = json.loads(_val[1])
    print(data['path'])
    print(data['data'])
    pathes = data['path'].split('/')
Ejemplo n.º 8
0
from firebase_streaming import Firebase


# Sample callback function
def p(x):
    print x


# Firebase object
fb = Firebase('https://myfirebase.firebaseio.com/')

# Add listener to colors child with no callback
no_callback = fb.child("colors").listener()

# Or use a custom callback
custom_callback = fb.child("shapes").listener(p)

# Start and stop the stream using the following
custom_callack.start()
raw_input("ENTER to stop...")
custom_callback.stop()
Ejemplo n.º 9
0
TRIG1 = 4
ECHO1 = 17
TRIG2 = 27
ECHO2 = 22
TRIG3 = 23
ECHO3 = 24

print "Distance Measurement In Progress"

GPIO.setup(TRIG1, GPIO.OUT)
GPIO.setup(ECHO1, GPIO.IN)
GPIO.setup(TRIG2, GPIO.OUT)
GPIO.setup(ECHO2, GPIO.IN)
GPIO.setup(TRIG3, GPIO.OUT)
GPIO.setup(ECHO3, GPIO.IN)
fb = Firebase('https://fir-rtdbtest.firebaseio.com/')

GPIO.output(TRIG1, False)
GPIO.output(TRIG2, False)
GPIO.output(TRIG3, False)
print "Waiting For Sensor To Settle"
time.sleep(2)
while True:
    GPIO.output(TRIG1, True)
    time.sleep(0.00001)
    GPIO.output(TRIG1, False)

    while GPIO.input(ECHO1) == 0:
        pulse_start1 = time.time()

    while GPIO.input(ECHO1) == 1: