Example #1
0
def AttachIncomingEvents():
    # Set callback handler for incoming notifications
    sm.SetIncomingCallback(ProcessIncomingEvent)
    # Enable notifications from incoming SMS
    try:
        sm.SetIncomingSMS()
    except gammu.ERR_NOTSUPPORTED:
        Constellation.WriteWarn('Incoming SMS notification is not supported.')
    # Enable notifications from calls
    try:
        sm.SetIncomingCall()
    except gammu.ERR_NOTSUPPORTED:
        Constellation.WriteWarn(
            'Incoming calls notification is not supported.')
    # Enable notifications from cell broadcast
    try:
        sm.SetIncomingCB()
    except gammu.ERR_NOTSUPPORTED:
        Constellation.WriteWarn('Incoming CB notification is not supported.')
    except gammu.ERR_SOURCENOTAVAILABLE:
        Constellation.WriteWarn(
            'Cell broadcasts support not enabled in Gammu.')
    # Enable notifications for incoming USSD
    try:
        sm.SetIncomingUSSD()
    except gammu.ERR_NOTSUPPORTED:
        Constellation.WriteWarn('Incoming USSD notification is not supported.')
def DoMeasure():
    # Start process
    process = subprocess.Popen("./" + EXECUTABLE_FILENAME,
                               stdout=subprocess.PIPE)
    # Reading  output
    for line in iter(process.stdout.readline, ''):
        # Parse line
        matchObj = re.match(
            'RC: (\d*)\((.*)\), broadband: (\d*), ir: (\d*), lux: (\d*)', line)
        if matchObj:
            # Reading value
            returnCode = int(matchObj.group(1))
            broadband = int(matchObj.group(3))
            ir = int(matchObj.group(4))
            lux = int(matchObj.group(5))
            # Push StateObject
            if returnCode != 0:
                Constellation.WriteWarn("Unknow return code %s : %s" %
                                        (returnCode, line))
            else:
                Constellation.PushStateObject(
                    "Lux", {
                        "Broadband": broadband,
                        "IR": ir,
                        "Lux": lux
                    },
                    "LightSensor.Lux",
                    lifetime=int(Constellation.GetSetting("Interval")) * 2)
        else:
            Constellation.WriteError("Unable to parse the output: %s" % line)
Example #3
0
def ClockUpdated(stateobject):
    global alarmName
    
    Constellation.WriteInfo("Check reveil %s" % stateobject.Name)
    if stateobject.Value.IsRinging == True:
        Constellation.WriteWarn("REVEIL '%s' en action !" % stateobject.Name)
        Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PLAYLIST", "uri":"spotify:user:officiallifeisstrange:playlist:1f5ZzLDTXHTDR8CYIEddpW"})
        #time.sleep(10)
        #Constellation.SendMessage(MUSIC_PACKAGE, "MusicControl", {"instruction":"PLAY_PAUSE"})
        Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"musique", "text":stateobject.Name,"time":None,"matrix":None})
        alarmName = stateobject.Value.ClockName
def ReadModbusRegister(registerAddress, registerCount, slaveId=1):
    '''
    Request input registers from the specified address

    :param int registerAddress: The Data Address of the first register requested
    :param int registerCount: The total number of registers requested
    :param int slaveId: The Slave Address [default: 1]
    :return list:List of register value
    '''
    debug = Constellation.GetSetting("ModbusDebug") == "true"
    # Create command
    cmdLine = [
        "./" + EXECUTABLE_FILENAME,
        str(slaveId),
        Constellation.GetSetting("Port"),
        Constellation.GetSetting("BaudRate"),
        Constellation.GetSetting("PinDE"),
        Constellation.GetSetting("PinRE"),
        str(registerAddress),
        str(registerCount)
    ]
    if debug:
        cmdLine.append("debug")
        Constellation.WriteWarn("Executing command: %s" % cmdLine)
    # Execute command
    with syncLock:
        process = subprocess.Popen(cmdLine, stdout=subprocess.PIPE)
    # Reading output
    result = []
    for line in iter(process.stdout.readline, ''):
        if debug:
            Constellation.WriteWarn(line)
        if not debug or (debug and line.startswith("Result:")):
            result = (line[7:] if debug else line).split(';')
    # Return result
    return map(int, filter(None, result))
Example #5
0
def OnStart():
    # Register callback on package shutdown
    Constellation.OnExitCallback = OnExit   
    
    # Write log & common properties
    Constellation.WriteInfo("Hi I'm '%s' and I currently running on %s and %s to Constellation" % (Constellation.PackageName, Constellation.SentinelName if not Constellation.IsStandAlone else 'local sandbox', "connected" if Constellation.IsConnected else "disconnected"))
    
    #  GetSetting
    Constellation.WriteInfo("Demo1 = " + str(Constellation.GetSetting("Demo1"))) # If setting not exist, return None !
    
    # Send message without parameter 
    Constellation.SendMessage("DemoPackage", "HelloWorld", [], Constellation.MessageScope.package)    
    # Send message with 2 parameter
    Constellation.SendMessage("DemoPackage", "SendMessage", [ "+33123456789", "Hi" ], Constellation.MessageScope.package)
    # Send message with complex parameter 
    Constellation.SendMessage("DemoPackage", "DemoComplex", { "A": "This is a string", "B": 123, "C": True }, Constellation.MessageScope.package)
    # Send message "MessageCallbackWithComplexeResponse" with "123" as parameter to "Demo" pasckage and write the "A" property of the response
    Constellation.SendMessageWithSaga(lambda response: Constellation.WriteInfo("A=%s" % response.A), "Demo", "MessageCallbackWithComplexResponse", 123)
    
    # Push basic StateObject
    Constellation.PushStateObject("DemoStr", "Demo de seb") # StateObject with "String" as value
    Constellation.PushStateObject("DemoBool", False, lifetime=10) # StateObject with "Bool" as value and a lifetime (10 sec here)
    Constellation.PushStateObject("DemoInt", 123, metadatas={ "DeviceId":"RPi", "Serial":"123" }) # StateObject with "Int" as value and metadatas    
    Constellation.PushStateObject("DemoFloat", 12.45, metadatas={ "DeviceId":"RPi", "Serial":"123" }, lifetime=10) # StateObject with "Float" as value, metadatas and lifetime
    
    # Custom type descriptions
    Constellation.DescribeMessageCallbackType("CredentialInfo", "Credential information", [
        { 'Name':'Username', 'Type':'string', 'Description': 'The username' },
        { 'Name':'Password', 'Type':'string', 'Description': 'The password' },
    ])
    Constellation.DescribeStateObjectType("DemoType", "Demo type", [
        { 'Name':'Sender', 'Type':'string', 'Description': 'The demo' },        
        { 'Name':'Credential', 'Type':'CredentialInfo', 'Description': 'The credential nested demo' }
    ])
    Constellation.DeclarePackageDescriptor()
    
    # Push complex StateObject
    Constellation.PushStateObject("Demo", { "Sender": "DemoPython", "Credential": { "Username": "******", "Password":"******" } }, "DemoType", { "DeviceId": "RPi", "Serial":"123" }) # StateObject with custom type
    
    # WriteInfo, WriteWarn & WriteError
    Constellation.WriteInfo("Hello world from Python !")
    Constellation.WriteWarn("This is a warning !")
    Constellation.WriteError("This is an error !")
    
    # Last StateObjects of the previous instance
    if Constellation.LastStateObjects:
        for so in Constellation.LastStateObjects:
            Constellation.WriteInfo(" + %s @ %s" % (so.Name, so.LastUpdate))
Example #6
0
def displayMusic():
    Constellation.WriteWarn("DISPLAY MUSIQUE")
    Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"musique", "text":"Musique !","time":None,"matrix":None})   
Example #7
0
def displayTwitter():
    Constellation.WriteWarn("DISPLAY TWITTER")
    Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"twitter_oiseau", "text":twitterSO.followers_count,"time":None,"matrix":None})
Example #8
0
def displayWeather():
    Constellation.WriteWarn("DISPLAY FORECAST")
    Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"cloudy", "text":str(int(round(weatherForecastIO.temperature,0))) + 'C',"time":None,"matrix":None})
Example #9
0
def displayHome():
    # Si l'on se trouve sur l'écran du module, on update en live:
    if(displays[currentDisplay] == displayHome):
        Constellation.WriteWarn("DISPLAY HOME !")
        threading.Timer(10.0, displayHome).start()
        Constellation.SendMessage(DISPLAY_PACKAGE, "DisplayContent", {"icon":"horloge", "text":datetime.now().strftime('%H:%M'),"time":None,"matrix":None})
Example #10
0
def FinDuJeu():
    "Bouton qui signale la fin du jeu"

    Constellation.WriteWarn("Game Over")