Commit f607624558fda3c77703d7288bace55407942722
1 parent
88e5c09f
Exists in
dev
penelope work part 1
Showing
9 changed files
with
77 additions
and
74 deletions
Show diff stats
simulators/plc/guitalens_worker.py
... | ... | @@ -35,7 +35,7 @@ class WorkerUrl(threading.Thread): |
35 | 35 | # call by thread.start() |
36 | 36 | def run(self): |
37 | 37 | self.shared.worker = 'start' |
38 | - self.shared.status = 'wait' | |
38 | + self.shared.status = 'init' | |
39 | 39 | logger.info('Worker up') |
40 | 40 | # as lonq worker = start |
41 | 41 | while self.shared.worker == 'start': |
... | ... | @@ -75,7 +75,7 @@ class WorkerUrl(threading.Thread): |
75 | 75 | success = (f.code == 200) |
76 | 76 | self.ret = json.loads(f.read().decode('utf-8')) |
77 | 77 | if success: |
78 | - self.set_values(self.ret["statuses"][0]["entities"][0]) | |
78 | + self.set_values(self.ret["entities"][0]) | |
79 | 79 | |
80 | 80 | def stop(self): |
81 | 81 | self.shared.worker = 'stop' | ... | ... |
simulators/plc/meteo_worker.py
... | ... | @@ -33,7 +33,7 @@ class WorkerLog(threading.Thread): |
33 | 33 | # call by thread.start() |
34 | 34 | def run(self): |
35 | 35 | self.shared.worker = 'start' |
36 | - self.shared.status = 'wait' | |
36 | + self.shared.status = 'init' | |
37 | 37 | logger.info('Worker up') |
38 | 38 | # as lonq worker = start |
39 | 39 | while self.shared.worker == 'start': | ... | ... |
simulators/plc/plcSimulator.py
... | ... | @@ -30,7 +30,7 @@ class PLCSimulator(DeviceSim, StatusManager): |
30 | 30 | super().__init__(argv) |
31 | 31 | # Listen to its own ip and port (the PLC's) |
32 | 32 | self.setDevice("PLC") |
33 | - self.loop = self.loop_2 | |
33 | + self.loop = self.loop_3 | |
34 | 34 | #PM Load PLC status in colibri-new-fixed-2.json |
35 | 35 | colibri_json = open("colibri-new-fixed-2.json") |
36 | 36 | colibri_struct = json.load(colibri_json) | ... | ... |
simulators/utils/DeviceSim.py
... | ... | @@ -143,7 +143,7 @@ class DeviceSim(object): |
143 | 143 | return (self.readBytes(size)) |
144 | 144 | |
145 | 145 | def blockAndReadMessage(self) -> str: |
146 | - return (self.blockAndReadBytes(1024)) | |
146 | + return (self.blockAndReadBytes(2048)) | |
147 | 147 | |
148 | 148 | def setBlocking(self, flag, connection): |
149 | 149 | if (not connection["connection"]): |
... | ... | @@ -151,9 +151,9 @@ class DeviceSim(object): |
151 | 151 | connection["connection"].setblocking(flag) |
152 | 152 | return (0) |
153 | 153 | |
154 | - # TODO maybe read more than 1024 bytes for a single message ????? | |
154 | + # TODO maybe read more than 2048 bytes for a single message ????? | |
155 | 155 | def readMessage(self, connection) -> str: |
156 | - return self.readBytes(1024, connection) | |
156 | + return self.readBytes(2048, connection) | |
157 | 157 | |
158 | 158 | #def getConnection(self, device_name): |
159 | 159 | def getConnection(self): | ... | ... |
src/dashboard/templates/dashboard/config_weather.html
... | ... | @@ -21,13 +21,13 @@ |
21 | 21 | <th>serial_number</th> |
22 | 22 | <th>valid</th> |
23 | 23 | <th>name</th> |
24 | - <th>monitor</th> | |
24 | + <th>monitor_name</th> | |
25 | 25 | <th>type</th> |
26 | 26 | <th>Select </th> |
27 | 27 | </tr> |
28 | 28 | </thead> |
29 | 29 | <tbody> |
30 | - {% for line in weather_config.captors_table %} | |
30 | + {% for line in weather_config.sensors_table %} | |
31 | 31 | <tr class="info"> |
32 | 32 | <td>{{line.0}}</td> |
33 | 33 | <td>{{line.1}}</td> |
... | ... | @@ -36,7 +36,7 @@ |
36 | 36 | <td>{{line.4}}</td> |
37 | 37 | <td onclick="alert('New value')">{{line.5}}</td> |
38 | 38 | <td>{{line.6}}</td> |
39 | - <td><input class="form-check-input" name="{{line.4}}" value="{{line.7}}" checked="" type="radio"></td> | |
39 | + <td><input class="form-check-input" name="{{line.5}}" value="{{line.8}}" {{line.7}} type="radio"></td> | |
40 | 40 | </tr> |
41 | 41 | {% endfor %} |
42 | 42 | </tbody> | ... | ... |
src/dashboard/views.py
... | ... | @@ -276,7 +276,7 @@ def weather_config(request): |
276 | 276 | #colibri_struct = json.load(colibri_json) |
277 | 277 | #plc_status = colibri_struct["statuses"][1]["entities"][0] |
278 | 278 | plc_checker = PlcChecker() |
279 | - _struct = {"origin":plc_checker.origin, "captors_table":plc_checker.captors_table} | |
279 | + _struct = {"origin":plc_checker.origin, "sensors_table":plc_checker.sensors_table} | |
280 | 280 | # Return template with sensors list |
281 | 281 | return render(request, 'dashboard/config_weather.html', {'weather_config' : _struct, 'base_template' : "base.html"}) |
282 | 282 | except Config.DoesNotExist: | ... | ... |
src/devices/Device.py
... | ... | @@ -107,6 +107,7 @@ class DeviceController(): |
107 | 107 | #raise (Exception("KO: socket error or not implemented command")) |
108 | 108 | |
109 | 109 | ret = self.sock.recv(size).decode() |
110 | + print(len(ret)) | |
110 | 111 | if (not ret): |
111 | 112 | if (settings.DEBUG): |
112 | 113 | self.log(self.name, "Connection has been killed") |
... | ... | @@ -125,7 +126,7 @@ class DeviceController(): |
125 | 126 | return (message) |
126 | 127 | |
127 | 128 | def blockAndReadMessage(self) -> str: |
128 | - return (self.blockAndReadBytes(1024)) | |
129 | + return (self.blockAndReadBytes(2048)) | |
129 | 130 | |
130 | 131 | def setBlocking(self, flag): |
131 | 132 | if (not self.sock): |
... | ... | @@ -133,9 +134,9 @@ class DeviceController(): |
133 | 134 | self.sock.setblocking(flag) |
134 | 135 | return (0) |
135 | 136 | |
136 | - # TODO: maybe read more than 1024 bytes ????? | |
137 | + # TODO: maybe read more than 2048 bytes ????? | |
137 | 138 | def readMessage(self) -> str: |
138 | - message = str(self.readBytes(1024)) | |
139 | + message = str(self.readBytes(2048)) | |
139 | 140 | #os.system("echo lol >> /home/portos/IRAP/pyros/src/POURKOICAMARCHPA") |
140 | 141 | Log.objects.create(agent=self.name, message='Message received : ' + message) |
141 | 142 | return message | ... | ... |
src/devices/PLC.py
... | ... | @@ -26,7 +26,7 @@ class PLCController(DeviceController): |
26 | 26 | if not status: |
27 | 27 | return "NOT_SET1" |
28 | 28 | # Read result FROM plc |
29 | - return (self.blockAndReadBytes(4096)) | |
29 | + return (self.blockAndReadBytes(8192)) | |
30 | 30 | |
31 | 31 | def switch_lights(self, command) : |
32 | 32 | command = command.split() | ... | ... |
src/monitoring/plc_checker.py
... | ... | @@ -18,29 +18,21 @@ class PlcChecker(object): |
18 | 18 | self.device_type = None |
19 | 19 | self.serial_number = None |
20 | 20 | self.valid = None |
21 | - self.captors = [ | |
22 | - "OutsideTemp", | |
23 | - "InsideTemp", | |
24 | - "OutsideHumidity", | |
25 | - "InsideHumidity", | |
26 | - "Pressure", | |
27 | - "RainRate", | |
28 | - "WindSpeed", | |
29 | - "WindDir", | |
30 | - "WindDirCardinal", | |
31 | - "DewPoint", | |
32 | - "analog", | |
33 | - "digital", | |
34 | - "SensorTemperature", | |
35 | - "SkyTemperature", | |
36 | - "status", | |
37 | - "current", | |
38 | - "plc_mode", | |
39 | - "LIGHTS", | |
40 | - "SHUTTERS", | |
41 | - ] | |
42 | - self.captors_conf = {} | |
43 | - self.captors_table = [] | |
21 | + self.sensors_monitor = { | |
22 | + "Temperature_outside": None, | |
23 | + "Humidity_outside": None, | |
24 | + "Rain_boolean": None, | |
25 | + "Wind_direction": None, | |
26 | + "Wind_speed": None, | |
27 | + "Temperature_sky": None, | |
28 | + "status": None, | |
29 | + "current": None, | |
30 | + "plc_mode": None, | |
31 | + "LIGHTS": None, | |
32 | + "SHUTTERS": None, | |
33 | + } | |
34 | + self.sensors_conf = {} | |
35 | + self.sensors_table = [] | |
44 | 36 | self.load_config() |
45 | 37 | |
46 | 38 | def load_config(self): |
... | ... | @@ -48,7 +40,7 @@ class PlcChecker(object): |
48 | 40 | colibri_json = open("./monitoring/plc_config.json") |
49 | 41 | _struct = json.load(colibri_json) |
50 | 42 | self.origin = _struct["origin"] |
51 | - self.captors_table = _struct["captors"] | |
43 | + self.sensors_table = _struct["sensors"] | |
52 | 44 | logger.info("Loaded : plc_config.json") |
53 | 45 | colibri_json.close |
54 | 46 | except: |
... | ... | @@ -58,7 +50,7 @@ class PlcChecker(object): |
58 | 50 | #try: |
59 | 51 | _struct = {} |
60 | 52 | _struct["origin"] = self.origin |
61 | - _struct["captors"] = self.captors_table | |
53 | + _struct["sensors"] = self.sensors_table | |
62 | 54 | _file = open("./monitoring/plc_config.json" , 'w') |
63 | 55 | _file.write(json.dumps(_struct)) |
64 | 56 | _file.close() |
... | ... | @@ -67,7 +59,10 @@ class PlcChecker(object): |
67 | 59 | logger.info("Not saved plc_config.json") |
68 | 60 | |
69 | 61 | def chk_config(self, status_plc): |
70 | - struct = json.loads(status_plc) | |
62 | + try: | |
63 | + struct = json.loads(status_plc) | |
64 | + except: | |
65 | + logger.info("Error loading plc json") | |
71 | 66 | if isinstance(struct, list): |
72 | 67 | self.struct = struct[0] |
73 | 68 | else: |
... | ... | @@ -76,11 +71,15 @@ class PlcChecker(object): |
76 | 71 | self.scan_sensors() |
77 | 72 | self.save_config() |
78 | 73 | |
79 | - def known_captor(self, name): | |
74 | + def monitored_sensor(self, name, _sensor_id): | |
80 | 75 | known = None |
81 | - if name in self.captors: | |
76 | + selected = "" | |
77 | + if name in self.sensors_monitor.keys(): | |
82 | 78 | known = name |
83 | - return known | |
79 | + if self.sensors_monitor[name] == None: | |
80 | + self.sensors_monitor[name] = _sensor_id | |
81 | + selected = "checked" | |
82 | + return known, selected | |
84 | 83 | |
85 | 84 | def same_origin(self): |
86 | 85 | # check new origin |
... | ... | @@ -100,8 +99,8 @@ class PlcChecker(object): |
100 | 99 | return ret |
101 | 100 | |
102 | 101 | def scan_sensors(self): |
103 | - # return captors table from struct | |
104 | - self.captors_table = [] | |
102 | + # return sensors table from struct | |
103 | + self.sensors_table = [] | |
105 | 104 | try: |
106 | 105 | logger.debug(self.struct["date"]) |
107 | 106 | except Exception as e: |
... | ... | @@ -112,46 +111,49 @@ class PlcChecker(object): |
112 | 111 | self.device_type = self.get_key(device, "device_type") |
113 | 112 | self.serial_number = self.get_key(device, "serial_number") |
114 | 113 | self.valid = self.get_key(device, "valid") |
115 | - ind1 += 1 | |
116 | - ind2 = 0 | |
117 | 114 | for device_values in device["device_values"]: |
118 | - captor = [] | |
119 | - captor.append(self.device_name) | |
120 | - captor.append(self.device_type) | |
121 | - captor.append(self.serial_number) | |
122 | - captor.append(self.valid) | |
115 | + sensor = [] | |
116 | + sensor.append(self.device_name) | |
117 | + sensor.append(self.device_type) | |
118 | + sensor.append(self.serial_number) | |
119 | + sensor.append(self.valid) | |
123 | 120 | _name = self.get_key(device_values, "name") |
124 | - captor.append(_name) | |
125 | - captor.append(self.known_captor(_name)) | |
126 | - captor.append(self.get_key(device_values, "type")) | |
127 | - captor.append(str(ind1) + "_" + str(ind2)) | |
128 | - self.captors_table.append(captor) | |
129 | - ind2 += 1 | |
130 | - | |
131 | - | |
132 | - # deprecated find captor list in struct | |
121 | + sensor.append(_name) | |
122 | + _sensor_id = "sel:/" + self.device_name + ":/" + self.serial_number + ":/" + _name | |
123 | + _monitoring_name, _selected = self.monitored_sensor(self.get_key(device_values, "monitoring_name"), _sensor_id) | |
124 | + sensor.append(_monitoring_name) | |
125 | + sensor.append(self.get_key(device_values, "type")) | |
126 | + sensor.append(_selected) | |
127 | + sensor.append(_sensor_id) | |
128 | + self.sensors_table.append(sensor) | |
129 | + | |
130 | + | |
131 | + # deprecated find sensor list in struct | |
132 | + """ | |
133 | 133 | def find_sensors(self): |
134 | 134 | try: |
135 | 135 | logger.debug(self.struct["date"]) |
136 | 136 | except Exception as e: |
137 | 137 | logger.debug("No date") |
138 | - for captor_type in self.captors: | |
139 | - self.captors_conf[captor_type] = {} | |
140 | - logger.debug(captor_type + ":") | |
138 | + for sensor_type in self.sensors: | |
139 | + self.sensors_conf[sensor_type] = {} | |
140 | + logger.debug(sensor_type + ":") | |
141 | 141 | try: |
142 | - self.cross_devices_list(captor_type) | |
142 | + self.cross_devices_list(sensor_type) | |
143 | 143 | except Exception as e: |
144 | - logger.debug(captor_type + " error") | |
144 | + logger.debug(sensor_type + " error") | |
145 | 145 | |
146 | - def cross_devices_list(self, captor_type): | |
146 | + def cross_devices_list(self, sensor_type): | |
147 | 147 | """""" |
148 | 148 | for device in self.struct["devices"]: |
149 | 149 | if device["device_name"] != "GLOBAL" and device["device_type"] == "meteo" and device["valid"] == "yes": |
150 | - self.cros_captor_list(device, captor_type) | |
150 | + self.cros_sensor_list(device, sensor_type) | |
151 | 151 | |
152 | - def cros_captor_list(self, device, captor_type): | |
152 | + def cros_sensor_list(self, device, sensor_type): | |
153 | 153 | device_id = device["device_name"] + "/" + device["serial_number"] |
154 | - for captor in device["device_values"]: | |
155 | - if captor["name"] == captor_type: | |
156 | - self.captors_conf[captor_type][device_id] = captor["value"] | |
157 | - logger.debug("-- " + device_id + " : " + str(captor["value"])) | |
158 | 154 | \ No newline at end of file |
155 | + for sensor in device["device_values"]: | |
156 | + if sensor["name"] == sensor_type: | |
157 | + self.sensors_conf[sensor_type][device_id] = sensor["value"] | |
158 | + logger.debug("-- " + device_id + " : " + str(sensor["value"])) | |
159 | + """ | |
160 | + | ... | ... |