Update
This commit is contained in:
parent
3f775aeb91
commit
bb36389d2a
@ -76,14 +76,14 @@ class Master:
|
|||||||
logging.info(f'Got temp from slave: {temp}ºC')
|
logging.info(f'Got temp from slave: {temp}ºC')
|
||||||
if temp:
|
if temp:
|
||||||
return float("{:.1f}".format(float(temp.decode())))
|
return float("{:.1f}".format(float(temp.decode())))
|
||||||
return False
|
return 0
|
||||||
|
|
||||||
def get_hmdt(self):
|
def get_hmdt(self):
|
||||||
hmdt = self.com.send_and_wait('iot_g_hmdt|')
|
hmdt = self.com.send_and_wait('iot_g_hmdt|')
|
||||||
logging.info(f'Got hmdt from slave: {hmdt}')
|
logging.info(f'Got hmdt from slave: {hmdt}')
|
||||||
if hmdt:
|
if hmdt:
|
||||||
return int(hmdt.decode())
|
return int(hmdt.decode())
|
||||||
return False
|
return 0
|
||||||
|
|
||||||
def run_pump(self, volume):
|
def run_pump(self, volume):
|
||||||
status = self.com.send_and_wait(f'iot_pmp_ctrl|{str(volume)}')
|
status = self.com.send_and_wait(f'iot_pmp_ctrl|{str(volume)}')
|
||||||
@ -102,7 +102,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
@node.route("/")
|
@node.route("/")
|
||||||
def root():
|
def root():
|
||||||
return "IoT-ICL DE Weateher Master Node running..."
|
return "IoT-ICL DE Weather Master Node running..."
|
||||||
|
|
||||||
@node.route("/hmdt")
|
@node.route("/hmdt")
|
||||||
def humidity():
|
def humidity():
|
||||||
|
|||||||
@ -45,8 +45,35 @@ class LoRa:
|
|||||||
|
|
||||||
|
|
||||||
class WateringPump:
|
class WateringPump:
|
||||||
|
__PINS = {'pwm': board.D20}
|
||||||
|
__FLOW_RATE = 130
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.ctrl_pin = self.__PINS['pwm']
|
||||||
|
self.pump = digitalio.DigitalInOut(self.ctrl_pin)
|
||||||
|
self.pump.direction = digitalio.Direction.OUTPUT
|
||||||
|
self.pump.value = False
|
||||||
|
logging.debug(f'Init\'d pump at pin {self.ctrl_pin}, Power state is {self.pump.value}')
|
||||||
|
|
||||||
|
def dispense(self, volume: int):
|
||||||
|
'''
|
||||||
|
Pump flow rate is 130 ml/min at 5V
|
||||||
|
need to convert vol in ml to time duration in s
|
||||||
|
target_vol*60/130 = pump dispensing duration in seconds
|
||||||
|
'''
|
||||||
|
flow_rate = self.__FLOW_RATE
|
||||||
|
run_duration_seconds = volume*60/flow_rate
|
||||||
|
self.run_for(run_duration_seconds)
|
||||||
|
|
||||||
|
def __run_for(self, duration: float):
|
||||||
|
start_time = time.time()
|
||||||
|
end_time = start_time + duration
|
||||||
|
self.pump.value = True
|
||||||
|
logging.info('Starting pump')
|
||||||
|
while time.time() < end_time:
|
||||||
pass
|
pass
|
||||||
|
self.pump.value = False
|
||||||
|
logging.info('Stopping pump')
|
||||||
|
|
||||||
|
|
||||||
class SoliSensor:
|
class SoliSensor:
|
||||||
@ -61,17 +88,23 @@ class SoliSensor:
|
|||||||
logging.debug(f'Init\'d soil sensor, humidity: {self.sensor.moisture_read()}, temp: {self.sensor.get_temp()}')
|
logging.debug(f'Init\'d soil sensor, humidity: {self.sensor.moisture_read()}, temp: {self.sensor.get_temp()}')
|
||||||
|
|
||||||
def get_temp(self):
|
def get_temp(self):
|
||||||
|
try:
|
||||||
temp = self.sensor.get_temp()
|
temp = self.sensor.get_temp()
|
||||||
logging.debug(f'Temp: {temp}')
|
logging.debug(f'Temp: {temp}')
|
||||||
return temp
|
return temp
|
||||||
|
except Exception:
|
||||||
|
return -50
|
||||||
|
|
||||||
def get_hmdt(self):
|
def get_hmdt(self):
|
||||||
|
try:
|
||||||
hmdt = self.sensor.moisture_read()
|
hmdt = self.sensor.moisture_read()
|
||||||
logging.debug(f'Humidity: {hmdt}')
|
logging.debug(f'Humidity: {hmdt}')
|
||||||
return hmdt
|
return hmdt
|
||||||
|
except Exception:
|
||||||
|
return -50
|
||||||
|
|
||||||
|
|
||||||
class Slave:
|
class SensorNode:
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.com = LoRa()
|
self.com = LoRa()
|
||||||
@ -110,13 +143,13 @@ class Slave:
|
|||||||
|
|
||||||
def pump_control(self, volume):
|
def pump_control(self, volume):
|
||||||
water_qty = int(volume)
|
water_qty = int(volume)
|
||||||
print(f'Running pump for {water_qty} ml.')
|
logging.info(f'Running pump for {water_qty} ml.')
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
self.com.send_message('OK')
|
self.com.send_message('OK')
|
||||||
time.sleep(water_qty)
|
self.pump.dispense(volume)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
logging.root.setLevel(logging.DEBUG)
|
logging.root.setLevel(logging.DEBUG)
|
||||||
slave = Slave()
|
sensor_node = SensorNode()
|
||||||
slave.wait_for_instructions()
|
sensor_node.wait_for_instructions()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user