Пример #1
0
    def __init__(self, KNX_Address, *args, **kwargs):
        if 'GAD_TABLE' in kwargs:
            self.GAD_TABLE = kwargs['GAD_TABLE']
        else:
            self.GAD_TABLE = ProjectSettings().GAD_TABLE

        self.KNX_Address = KNX_Address

        if KNX_Address is not '':
            if self.KNX_Address in self.GAD_TABLE:
                GAD_list = self.GAD_TABLE[self.KNX_Address]
                self.name = GAD_list["name"]
                self.dpt = GAD_list["dptId"]
                self.readwrite = GAD_list["read_write"]
                self.flags = Flags(GAD_list["flags"])
                self.flagsString = GAD_list["flags"]

        elif 'name' in kwargs:
            for (GAD_key, GAD_list) in self.GAD_TABLE.items():
                if kwargs['name'] == GAD_list['name']:
                    self.KNX_Address = GAD_key
                    self.name = GAD_list["name"]
                    self.dpt = GAD_list["dptId"]
                    self.readwrite = GAD_list["read_write"]
                    self.flags = Flags(GAD_list["flags"])
                    self.flagsString = GAD_list["flags"]
Пример #2
0
def testing():
    ActivityCheck().start()
    settings = ProjectSettings()
    settings.GAD_TABLE = GAD_MAP_TABLE_OUTSIDE
    KNXWriter(name='b0_Set_Pos', value=str(random.randint(0, 100)))
    time.sleep(12)
    tempData = KNXReader(name="externalTemp")
    val = tempData.ReadValue()
    print(val)
    time.sleep(12)
    KNXWriter(name='b0_Set_Pos', value='50')
Пример #3
0
class StartInfo:
    g_SETTINGS = ProjectSettings()
    g_DATA = currentValues()

    def __init__(self, *args, **kwargs):
        pass

    def SendInfo(self):
        try:
            print("sending start info")
            info = {
                'time': datetime.now().strftime("%m/%d/%Y, %H:%M:%S"),
                'status': "STARTING NEW SESSION.",
                'ID': self.g_DATA.ID
            }
            print("sending start info {} ".format(info))
            r = requests.post(self.g_SETTINGS.ServerIP + '/MBPC/b',
                              timeout=10,
                              json=info)
            response = r.json()
            print(info)
            print(response)
        except Exception as e:
            print(e)
Пример #4
0
            mapper = GroupAddressTableMapper(GAD=self.GAD_TABLE)
            translator = mapper.getDptXlator(self.KNX_Address)
            if value == '' or value is None:
                return ''
            else:
                self.value = value
                self.valueData = translator.valueToData(value)
                self.valueAsFrame = translator.dataToFrame(self.valueData)
                self.valueAsFrameHEX = self.valueAsFrame.hex()
                return str(self.valueAsFrameHEX)
        except Exception as e:
            pass


if __name__ == "__main__":
    try:
        settings = ProjectSettings()
        from LKNX_ProjectSettings import ProjectSettings
        from DATA_KNXAdresses import GAD_MAP_TABLE_OUTSIDE
        settings.GAD_TABLE = GAD_MAP_TABLE_OUTSIDE

        #tempData = KNXReader(name= "indoorTemp")
        #curVal,error = tempData.ReadValue()

        #settings.ServerIP = "http://90.145.162.7:8109"
        #startLogging()
        #main()

    except Exception as e:
        pass
Пример #5
0
class ConnectToServer(threading.Thread):
    g_SETTINGS = ProjectSettings()
    g_DATA = currentValues()

    def __init__(self, *args, **kwargs):
        threading.Thread.__init__(self)
        self.setDaemon(False)
        print('INFO: connecting to server...')

    def run(self):
        runStartedTime = datetime.now().strftime("%m_%d-%H_%M_%S")
        runCounter = 0
        firstRun = True
        locaJSONData = dict()
        waitTime = 300
        print("starting while loop...")
        while True:
            LOG_MAIN.info("MAIN CLIENT-SERVER LOOP RUNNING")
            runCounter = runCounter + 1
            print("connecting to server for the {}x time\run started on:{}".
                  format(runCounter, runStartedTime))
            try:
                KNX().refreshKNXData()
                ActivityData().refreshData()

                print("while loop... get updated values...")
                print(self.g_DATA)
                localJSONData = self.g_DATA.getUpdatedValues()
                print("LocalJsonData:",
                      json.dumps(localJSONData, sort_keys=True, indent=4))

                time.sleep(5)

                #                continue
                #                if runCounter==1:#we do this to prevent 800 values at the start
                #                    time.sleep(waitTime)
                #                    continue

                server_BlindsData = self.getServerData(localJSONData)
                print("ServerJsonData:",
                      json.dumps(server_BlindsData, sort_keys=True, indent=4))

                if "error" in server_BlindsData or "error" in localJSONData:
                    time.sleep(waitTime)
                    continue

                time.sleep(5)

                print('comparing and moving blinds...')
                self.compareAndupdatePhysicalBlindsPosition(
                    server_BlindsData, localJSONData)
                ActivityData().ServerActive()
                time.sleep(5)

                print("waiting 300 seconds to send new data to server...")
                time.sleep(waitTime)

            except Exception as e:
                exc_type, exc_value, exc_tb = sys.exc_info()
                tb = traceback.format_exception(exc_type, exc_value, exc_tb)
                LOG_MAIN.error(tb)
                print(
                    "error ... waiting 300 seconds to try send new data to server...\n{}"
                    .format(e))
                #emailNotice = EmailError()
                #emailNotice.emailMe(e)
                #time.sleep(waitTime)
                raise e

    def getServerData(self, current_blinds_values):
        error = False
        errorList = list()
        try:
            r = requests.post(self.g_SETTINGS.ServerIP + '/MBPC/b',
                              timeout=50,
                              json=current_blinds_values)
            server_blinds_values = r.json()
            LOG_SENT_RECIEVED.info(current_blinds_values)
            LOG_SENT_RECIEVED.info(server_blinds_values)

            if 'error' in server_blinds_values['status']:
                return server_blinds_values
            else:
                return server_blinds_values
        except Exception as e:
            error = EmailError()
            error.emailMe(e)
            print("error getting server data")
            return "error"

    def compareAndupdatePhysicalBlindsPosition(self, server_blinds_values,
                                               current_JSON):
        from LKNX.LKNX_ReadWriteValue import KNXWriter
        current_blinds_values = current_JSON['get_controls']

        if server_blinds_values['status'] == 'ok':
            preferred_blind = server_blinds_values['preferred_blind']

            #WRITE TO PREFERED GROUP
            for group_name in server_blinds_values:
                if any(val in group_name
                       for val in ['status', 'time', 'preferred_blind']):
                    continue

                if str(preferred_blind) in group_name:
                    curBlindPos = current_blinds_values[group_name]
                    requestedBlindPos = server_blinds_values[group_name]

                    #move prefered blind if change is beyond "threshold" (no point moving it 1%)
                    if abs(curBlindPos - requestedBlindPos) > 3:
                        print(
                            "move blind...curBlindPos = {} requestedBlindPos = {}"
                            .format(curBlindPos, requestedBlindPos))
                        print("move blind...moving group: {} value: {}".format(
                            group_name, requestedBlindPos))
                        KNXWriter(name=group_name, value=requestedBlindPos)
                        print('move blind...WRITE COMPLETE')
                        #TODO CREATE DERIVED THREADED CLASS FROM KNXWRITER THAT PERFORMS CHECK AFTER 2 MINUTES
                else:
                    #move non preffered blind to default position
                    print('move non preffered blind to default position...')
                    KNXWriter(name=group_name, value=0)

            #DISABLED. Store previous data for any future comparison
            #self.old_blinds_values = server_blinds_values

        else:
            error = EmailError()
            error.emailMe("move blind...error with parsing blinds values")
            print('move blind...server status not OK')
            time.sleep(25)
            pass
Пример #6
0
            response = r.json()
            print(info)
            print(response)
        except Exception as e:
            print(e)


''' experiments '''
if __name__ == "__main__2":
    kipLogger = KippZonen()
    connection = ConnectToServer()
    while True:
        running = False
        try:
            if running == False:
                settings = ProjectSettings()
                settings.GAD_TABLE = GAD_MAP_TABLE_OUTSIDE
                settings.ServerIP = "http://90.145.162.7:8109"  #"http://90.145.162.7:8109"
                startLogging()
                kipLogger.start()
                connection.start()
                running = True

        except Exception as e:
            emailNotice = EmailError()
            emailNotice.emailMe(e)
            connection.join()
            kipLogger.join()
            running = False

Пример #7
0
 def __init__(self, *args, **kwargs):
     if "GAD_TABLE" in kwargs:
         self.GAD_TABLE = kwargs['GAD_TABLE']
     else:
         self.GAD_TABLE = ProjectSettings().GAD_TABLE