예제 #1
0
pycom.heartbeat(False)

py = Pytrack()
# py = Pysense()

# enabling garbage collector
gc.enable()

# display the reset reason code and the sleep remaining in seconds
# possible values of wakeup reason are:
# WAKE_REASON_ACCELEROMETER = 1
# WAKE_REASON_PUSH_BUTTON = 2
# WAKE_REASON_TIMER = 4
# WAKE_REASON_INT_PIN = 8
print("Wakeup reason: " + str(py.get_wake_reason()) +
      "; Aproximate sleep remaining: " + str(py.get_sleep_remaining()) +
      " sec")
time.sleep(0.5)

# enable wakeup source from INT pin
py.setup_int_pin_wake_up(False)

# enable activity and also inactivity interrupts, using the default callback handler
py.setup_int_wake_up(True, True)

acc = LIS2HH12()
# enable the activity/inactivity interrupts
# set the accelereation threshold to 2000mG (2G) and the min duration to 200ms
acc.enable_activity_interrupt(2000, 200)

# check if we were awaken due to activity
예제 #2
0
import config

# Possible values of wakeup reason are:
WAKE_REASON_ACCELEROMETER = 1
WAKE_REASON_PUSH_BUTTON = 2
WAKE_REASON_TIMER = 4
WAKE_REASON_INT_PIN = 8

# Init Pytrack
py = Pytrack()
fw_version = py.read_fw_version()
print("Pytrack firmware version: " + str(fw_version))
# Get wakeup reason
wakeup = py.get_wake_reason()
print("Wakeup reason: " + str(wakeup) + "; Aproximate sleep remaining: " +
      str(py.get_sleep_remaining()) + " sec")
# Init GPS
gps = L76GNSS(py, timeout=10)
# Init accelerometer
acc = LIS2HH12()
# Init CayenneLPP buffer
lpp = CayenneLPP()
# Init LoRaWAN
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868, adr=config.ADR)
# Restore LoRaWAN states after deepsleep
lora.nvram_restore()


def blink_led(color, delay=0.2):
    """ blink led for a short time """
    pycom.rgbled(color)
예제 #3
0
print("Connected to Wifi %s"%SSID)

queue = MessageBuffer(broker=BROKER, topic=TOPIC)

py = Pytrack()
# display the reset reason code and the sleep remaining in seconds
# possible values of wakeup reason are:
# WAKE_REASON_ACCELEROMETER = 1
# WAKE_REASON_PUSH_BUTTON = 2
# WAKE_REASON_TIMER = 4
# WAKE_REASON_INT_PIN = 8

message = "Wake up reason: " + str(py.get_wake_reason())
print(message)
queue.push(message)
print("Approximate sleep remaining: " + str(py.get_sleep_remaining()) + " sec")
time.sleep(0.5)

# enable wakeup source from INT pin
py.setup_int_pin_wake_up(False)



def check_inactivity(alarm):
    global queue, MAX_TIMEOUT, py
    inactivity_time = queue.get_timeout()
    print('Inactivity timer acc:', inactivity_time)
    if inactivity_time > MAX_TIMEOUT:
        print('Going to sleep for %ss'%TIME_TO_SLEEP)
        queue.push('Sleeping..')
        queue._chrono.reset()
예제 #4
0
                rcz=Sigfox.RCZ1)  # init Sigfox for RCZ1 (Europe)
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)  # create a Sigfox socket
s.setblocking(True)  # make the socket blocking
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX,
             False)  # configure it as uplink only
sigfoxCounter = 0  # count numbre of sigfox trnasmissions (max 140 a day)

gc.enable()
l76 = L76GNSS(py, timeout=60)  # setup GPS

gc.collect()
noLock = 0
lock = False
pycom.rgbled(0xFF0000)  # red
print("Activity")
asleepTime = maxSleep - py.get_sleep_remaining()  # seconds, not accurate

print("We were asleep for ", asleepTime, " Seconds.")

while (lock == False) and (
        noLock < 6):  # Try get GPS 6 Times before giving up and going to Sleep
    coord = l76.coordinates(debug=False)
    print("{} - {} KB".format(coord, gc.mem_free() / 1000))
    if not all(coord):  # returns false if none is in the truple
        print(noLock, " - No lock found")
        noLock = noLock + 1
        wdt.feed()  # tell watchdog we're stll alive
    else:
        print("lock found")
        lock = True
        wdt.feed()  # tell watchdog were stll alive