Ejemplo n.º 1
0
def main():
    #Connects to smart space
    
    global ts, sc
    
    try:
        ts = TripleStore()
        connected = True
        
        addEvent("ConnectEvent")

    except:
        print "Cannot connect to smart space."
        return    
       
    if connected:
        registerDevice()
        
        print "Checking for existing connections.."
        qs = node.CreateQueryTransaction(smartSpace)
        result = qs.rdf_query([((None, sc_ns+"connectedTo", ie_ns+deviceID),"uri")])
        for source in result:
            subscribeToSourceEvents(source[0][0])          
    
        print "Subscribing to new connections..."
        rs1 = node.CreateSubscribeTransaction(smartSpace)
        result_rdf1 = rs1.subscribe_rdf([((None, sc_ns+"connectedTo", ie_ns+deviceID), 'uri')], newConnectionHandler())
        
        print "Subscribing to SystemEvents..."
        rs2 = node.CreateSubscribeTransaction(smartSpace)
        result_rdf2 = rs2.subscribe_rdf([((None, "rdf:type", ie_ns+"SystemEvent"), 'uri')], eventHandler())
        
    
                 
#        print "Subscribing to AlarmSetEvents.."
#        rs1 = node.CreateSubscribeTransaction(smartSpace)
#        result_rdf1 = rs1.subscribe_rdf([((None, None, ie_ns+"AlarmSetEvent"), 'uri')], RdfMsgHandler())
#        rs2 = node.CreateSubscribeTransaction(smartSpace)
#        result_rdf2 = rs2.subscribe_rdf([((None, None, ie_ns+"TimeSetEvent"), 'uri')], RdfMsgHandler())

    sc = Server(hostname="127.0.0.1", port=9090, username="******", password="******")
    sc.connect()
    sc.subscribe(SBMsgHandler(),"00:04:20:2A:B0:A5")
    
    print "Logged in: %s" % sc.logged_in
    print "Version: %s" % sc.get_version()

    print "Ctrl+C to exit"

    try:
	    while 42:
	        getPlayer()
            raw_input()
                
    except KeyboardInterrupt: #So use Ctrl+C to exit event loop
        
        print "Unsubscribing RDF subscriptions"
        node.CloseSubscribeTransaction(rs1)
        node.CloseSubscribeTransaction(rs2)
        
        
        sc.unsubscribe()

        print "Leaving smart space.."
        if connected:
            addEvent("DisconnectEvent")
            node.leave(smartSpace)
            print("Exiting..")
            os._exit(1) #this is required because excepting a KeyboardInterrupt makes it difficult to exit the program
Ejemplo n.º 2
0
#!/usr/bin/env python

from pysqueezecenter.server import Server
from pysqueezecenter.player import Player

sc = Server(hostname="127.0.0.1", port=9090, username="******", password="******")
sc.connect()

print "Version: %s" % sc.get_version()

sq = sc.get_player("00:04:20:2A:B0:A5")

print "Name: %s | Mode: %s | Time: %s | Connected: %s | WiFi: %s" % (sq.get_name(), sq.get_mode(), sq.get_time_elapsed(), sq.is_connected, sq.get_wifi_signal_strength())

print sq.get_track_title()
print sq.get_time_remaining()

#Delete all alarms
alarms  = str(sq.get_alarms(50,"all"))
for b in alarms.split(" "):
    item = b.split(":")
    if  item[0] == "id":
        print item[1]
        sq.delete_alarm(item[1])