예제 #1
0
def main():
    global outputFile, directory
    try:
        opts, args = getopt.getopt(sys.argv[1:],"ho:",["output="])
    except getopt.GetoptError:
        print '%s -o <outputfile>' % sys.argv[0]
        sys.exit(2)

    for opt, arg in opts:
      if opt == '-h':
         print '%s -o <outputfile>' % sys.argv[0]
         sys.exit()
      elif opt in ("-o", "--output"):
         outputFile = arg

    if outputFile == None:
        print "No output file specified, output to console."

    radio.init()
    OpenThings.init(Devices.CRYPT_PID)

    try:
        dumpDirectory()
        monitor_loop()

    finally:
        radio.finished()
        directory = {"__META": {"time": int(time.time())}}
        dumpDirectory()
예제 #2
0
    def __init__(self, mfrid= Devices.MFRID_ENERGENIE, 
                    productid= Devices.PRODUCTID_R1_MONITOR_AND_CONTROL, 
                    sensorid= 0):
        
        self.logger = logging.getLogger('root')

        self.directory = {}

        self.msg_join_ack = MESSAGE_JOIN_ACK
        self.msg_join_ack['header']['mfrid'] = mfrid
        self.msg_join_ack['header']['productid'] = productid
        self.msg_join_ack['header']['sensorid'] = sensorid

        self.msg_switch = MESSAGE_SWITCH
        self.msg_switch['header']['sensorid'] = sensorid
        
        radio.init()
        OpenHEMS.init(Devices.CRYPT_PID)
예제 #3
0
    def __init__(self,
                 mfrid=Devices.MFRID_ENERGENIE,
                 productid=Devices.PRODUCTID_R1_MONITOR_AND_CONTROL,
                 sensorid=0):

        self.logger = logging.getLogger('root')

        self.directory = {}

        self.msg_join_ack = MESSAGE_JOIN_ACK
        self.msg_join_ack['header']['mfrid'] = mfrid
        self.msg_join_ack['header']['productid'] = productid
        self.msg_join_ack['header']['sensorid'] = sensorid

        self.msg_switch = MESSAGE_SWITCH
        self.msg_switch['header']['sensorid'] = sensorid

        radio.init()
        OpenHEMS.init(Devices.CRYPT_PID)
예제 #4
0
            Registry.update(decoded)
            ##trace(decoded)
            Logger.logMessage(decoded)

            # Process any JOIN messages by sending back a JOIN-ACK to turn the LED off
            if len(decoded["recs"]) == 0:
                # handle messages with zero recs in them silently
                print("Empty record:%s" % decoded)
            else:
                # assume only 1 rec in a join, for now
                if decoded["recs"][0]["paramid"] == OpenThings.PARAM_JOIN:
                    mfrid     = OpenThings.getFromMessage(decoded, "header_mfrid")
                    productid = OpenThings.getFromMessage(decoded, "header_productid")
                    sensorid  = OpenThings.getFromMessage(decoded, "header_sensorid")
                    Messages.send_join_ack(radio, mfrid, productid, sensorid)


if __name__ == "__main__":
    
    trace("starting monitor tester")
    radio.init()
    OpenThings.init(Devices.CRYPT_PID)

    try:
        monitor_loop()

    finally:
        radio.finished()

# END
예제 #5
0
                                                  header_sensorid=sensorid,
                                                  recs_0_value=switch_state)
                p = OpenThings.encode(request)
                print("Sending switch message to %s %s" %
                      (hex(productid), hex(sensorid)))
                # Transmit multiple times, hope one of them gets through
                radio.transmit(p, inner_times=2)

        radio.receiver()
        switch_state = (switch_state + 1) % 2  # toggle


if __name__ == "__main__":

    trace("starting switch tester")
    radio.init()
    OpenThings.init(Devices.CRYPT_PID)

    # Seed the registry with a known device, to simplify tx-only testing
    SENSOR_ID = 0x68B  # captured from a real device
    device_header = OpenThings.alterMessage(
        Messages.REGISTERED_SENSOR,
        header_mfrid=Devices.MFRID,
        header_productid=Devices.PRODUCTID_MIHO005,  # adaptor plus
        header_sensorid=SENSOR_ID)
    Registry.update(device_header)

    sendSwitchTimer = Timer(TX_RATE, 1)  # every n seconds offset by initial 1
    switch_state = 0  # OFF
    radio.receiver()