def telemetry_callback(self, client, userdata, msg): """ Handle telemetry messages from devices Topic: esp_hub/device/+/telemetry """ data = self.extract_payload(msg) device_id = self.extract_device_id(msg) print(data) telemetry = DAO.Telemetry(device_id, datetime.now(), rssi=data.get('rssi', '0'), heap=data.get('heap', '0'), cycles=data.get('cycles', '0'), ip=data.get('local_ip', '0'), mac=data.get('mac', '0'), voltage=data.get('voltage', '0'), ssid=data.get('ssid', '0')) self.db.insert_telemetry(telemetry)
def get_telemetry(self, device_id): """ Get single telemetry record by device_id :param device_id :return: DAO telemetry record """ con = self._get_connection() try: cur = con.cursor() cur.row_factory = sql.Row # return data from cursor as dictionary cur.execute("SELECT * FROM Telemetry WHERE Device_id=:Device_id", {'Device_id': device_id}) row = (cur.fetchall())[0] return DAO.Telemetry(row['Device_id'], row['Time'], row['Rssi'], row['Heap'], row['Cycles'], row['Voltage'], row['Ip'], row['Mac'], row['Ssid']) except sql.Error as e: print(e.args[0]) return None except IndexError: print("No item found") return None finally: con.close()