async def do_calibration(self, tick: Ticket = None): self.logger.info("manual do calibration") result = await self.worker.do_calibration() if tick: tick.result = result else: return result
async def get_info(self, tick: Ticket = None): ans = await self.sensor.send_command("?\r\n") self.logger.debug("Getting info from SBA5") if tick: tick.result = ans else: return ans
async def stop_ventilation(self, tick: Ticket = None): self.logger.info("manual stop ventilation") result = await self.worker.stop_ventilation() if tick: tick.result = result else: return result
async def start_draining(self, tick: Ticket = None): self.logger.info("Gpio start_draining") res = "" # at first open valves for pin in self.drain_valve_pins: res += self.gpio.write(pin, False) # false - because our relay is low level trigger self.pins[pin] = False self.logger.info("Start opening drain valves") # then wait magic time await asyncio.sleep(self.drain_valve_time) self.logger.info("Drain valves should be open now") # then set up air pumps for pin in self.drain_pump_pins: res += self.gpio.write(pin, False) # false - because our relay is low level trigger self.pins[pin] = False self.logger.info("Start drain pumps") # results self.logger.debug(res) if tick: tick.result = res else: return res
async def do_measure(self, tick: Ticket = None): self.logger.info("manual do measure") result = await self.worker.measure() if tick: tick.result = result else: return result
async def get_info(self, tick: Ticket = None): self.logger.debug("Gpio get_info") res = self.pins if tick: tick.result = res else: return res
async def do_calibration(self, tick: Ticket = None): ans = await self.sensor.send_command("Z\r\n") self.logger.info("Starting calibration of SBA5") if tick: tick.result = ans else: return ans
async def get_data(self, tick: Ticket = None): co2, logs = self.sensor.get_data() self.logger.debug("K30 CO2 got results: {}".format(logs)) if tick: tick.result = co2 else: return co2
async def get_data(self, tick: Ticket = None): res = self.hx.get_data() self.logger.debug("Weight unit get data: {}".format(res)) if tick: tick.result = res else: return res
async def pause(self, tick: Ticket = None): self.logger.info("manual pause") await self.worker.pause() result = "worker paused" if tick: tick.result = result else: return result
async def do_reconfiguration(self, tick: Ticket = None): self.logger.info("manual do_reconfiguration") await self.worker.do_reconfiguration() result = "worker do_reconfiguration" if tick: tick.result = result else: return result
async def continue_(self, tick: Ticket = None): self.logger.info("manual continue") await self.worker.continue_() result = "worker continued" if tick: tick.result = result else: return result
async def set_pin(self, pin: int, state: bool, tick: Ticket = None): self.logger.info("Gpio manually set pin") res = self.gpio.write(pin, state) self.pins[pin] = state self.logger.debug(res) if tick: tick.result = res else: return res
async def stop(self, tick: Ticket = None): self.logger.info("Gpio stop") self.gpio.deleter() res = "Gpio cleaned up" self.logger.debug(res) if tick: tick.result = res else: return res
async def do_measurement(self, tick: Ticket = None): ans = await self.sensor.send_command("M\r\n") self.logger.debug("Do measure SBA5") self.logger.debug(("SBA5 result is {}".format(ans) )[:-1]) #its try to remove last \n from here if tick: tick.result = ans else: return ans
async def start(self, tick: Ticket = None): self._started = True self.logger.info("Started") res = self.uart_wrapper.START()[1] self.logger.debug(res) if tick: tick.result = res else: return res
async def stop(self, tick: Ticket = None): self.logger.info("manual kill worker") # TODO: check if it really works await self.worker.stop() result = "worker killed" if tick: tick.result = result else: return result
async def get_info(self, tick: Ticket): self.logger.info("get info") proc = await asyncio.create_subprocess_shell( "uname -a", stdout=asyncio.subprocess.PIPE) stdout, stderr = await proc.communicate() content = stdout.decode().strip() if tick: tick.result = content else: return content
async def get_info(self, tick: Ticket = None): self.logger.info( "Info. Unit {}, red current = {}, white current = {}".format( "started" if self._started else "stopped", self._red, self._white)) res = self.uart_wrapper.GET_STATUS()[1] self.logger.debug(res) if tick: tick.result = res else: return res
async def stop_ventilation(self, tick: Ticket = None): self.logger.info("Gpio stop_ventilation") res = "" for i in self.vent_pins: res = self.gpio.write(i, True) self.pins[i] = True self.logger.debug(res) if tick: tick.result = res else: return res
async def stop_coolers(self, tick: Ticket = None): self.logger.info("Gpio stop coolers") for i in self.cooler_pin: res = self.gpio.write(i, True) # false - because our relay is low level trigger self.pins[i] = True self.logger.debug(res) if tick: tick.result = res else: return res
async def get_info(self, tick: Ticket = None): self.logger.debug("Dht get info function") if platf != "RPi": self.logger.error( "We are not on RPi, so this unit will be only a stub") else: self.logger.debug((self.pin, self.dhttype)) if tick: tick.result = (self.pin, self.dhttype) else: return self.pin, self.dhttype
async def start_ventilation(self, tick: Ticket = None): self.logger.info("Gpio start_ventilation") res = "" for i in self.vent_pins: res += self.gpio.write(i, False) # false - because our relay is low level trigger self.pins[i] = False self.logger.debug(res) if tick: tick.result = res else: return res
async def get_data(self, tick: Ticket = None): self.logger.debug("Dht get data function") if platf != "RPi": self.logger.error( "We are not on RPi, so this unit will be only a stub") else: h, t = self.sensor.get_data() self.logger.debug((t, h)) if tick: tick.result = (t, h) else: return t, h
async def create_tunnel(self, tick: Ticket): self.logger.info("manual create tunnel") # TODO: mb remove it ? It is dangerous cmd = 'autossh -M 10984 -N -f -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" -i /home/pi/.ssh/id_rsa -R 6666:localhost:22 [email protected] &' proc = await asyncio.create_subprocess_shell( cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) stdout, stderr = await proc.communicate() content = stdout.decode().strip() if tick: tick.result = content else: return content
async def stop_calibration(self, tick: Ticket = None): self.logger.info("Gpio stop_calibration") for i in self.calibration_pins: res = self.gpio.write(i, True) # false - because our relay is low level trigger self.pins[i] = True # then we need to start pump3 for i in self.measure_pins: res = self.gpio.write(i, False) # false - because our relay is low level trigger self.pins[i] = False self.logger.debug(res) if tick: tick.result = res else: return res
async def set_current(self, tick: Ticket = None, red=10, white=10): self._red = int(red) self._white = int(white) # TODO: handle incorrect current values such as (10000, 0) or smth self.logger.info( "Trying to set red current to {}, white - to {}".format( red, white)) res = "sorry, results in log" # TODO : think about what send back to user as result self.logger.info(self.uart_wrapper.STOP()[1]) self.logger.info(self.uart_wrapper.START_CONFIGURE()[1]) self.logger.info(self.uart_wrapper.SET_CURRENT(0, self._red)[1]) self.logger.info(self.uart_wrapper.SET_CURRENT(1, self._white)[1]) self.logger.info(self.uart_wrapper.FINISH_CONFIGURE_WITH_SAVING()[1]) self.logger.info(self.uart_wrapper.START()[1]) self.logger.debug(res) self._started = True if tick: tick.result = res else: return res
async def stop_draining(self, tick: Ticket = None): self.logger.info("Gpio stop_draining") res = "" # set off air pumps for pin in self.drain_pump_pins: res += self.gpio.write(pin, True) # false - because our relay is low level trigger self.pins[pin] = True self.logger.info("Stop drain pumps") # then close valves for pin in self.drain_valve_pins: res += self.gpio.write(pin, True) # false - because our relay is low level trigger self.pins[pin] = True self.logger.info("Close drain valves") self.logger.debug(res) if tick: tick.result = res else: return res
async def do_command(self, tick: Ticket, com: str): ans = await self.sensor.send_command(com) self.logger.info("send {} command to SBA5".format(com)) tick.result = ans