Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vcoman/keep ble #76

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions samples/demos/end_to_end_agriculture/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@

identified = False
finished = False
simulate_temp = True
simulate_temp = False

time_seconds = 0
weather_condition = WEATHER_SUNNY
Expand All @@ -147,6 +147,10 @@

sensor = None

LED_PIN_ID = "D9"

led_pin = Pin(LED_PIN_ID, Pin.OUT, value=VALUE_DISABLED)


def read_properties():
"""
Expand Down Expand Up @@ -299,7 +303,7 @@ def relay_frame_callback(relay_frame):
elif operation == OP_FINISH:
print("- BLE: Finish request received.")
# Disable BLE interface. This operation does not require a response.
xbee.atcmd(AT_CMD_BT, VALUE_DISABLED)
# xbee.atcmd(AT_CMD_BT, VALUE_DISABLED)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be removed instead of commented out.

# Write settings in the device.
xbee.atcmd(AT_CMD_WR)
finished = True
Expand Down Expand Up @@ -531,6 +535,22 @@ def set_status_value(status_id, status_value):
led_pin.value(valve_pos)


def toggle_valve():
"""
Toggles the status of the electronic valve.
"""
global valve_pos
status = valve_pos

if status == 0:
valve_pos = True
else:
valve_pos = False

print("- Toggling valve status to '{}'.".format("Open" if valve_pos == True else "Closed"))
led_pin.value(valve_pos)


def get_mac():
"""
Returns the XBee MAC address of the device.
Expand Down Expand Up @@ -613,15 +633,22 @@ def main():
# Sleep 100 ms.
time.sleep_ms(100)

if sensor is not None:
# If the button has been pressed, swap the temperature source
# (reading or simulation).
if not was_btn_pressed and is_button_pressed():
simulate_temp = not simulate_temp
print("- Temperature source changed to %s"
% ("simulation" if simulate_temp else "reading"))
# If the button has been pressed, swap the temperature source
# (reading or simulation).
if not was_btn_pressed and is_button_pressed():
toggle_valve()
status_response = {
ITEM_OP: OP_STATUS,
ITEM_PROP: get_sensors_values()
}
print("- Reporting status data: %s" % status_response)
try:
xbee.transmit(xbee.ADDR_COORDINATOR,
ujson.dumps(status_response))
except Exception as e:
print(" - Transmit failure: %s" % str(e))

was_btn_pressed = is_button_pressed()
was_btn_pressed = is_button_pressed()

# Blink identification LED if necessary.
if identified:
Expand Down