#! /usr/bin/perl -w sub AUSSENSENSOR_ONRECEIVED; sub TUERENFENSTER_ONRECEIVED; sub Timer_1Sekunde; sub telegrammessage; sub irgendeine_lampe_im_raum_an; sub debug; sub write_errorlog; sub read_data; sub write_data; sub save_ini; sub check_for_new_commands; sub check_serversocket; sub send_singlecast; sub set_new_rollopos; my %Data = ("FILES", {"CONFIGFILE", "/shares/www/cgi-bin/data.ini", "DEBUG","NO", "ERRORLOG","YES", "DAILYDEBUG","NO", "ERRORLOGFILEPATH","/shares/www/cgi-bin/logs/", "DAILYDEBUGFILEPATH","/shares/www/cgi-bin/logs/", "BACKUPFILEPATH","/shares/www/cgi-bin/logs/"}, "GENERAL", {"LASTDEVICE","36", "TIMEOUTDEVICE", "1", "TIMEOUTGETURL", "1", "MAXIMUM_SEND_ATTEMPTS","5", "SYSTEMSTARTTIME", "00:00:00", "SYSTEMSTARTDATE", "00.00.1900"}, "LOAD_AVERAGE", {"ID", "0", "SECCOUNTER", "0", "MINUTE_0", "0", "MINUTE_1", "0", "MINUTE_2", "0", "MINUTE_3", "0", "MINUTE_4", "0", "MINUTE_5", "0", "MINUTE_6", "0", "MINUTE_7", "0", "MINUTE_8", "0", "MINUTE_9", "0"}, "DEVICE_0", {"NAME","Flur EG", "DEVICEID","0", "IP","192.168.0.111", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_1", {"NAME","WC", "DEVICEID","1", "IP","192.168.0.112", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["WC", "WC"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2"], "DATAMASKPOS", [7,8], "DATAMASKLEN", [1,1], "ONRECEIVED", undef}, "DEVICE_2", {"NAME","Arbeitszimmer", "DEVICEID","2", "IP","192.168.0.113", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["ARBEITSZIMMER", "ARBEITSZIMMER", "ARBEITSZIMMER", "ARBEITSZIMMER", "ARBEITSZIMMER", "ARBEITSZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,13,16], "DATAMASKLEN", [1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_3", {"NAME","Wohnzimmer", "DEVICEID","3", "IP","192.168.0.114", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_4", {"NAME","Esszimmer", "DEVICEID","4", "IP","192.168.0.115", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["ESSZIMMER", "ESSZIMMER", "ESSZIMMER", "ESSZIMMER", "ESSZIMMER", "ESSZIMMER", "ESSZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,11,14,17], "DATAMASKLEN", [1,1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_5", {"NAME","Kueche", "DEVICEID","5", "IP","192.168.0.116", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["KUECHE", "KUECHE", "KUECHE", "KUECHE", "KUECHE", "KUECHE", "KUECHE"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,11,14,17], "DATAMASKLEN", [1,1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_6", {"NAME","Heizung EG", "DEVICEID","6", "IP","192.168.0.117", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "YES", "DATAMASKRAUM", ["FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "ESSZIMMER", "KUECHE"], "DATAMASKELEMENT", ["STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG"], "DATAMASKPOS", [7,7,8,9,9,10], "DATAMASKLEN", [1,1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_7", {"NAME","Flur KG", "DEVICEID","7", "IP","192.168.0.118", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["FLUR_KG", "FLUR_KG", "FLUR_KG", "FLUR_KG", "FLUR_KG", "FLUR_KG"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,13,16], "DATAMASKLEN", [1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_8", {"NAME","Hausanschlussraum", "DEVICEID","8", "IP","192.168.0.119", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["HAUSANSCHLUSSRAUM"], "DATAMASKELEMENT", ["STATUS_LAMPE1"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_9", {"NAME","Schlafzimmer", "DEVICEID","9", "IP","192.168.0.120", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["SCHLAFZIMMER", "SCHLAFZIMMER", "SCHLAFZIMMER", "SCHLAFZIMMER", "SCHLAFZIMMER", "SCHLAFZIMMER", "SCHLAFZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,11,14,17], "DATAMASKLEN", [1,1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_10", {"NAME","Vorratsraum", "DEVICEID","10", "IP","192.168.0.121", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["VORRATSRAUM"], "DATAMASKELEMENT", ["STATUS_LAMPE1"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_11", {"NAME","Kinderzimmer", "DEVICEID","11", "IP","192.168.0.122", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["KINDERZIMMER", "KINDERZIMMER", "KINDERZIMMER", "KINDERZIMMER", "KINDERZIMMER", "KINDERZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,13,16], "DATAMASKLEN", [1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_12", {"NAME","Gaestezimmer", "DEVICEID","12", "IP","192.168.0.123", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["GAESTEZIMMER", "GAESTEZIMMER", "GAESTEZIMMER", "GAESTEZIMMER", "GAESTEZIMMER", "GAESTEZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE"], "DATAMASKPOS", [7,8,9,10,13,16], "DATAMASKLEN", [1,1,1,3,3,3], "ONRECEIVED", undef}, "DEVICE_13", {"NAME","Bad", "DEVICEID","13", "IP","192.168.0.124", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["BADEZIMMER", "BADEZIMMER", "BADEZIMMER", "BADEZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4"], "DATAMASKPOS", [7,8,9,10], "DATAMASKLEN", [1,1,1,1], "ONRECEIVED", undef}, "DEVICE_14", {"NAME","Heizung KG", "DEVICEID","14", "IP","192.168.0.125", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "YES", "DATAMASKRAUM", ["FLUR_KG", "VORRATSRAUM", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER", "BADEZIMMER"], "DATAMASKELEMENT", ["STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG", "STATUS_HEIZUNG"], "DATAMASKPOS", [7,7,8,9,10,11], "DATAMASKLEN", [1,1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_15", {"NAME","Tueren und Fenster", "DEVICEID","15", "IP","192.168.0.126", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["FLUR_EG", "FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER"], "DATAMASKELEMENT", ["STATUS_HAUSTUER", "STATUS_HAUSTUER_ABGESCHLOSSEN", "STATUS_FENSTER", "STATUS_FENSTER", "STATUS_FENSTER", "STATUS_FENSTER", "STATUS_FENSTER", "STATUS_FENSTER", "STATUS_KELLERTUER", "STATUS_KELLERTUER_ABGESCHLOSSEN", "STATUS_FENSTER", "STATUS_FENSTER", "STATUS_FENSTER"], "DATAMASKPOS", [7,8,9,10,11,12,13,14,15,16,18,17,19], "DATAMASKLEN", [1,1,1,1,1,1,1,1,1,1,1,1,1], "ONRECEIVED", \&TUERENFENSTER_ONRECEIVED}, "DEVICE_16", {"NAME","Musikmatrix", "DEVICEID","16", "IP","192.168.0.127", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "MUSIKMATRIX", "WOHNZIMMER_LINKS", "ESSZIMMER", "KUECHE", "SCHLAFZIMMER", "BADEZIMMER"], "DATAMASKELEMENT", ["STATUS_AUSGANGSROUTING_SOLL1", "STATUS_AUSGANGSROUTING_SOLL2", "STATUS_AUSGANGSROUTING_SOLL3", "STATUS_AUSGANGSROUTING_SOLL4", "STATUS_AUSGANGSROUTING_SOLL5", "STATUS_AUSGANGSROUTING_SOLL6", "STATUS_AUSGANGSROUTING_SOLL7", "STATUS_AUSGANGSROUTING_SOLL8", "STATUS_AUSGANGSROUTING_IST1", "STATUS_AUSGANGSROUTING_IST2", "STATUS_AUSGANGSROUTING_IST3", "STATUS_AUSGANGSROUTING_IST4", "STATUS_AUSGANGSROUTING_IST5", "STATUS_AUSGANGSROUTING_IST6", "STATUS_AUSGANGSROUTING_IST7", "STATUS_AUSGANGSROUTING_IST8", "STATUS_EINGANG1", "STATUS_EINGANG2", "STATUS_EINGANG3", "STATUS_EINGANG4", "STATUS_EINGANG5", "STATUS_EINGANG6", "STATUS_EINGANG7", "STATUS_EINGANG8", "STATUS_AUTOROUTING1", "STATUS_AUTOROUTING2", "STATUS_AUTOROUTING3", "STATUS_AUTOROUTING4", "STATUS_AUTOROUTING5", "STATUS_AUTOROUTING6", "STATUS_AUTOROUTING7", "STATUS_AUTOROUTING8", "STATUS_LAUTSPRECHER", "STATUS_LAUTSPRECHER", "STATUS_LAUTSPRECHER", "STATUS_LAUTSPRECHER", "STATUS_LAUTSPRECHER"], "DATAMASKPOS", [7,8,9,10,11,12,13,14, 16,17,18,19,20,21,22,23, 25,26,27,28,29,30,31,32, 34,37,40,43,46,49,52,55, 16,18,19,21,22], "DATAMASKLEN", [1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 3,3,3,3,3,3,3,3, 1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_17", {"NAME","Terrasse", "DEVICEID","17", "IP","192.168.0.128", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["TERRASSE", "TERRASSE", "TERRASSE", "TERRASSE", "TERRASSE", "TERRASSE"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_LAMPE6"], "DATAMASKPOS", [7,8,9,10,11,12], "DATAMASKLEN", [1,1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_18", {"NAME","Zisterne", "DEVICEID","18", "IP","192.168.0.129", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_19", {"NAME","Werkstatt", "DEVICEID","19", "IP","192.168.0.130", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["WERKSTATT", "WERKSTATT", "WERKSTATT", "WERKSTATT", "WERKSTATT", "WERKSTATT", "WERKSTATT", "WERKSTATT", "WERKSTATT"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_LAMPE6", "STATUS_HOFTUER", "STATUS_KELLERTUER", "STATUS_FENSTER"], "DATAMASKPOS", [7,8,9,10,11,12,14,15,16], "DATAMASKLEN", [1,1,1,1,1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_20", {"NAME","Garagentore", "DEVICEID","20", "IP","192.168.0.131", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_21", {"NAME","Garagenlicht", "DEVICEID","21", "IP","192.168.0.132", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["GARAGE_VERMIETER", "GARAGE_VERMIETER", "GARAGE_VERMIETER", "GARAGE_VERMIETER", "GARAGE_VERMIETER", "GARAGE_VERMIETER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_LAMPE6"], "DATAMASKPOS", [7,8,9,10,11,12], "DATAMASKLEN", [1,1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_22", {"NAME","Garagenlager", "DEVICEID","22", "IP","192.168.0.133", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["GARAGE_LAGER", "GARAGE_LAGER", "GARAGE_FLUR", "GARAGE_WC", "GARAGE_LAGER"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE1", "STATUS_LAMPE1", "STATUS_TUER"], "DATAMASKPOS", [7,8,9,10,13], "DATAMASKLEN", [1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_23", {"NAME","Gartenhaus", "DEVICEID","23", "IP","192.168.0.134", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["GARTENHAUS", "GARTENHAUS", "GARTENHAUS", "GARTENHAUS"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4"], "DATAMASKPOS", [7,8,9,10], "DATAMASKLEN", [1,1,1,1], "ONRECEIVED", undef}, "DEVICE_24", {"NAME","Garten", "DEVICEID","24", "IP","192.168.0.135", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["GARTEN", "GARTEN", "GARTEN", "GARTEN", "GARTEN", "GARTEN", "GARTEN", "GARTEN"], "DATAMASKELEMENT", ["STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_LAMPE6", "STATUS_LAMPE7", "STATUS_LAMPE8"], "DATAMASKPOS", [7,8,9,10,11,12,13,15], "DATAMASKLEN", [1,1,1,1,1,1,1,1], "ONRECEIVED", undef}, "DEVICE_25", {"NAME","Garten DMX", "DEVICEID","25", "IP","192.168.0.136", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_26", {"NAME","Aussensensor", "DEVICEID","26", "IP","192.168.0.137", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["AUSSENSENSOR", "AUSSENSENSOR", "ALARMANLAGE", "ALARMANLAGE"], "DATAMASKELEMENT", ["TEMPERATUR", "HELLIGKEIT", "RUNDUMLEUCHTE", "SIRENE"], "DATAMASKPOS", [7,13,18,20], "DATAMASKLEN", [5,4,1,1], "ONRECEIVED", \&AUSSENSENSOR_ONRECEIVED}, "DEVICE_27", {"NAME","Vorgarten und Hauseingang", "DEVICEID","27", "IP","192.168.0.138", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_28", {"NAME","Alarmanlage", "DEVICEID","28", "IP","192.168.0.139", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_29", {"NAME","Wohnzimmer TV-Wand", "DEVICEID","29", "IP","192.168.0.140", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["WOHNZIMMER_LINKS", "WOHNZIMMER_LINKS", "WOHNZIMMER_LINKS"], "DATAMASKELEMENT", ["STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5"], "DATAMASKPOS", [7,8,9], "DATAMASKLEN", [1,1,1], "ONRECEIVED", undef}, "DEVICE_30", {"NAME","Esszimmer Baeren", "DEVICEID","30", "IP","192.168.0.141", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["ESSZIMMER"], "DATAMASKELEMENT", ["STATUS_LAMPE3"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_31", {"NAME","Raspberry PI Wohnzimmer", "DEVICEID","31", "IP","192.168.0.101", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["WOHNZIMMER_LINKS"], "DATAMASKELEMENT", ["RASPBERRYBACKLIGHT"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_32", {"NAME","Raspberry PI Finisherboard", "DEVICEID","32", "IP","192.168.0.105", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["ESSZIMMER"], "DATAMASKELEMENT", ["RASPBERRYBACKLIGHT"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_33", {"NAME","Raspberry PI Haustuere", "DEVICEID","33", "IP","192.168.0.103", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["FLUR_EG"], "DATAMASKELEMENT", ["RASPBERRYBACKLIGHT"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_34", {"NAME","Raspberry PI Wecker", "DEVICEID","34", "IP","192.168.0.102", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "NO", "SKIPSTATUS", "NO", "DATAMASKRAUM", ["SCHLAFZIMMER"], "DATAMASKELEMENT", ["RASPBERRYBACKLIGHT"], "DATAMASKPOS", [7], "DATAMASKLEN", [1], "ONRECEIVED", undef}, "DEVICE_35", {"NAME","Kuechenarbeitszeile", "DEVICEID","35", "IP","192.168.0.142", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "DEVICE_36", {"NAME","Wohnzimmer Highboard", "DEVICEID","36", "IP","192.168.0.143", "LASTTRYSUCCESSFUL","NO", "LASTERROR","--", "LASTRESPONSE","0", "LASTRESPONSETIME","--", "ERRORCOUNTER","0", "ERRORNOCONNECTION", "0", "ERRORREADTIMEOUT", "0", "ERRORILLEGALRESPONSE", "0", "CONNECTIONERRORCOUNTER","0", "CONNECTIONTRYCOUNTER","0", "CONNECTIONSUCCESSFULCOUNTER","0", "ERRORSAFTERLASTSUCCESS","0", "SKIPCOMMUNICATION", "YES", "SKIPSTATUS", "NO", "DATAMASKRAUM", [], "DATAMASKELEMENT", [], "DATAMASKPOS", [], "DATAMASKLEN", [], "ONRECEIVED", undef}, "ENVIRONMENTS", {"BEWOHNERANWESEND", "0", "HELL","1", "DAEMMERUNG","0", "DUNKEL","0", "ZEITLICH_IST_TAG","1", "SYSTEMMODUS_TAG","1", "COMMANDS", []}, "FLUR_EG", {"NACHLAUFZEIT","5", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_FENSTER","1", "STATUS_HAUSTUER","1", "STATUS_HAUSTUER_ABGESCHLOSSEN","1", "STATUS_HEIZUNG","0", "RASPBERRYBACKLIGHT","0"}, "WC", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0"}, "ARBEITSZIMMER", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0"}, "WOHNZIMMER_LINKS", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0", "STATUS_LAUTSPRECHER","1", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "RASPBERRYBACKLIGHT","0"}, "WOHNZIMMER_RECHTS", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1"}, "ESSZIMMER", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0", "STATUS_LAUTSPRECHER","1", "RASPBERRYBACKLIGHT","0"}, "KUECHE", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0", "STATUS_LAUTSPRECHER","1"}, "FLUR_KG", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "NACHLAUFZEIT","5", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_KELLERTUER","1", "STATUS_KELLERTUER_ABGESCHLOSSEN","1", "STATUS_HEIZUNG","0"}, "HAUSANSCHLUSSRAUM", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0"}, "SCHLAFZIMMER", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0", "STATUS_LAUTSPRECHER","1", "RASPBERRYBACKLIGHT","0"}, "VORRATSRAUM", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_HEIZUNG","0"}, "KINDERZIMMER", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0"}, "GAESTEZIMMER", {"TAG_NACHTGESTEUERT","1", "ZEIT_AUF","07:00", "ZEIT_ZU","07:00", "MORGENS_GANZ_AUF","1", "BEWOHNERGESTEUERT","1", "BEWOHNERGESTEUERT_RESTOEFFNUNG","040", "NACHTS_FENSTERGESTEUERT","1", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG","020", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_MOTOR_AB","0", "STATUS_MOTOR_AUF","0", "POSITION_ROLLO_IST","000", "POSITION_ROLLO_SOLL","000", "POSITION_ROLLO_LETZTE_MANUELLE","000", "BEWOHNERANWESEND","0", "TAGMODUS","0", "STATUS_NACHTS_FENSTER", "0", "STATUS_FENSTER","1", "STATUS_HEIZUNG","0"}, "BADEZIMMER", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_HEIZUNG","0", "STATUS_LAUTSPRECHER","0"}, "VORGARTEN", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "AUTOTAGESLICHT_HAUSNUMMER","0", "AUTOTAGESLICHT_BRUNNEN","0", "AUTOTAGESLICHT_BELEUCHTUNG","0"}, "HAUSEINGANG", {"AUTOTAGESLICHT_STECKDOSE","0"}, "TERRASSE", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "AUTOTAGESLICHT_BELEUCHTUNG","0"}, "ZISTERNE", {"FUELLSTAND","000", "WASSERDRUCK","0.0", "FRISCHWASSERNUTZUNG","0"}, "WERKSTATT", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "STATUS_FENSTER","0", "STATUS_HOFTUER","1", "STATUS_KELLERTUER","0"}, "GARAGE_VERMIETER", {"STATUS_TORLICHT","0", "STATUS_TOR","0", "TORCODE1","0000", "TORCODE2","0000", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0"}, "GARAGE_MIETER", {"STATUS_TORLICHT","0", "STATUS_TOR","1", "TORCODE1","0000", "TORCODE2","0000", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0"}, "GARAGE_LAGER", {"STATUS_TUER","1", "STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0"}, "GARAGE_FLUR", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0"}, "GARAGE_WC", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0"}, "GARTEN", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "AUTOTAGESLICHT_STECKDOSE_WASSERTANK","0", "AUTOTAGESLICHT_STECKDOSE_TERRASSE","0"}, "GARTENHAUS", {"STATUS_LAMPE1","0", "STATUS_LAMPE2","0", "STATUS_LAMPE3","0", "STATUS_LAMPE4","0", "STATUS_LAMPE5","0", "STATUS_LAMPE6","0", "STATUS_LAMPE7","0", "STATUS_LAMPE8","0", "AUTOTAGESLICHT_STECKDOSE_GARAGENDACH","0"}, "AUSSENSENSOR", {"HELLIGKEIT","0000", "DAEMMERUNG_SCHWELLWERT","0500", "DUNKELHEIT_SCHWELLWERT","0150", "HELL","1", "DAEMMERUNG","0", "DUNKEL","0", "TEMPERATUR","+00.0", "TAG_IST_MINDESTENS_BIS","19", "TAG_IST_FRUEHESTENS_VON","07", "ZEITLICH_IST_TAG","1", "SYSTEMMODUS_TAG","1"}, "ALARMANLAGE", {"STATUS","0", # Status 0 -> AUS # Status 1 -> "Scharf" # Status 2 -> ausgelöst, wartend # Status 3 -> ausgelöst "SAFE_HAUSTUER","1", "SAFE_HAUSTUER_ABGESCHLOSSEN","1", "SAFE_FENSTER_WC","1", "SAFE_FENSTER_ARBEITSZIMMER","1", "SAFE_FENSTER_WOHNZIMMER_LINKS","1", "SAFE_FENSTER_WOHNZIMMER_RECHTS","1", "SAFE_FENSTER_ESSZIMMER","1", "SAFE_FENSTER_KUECHE","0", "SAFE_KELLERTUER","1", "SAFE_KELLERTUER_ABGESCHLOSSEN","1", "SAFE_FENSTER_SCHLAFZIMMER","1", "SAFE_FENSTER_KINDERZIMMER","1", "SAFE_FENSTER_GAESTEZIMMER","1", "ALARMDAUER_SIRENE","010", "ALARMDAUER_HAUSMELDER","600", "SIRENE","0", "RUNDUMLEUCHTE","0", "PIN1","", "PIN2","", "PIN3","", "PIN4","", "PIN5","", "PIN6","", "PIN7","", "PIN8","", "HAUSTUERGESTEUERT","1", "ALARMDELAY","-1", "ALARMDELAYINI","30"}, "MUSIKMATRIX", {"STATUS_AUSGANGSROUTING_SOLL1","1", "STATUS_AUSGANGSROUTING_SOLL2","0", "STATUS_AUSGANGSROUTING_SOLL3","0", "STATUS_AUSGANGSROUTING_SOLL4","0", "STATUS_AUSGANGSROUTING_SOLL5","0", "STATUS_AUSGANGSROUTING_SOLL6","0", "STATUS_AUSGANGSROUTING_SOLL7","0", "STATUS_AUSGANGSROUTING_SOLL8","0", "STATUS_AUSGANGSROUTING_IST1","1", "STATUS_AUSGANGSROUTING_IST2","0", "STATUS_AUSGANGSROUTING_IST3","0", "STATUS_AUSGANGSROUTING_IST4","0", "STATUS_AUSGANGSROUTING_IST5","0", "STATUS_AUSGANGSROUTING_IST6","0", "STATUS_AUSGANGSROUTING_IST7","0", "STATUS_AUSGANGSROUTING_IST8","0", "STATUS_EINGANG1","1", "STATUS_EINGANG2","0", "STATUS_EINGANG3","0", "STATUS_EINGANG4","0", "STATUS_EINGANG5","0", "STATUS_EINGANG6","0", "STATUS_EINGANG7","0", "STATUS_EINGANG8","0", "STATUS_AUTOROUTING1","001", "STATUS_AUTOROUTING2","013", "STATUS_AUTOROUTING3","013", "STATUS_AUTOROUTING4","008", "STATUS_AUTOROUTING5","096", "STATUS_AUTOROUTING6","032", "STATUS_AUTOROUTING7","000", "STATUS_AUTOROUTING8","000"}, "WECKER", {"ALARM_ZEIT","07_30", "ALARM_EINGESCHALTET","0", "ALARM_DECKENLAMPE_EIN","1", "ALARM_WANDLAMPE_EIN","1", "ALARM_LAMPEN_NUR_BEI_DUNKELHEIT","1", "PLAYERINDEX","2", "SLEEPZEIT","020"} ); #use strict; use POSIX qw/ strftime /; use IO::Socket::INET; use IO::Socket::Timeout; use Errno qw(ETIMEDOUT EWOULDBLOCK); use Time::HiRes; use Time::HiRes qw(usleep nanosleep); use Time::HiRes 'time'; use Storable; use LWP::Simple qw ($ua head get); $ua->timeout(read_data("GENERAL", "TIMEOUTGETURL")); # Timeout für GET / GET-Webpage use Fcntl; use File::Copy; $| = 1; # flush after every write # Zeitvariablen my $DateForHuman = strftime("%d.%m.%Y", localtime); my $TimeForHuman = strftime("%H:%M:%S", localtime); my $DateForFiles = strftime("%Y%m%d", localtime); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); my $Timer1SekundeAlteZeit = time(); # Server Variablen # Variablen die zur Socket-Kommunication mit dem Webserver dienen my $ServerSocket; my $ClientSocket; my $ServerSocketFlags; my $ClientReceivedData; my $ClientSendData; # Polling-Client Variablen # Variablen die zur Socket-Kommunication mit den Aktoren dienen (polling) my $MasterSocket; my $MasterSocketResponse; # Variablen zur Befehlsverarbeitung my %Command = ("ID","","SEND","","COUNT",""); my $CommandLine = ""; # Variablen zum laden/speichern de Configdatei my @ConfigFileLineSplitt; my $ConfigFileLine; my $Gruppe; my $Element; #Allgemeine Variablen my $Nil; my $INDEX; my $RAUM; my %RAUM; my $Befehl; my %ID; my $PARAMETER; my $CurentDeviceID = -1; write_errorlog("Service-Start at $DateForHuman, $TimeForHuman","2"); write_data("GENERAL", "SYSTEMSTARTTIME", strftime("%H:%M:%S", localtime)); write_data("GENERAL", "SYSTEMSTARTDATE", strftime("%d.%m.%Y", localtime)); debug("ACHTUNG: Debug-Mode ist eingeschaltet!!"); # Reload Data from file if possible debug("Reload Data from INI-file: ".read_data("FILES", "CONFIGFILE")); open ConfigFileObject, "< ".read_data("FILES", "CONFIGFILE") || write_errorlog("ERROR: $! : ".read_data("FILES", "CONFIGFILE"),"3"); while (! eof(ConfigFileObject)) { $ConfigFileLine = ; # Entferne die letzten beiden Zeichen im String. Dabei handelt es sich um $ConfigFileLine = substr($ConfigFileLine,0,-1); @ConfigFileLineSplitt = split /[|]/, $ConfigFileLine; # Ausnahmen, die NICHT aus der Datei syncronisiert werde dürfen! if (($ConfigFileLineSplitt[0] ne "FILES") and ($ConfigFileLineSplitt[0] ne "GENERAL") and ($ConfigFileLineSplitt[0] ne "LOAD_AVERAGE") and (index($ConfigFileLineSplitt[0], "DEVICE_") eq -1)) { write_data($ConfigFileLineSplitt[0], $ConfigFileLineSplitt[1], $ConfigFileLineSplitt[2]); } } close(ConfigFileObject); # Creat Server-Socket for connections FROM the ClientSevices and WebServices debug("Try to open the Server-Socket on Port 5000..."); $ServerSocket = new IO::Socket::INET ( LocalHost => '0.0.0.0', LocalPort => '5000', Proto => 'tcp', Listen => 5, Reuse => 1, ); unless ($ServerSocket) { write_errorlog("ERROR by creating ServerSocket : $!","3"); } use Fcntl qw(F_GETFL F_SETFL O_NONBLOCK); $ServerSocketFlags = fcntl($ServerSocket, F_GETFL, 0) or write_errorlog("ERROR: Can't get flags for the Server-Socket: $!","3"); fcntl($ServerSocket, F_SETFL, $ServerSocketFlags | O_NONBLOCK) or write_errorlog("ERROR: Can't set new flags for the Server-Socket: $!","3"); debug("Now listen on Port 5000!"); ################################################################################################################################################################## ################################################################################################################################################################## # Subroutines: ################################################################################################################################################### ################################################################################################################################################################## ################################################################################################################################################################## sub Timer_1Sekunde { if ($Timer1SekundeAlteZeit < time()) { $Timer1SekundeAlteZeit = int(time())+1; # SEKUNDENTIMER!! # Diese Routine wird jede Sekunde aufgerufen $DateForHuman = strftime("%d.%m.%Y", localtime); $TimeForHuman = strftime("%H:%M:%S", localtime); $DateForFiles = strftime("%Y%m%d", localtime); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); # Load Average Data / ID if (read_data("LOAD_AVERAGE", "SECCOUNTER") eq "59") { if (read_data("LOAD_AVERAGE", "ID") eq "9") { write_data("LOAD_AVERAGE", "ID", "0"); } else { write_data("LOAD_AVERAGE", "ID", read_data("LOAD_AVERAGE", "ID", "0")+1 ); } write_data("LOAD_AVERAGE", "SECCOUNTER", "0"); write_data("LOAD_AVERAGE", "MINUTE_".read_data("LOAD_AVERAGE", "ID"), "0"); } else { write_data("LOAD_AVERAGE", "SECCOUNTER", read_data("LOAD_AVERAGE", "SECCOUNTER")+1); }; # check Zeitbasierte Steuerung debug("Checking environments...Zeitlich ist Tag?..."); if (($hour >= read_data("AUSSENSENSOR", "TAG_IST_FRUEHESTENS_VON")) and ($hour < read_data("AUSSENSENSOR", "TAG_IST_MINDESTENS_BIS")) and (read_data("AUSSENSENSOR", "ZEITLICH_IST_TAG") eq "0")) { debug("Checking environments...Zeitlich ist Tag?...Zeitliche Tagumschaltung"); write_data("AUSSENSENSOR", "ZEITLICH_IST_TAG", "1"); } elsif ((($hour >= read_data("AUSSENSENSOR", "TAG_IST_MINDESTENS_BIS")) or ($hour < read_data("AUSSENSENSOR", "TAG_IST_FRUEHESTENS_VON"))) and (read_data("AUSSENSENSOR", "ZEITLICH_IST_TAG") eq "1")) { debug("Checking environments...Zeitlich ist Tag?...Zeitliche Nachtumschaltung"); write_data("AUSSENSENSOR", "ZEITLICH_IST_TAG", "0"); }; # Check Alarmanlage if (read_data("ALARMANLAGE", "STATUS") eq 2) { write_data("ALARMANLAGE", "ALARMDELAY", read_data("ALARMANLAGE", "ALARMDELAY")-1); if (read_data("ALARMANLAGE", "ALARMDELAY") eq 0) { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "26", "SEND", "SIRENE!".read_data("ALARMANLAGE", "ALARMDAUER_SIRENE"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "28", "SEND", "SIRENE!".read_data("ALARMANLAGE", "ALARMDAUER_HAUSMELDER"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; telegrammessage("Alarmanlage wurde ausgelöst !!!!"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "26", "SEND", "RUNDUMLEUCHTE!1", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data("ALARMANLAGE", "STATUS", "3"); }; }; # check Garagentor Status debug("Checking environments...Garagentor..."); $Nil=get("http://192.168.0.2/cgi-bin/rs485_getdata.pl?get=B16"); if (read_data("GARAGE_VERMIETER", "STATUS_TOR") ne substr($Nil, 16,1)) { debug("New status Garagentor: Tor offen = ".substr($Nil,16,1)); if (substr($Nil, 16,1) eq "0") { write_data("GARAGE_VERMIETER", "STATUS_TOR", "0"); } elsif (substr($Nil, 16,1) eq "1") { write_data("GARAGE_VERMIETER", "STATUS_TOR", "1"); }; }; debug("Checking environments...Garagentorbeleuchtung Mieter..."); if ((substr($Nil, 29,1) eq "0") and (read_data("GARAGE_MIETER", "STATUS_TORLICHT") eq "1")) { debug("New status Garagentore Mieter: Garagenbeleuchtung ausschalten."); write_data("GARAGE_MIETER", "STATUS_TORLICHT", "0"); } elsif ((substr($Nil, 29,1) eq "1") and (read_data("GARAGE_MIETER", "STATUS_TORLICHT") eq "0")) { debug("New status Garagentore Mieter: Garagenbeleuchtung einschalten."); write_data("GARAGE_MIETER", "STATUS_TORLICHT", "1"); }; debug("Checking environments...Garagentorbeleuchtung Vermieter..."); if ((substr($Nil, 18,1) eq "0") and (read_data("GARAGE_VERMIETER", "STATUS_TORLICHT") eq "1")) { debug("New status Garagentore Vermieter: Garagenbeleuchtung ausschalten."); write_data("GARAGE_VERMIETER", "STATUS_TORLICHT", "0"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "21", "SEND", "TOROFFEN!0", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } elsif ((substr($Nil, 18,1) eq "1") and (read_data("GARAGE_VERMIETER", "STATUS_TORLICHT") eq "0")) { debug("New status Garagentore Vermieter: Garagenbeleuchtung einschalten."); write_data("GARAGE_VERMIETER", "STATUS_TORLICHT", "1"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "21", "SEND", "TOROFFEN!1", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; }; debug("Checking environments...Garagentor-Hofbeleuchtung..."); # Wenn eines der beides Garagentore gefahren wird (das TorLicht eingaschlatet ist) und es dunkel ist if (((read_data("GARAGE_VERMIETER", "STATUS_TORLICHT") eq "1") or (read_data("GARAGE_MIETER", "STATUS_TORLICHT") eq "1")) and (read_data("AUSSENSENSOR", "HELL") eq "0")and (read_data("TERRASSE", "STATUS_LAMPE1") ne "A")) { debug("New Status Hofbeleuchtung: Automatik an wegen Garagentor"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "17", "SEND", "TOROFFEN!1", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } elsif ((read_data("GARAGE_VERMIETER", "STATUS_TORLICHT") eq "0") and (read_data("GARAGE_MIETER", "STATUS_TORLICHT") eq "0") and (read_data("TERRASSE", "STATUS_LAMPE1") eq "A")) { debug("New Status Hofbeleuchtung: Automatik aus wegen Garagentor"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "17", "SEND", "TOROFFEN!0", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; }; }; }; ################################################################################################################################################################## ################################################################################################################################################################## sub TUERENFENSTER_ONRECEIVED { my ($RECEIVEDDATA) = @_; if (read_data("FLUR_EG", "STATUS_HAUSTUER_ABGESCHLOSSEN") eq "1") { write_data("FLUR_EG", "STATUS_FENSTER", "2"); } else { write_data("FLUR_EG", "STATUS_FENSTER", read_data("FLUR_EG", "STATUS_HAUSTUER")); }; if (read_data("FLUR_KG", "STATUS_KELLERTUER_ABGESCHLOSSEN") eq "1") { write_data("FLUR_KG", "STATUS_FENSTER", "2"); } else { write_data("FLUR_KG", "STATUS_FENSTER", read_data("FLUR_KG", "STATUS_KELLERTUER")); }; if ((read_data("ENVIRONMENTS", "BEWOHNERANWESEND") eq "1") and (read_data("FLUR_EG", "STATUS_HAUSTUER_ABGESCHLOSSEN") eq "1")) { debug("Haustuere wurde verschlossen, niemand anwesend..."); write_data("ENVIRONMENTS", "BEWOHNERANWESEND", "0"); # Übergangsweise wird hier ein "PING"-Befehl gesendet. get("http://192.168.0.2/cgi-bin/rs485_send.pl?befehl=!PING00000000"); # ...schicke die Raspberrys in den Schlaf debug("Raspberry Backlight aus..."); foreach $INDEX ( "31", "32", "33", "34" ) { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $INDEX, "SEND", "BACKLIGHT!0", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } # ...schalte Lampen aus debug("Lampen aus..."); # Für STANDARD-Lampenaktoren foreach $INDEX ( "1", "2", "3", "4", "5", "7", "8", "9", "10", "11", "12", "13", "19", "21", "22", "23", "24", "29", "30", "35", "36" ) { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $INDEX, "SEND", "LAMPE!00000000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } # Die Baumbeleuchtung wird automatisch bei Dunkelheit bis zum Nachtmodus eingeschaltet und sollte hier nicht abgeschaltet werden. push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "17", "SEND", "LAMPE!00020000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } elsif ((read_data("ENVIRONMENTS", "BEWOHNERANWESEND") eq "0") and (read_data("FLUR_EG", "STATUS_HAUSTUER_ABGESCHLOSSEN") eq "0")) { debug("Haustuere wurde aufgeschlossen, Bewohner anwesend..."); write_data("ENVIRONMENTS", "BEWOHNERANWESEND", "1"); # Übergangsweise wird hier ein "PING"-Befehl gesendet. get("http://192.168.0.2/cgi-bin/rs485_send.pl?befehl=!PING00000001"); # ...wecke die Raspberrys aus dem Schlaf debug("Raspberry Backlight an..."); foreach $INDEX ( "31", "32", "33", "34" ) { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $INDEX, "SEND", "BACKLIGHT!1", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } } set_new_rollopos(); # Die Tuer- und Fensterdaten auch für die Alarmanlage speichern, wenn diese DEaktiviert ist if (read_data("ALARMANLAGE", "STATUS") eq "0") { write_data("ALARMANLAGE", "SAFE_HAUSTUER", read_data("FLUR_EG", "STATUS_HAUSTUER")); write_data("ALARMANLAGE", "SAFE_HAUSTUER_ABGESCHLOSSEN", read_data("FLUR_EG", "STATUS_HAUSTUER_ABGESCHLOSSEN")); if ((read_data("ALARMANLAGE", "HAUSTUERGESTEUERT") eq "1") and (read_data("ALARMANLAGE", "SAFE_HAUSTUER_ABGESCHLOSSEN") eq "1")) { write_data("ALARMANLAGE", "STATUS", "1"); debug("Haustuere verschlossen: Alarmanlage aktiviert!"); }; write_data("ALARMANLAGE", "SAFE_FENSTER_WC", read_data("WC", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_ARBEITSZIMMER", read_data("ARBEITSZIMMER", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_WOHNZIMMER_LINKS", read_data("WOHNZIMMER_LINKS", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_WOHNZIMMER_RECHTS", read_data("WOHNZIMMER_RECHTS", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_ESSZIMMER", read_data("ESSZIMMER", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_KUECHE", read_data("KUECHE", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_KELLERTUER", read_data("FLUR_KG", "STATUS_KELLERTUER")); write_data("ALARMANLAGE", "SAFE_KELLERTUER_ABGESCHLOSSEN", read_data("FLUR_KG", "STATUS_KELLERTUER_ABGESCHLOSSEN")); write_data("ALARMANLAGE", "SAFE_FENSTER_SCHLAFZIMMER", read_data("SCHLAFZIMMER", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_KINDERZIMMER", read_data("KINDERZIMMER", "STATUS_FENSTER")); write_data("ALARMANLAGE", "SAFE_FENSTER_GAESTEZIMMER", read_data("GAESTEZIMMER", "STATUS_FENSTER")); # Wenn diese jedoch aktiviert ist, vergleiche die Sensoren mit den abgespeicherten Werten } elsif (read_data("ALARMANLAGE", "STATUS") eq "1") { if ((read_data("ALARMANLAGE", "HAUSTUERGESTEUERT") eq "1") and (read_data("FLUR_EG", "STATUS_HAUSTUER_ABGESCHLOSSEN") eq "0")) { write_data("ALARMANLAGE", "STATUS", "0"); }; if ((read_data("ALARMANLAGE", "HAUSTUERGESTEUERT") eq "1") and (read_data("FLUR_EG", "STATUS_HAUSTUER_ABGESCHLOSSEN") eq "0")) { write_data("ALARMANLAGE", "STATUS", "0"); debug("Haustuere unverschlossen: Alarmanlage deaktiviert!"); } elsif ((read_data("ALARMANLAGE", "SAFE_HAUSTUER") ne read_data("FLUR_EG", "STATUS_HAUSTUER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_WC") ne read_data("WC", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_ARBEITSZIMMER") ne read_data("ARBEITSZIMMER", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_WOHNZIMMER_LINKS") ne read_data("WOHNZIMMER_LINKS", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_WOHNZIMMER_RECHTS") ne read_data("WOHNZIMMER_RECHTS", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_ESSZIMMER") ne read_data("ESSZIMMER", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_KUECHE") ne read_data("KUECHE", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_KELLERTUER") ne read_data("FLUR_KG", "STATUS_KELLERTUER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_SCHLAFZIMMER") ne read_data("SCHLAFZIMMER", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_KINDERZIMMER") ne read_data("KINDERZIMMER", "STATUS_FENSTER")) or (read_data("ALARMANLAGE", "SAFE_FENSTER_GAESTEZIMMER") ne read_data("GAESTEZIMMER", "STATUS_FENSTER"))) { write_data("ALARMANLAGE", "STATUS", "2"); write_data("ALARMANLAGE", "ALARMDELAY", read_data("ALARMANLAGE", "ALARMDELAYINI")); } } # ACHTUNG: Hier wird für das RS485 System die Daten auf dessen Bus gesendet get("http://192.168.0.2/cgi-bin/rs485_send.pl?befehl=%26A".substr($RECEIVEDDATA,7,1).substr($RECEIVEDDATA,9,7)."0".substr($RECEIVEDDATA,17,1)."0".substr($RECEIVEDDATA,18,2)."0".substr($RECEIVEDDATA,8,1).substr($RECEIVEDDATA,16,1)."1"); # Sende die Tuer und Fenster Statusdaten an das Heizungsystem debug("Sende neue Tueren / Fenster Status an das Heizungssystem..."); $Befehl = "FENSTER!" . read_data("FLUR_EG", "STATUS_FENSTER") . read_data("WC", "STATUS_FENSTER") . read_data("ARBEITSZIMMER", "STATUS_FENSTER"); $Befehl = $Befehl . read_data("WOHNZIMMER_LINKS", "STATUS_FENSTER") . read_data("WOHNZIMMER_RECHTS", "STATUS_FENSTER"); $Befehl = $Befehl . read_data("ESSZIMMER", "STATUS_FENSTER") . read_data("KUECHE", "STATUS_FENSTER"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "6", "SEND", $Befehl, "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; $Befehl = "FENSTER!" . read_data("FLUR_KG", "STATUS_FENSTER") . read_data("SCHLAFZIMMER", "STATUS_FENSTER") . read_data("KINDERZIMMER", "STATUS_FENSTER") . read_data("GAESTEZIMMER", "STATUS_FENSTER"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "14", "SEND", $Befehl, "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } ################################################################################################################################################################## ################################################################################################################################################################## sub AUSSENSENSOR_ONRECEIVED { my ($RECEIVEDDATA) = @_; debug("Checking environments...Aussensensor...Hell/Daemmerung/Dunkel"); # HELL if ((read_data("AUSSENSENSOR", "HELLIGKEIT") > read_data("AUSSENSENSOR", "DAEMMERUNG_SCHWELLWERT")) and (read_data("AUSSENSENSOR", "HELL") eq "0")) { debug("Checking environments...Aussensensor...Es wird Hell"); write_data("AUSSENSENSOR", "HELL", "1"); write_data("AUSSENSENSOR", "DAEMMERUNG", "0"); write_data("AUSSENSENSOR", "DUNKEL", "0"); write_data("ENVIRONMENTS", "HELL", "1"); write_data("ENVIRONMENTS", "DAEMMERUNG", "0"); write_data("ENVIRONMENTS", "DUNKEL", "0"); if (read_data("TERRASSE", "AUTOTAGESLICHT_BELEUCHTUNG") eq "1") { # Terrasse, Baumbeleuchtung push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "17", "SEND", "LAMPE!222022", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "19", "SEND", "HELL!1", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; # Daemmerung } elsif ((read_data("AUSSENSENSOR", "HELLIGKEIT") < read_data("AUSSENSENSOR", "DAEMMERUNG_SCHWELLWERT")) and (read_data("AUSSENSENSOR", "HELLIGKEIT") > read_data("AUSSENSENSOR", "DUNKELHEIT_SCHWELLWERT")) and (read_data("AUSSENSENSOR", "DAEMMERUNG") eq "0")) { debug("Checking environments...Aussensensor...Es Daemmert"); write_data("AUSSENSENSOR", "HELL", "0"); write_data("AUSSENSENSOR", "DAEMMERUNG", "1"); write_data("AUSSENSENSOR", "DUNKEL", "0"); write_data("ENVIRONMENTS", "HELL", "0"); write_data("ENVIRONMENTS", "DAEMMERUNG", "1"); write_data("ENVIRONMENTS", "DUNKEL", "0"); if (read_data("TERRASSE", "AUTOTAGESLICHT_BELEUCHTUNG") eq "1") { # Terrasse, Baumbeleuchtung push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "17", "SEND", "LAMPE!222122", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "19", "SEND", "HELL!0", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; # Dunkel } elsif ((read_data("AUSSENSENSOR", "HELLIGKEIT") < read_data("AUSSENSENSOR", "DUNKELHEIT_SCHWELLWERT")) and (read_data("AUSSENSENSOR", "DUNKEL") eq "0")) { debug("Checking environments...Aussensensor...Es wird Dunkel"); write_data("AUSSENSENSOR", "HELL", "0"); write_data("AUSSENSENSOR", "DAEMMERUNG", "0"); write_data("AUSSENSENSOR", "DUNKEL", "1"); write_data("ENVIRONMENTS", "HELL", "0"); write_data("ENVIRONMENTS", "DAEMMERUNG", "0"); write_data("ENVIRONMENTS", "DUNKEL", "1"); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "19", "SEND", "HELL!0", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } debug("Checking environments...Aussensensor...Tag/Nacht"); if ((read_data("AUSSENSENSOR", "DUNKEL") eq "1") and (read_data("AUSSENSENSOR", "ZEITLICH_IST_TAG") eq "0") and (read_data("AUSSENSENSOR", "SYSTEMMODUS_TAG") eq "1")) { debug("Checking environments...Aussensensor...Nachtumschaltung..."); write_data("AUSSENSENSOR", "SYSTEMMODUS_TAG", "0"); write_data("ENVIRONMENTS", "SYSTEMMODUS_TAG", "0"); if (read_data("TERRASSE", "AUTOTAGESLICHT_BELEUCHTUNG") eq "1") { # Terrasse, Baumbeleuchtung push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "17", "SEND", "LAMPE!222022", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } } elsif ((read_data("AUSSENSENSOR", "HELL") eq "1") and (read_data("AUSSENSENSOR", "ZEITLICH_IST_TAG") eq "1") and (read_data("AUSSENSENSOR", "SYSTEMMODUS_TAG") eq "0")) { debug("Checking environments...Aussensensor...Tagumschaltung..."); write_data("AUSSENSENSOR", "SYSTEMMODUS_TAG", "1"); write_data("ENVIRONMENTS", "SYSTEMMODUS_TAG", "1"); } # ACHTUNG: Hier wird für das RS485 System die Daten auf dessen Bus gesendet # &S00:01:1008.08.19+1170000 00 21:54:33S06.08.19007190090000150 get("http://192.168.0.2/cgi-bin/rs485_send.pl?befehl=%26S00:00:0001.01.19+0001111".read_data("AUSSENSENSOR", "HELL").read_data("AUSSENSENSOR", "SYSTEMMODUS_TAG")."00:00:00S01.01.1907190090000150"); } ################################################################################################################################################################## ################################################################################################################################################################## sub telegrammessage { my ($Text) = @_; # Erklärung hierzu siehe # https://www.tutonaut.de/anleitung-einfuehrung-in-telegram-bots-nachrichten-und-dateien-aus-dem-terminal-senden/ get("https://api.telegram.org/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&text=".$Text); return 1; } ################################################################################################################################################################## ################################################################################################################################################################## sub irgendeine_lampe_im_raum_an { my ($Raum) = @_; if ((read_data($Raum, "STATUS_LAMPE1") eq "1") or (read_data($Raum, "STATUS_LAMPE2") eq "1") or (read_data($Raum, "STATUS_LAMPE3") eq "1") or (read_data($Raum, "STATUS_LAMPE4") eq "1") or (read_data($Raum, "STATUS_LAMPE5") eq "1") or (read_data($Raum, "STATUS_LAMPE6") eq "1") or (read_data($Raum, "STATUS_LAMPE7") eq "1") or (read_data($Raum, "STATUS_LAMPE8") eq "1")) { return "1"; } elsif ((read_data($Raum, "STATUS_LAMPE1") eq "A") or (read_data($Raum, "STATUS_LAMPE2") eq "A") or (read_data($Raum, "STATUS_LAMPE3") eq "A") or (read_data($Raum, "STATUS_LAMPE4") eq "A") or (read_data($Raum, "STATUS_LAMPE5") eq "A") or (read_data($Raum, "STATUS_LAMPE6") eq "A") or (read_data($Raum, "STATUS_LAMPE7") eq "A") or (read_data($Raum, "STATUS_LAMPE8") eq "A")) { return "A"; } else { return "0"; }; } ################################################################################################################################################################## ################################################################################################################################################################## sub debug { my ($Debugstring) = @_; if (read_data("FILES", "DEBUG") eq "YES") { print "$DateForHuman $TimeForHuman : $Debugstring\n"; } if (read_data("FILES", "DAILYDEBUG") eq "YES") { open (DailyDebugFileObject, ">>".read_data("FILES", "DAILYDEBUGFILEPATH").$DateForFiles."_DEBUG.log") || write_errorlog("ERROR: $! : ".read_data("FILES", "CONFIGFILE"),"3"); print DailyDebugFileObject "$DateForHuman $TimeForHuman : $Debugstring\n" ; close (DailyDebugFileObject); } return 1; } ################################################################################################################################################################## ################################################################################################################################################################## sub write_errorlog { my ($Logstring, $CriticalState) = @_; debug($Logstring); if (read_data("FILES", "ERRORLOG") eq "YES") { open (ErrorFileObject, ">>".read_data("FILES", "ERRORLOGFILEPATH").$DateForFiles."_ERROR.log") || write_errorlog("ERROR: $! : ".read_data("FILES", "CONFIGFILE"),"3"); print ErrorFileObject "$DateForHuman $TimeForHuman : $Logstring\n" ; close (ErrorFileObject); } if ($CriticalState eq "2") { telegrammessage($Logstring); } elsif ($CriticalState eq "3") { telegrammessage($Logstring); telegrammessage("Prozess muss beendet werden!"); die; } } ################################################################################################################################################################## ################################################################################################################################################################## sub read_data{ my ($Section, $Parameter) = @_; if (exists $Data{$Section}{$Parameter}) { return $Data{$Section}{$Parameter}; } else { write_errorlog("ERROR by reading Data : $Section - $Parameter -> Not found!","2"); return undef; } } ################################################################################################################################################################## ################################################################################################################################################################## sub write_data{ my ($Section, $Parameter, $Wert) = @_; if ($Wert ne "") { if (exists $Data{$Section}{$Parameter}) { $Data{$Section}{$Parameter} = $Wert; return 1; } else { write_errorlog("ERROR by writing Data : $Section - $Parameter -> Not found!","2"); return 0; } } } ################################################################################################################################################################## ################################################################################################################################################################## sub save_ini{ open (INIFileObject, ">".read_data("FILES", "CONFIGFILE")) || write_errorlog("ERROR: $! : ".read_data("FILES", "CONFIGFILE"),"3"); debug("Saving INI-File..."); foreach $Gruppe (sort keys %Data) { foreach $Element (sort keys %{$Data{$Gruppe}}) { print INIFileObject $Gruppe . "|" . $Element . "|" . $Data{$Gruppe}{$Element} . "\n"; }; }; close (INIFileObject); return 1; } ################################################################################################################################################################## ################################################################################################################################################################## sub check_for_new_commands { debug("Checking for commands ...."); while (@{read_data("ENVIRONMENTS", "COMMANDS")}) { %Command = %{shift @{read_data("ENVIRONMENTS", "COMMANDS")}}; if (($Command{"ID"} >= 0) and ($Command{"ID"} <= read_data("GENERAL", "LASTDEVICE"))) { debug("....found new command: ".read_data("DEVICE_".$Command{"ID"}, "NAME")." -> $Command{'SEND'}"); if (index(send_singlecast($Command{"ID"}, $Command{"SEND"}), "ERROR") != -1) { # Wenn es beim senden des Befehls zu einer Fehler kam... if ($Command{"COUNT"} > 1) { $Command{'COUNT'} = $Command{'COUNT'}-1; push @{read_data("ENVIRONMENTS", "COMMANDS")}, %Command; write_errorlog("ERROR while sending command to device: ".read_data("DEVICE_".$Command{"ID"}, "NAME")." -> $Command{'SEND'}... prepare to resend (NEWCounter: $Command{'COUNT'}).", "1"); } else { write_errorlog("ERROR while sending command to device: ".read_data("DEVICE_".$Command{"ID"}, "NAME")." -> $Command{'SEND'}... command is rejected.", "1"); }; }; }; } debug("....no (more) commands found."); } ################################################################################################################################################################## ################################################################################################################################################################## sub check_serversocket { # waiting for a new client connection debug("Checking for new Server-Socket-Connection..."); $ClientSocket = $ServerSocket->accept(); while (defined $ClientSocket) { # get information about a newly connected client debug("Connected to " . $ClientSocket->peerhost() . ":" . $ClientSocket->peerport()); # read up to 1024 characters from the connected client $ClientSocket->recv($ClientReceivedData, 1024); %Command = split /[:,]/, $ClientReceivedData; debug("and received data: $ClientReceivedData"); $ClientSendData = $Command{"ID"}.":"; if ($Command{"ID"} eq "UEBERSICHT_HAUS") { foreach $RAUM ("FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_FENSTER"); }; foreach $RAUM ("FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "ESSZIMMER", "KUECHE") { $ClientSendData = $ClientSendData . irgendeine_lampe_im_raum_an($RAUM); }; foreach $RAUM ("FLUR_EG", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "KUECHE") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_HEIZUNG"); }; foreach $RAUM ("FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_FENSTER"); }; foreach $RAUM ("FLUR_KG", "HAUSANSCHLUSSRAUM", "SCHLAFZIMMER", "VORRATSRAUM", "KINDERZIMMER", "GAESTEZIMMER", "BADEZIMMER") { $ClientSendData = $ClientSendData . irgendeine_lampe_im_raum_an($RAUM); }; foreach $RAUM ("FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER", "BADEZIMMER") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_HEIZUNG"); }; foreach $RAUM ("ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { $ClientSendData = $ClientSendData . read_data($RAUM, "POSITION_ROLLO_IST"); }; } elsif ($Command{"ID"} eq "FLUR_EG") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_HEIZUNG", "RASPBERRYBACKLIGHT") { $ClientSendData = $ClientSendData . read_data("FLUR_EG", $PARAMETER); }; } elsif ($Command{"ID"} eq "WC") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_FENSTER", "STATUS_HEIZUNG") { $ClientSendData = $ClientSendData . read_data("WC", $PARAMETER); }; } elsif (($Command{"ID"} eq "ARBEITSZIMMER") or ($Command{"ID"} eq "FLUR_KG") or ($Command{"ID"} eq "KINDERZIMMER") or ($Command{"ID"} eq "GAESTEZIMMER")) { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_FENSTER", "STATUS_HEIZUNG", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST") { $ClientSendData = $ClientSendData . read_data($Command{"ID"}, $PARAMETER); }; } elsif ($Command{"ID"} eq "WOHNZIMMER") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_FENSTER", "STATUS_HEIZUNG", "STATUS_LAUTSPRECHER", "RASPBERRYBACKLIGHT", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST") { $ClientSendData = $ClientSendData . read_data("WOHNZIMMER_LINKS", $PARAMETER); }; foreach $PARAMETER ("STATUS_FENSTER", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST") { $ClientSendData = $ClientSendData . read_data("WOHNZIMMER_RECHTS", $PARAMETER); }; foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_FENSTER", "STATUS_HEIZUNG", "STATUS_LAUTSPRECHER", "RASPBERRYBACKLIGHT", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST") { $ClientSendData = $ClientSendData . read_data("ESSZIMMER", $PARAMETER); }; } elsif (($Command{"ID"} eq "KUECHE") or ($Command{"ID"} eq "SCHLAFZIMMER")) { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_FENSTER", "STATUS_HEIZUNG", "STATUS_LAUTSPRECHER", "STATUS_MOTOR_AB", "STATUS_MOTOR_AUF", "POSITION_ROLLO_IST") { $ClientSendData = $ClientSendData . read_data($Command{"ID"}, $PARAMETER); }; } elsif ($Command{"ID"} eq "HAUSANSCHLUSSRAUM") { $ClientSendData = $ClientSendData . read_data("HAUSANSCHLUSSRAUM", "STATUS_LAMPE1"); } elsif ($Command{"ID"} eq "VORRATSRAUM") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_HEIZUNG") { $ClientSendData = $ClientSendData . read_data("VORRATSRAUM", $PARAMETER); }; } elsif ($Command{"ID"} eq "BADEZIMMER") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_HEIZUNG", "STATUS_LAUTSPRECHER") { $ClientSendData = $ClientSendData . read_data("BADEZIMMER", $PARAMETER); }; } elsif ($Command{"ID"} eq "TERRASSE") { for ($INDEX=1; $INDEX<7; $INDEX++) { $ClientSendData = $ClientSendData . read_data("TERRASSE", "STATUS_LAMPE".$INDEX); }; } elsif ($Command{"ID"} eq "WERKSTATT") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_HOFTUER", "STATUS_KELLERTUER", "STATUS_FENSTER") { $ClientSendData = $ClientSendData . read_data("WERKSTATT", $PARAMETER); }; } elsif ($Command{"ID"} eq "GARAGE") { foreach $PARAMETER ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_LAMPE3", "STATUS_LAMPE4", "STATUS_LAMPE5", "STATUS_TOR") { $ClientSendData = $ClientSendData . read_data("GARAGE_VERMIETER", $PARAMETER); }; } elsif ($Command{"ID"} eq "GARAGE_FLUR_LAGER_WC") { foreach $RAUM ("STATUS_LAMPE1", "STATUS_LAMPE2", "STATUS_TUER") { $ClientSendData = $ClientSendData . read_data("GARAGE_LAGER", "STATUS_FENSTER"); }; $ClientSendData = $ClientSendData . read_data("GARAGE_FLUR", "STATUS_LAMPE1") . read_data("GARAGE_WC", "STATUS_LAMPE1"); } elsif ($Command{"ID"} eq "GARTEN") { for ($INDEX=1; $INDEX<9; $INDEX++) { $ClientSendData = $ClientSendData . read_data("GARTEN", "STATUS_LAMPE".$INDEX); }; } elsif ($Command{"ID"} eq "GARTENHAUS") { for ($INDEX=1; $INDEX<5; $INDEX++) { $ClientSendData = $ClientSendData . read_data("GARTENHAUS", "STATUS_LAMPE".$INDEX); }; } elsif ($Command{"ID"} eq "GUI_WOHNZIMMER") { foreach $RAUM ("FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_FENSTER"); }; $ClientSendData = $ClientSendData . read_data("WERKSTATT", "STATUS_HOFTUER") . read_data("GARAGE_VERMIETER", "STATUS_TOR") . read_data("GARAGE_LAGER", "STATUS_TUER") . read_data("TERRASSE", "STATUS_LAMPE1"); } elsif ($Command{"ID"} eq "GUI_HAUSTUER") { $ClientSendData = $ClientSendData . read_data("GARAGE_VERMIETER", "STATUS_TOR") . read_data("TERRASSE", "STATUS_LAMPE1") . read_data("ALARMANLAGE", "STATUS"); } elsif ($Command{"ID"} eq "GUI_WECKER") { foreach $PARAMETER ("ALARM_ZEIT", "ALARM_EINGESCHALTET", "ALARM_DECKENLAMPE_EIN", "ALARM_WANDLAMPE_EIN", "ALARM_LAMPEN_NUR_BEI_DUNKELHEIT") { $ClientSendData = $ClientSendData . read_data("WECKER", $PARAMETER); }; $ClientSendData = $ClientSendData . read_data("AUSSENSENSOR", "HELL") . read_data("WECKER", "PLAYERINDEX") . read_data("WECKER", "SLEEPZEIT") . read_data("SCHLAFZIMMER", "STATUS_LAMPE1") . read_data("SCHLAFZIMMER", "STATUS_LAMPE2") . "_"; foreach $RAUM ("FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_FENSTER"); }; $ClientSendData = $ClientSendData . read_data("WERKSTATT", "STATUS_HOFTUER") . read_data("GARAGE_VERMIETER", "STATUS_TOR") . read_data("GARAGE_LAGER", "STATUS_TUER"); } elsif ($Command{"ID"} eq "AUSSENSENSOR") { $ClientSendData = $ClientSendData . read_data("ZISTERNE", "FUELLSTAND") . read_data("ZISTERNE", "FRISCHWASSERNUTZUNG"); foreach $PARAMETER ("HELLIGKEIT", "SYSTEMMODUS_TAG", "TEMPERATUR") { $ClientSendData = $ClientSendData . read_data("AUSSENSENSOR", $PARAMETER); }; } elsif ($Command{"ID"} eq "CONFIG_AUSSENSENSOR") { foreach $PARAMETER ("TAG_IST_FRUEHESTENS_VON", "TAG_IST_MINDESTENS_BIS", "DAEMMERUNG_SCHWELLWERT", "DUNKELHEIT_SCHWELLWERT") { $ClientSendData = $ClientSendData . read_data("AUSSENSENSOR", $PARAMETER); }; } elsif ($Command{"ID"} eq "MUSIKMATRIX") { for ($INDEX=1; $INDEX<9; $INDEX++) { $ClientSendData = $ClientSendData . read_data("MUSIKMATRIX", "STATUS_EINGANG".$INDEX); }; for ($INDEX=1; $INDEX<9; $INDEX++) { $ClientSendData = $ClientSendData . read_data("MUSIKMATRIX", "STATUS_AUSGANGSROUTING_IST".$INDEX); }; for ($INDEX=1; $INDEX<9; $INDEX++) { $ClientSendData = $ClientSendData . read_data("MUSIKMATRIX", "STATUS_AUTOROUTING".$INDEX); }; } elsif ($Command{"ID"} eq "GERAETEINFOS") { $ClientSendData = $ClientSendData . "|" . read_data("GENERAL", "SYSTEMSTARTDATE") . ", " .read_data("GENERAL", "SYSTEMSTARTTIME") . "|" . read_data("GENERAL", "LASTDEVICE") . "|"; for ($INDEX = read_data("LOAD_AVERAGE", "ID")+1; $INDEX 9) { $ClientSendData = $ClientSendData . read_data("LOAD_AVERAGE", "MINUTE_".($INDEX-10)) . "|"; } else { $ClientSendData = $ClientSendData . read_data("LOAD_AVERAGE", "MINUTE_".$INDEX) . "|"; }; }; for ($INDEX = 0; $INDEX<=read_data("GENERAL", "LASTDEVICE"); $INDEX++){ foreach $PARAMETER ("NAME", "IP", "CONNECTIONTRYCOUNTER", "CONNECTIONERRORCOUNTER", "CONNECTIONSUCCESSFULCOUNTER", "LASTTRYSUCCESSFUL", "LASTRESPONSETIME", "LASTRESPONSE") { $ClientSendData = $ClientSendData . read_data("DEVICE_".$INDEX, $PARAMETER) . "|"; }; } } elsif ($Command{"ID"} eq "KOMPLETTE_SYSTEMDATEN") { $ClientSendData = $ClientSendData . "|"; foreach $Gruppe (sort keys %Data) { foreach $Element (sort keys %{$Data{$Gruppe}}) { if (defined $Data{$Gruppe}{$Element}) { $ClientSendData = $ClientSendData . $Gruppe . "|" . $Element . "|" . $Data{$Gruppe}{$Element} . "|"; } else { $ClientSendData = $ClientSendData . $Gruppe . "|" . $Element . "|undef|"; } }; }; } elsif ($Command{"ID"} eq "ALARMANLAGE") { $ClientSendData = $ClientSendData . read_data("ALARMANLAGE", "STATUS") . "_"; foreach $RAUM ("FLUR_EG", "WC", "ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { $ClientSendData = $ClientSendData . read_data($RAUM, "STATUS_FENSTER"); }; $ClientSendData = $ClientSendData . "_"; foreach $RAUM ("SAFE_HAUSTUER", "SAFE_FENSTER_WC", "SAFE_FENSTER_ARBEITSZIMMER", "SAFE_FENSTER_WOHNZIMMER_LINKS", "SAFE_FENSTER_WOHNZIMMER_RECHTS", "SAFE_FENSTER_ESSZIMMER", "SAFE_FENSTER_KUECHE", "SAFE_KELLERTUER", "SAFE_FENSTER_SCHLAFZIMMER", "SAFE_FENSTER_KINDERZIMMER", "SAFE_FENSTER_GAESTEZIMMER") { $ClientSendData = $ClientSendData . read_data("ALARMANLAGE", $RAUM); }; } elsif ($Command{"ID"} eq "ALARMANLAGE_CONFIG") { foreach $PARAMETER ("PIN1", "PIN2", "PIN3", "PIN4", "PIN5", "PIN6", "PIN7", "PIN8", "HAUSTUERGESTEUERT", "ALARMDAUER_SIRENE", "ALARMDAUER_HAUSMELDER", "ALARMDELAYINI") { $ClientSendData = $ClientSendData . read_data("ALARMANLAGE", $PARAMETER); }; } elsif ($Command{"ID"} eq "HELLIGKEITSAUTOMATION_CONFIG") { $ClientSendData = $ClientSendData . read_data("VORGARTEN", "AUTOTAGESLICHT_HAUSNUMMER") . read_data("VORGARTEN", "AUTOTAGESLICHT_BRUNNEN") . read_data("VORGARTEN", "AUTOTAGESLICHT_BELEUCHTUNG") . read_data("HAUSEINGANG", "AUTOTAGESLICHT_STECKDOSE") . read_data("TERRASSE", "AUTOTAGESLICHT_BELEUCHTUNG") . read_data("GARTEN", "AUTOTAGESLICHT_STECKDOSE_WASSERTANK") . read_data("GARTEN", "AUTOTAGESLICHT_STECKDOSE_TERRASSE") . read_data("GARTENHAUS", "AUTOTAGESLICHT_STECKDOSE_GARAGENDACH"); } elsif ($Command{"ID"} eq "ROLLADEN_CONFIG") { foreach $RAUM ("ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { foreach $PARAMETER ("TAG_NACHTGESTEUERT", "ZEIT_AUF", "ZEIT_ZU", "MORGENS_GANZ_AUF", "BEWOHNERGESTEUERT", "BEWOHNERGESTEUERT_RESTOEFFNUNG", "NACHTS_FENSTERGESTEUERT", "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG", "POSITION_ROLLO_IST", "POSITION_ROLLO_SOLL", "POSITION_ROLLO_LETZTE_MANUELLE") { $ClientSendData = $ClientSendData . read_data($RAUM, $PARAMETER); }; $ClientSendData = $ClientSendData . "_"; } } elsif (index($Command{"ID"}, "DEVICE_") > -1) { $ClientSendData = $ClientSendData . read_data($Command{"ID"}, "LASTRESPONSE"); } elsif ($Command{"ID"} eq "INI.AUSSENSENSOR") { debug("....found new command: SET AUSSENSENSOR -> $Command{'SEND'}"); write_data("AUSSENSENSOR", "DAEMMERUNG_SCHWELLWERT", substr($Command{'SEND'},0,4)); write_data("AUSSENSENSOR", "DUNKELHEIT_SCHWELLWERT", substr($Command{'SEND'},4,4)); write_data("AUSSENSENSOR", "TAG_IST_MINDESTENS_BIS", substr($Command{'SEND'},8,2)); write_data("AUSSENSENSOR", "TAG_IST_FRUEHESTENS_VON", substr($Command{'SEND'},10,2)); save_ini(); $ClientSendData = $ClientSendData . "Set Aussensensor"; } elsif ($Command{"ID"} eq "INI.WRITEDATADIRECT") { debug("....found new command: WRITE DATA DIRECT -> $Command{'SEND'}"); write_data((split /[|]/, $Command{'SEND'})[0], (split /[|]/, $Command{'SEND'})[1], (split /[|]/, $Command{'SEND'})[2]); save_ini(); $ClientSendData = $ClientSendData . "Write Data direct"; } elsif ($Command{"ID"} eq "INI.ALARMANLAGE_STATUS") { debug("....found new command: SET ALARMANLAGE-STATUS -> $Command{'SEND'}"); if (substr($Command{'SEND'},0,4) eq "LOCK") { write_data("ALARMANLAGE", "STATUS", "1"); } elsif (substr($Command{'SEND'},0,6) eq "UNLOCK") { if ((read_data("ALARMANLAGE", "PIN1") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN2") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN3") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN4") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN5") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN6") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN7") eq substr($Command{'SEND'},6,4)) or (read_data("ALARMANLAGE", "PIN8") eq substr($Command{'SEND'},6,4))) { write_data("ALARMANLAGE", "STATUS", "0"); write_data("ALARMANLAGE", "ALARMDELAY", 0); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "26", "SEND", "SIRENE!000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "28", "SEND", "SIRENE!000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", "26", "SEND", "RUNDUMLEUCHTE!0", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } } $ClientSendData = $ClientSendData . "Rest Alarmanlage"; } elsif ($Command{"ID"} eq "INI.ALARMANLAGE") { debug("....found new command: SET ALARMANLAGE -> $Command{'SEND'}"); for ($INDEX=1; $INDEX<9; $INDEX++) { write_data("ALARMANLAGE", "PIN".$INDEX, substr($Command{'SEND'},($INDEX-1)*4,4)); }; write_data("ALARMANLAGE", "HAUSTUERGESTEUERT", substr($Command{'SEND'},32,1)); write_data("ALARMANLAGE", "ALARMDAUER_SIRENE", substr($Command{'SEND'},33,3)); write_data("ALARMANLAGE", "ALARMDAUER_HAUSMELDER", substr($Command{'SEND'},36,3)); write_data("ALARMANLAGE", "ALARMDELAYINI", substr($Command{'SEND'},39,2)); save_ini(); $ClientSendData = $ClientSendData . "Set Alarmanlage"; } elsif ($Command{"ID"} eq "INI.WECKER") { debug("....found new command: SET WECKER -> $Command{'SEND'}"); write_data("WECKER", "ALARM_ZEIT", substr($Command{'SEND'},0,5)); write_data("WECKER", "ALARM_EINGESCHALTET", substr($Command{'SEND'},5,1)); write_data("WECKER", "ALARM_DECKENLAMPE_EIN", substr($Command{'SEND'},6,1)); write_data("WECKER", "ALARM_WANDLAMPE_EIN", substr($Command{'SEND'},7,1)); write_data("WECKER", "ALARM_LAMPEN_NUR_BEI_DUNKELHEIT", substr($Command{'SEND'},8,1)); write_data("WECKER", "PLAYERINDEX", substr($Command{'SEND'},9,1)); write_data("WECKER", "SLEEPZEIT", substr($Command{'SEND'},10,3)); save_ini(); $ClientSendData = $ClientSendData . "Set Wecker"; } elsif ($Command{"ID"} eq "INI.HELLIGKEITSAUTOMATION") { debug("....found new command: SET HELLIGKEITSAUTOMATION -> $Command{'SEND'}"); write_data("VORGARTEN", "AUTOTAGESLICHT_HAUSNUMMER", substr($Command{'SEND'},0,1)); write_data("VORGARTEN", "AUTOTAGESLICHT_BRUNNEN", substr($Command{'SEND'},1,1)); write_data("VORGARTEN", "AUTOTAGESLICHT_BELEUCHTUNG", substr($Command{'SEND'},2,1)); write_data("HAUSEINGANG", "AUTOTAGESLICHT_STECKDOSE", substr($Command{'SEND'},3,1)); write_data("TERRASSE", "AUTOTAGESLICHT_BELEUCHTUNG", substr($Command{'SEND'},4,1)); write_data("GARTEN", "AUTOTAGESLICHT_STECKDOSE_WASSERTANK", substr($Command{'SEND'},5,1)); write_data("GARTEN", "AUTOTAGESLICHT_STECKDOSE_TERRASSE", substr($Command{'SEND'},6,1)); write_data("GARTENHAUS", "AUTOTAGESLICHT_STECKDOSE_GARAGENDACH", substr($Command{'SEND'},7,1)); save_ini(); $ClientSendData = $ClientSendData . "Set HELLIGKEITSAUTOMATION"; } elsif ($Command{"ID"} eq "INI.ROLLADEN") { debug("....found new command: SET ROLLADEN -> $Command{'SEND'}"); $INDEX = 0; foreach $RAUM ("ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { write_data($RAUM, "TAG_NACHTGESTEUERT", substr($Command{'SEND'},$INDEX*21+0,1)); write_data($RAUM, "ZEIT_AUF", substr($Command{'SEND'},$INDEX*21+1,5)); write_data($RAUM, "ZEIT_ZU", substr($Command{'SEND'},$INDEX*21+6,5)); write_data($RAUM, "MORGENS_GANZ_AUF", substr($Command{'SEND'},$INDEX*21+11,1)); write_data($RAUM, "BEWOHNERGESTEUERT", substr($Command{'SEND'},$INDEX*21+12,1)); write_data($RAUM, "BEWOHNERGESTEUERT_RESTOEFFNUNG", substr($Command{'SEND'},$INDEX*21+13,3)); write_data($RAUM, "NACHTS_FENSTERGESTEUERT", substr($Command{'SEND'},$INDEX*21+16,1)); write_data($RAUM, "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG", substr($Command{'SEND'},$INDEX*21+17,3)); $INDEX++; } save_ini(); $ClientSendData = $ClientSendData . "Set Rolladen"; } elsif (($Command{"ID"} >= 0) and ($Command{"ID"} <= read_data("GENERAL", "LASTDEVICE"))) { debug("....found new command: ".read_data("DEVICE_".$Command{"ID"}, "NAME")." -> $Command{'SEND'}"); if (index(send_singlecast($Command{"ID"}, $Command{"SEND"}), "ERROR") != -1) { # Wenn es beim senden des Befehls zu einer Fehler kam... if ($Command{"COUNT"} > 1) { $Command{'COUNT'} = $Command{'COUNT'}-1; write_errorlog("ERROR while sending command to device: ".read_data("DEVICE_".$Command{"ID"}, "NAME")." -> $Command{'SEND'}... prepare to resend (NEWCounter: $Command{'COUNT'}).", "1"); write_command_to_file($Command{"ID"}, $Command{"SEND"}, $Command{"COUNT"}); } else { write_errorlog("ERROR while sending command to device: ".read_data("DEVICE_".$Command{"ID"}, "NAME")." -> $Command{'SEND'}... command is rejected.", "1"); }; } $ClientSendData = $ClientSendData . "Send Command"; } else { $ClientSendData = $ClientSendData . "unklarer Parameter!"; } # write response data to the connected client $ClientSocket->send($ClientSendData); # notify client that response has been sent shutdown($ClientSocket, 1); # look for more conextion $ClientSocket = $ServerSocket->accept(); }; debug("no (more) connection."); } ################################################################################################################################################################## ################################################################################################################################################################## sub send_singlecast { my ($NetDeviceID, $Send_String) = @_; if (read_data("DEVICE_".$NetDeviceID, "SKIPCOMMUNICATION") eq "YES") { debug("SKIPCOMMUNICATION DEVICE: ".read_data("DEVICE_".$NetDeviceID, "NAME")); return("SKIPCOMMUNICATION DEVICE: ".read_data("DEVICE_".$NetDeviceID, "NAME")); } debug("Store load avarage data..."); write_data("LOAD_AVERAGE", "MINUTE_".read_data("LOAD_AVERAGE", "ID"),read_data("LOAD_AVERAGE", "MINUTE_".read_data("LOAD_AVERAGE", "ID"))+1); debug("Try to connect to Server " . read_data("DEVICE_".$NetDeviceID, "NAME") . " (" . read_data("DEVICE_".$NetDeviceID, "IP") . ")..."); write_data("DEVICE_".$NetDeviceID, "CONNECTIONTRYCOUNTER", read_data("DEVICE_".$NetDeviceID, "CONNECTIONTRYCOUNTER")+1); $MasterSocket = new IO::Socket::INET ( Broadcast => 0, PeerHost => read_data("DEVICE_".$NetDeviceID, "IP"), PeerPort => '5000', Proto => 'tcp', Timeout => read_data("GENERAL","TIMEOUTDEVICE"), ); if (defined $MasterSocket) { debug("Successfull connected."); $MasterSocket->autoflush(1); debug("Enable timeouts."); IO::Socket::Timeout->enable_timeouts_on($MasterSocket); $MasterSocket->read_timeout(read_data("GENERAL","TIMEOUTDEVICE")); $MasterSocket->write_timeout(read_data("GENERAL","TIMEOUTDEVICE")); # Asking for status or sending command $MasterSocket->send($Send_String.chr(10).chr(13)); debug("Command '$Send_String' send to ".read_data("DEVICE_".$NetDeviceID, "NAME").", waiting for response..."); # Read the socket data sent by server $MasterSocketResponse = $MasterSocket -> getline; if (! $MasterSocketResponse && ( 0+$! == ETIMEDOUT || 0+$! == EWOULDBLOCK )) { write_errorlog("ERROR by reading from Socket : ".read_data("DEVICE_".$NetDeviceID, "NAME")." -> Timeout","1"); write_data("DEVICE_".$NetDeviceID, "LASTERROR", "$DateForHuman $TimeForHuman : Read-Timeout"); write_data("DEVICE_".$NetDeviceID, "LASTTRYSUCCESSFUL", "NO"); write_data("DEVICE_".$NetDeviceID, "CONNECTIONERRORCOUNTER", read_data("DEVICE_".$NetDeviceID, "CONNECTIONERRORCOUNTER")+1); write_data("DEVICE_".$NetDeviceID, "ERRORREADTIMEOUT", read_data("DEVICE_".$NetDeviceID, "ERRORREADTIMEOUT")+1); write_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS", read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS")+1); if (read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS") % 25 eq "0") { write_errorlog(read_data("DEVICE_".$NetDeviceID, "NAME")." didn't answer for the last ".read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS")." times.","2"); } $MasterSocket->close; $MasterSocket=undef; return("ERROR by reading from Socket : ".read_data("DEVICE_".$NetDeviceID, "NAME")." -> Timeout"); } else { # Entferne die letzten beiden Zeichen im String. Dabei handelt es sich um $MasterSocketResponse = substr($MasterSocketResponse,0,-2); if (index($MasterSocketResponse, "STATUS:") != -1) { debug("received from ".read_data("DEVICE_".$NetDeviceID, "NAME")." : $MasterSocketResponse"); write_data("DEVICE_".$NetDeviceID, "LASTTRYSUCCESSFUL", "YES"); write_data("DEVICE_".$NetDeviceID, "LASTRESPONSETIME", "$DateForHuman $TimeForHuman"); write_data("DEVICE_".$NetDeviceID, "LASTRESPONSE", $MasterSocketResponse); write_data("DEVICE_".$NetDeviceID, "CONNECTIONSUCCESSFULCOUNTER", read_data("DEVICE_".$NetDeviceID, "CONNECTIONSUCCESSFULCOUNTER")+1); write_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS", 0); # Analyze response for ($INDEX=0; $INDEX < @{read_data("DEVICE_".$NetDeviceID, "DATAMASKRAUM")}; $INDEX++) { write_data( @{read_data("DEVICE_".$NetDeviceID, "DATAMASKRAUM")}[$INDEX], @{read_data("DEVICE_".$NetDeviceID, "DATAMASKELEMENT")}[$INDEX], substr($MasterSocketResponse, @{read_data("DEVICE_".$NetDeviceID, "DATAMASKPOS")}[$INDEX], @{read_data("DEVICE_".$NetDeviceID, "DATAMASKLEN")}[$INDEX])); } if (read_data("DEVICE_".$NetDeviceID, "ONRECEIVED")) { &{read_data("DEVICE_".$NetDeviceID, "ONRECEIVED")}($MasterSocketResponse); }; $MasterSocket->close; $MasterSocket=undef; return($MasterSocketResponse); } else { write_errorlog("ERROR ILLEGAL RESPONSE from Socket : ".read_data("DEVICE_".$NetDeviceID, "NAME")." -> $MasterSocketResponse","2"); write_data("DEVICE_".$NetDeviceID, "LASTERROR", "$DateForHuman $TimeForHuman : Illegal response -> $MasterSocketResponse"); write_data("DEVICE_".$NetDeviceID, "LASTTRYSUCCESSFUL", "NO"); write_data("DEVICE_".$NetDeviceID, "CONNECTIONERRORCOUNTER", read_data("DEVICE_".$NetDeviceID, "CONNECTIONERRORCOUNTER")+1); write_data("DEVICE_".$NetDeviceID, "ERRORILLEGALRESPONSE", read_data("DEVICE_".$NetDeviceID, "ERRORILLEGALRESPONSE")+1); write_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS", read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS")+1); if (read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS") % 25 eq "0") { write_errorlog(read_data("DEVICE_".$NetDeviceID, "NAME")." didn't answer for the last ".read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS")." times.","2"); } $MasterSocket->close; $MasterSocket=undef; return("ERROR ILLEGAL RESPONSE from Socket : ".read_data("DEVICE_".$NetDeviceID, "NAME")." -> $MasterSocketResponse"); } } } else { # Write ErrorLog write_errorlog("ERROR in Socket Creation : ".read_data("DEVICE_".$NetDeviceID, "NAME")." -> $!","1"); write_data("DEVICE_".$NetDeviceID, "LASTERROR", "$DateForHuman $TimeForHuman : No connection ($!)"); write_data("DEVICE_".$NetDeviceID, "LASTTRYSUCCESSFUL", "NO"); write_data("DEVICE_".$NetDeviceID, "CONNECTIONERRORCOUNTER", read_data("DEVICE_".$NetDeviceID, "CONNECTIONERRORCOUNTER")+1); write_data("DEVICE_".$NetDeviceID, "ERRORNOCONNECTION", read_data("DEVICE_".$NetDeviceID, "ERRORNOCONNECTION")+1); write_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS", read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS")+1); if (read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS") % 25 eq "0") { write_errorlog(read_data("DEVICE_".$NetDeviceID, "NAME")." didn't answer for the last ".read_data("DEVICE_".$NetDeviceID, "ERRORSAFTERLASTSUCCESS")." times.","2"); } return("ERROR in Socket Creation : ".read_data("DEVICE_".$NetDeviceID, "NAME")." -> $!"); } } ################################################################################################################################################################## ################################################################################################################################################################## sub set_new_rollopos{ %ID = ("ARBEITSZIMMER","2", "WOHNZIMMER_LINKS","3", "WOHNZIMMER_RECHTS","3", "ESSZIMMER","4", "KUECHE","5", "FLUR_KG","7", "SCHLAFZIMMER","9", "KINDERZIMMER","11", "GAESTEZIMMER","12"); foreach $RAUM ("ARBEITSZIMMER", "WOHNZIMMER_LINKS", "WOHNZIMMER_RECHTS", "ESSZIMMER", "KUECHE", "FLUR_KG", "SCHLAFZIMMER", "KINDERZIMMER", "GAESTEZIMMER") { $Befehl = ""; debug("Checking Window..." . $RAUM . "..."); # Tag / Nachtumschaltung für das Fenster if (read_data($RAUM, "TAG_NACHTGESTEUERT") eq "1") { if ((read_data("AUSSENSENSOR", "SYSTEMMODUS_TAG") eq "1") and (read_data($RAUM, "TAGMODUS") eq "0")) { debug("It's day time, open shutters..."); if (read_data($RAUM, "MORGENS_GANZ_AUF") eq "1") { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "MANUELLEPOS!100", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } else { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!" . read_data($RAUM, "POSITION_ROLLO_LETZTE_MANUELLE"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } write_data($RAUM, "TAGMODUS", "1"); # Damit morgens die Bewohnersteuerung für das Fenster berücksichtigt wird! write_data($RAUM, "BEWOHNERANWESEND", "1"); } elsif ((read_data("AUSSENSENSOR", "SYSTEMMODUS_TAG") eq "0") and (read_data($RAUM, "TAGMODUS") eq "1")) { debug("It's night time, close shutters..."); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data($RAUM, "TAGMODUS", "0"); # Damit bei der Umschaltung zur Nacht das offene Fenster berücksichtigt wird! write_data($RAUM, "STATUS_NACHTS_FENSTER", "1"); } } else { if ((read_data($RAUM, "ZEIT_AUF") eq ($hour."_".$min)) and (read_data($RAUM, "TAGMODUS") eq "0")) { debug("It's day time, open shutters..."); if (read_data($RAUM, "MORGENS_GANZ_AUF") eq "1") { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "MANUELLEPOS!100", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } else { push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!" . read_data($RAUM, "POSITION_ROLLO_LETZTE_MANUELLE"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; } write_data($RAUM, "TAGMODUS", "1"); # Damit morgens die Bewohnersteuerung für das Fenster berücksichtigt wird! write_data($RAUM, "BEWOHNERANWESEND", "1"); } elsif ((read_data($RAUM, "ZEIT_ZU") eq ($hour."_".$min)) and (read_data($RAUM, "TAGMODUS") eq "1")) { debug("It's night time, close shutters..."); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data($RAUM, "TAGMODUS", "0"); # Damit bei der Umschaltung zur Nacht das offene Fenster berücksichtigt wird! write_data($RAUM, "STATUS_NACHTS_FENSTER", "1"); } } # Bewohnersteuerung if ((read_data($RAUM, "TAGMODUS") eq "1") and (read_data($RAUM, "BEWOHNERGESTEUERT") eq "1")) { if ((read_data("FLUR_EG", "STATUS_FENSTER") eq "2") and (read_data($RAUM, "BEWOHNERANWESEND") eq "1")) { debug("residents absent, close shutters..."); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!" . read_data($RAUM, "BEWOHNERGESTEUERT_RESTOEFFNUNG"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data($RAUM, "BEWOHNERANWESEND", "0"); } elsif ((read_data("FLUR_EG", "STATUS_FENSTER") ne "2") and (read_data($RAUM, "BEWOHNERANWESEND") eq "0")) { debug("residents present, (re)open shutters..."); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!" . read_data($RAUM, "POSITION_ROLLO_LETZTE_MANUELLE"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data($RAUM, "BEWOHNERANWESEND", "1"); } } # Fenstersteuerung bei Nacht if ((read_data($RAUM, "TAGMODUS") eq "0") and (read_data($RAUM, "NACHTS_FENSTERGESTEUERT") eq "1")) { if ((read_data($RAUM, "STATUS_FENSTER") eq "0") and (read_data($RAUM, "STATUS_NACHTS_FENSTER") eq "1")) { debug("window opened, open shutters for night..."); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!" . read_data($RAUM, "NACHTS_FENSTERGESTEUERT_RESTOEFFNUNG"), "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data($RAUM, "STATUS_NACHTS_FENSTER", "0"); } elsif ((read_data($RAUM, "STATUS_FENSTER") eq "1") and (read_data($RAUM, "STATUS_NACHTS_FENSTER") eq "0")) { debug("window closed, close shutters..."); push @{read_data("ENVIRONMENTS", "COMMANDS")}, {"ID", $ID{$RAUM}, "SEND", "ROLLO!000", "COUNTER", read_data("GENERAL", "MAXIMUM_SEND_ATTEMPTS")}; write_data($RAUM, "STATUS_NACHTS_FENSTER", "1"); } } } } ################################################################################################################################################################## ################################################################################################################################################################## # ENDE Subroutines: ############################################################################################################################################## ################################################################################################################################################################## ################################################################################################################################################################## while (1) { # Timer überprüfen Timer_1Sekunde; # Checking ServerSocket check_serversocket; # Checking for commands / user-commands check_for_new_commands; # Take the next device in the line and ask for its status do { $CurentDeviceID++; if ($CurentDeviceID > read_data("GENERAL", "LASTDEVICE")) { $CurentDeviceID = 0; }; } until ((read_data("DEVICE_".$CurentDeviceID, "SKIPCOMMUNICATION") eq "NO") and (read_data("DEVICE_".$CurentDeviceID, "SKIPSTATUS") eq "NO")); send_singlecast($CurentDeviceID, "STATUS?"); }; debug("Close ServerSocket..."); ServerSocket->close(); write_errorlog("Program ended, but that shouldn't happen !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");