Home/Support/Support Forum/how to enter pin sleep on xbee cellular upython script
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

how to enter pin sleep on xbee cellular upython script

0 votes
I have followed the example, but I cannot get the module to sleep....

from machine import Pin
import network
import time
import xbee

alarm_enabled = False
alarm = False
last_upload = 0

def read_sensors():
# add code here to actually read sensors
# might set the alarm for unusual readings
time.sleep(1)
print("read sensors")

def set_alarm_condition():
global alarm
print("alarm!")
alarm = True

def send_data():
time.sleep(1)
global alarm, last_upload
# add code here to connect to a server to upload sensor readings
print("sent data and reported any alarms")
alarm = False
last_upload = time.ticks_ms()

def time_for_upload():
global alarm, last_upload

# upload if there's been an alarm, or it's been an hour since last upload
return alarm or (time.ticks_diff(time.ticks_ms(), last_upload) > 60 * 60 * 100)

def upload_then_sleep():
time.sleep(1)
print("virtual uploading...")
send_data()

c = network.Cellular()
x = xbee.XBee()

x.atcmd('SM', 0) # make sure MicroPython fully controls sleep

# must configure DIO8 as an input with pullup if we want to read and use it for waking
dio8 = Pin("D8", Pin.IN, Pin.PULL_UP)

# upload data then put module to sleep
upload_then_sleep()

while True:
read_sensors()
if time_for_upload():
upload_then_sleep();

if not alarm_enabled and dio8():
print("DIO8 high, re-enabling alarm")
alarm_enabled = True

# sleep for 60 seconds, wake early if DIO8 is low
print("sleeping for 6 seconds")
sleep_ms = x.sleep_now(60000, alarm_enabled)

print("slept for %u ms" % sleep_ms)
if x.wake_reason() is xbee.PIN_WAKE:
print("woke early on DIO8 low")
set_alarm_condition()
alarm_enabled = False
asked Jan 25, 2018 in Python by kennemon New to the Community (2 points)

Please log in or register to answer this question.

2 Answers

0 votes
which xbee cellular module is this and what firmware version are you working with?
answered Jan 25, 2018 by mvut Veteran of the Digi Community (11,300 points)
0 votes
thanks for the reply.

latest firmware installed, 100A

it is a LTE cat1 module
answered Feb 5, 2018 by kennemon New to the Community (2 points)
...