|
137 | 137 |
|
138 | 138 | identified = False |
139 | 139 | finished = False |
140 | | -simulate_temp = True |
| 140 | +simulate_temp = False |
141 | 141 |
|
142 | 142 | time_seconds = 0 |
143 | 143 | weather_condition = WEATHER_SUNNY |
@@ -531,6 +531,22 @@ def set_status_value(status_id, status_value): |
531 | 531 | led_pin.value(valve_pos) |
532 | 532 |
|
533 | 533 |
|
| 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 | + |
534 | 550 | def get_mac(): |
535 | 551 | """ |
536 | 552 | Returns the XBee MAC address of the device. |
@@ -613,15 +629,22 @@ def main(): |
613 | 629 | # Sleep 100 ms. |
614 | 630 | time.sleep_ms(100) |
615 | 631 |
|
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)) |
623 | 646 |
|
624 | | - was_btn_pressed = is_button_pressed() |
| 647 | + was_btn_pressed = is_button_pressed() |
625 | 648 |
|
626 | 649 | # Blink identification LED if necessary. |
627 | 650 | if identified: |
|
0 commit comments