Skip to content

Commit f1d3d7a

Browse files
committed
samples/agriculture: change functionality of button DIO0
- Before when you pressed the button, it was switching between simulation and real data. - Now it always works with real data, and the button just toggles the electronic water valve to open or close. Signed-off-by: Victor Coman <victor.coman@digi.com>
1 parent 981ffb4 commit f1d3d7a

File tree

1 file changed

+32
-9
lines changed
  • samples/demos/end_to_end_agriculture

1 file changed

+32
-9
lines changed

samples/demos/end_to_end_agriculture/main.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137

138138
identified = False
139139
finished = False
140-
simulate_temp = True
140+
simulate_temp = False
141141

142142
time_seconds = 0
143143
weather_condition = WEATHER_SUNNY
@@ -531,6 +531,22 @@ def set_status_value(status_id, status_value):
531531
led_pin.value(valve_pos)
532532

533533

534+
def toggle_valve():
535+
"""
536+
Toggles the status of the electronic valve.
537+
"""
538+
global valve_pos
539+
status = valve_pos
540+
541+
if status == 0:
542+
valve_pos = 1
543+
else:
544+
valve_pos = 0
545+
546+
print("- Toggling valve status to '{}'.".format("Open" if valve_pos == 1 else "Closed"))
547+
# set_valve_open(new_status)
548+
549+
534550
def get_mac():
535551
"""
536552
Returns the XBee MAC address of the device.
@@ -613,15 +629,22 @@ def main():
613629
# Sleep 100 ms.
614630
time.sleep_ms(100)
615631

616-
if sensor is not None:
617-
# If the button has been pressed, swap the temperature source
618-
# (reading or simulation).
619-
if not was_btn_pressed and is_button_pressed():
620-
simulate_temp = not simulate_temp
621-
print("- Temperature source changed to %s"
622-
% ("simulation" if simulate_temp else "reading"))
632+
# If the button has been pressed, swap the temperature source
633+
# (reading or simulation).
634+
if not was_btn_pressed and is_button_pressed():
635+
toggle_valve()
636+
status_response = {
637+
ITEM_OP: OP_STATUS,
638+
ITEM_PROP: get_sensors_values()
639+
}
640+
print("- Reporting status data: %s" % status_response)
641+
try:
642+
xbee.transmit(xbee.ADDR_COORDINATOR,
643+
ujson.dumps(status_response))
644+
except Exception as e:
645+
print(" - Transmit failure: %s" % str(e))
623646

624-
was_btn_pressed = is_button_pressed()
647+
was_btn_pressed = is_button_pressed()
625648

626649
# Blink identification LED if necessary.
627650
if identified:

0 commit comments

Comments
 (0)