示例#1
0
port = hv["iriscontrol"]["port"]

#-------------------------------------------------
logging.basicConfig()

# now to get the list of switches out of the database so I can use them
createSwitchList()
# I'm showing the switch list for debugging and logging purposes
lprint("Switches found in database")
for key in sSwitches:
    lprint(key)
    lprint('  long address ', repr(sSwitches[key]['lAddress']))
    lprint('  short address ', repr(sSwitches[key]['sAddress']))

#------------------If you want to schedule something to happen -----
keepAliveTimer = timer(timeInLog, minutes=15)

#-----------------------------------------------------------------

# Create XBee library API object, which spawns a new thread
zb = ZigBee(ser, callback=messageReceived)

lprint("started")
# Now configure the cherrypy server using the values grabbed from .houserc
cherrypy.config.update({
    'server.socket_host':
    ipAddress.encode('ascii', 'ignore'),
    'server.socket_port':
    port,
    'engine.autoreload.on':
    False,
示例#2
0
hv = getHouseValues()
# the database where I'm storing house stuff
hdbName = hv["houseDatabase"]
hdbHost = hv["houseHost"]
hdbPassword = hv["housePassword"]
hdbUser = hv["houseUser"]
# the iris switch controller
irisControl = hv["iriscontrol"]["ipAddress"] + ":" + \
                    str(hv["iriscontrol"]["port"])
lprint("Iris Control is:", irisControl)
# the wemo switch controller
wemoControl = hv["wemocontrol"]["ipAddress"] + ":" + \
                    str(hv["wemocontrol"]["port"])
lprint("Wemo Control is:", wemoControl)

checkTimer = timer(None)

#
# Now the mqtt server that will be used
processName = os.path.basename(sys.argv[0])
mqttc = mqtt.Client(client_id=processName, clean_session=True)
mqttServer = hv["mqttserver"]
mqttc.connect(mqttServer, 1883, 60)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
# one minute timer for updating power record
minute = timer(updatePower, minutes=1)
try:
    # Blocking call that processes network traffic, dispatches callbacks and
    # handles reconnecting.
    lprint("Going into the mqtt wait loop")
示例#3
0
from houseutils import lprint, getHouseValues, timer, checkTimer

# This is where the actual 'Hello World' goes out to the browser
class WemoSC(object):
    @cherrypy.expose
    def index(self):
        return "Hello world!"
    
# This is the callback for my simple timer class
def ticker():
    lprint ("tick")
    
if __name__ == '__main__':
    # This timer will handle something on a periodic basis
    # Things like polling lights to see what they're doing right now
    jobTimer = timer(ticker, seconds=2)

    # Get the ip address and port number you want to use
    # from the houserc file
    ipAddress=getHouseValues()["wemocontrol"]["ipAddress"]
    port = getHouseValues()["wemocontrol"]["port"]
    # Now configure the cherrypy server using the values
    cherrypy.config.update({'server.socket_host' : ipAddress,
                            'server.socket_port': port,
                            'engine.autoreload_on': False,
                            })
    # Subscribe to the 'main' channel in cherrypy with my timer
    # tuck so the timers I use get updated
    cherrypy.engine.subscribe("main", checkTimer.tick)
    # Now just hang on the HTTP server looking for something to 
    # come in.  The cherrypy dispatcher will update the things that
示例#4
0
     except mdb.Error, e:
         lprint ("Database Error %d: %s" % (e.args[0],e.args[1]))
     dbconn.commit()
 dbconn.close()
 lprint ("")
 lprint ("The list of", len(switches), "switches found is")
 for item in switches:
     lprint ("Friendly name:", item["name"])
     lprint ("Model:", item["model"])
     lprint ("IP address:", item["ip"])
     lprint ("Port number:", item["port"])
     lprint ("MAC:", item["mac"])
     lprint ('')
     
 # timed things.
 checkLightsTimer = timer(doLights, seconds=2)
 keepAliveTimer = timer(keepAlive, minutes=4)
 # Now configure the cherrypy server using the values
 cherrypy.config.update({'server.socket_host' : ipAddress.encode('ascii','ignore'),
                         'server.socket_port': port,
                         'engine.autoreload.on': False,
                         })
 # Subscribe to the 'main' channel in cherrypy with my timer
 cherrypy.engine.subscribe("main", checkTimer.tick)
 lprint ("Hanging on the wait for HTTP message")
 # Now just hang on the HTTP server looking for something to 
 # come in.  The cherrypy dispatcher will update the things that
 # are subscribed which will update the timers so the light
 # status gets recorded.
 cherrypy.quickstart(WemoSC())
 
示例#5
0
    # the databases where I'm storing stuff
    hv = getHouseValues()
    # the weather database
    dbName = hv["weatherDatabase"]
    dbHost = hv["weatherHost"]
    dbPassword = hv["weatherPassword"]
    dbUser = hv["weatherUser"]
    # the house database
    hdbName = hv["houseDatabase"]
    hdbHost = hv["houseHost"]
    hdbPassword = hv["housePassword"]
    hdbUser = hv["houseUser"]

    # Now that everything is ready, start the two mqtt loops
    # I'm not I have to wait, but it feels safer
    awsMqtt.loop_start()
    # I have to loop both of them or they time out and I get an
    # err 32 (broken pipe)
    dhMqtt.loop_start()
    lprint("both mqtt loops started")

    # this timer fires every so often to update the
    # Amazon alexa device shaddow; check 'seconds' below
    shadowUpdateTimer = timer(updateIotShadow, seconds=10)
    lprint("Alexa Handling started")

    # The main loop
    while True:
        # Wait a bit
        checkTimer.tick()
        time.sleep(0.5)
     except mdb.Error, e:
         lprint ("Database Error %d: %s" % (e.args[0],e.args[1]))
     dbconn.commit()
 dbconn.close()
 lprint ("")
 lprint ("The list of", len(switches), "switches found is")
 for item in switches:
     lprint ("Friendly name:", item["name"])
     lprint ("Model:", item["model"])
     lprint ("IP address:", item["ip"])
     lprint ("Port number:", item["port"])
     lprint ("MAC:", item["mac"])
     lprint ('')
     
 # timed things.
 checkLightsTimer = timer(doLights, seconds=2)
 keepAliveTimer = timer(keepAlive, minutes=4)
 # Now configure the cherrypy server using the values
 cherrypy.config.update({'server.socket_host' : ipAddress.encode('ascii','ignore'),
                         'server.socket_port': port,
                         'engine.autoreload.on': False,
                         })
 # Subscribe to the 'main' channel in cherrypy with my timer
 cherrypy.engine.subscribe("main", checkTimer.tick)
 lprint ("Hanging on the wait for HTTP message")
 # Now just hang on the HTTP server looking for something to 
 # come in.  The cherrypy dispatcher will update the things that
 # are subscribed which will update the timers so the light
 # status gets recorded.
 cherrypy.quickstart(WemoSC())
 
示例#7
0
hv = getHouseValues()
# the database where I'm storing house stuff
hdbName = hv["houseDatabase"]
hdbHost = hv["houseHost"]
hdbPassword = hv["housePassword"]
hdbUser = hv["houseUser"]
# the iris switch controller
irisControl = hv["iriscontrol"]["ipAddress"] + ":" + \
                    str(hv["iriscontrol"]["port"])
lprint("Iris Control is:", irisControl);
# the wemo switch controller
wemoControl = hv["wemocontrol"]["ipAddress"] + ":" + \
                    str(hv["wemocontrol"]["port"])
lprint("Wemo Control is:", wemoControl)

checkTimer = timer(None)

#
# Now the mqtt server that will be used
processName = os.path.basename(sys.argv[0])
mqttc = mqtt.Client(client_id=processName, clean_session=True)
mqttServer = hv["mqttserver"]
mqttc.connect(mqttServer, 1883, 60)
mqttc.on_connect = on_connect
mqttc.on_message = on_message
# one minute timer for updating power record
minute = timer(updatePower, minutes=1)
try:
    # Blocking call that processes network traffic, dispatches callbacks and
    # handles reconnecting.
    lprint ("Going into the mqtt wait loop")
示例#8
0
    # the databases where I'm storing stuff
    hv = getHouseValues()
    # the weather database
    dbName = hv["weatherDatabase"]
    dbHost = hv["weatherHost"]
    dbPassword = hv["weatherPassword"]
    dbUser = hv["weatherUser"]
    # the house database
    hdbName = hv["houseDatabase"]
    hdbHost = hv["houseHost"]
    hdbPassword = hv["housePassword"]
    hdbUser = hv["houseUser"]
    
    # Now that everything is ready, start the two mqtt loops
    # I'm not I have to wait, but it feels safer
    awsMqtt.loop_start()
    # I have to loop both of them or they time out and I get an 
    # err 32 (broken pipe)
    dhMqtt.loop_start()
    lprint ("both mqtt loops started")

    # this timer fires every so often to update the
    # Amazon alexa device shaddow; check 'seconds' below
    shadowUpdateTimer = timer(updateIotShadow, seconds=10)
    lprint("Alexa Handling started")

    # The main loop
    while True:
        # Wait a bit
        checkTimer.tick()
        time.sleep(0.5)
示例#9
0
       print "Running with debug on"
       debug = True
 
   # the database where I'm storing stuff
   hv = getHouseValues()
   dbName = hv["weatherDatabase"]
   dbHost = hv["weatherHost"]
   dbPassword = hv["weatherPassword"]
   dbUser = hv["weatherUser"]
  # Get the ip address and port number you want to use
   # from the houserc file
   ipAddress=getHouseValues()["giveweather"]["ipAddress"]
   port = getHouseValues()["giveweather"]["port"]
   # periodically put a message into the log to indicate that
   # this is still alive
   keepAliveTimer = timer(keepAlive, minutes=4)
 
   cherrypy.config.update({'server.socket_host' : ipAddress.encode('ascii','ignore'),
                           'server.socket_port': port,
                           'engine.autoreload.on': False,
                           })
   # Subscribe to the 'main' channel in cherrypy with my timer
   cherrypy.engine.subscribe("main", checkTimer.tick)
   lprint ("Hanging on the wait for HTTP message")
   # Now just hang on the HTTP server looking for something to 
   # come in.  The cherrypy dispatcher will update the things that
   # are subscribed which will update the timers so the light
   # status gets recorded.
   cherrypy.quickstart(WeatherSC())
   
   sys.exit("Told to shut down");
示例#10
0
#-------------------------------------------------
logging.basicConfig()


# now to get the list of switches out of the database so I can use them
createSwitchList()
# I'm showing the switch list for debugging and logging purposes
lprint("Switches found in database")
for key in sSwitches:
    lprint (key)
    lprint ('  long address ', repr(sSwitches[key]['lAddress']))
    lprint ('  short address ', repr(sSwitches[key]['sAddress']))
 
#------------------If you want to schedule something to happen -----
keepAliveTimer = timer(timeInLog, minutes=15)

#-----------------------------------------------------------------

# Create XBee library API object, which spawns a new thread
zb = ZigBee(ser, callback=messageReceived)

lprint ("started")
# Now configure the cherrypy server using the values grabbed from .houserc
cherrypy.config.update({'server.socket_host' : ipAddress.encode('ascii','ignore'),
                        'server.socket_port': port,
                        'engine.autoreload.on': False,
                        })
# Subscribe to the 'main' channel in cherrypy with my timer
cherrypy.engine.subscribe("main", checkTimer.tick)
# and this will kill the separate XBee receive thread 
示例#11
0
# This is where the actual 'Hello World' goes out to the browser
class WemoSC(object):
    @cherrypy.expose
    def index(self):
        return "Hello world!"


# This is the callback for my simple timer class
def ticker():
    lprint("tick")


if __name__ == '__main__':
    # This timer will handle something on a periodic basis
    # Things like polling lights to see what they're doing right now
    jobTimer = timer(ticker, seconds=2)

    # Get the ip address and port number you want to use
    # from the houserc file
    ipAddress = getHouseValues()["wemocontrol"]["ipAddress"]
    port = getHouseValues()["wemocontrol"]["port"]
    # Now configure the cherrypy server using the values
    cherrypy.config.update({
        'server.socket_host': ipAddress,
        'server.socket_port': port,
        'engine.autoreload_on': False,
    })
    # Subscribe to the 'main' channel in cherrypy with my timer
    # tuck so the timers I use get updated
    cherrypy.engine.subscribe("main", checkTimer.tick)
    # Now just hang on the HTTP server looking for something to