def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = P2pBluetooth(3.0, 30, self._sensorId) self.SetP2P() self.sensor = HeartRateSensor(3.0) self.ble.ToRxMode()
class oximeterController(MicroController): _characteristicsPath = "Characteristics/oximeterController.json" def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = Bluetooth(3.0, 30) self.ts = oximeterSensor(3.0) def __init__(self): self.jsonHandler = JsonHandler() self._ControllerChar = self.jsonHandler.LoadJson( self._characteristicsPath) self.Setup() self.ConnectHandlers() super().__init__(3.0) try: while (True): self.Run() except KeyboardInterrupt: self._ControllerChar['Battery']['CurrentState'][ 'Power'] = self.bt.GetCurrentCharge() self.__del__() exit(1) def __del__(self): self.jsonHandler.WriteJson(self._characteristicsPath, self._ControllerChar) self.ble.__del__() self.ts.__del__() self.bt.__del__() super().__del__() def ConnectHandlers(self): self.ble._batteryEvent.addHandler(self.bt.Discharging) self.ts._batteryEvent.addHandler(self.bt.Discharging) self._batteryEvent.addHandler(self.bt.Discharging) def Run(self): time.sleep(3) temp = self.ReadOxygenLevel() #time.sleep(3) print("Oximeter---->" + str(temp)) if (temp < 90): self.WriteBluetooth(temp) time.sleep(3) def ReadOxygenLevel(self): self.I2CRead() return self.ts.I2CRead() def WriteBluetooth(self, data): super().I2CWrite() data = str(data) + '| OxygenLevel' self.ble.Tx(data)
class EdgeNodeController(EdgeController): _characteristicsPath = "Characteristics/TemperatureController.json" def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = Bluetooth(3.0, 30) self.ble.ToRxMode() def __init__(self): self.jsonHandler = JsonHandler() self._ControllerChar = self.jsonHandler.LoadJson( self._characteristicsPath) self.Setup() self.ConnectHandlers() self._mqttService = MqttPublisher("EdgeNode", "DS/Node1/Temperature") super().__init__(3.0) try: while (True): self.Run() except KeyboardInterrupt: self._ControllerChar['Battery']['CurrentState'][ 'Power'] = self.bt.GetCurrentCharge() self.__del__() exit(1) def __del__(self): self.jsonHandler.WriteJson(self._characteristicsPath, self._ControllerChar) self.ble.__del__() self.bt.__del__() super().__del__() def ConnectHandlers(self): self.ble._batteryEvent.addHandler(self.bt.Discharging) self._batteryEvent.addHandler(self.bt.Discharging) self.ble._uartEvent.addHandler(self.UartRx) def Run(self): pass def UartRx(self, **kwargs): data = kwargs.get('data') self.UartPowerConsumed(data) print('RX --->>>', str(data)) self.WifiPowerConsumed(data) self._mqttService.Publish(data)
def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = Bluetooth(3.0, 30) self.ts = oximeterSensor(3.0)
class OxyMeterController (EdgeController) : _characteristicsPath = "Characteristics/TemperatureController.json" _sensorId = 'OxyMeter' def Setup(self): self.bt = Battery(self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = P2pBluetooth(3.0,30,self._sensorId) self.SetP2P() self.sensor = HeartRateSensor(3.0) self.ble.ToRxMode() def __init__(self): self.jsonHandler = JsonHandler() self._ControllerChar = self.jsonHandler.LoadJson(self._characteristicsPath) self.Setup() self.ConnectHandlers() self._privateKey = self._ControllerChar['PrivateKey'] mqtt = self._ControllerChar['Mqtt'] self._mqttService = MqttPublisher(mqtt['Name'],mqtt['Topic']) self._LogData = [] self._bulkPushTimer = Timer(150,self.BulkPushTimerHit) self._bulkPushTimer.start() super().__init__(3.0,self._sensorId) try: while(True): self.Run() except KeyboardInterrupt: self.BulkPushTimerHit() self._ControllerChar['Battery']['CurrentState']['Power'] = self.bt.GetCurrentCharge() self.__del__() exit(1) def __del__(self): self.jsonHandler.WriteJson(self._characteristicsPath,self._ControllerChar) self.ble.__del__() self.bt.__del__() super().__del__() def SetP2P(self): self._p2pTimer = Timer(10,self.P2pTimerHit) self._p2pTimer.start() def P2pTimerHit(self): self.ble.BroadCasting(self.bt.GetCurrentCharge()) self._p2pTimer = Timer(10,self.P2pTimerHit) self._p2pTimer.start() def ConnectHandlers(self): self.ble._batteryEvent.addHandler(self.bt.Discharging) self.sensor._batteryEvent.addHandler(self.bt.Discharging) self._batteryEvent.addHandler(self.bt.Discharging) self.ble._uartEvent.addHandler(self.UartRx) def Run(self): self.PushAll() def PushAll(self): time.sleep(3) temp = self.ReadTemperature() print('OxyMeter--->>',temp) time.sleep(1) #time.sleep(3) self.WifiTx(self.Encrypt(temp),'HeartRate') def Push(self): pass def UartRx(self,**kwargs): data = kwargs.get('data') self.UartPowerConsumed(data) print('RX --->>>', str(data)) dataArray = str(data).split('|') if dataArray[2] == '0' : self.WifiTx(dataArray[0],dataArray[1]) else: self._LogData.append(data) pass def WifiTx(self,data,topic): self.WifiPowerConsumed(data) self._mqttService.Publish(data,topic) def WifiBulkPush(self): data = self._LogData self.WifiPowerConsumed(data,True,False) data = {"Data" : data} self._mqttService.Publish(json.dumps(data),'BulkPush') self._LogData = [] def BulkPushTimerHit(self): if len(self._LogData) > 0 : self.WifiBulkPush() self._bulkPushTimer = Timer(150,self.BulkPushTimerHit) self._bulkPushTimer.start() def ReadTemperature(self): self.I2CRead() return self.sensor.I2CRead()
def Setup(self): self.bt = Battery() self.ble = Bluetooth(3.0) self.ts = TemperatureSensor(3.0)
def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = Bluetooth(3.0, 30) self.ble.ToRxMode()
class EdgeNodeController(EdgeController): _characteristicsPath = "Characteristics/ECGController.json" def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = Bluetooth(3.0, 30) self.ble.ToRxMode() def __init__(self): self.jsonHandler = JsonHandler() self._ControllerChar = self.jsonHandler.LoadJson( self._characteristicsPath) self.Setup() self.ConnectHandlers() self._mqttService = MqttPublisher("EdgeNode", "PatientMonitoring/Edge3/") super().__init__(3.0) try: while (True): self.Run() except KeyboardInterrupt: self._ControllerChar['Battery']['CurrentState'][ 'Power'] = self.bt.GetCurrentCharge() self.__del__() exit(1) def __del__(self): self.jsonHandler.WriteJson(self._characteristicsPath, self._ControllerChar) self.ble.__del__() self.bt.__del__() super().__del__() def ConnectHandlers(self): self.ble._batteryEvent.addHandler(self.bt.Discharging) self._batteryEvent.addHandler(self.bt.Discharging) self.ble._uartEvent.addHandler(self.UartRx) def Run(self): pass def Encript(self, data): password_provided = "password" # This is input in the form of a string password = password_provided.encode() # Convert to type bytes salt = b'salt_' # CHANGE THIS - recommend using a key from os.urandom(16), must be of type bytes kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000, backend=default_backend()) key = base64.urlsafe_b64encode( kdf.derive(password)) # Can only use kdf once message = data.encode() f = Fernet(key) encrypted = f.encrypt(message) #print('RX --->>>', str(encrypted)) return encrypted def UartRx(self, **kwargs): data = kwargs.get('data') self.UartPowerConsumed(data) print('RX --->>>', str(data)) data = str(data).split('| ') #temp = int(data[0]) encdata = self.Encript(data[0]) self.WifiPowerConsumed(encdata) #if(temp>400 or temp<70): self._mqttService.Publish(encdata, data[1])
class HeartRateController (MicroController) : _characteristicsPath = "Characteristics/TemperatureController.json" _sensorId = 'HeartRate' def Setup(self): self.bt = Battery(self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = P2pBluetooth(3.0,30,self._sensorId) self.SetP2P() self.sensor = HeartRateSensor(3.0) self.ble.ToRxMode() def __init__(self): self.jsonHandler = JsonHandler() self._ControllerChar = self.jsonHandler.LoadJson(self._characteristicsPath) self.Setup() self.ConnectHandlers() self._privateKey = self._ControllerChar['PrivateKey'] mqtt = self._ControllerChar['Mqtt'] self._mqttService = MqttPublisher(mqtt['Name'],mqtt['Topic']) self._LogData = [] super().__init__(3.0,self._sensorId) try: while(True): self.Run() except KeyboardInterrupt: self._ControllerChar['Battery']['CurrentState']['Power'] = self.bt.GetCurrentCharge() self.__del__() exit(1) def __del__(self): self.jsonHandler.WriteJson(self._characteristicsPath,self._ControllerChar) self.ble.__del__() self.bt.__del__() super().__del__() def SetP2P(self): self._p2pTimer = Timer(10,self.P2pTimerHit) self._p2pTimer.start() def P2pTimerHit(self): self.ble.BroadCasting(self.bt.GetCurrentCharge()) self._p2pTimer = Timer(10,self.P2pTimerHit) self._p2pTimer.start() def ConnectHandlers(self): self.ble._batteryEvent.addHandler(self.bt.Discharging) self.ble._uartEvent.addHandler(self.UartRx) self.sensor._batteryEvent.addHandler(self.bt.Discharging) self._batteryEvent.addHandler(self.bt.Discharging) def Run(self): self.PushAll() def PushAll(self): time.sleep(3) temp = self.ReadTemperature() print('HEartRate--->>',temp) time.sleep(1) #time.sleep(3) self.WriteBluetooth(temp) def Push(self): pass def ReadTemperature(self): self.I2CRead() return self.sensor.I2CRead() def WriteBluetooth(self,data): data = self.Encrypt(data) data = str(data) + '|HeartRate|0' self.UartPowerConsumed(data) self.ble.Tx(data) def UartRx(self,**kwargs): data = kwargs.get('data') self.UartPowerConsumed(data) self.UartPowerConsumed(data) self.ble.Tx(data)
def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = P2pBluetooth(3.0, 30, self._sensorId) self.ts = TemperatureSensor(3.0)
class TemperatureController(MicroController): _characteristicsPath = "Characteristics/TemperatureController.json" _sensorId = 'Temperature' def Setup(self): self.bt = Battery( self._ControllerChar['Battery']['CurrentState']['Power']) self.ble = P2pBluetooth(3.0, 30, self._sensorId) self.ts = TemperatureSensor(3.0) def __init__(self): self.jsonHandler = JsonHandler() self._ControllerChar = self.jsonHandler.LoadJson( self._characteristicsPath) self.Setup() self.ConnectHandlers() super().__init__(3.0, self._sensorId) #Change Mode -->> self.ts.SetRegister() try: while (True): self.Run() except KeyboardInterrupt: self._ControllerChar['Battery']['CurrentState'][ 'Power'] = self.bt.GetCurrentCharge() self.__del__() exit(1) def __del__(self): self.jsonHandler.WriteJson(self._characteristicsPath, self._ControllerChar) self.ble.__del__() self.ts.__del__() self.bt.__del__() super().__del__() def ConnectHandlers(self): self.ble._batteryEvent.addHandler(self.bt.Discharging) self.ts._batteryEvent.addHandler(self.bt.Discharging) self.ts._interupt.addHandler(self.ReceiveInterupt) self._batteryEvent.addHandler(self.bt.Discharging) def Run(self): pass def ReceiveInterupt(self): self.I2CRead() data = self.ts.RI2CRead() self.WriteBluetooth(data) def ReadTemperature(self): self.I2CRead() return self.ts.I2CRead() def WriteBluetooth(self, data): data = self.Encrypt(data) data = str(data) + '|Temperature|1' self.UartPowerConsumed(data) self.ble.Tx(data)