def deep_sleep(time_to_deep_sleep): """ Function to set Pytrack in ultra low power (deep sleep) during x time. Returns ------- time_to_deep_sleep: int seconds to stay in deep sleep """ i2c = machine.I2C(0, mode=I2C.MASTER, pins=('P22', 'P21')) py = Pytrack(i2c=i2c) py.setup_sleep(time_to_deep_sleep) py.go_to_sleep(gps=True) i2c.deinit()
class InactivitySensor(PeriodicSensor): def __init__(self, queue, period, wait_before_sleep=WAIT_BEFORE_SLEEP, time_to_sleep=TIME_TO_SLEEP): self._wait_before_sleep = wait_before_sleep self._time_to_sleep = time_to_sleep self._queue = queue self._py = Pytrack() message = "Wake up reason: " + str(self._py.get_wake_reason()) # 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 self.printout(message) time.sleep(0.5) # enable wakeup source from INT pin self._py.setup_int_pin_wake_up(False) self.value = 0 # enable activity and also inactivity interrupts, using the default callback handler self._py.setup_int_wake_up(True, True) PeriodicSensor.__init__(self, queue, period) def read(self): self.value = self._queue.get_timeout() if self.value > self._wait_before_sleep: self._sleep() def _sleep(self): self.printout('Sleeping') EventSensor._event_handler(self) #self._queue._client.publish(self._queue._topic, 'Sleeping') self._py.setup_sleep(self._time_to_sleep) self._py.go_to_sleep() pass
# 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 if acc.activity(): pycom.rgbled(0xFF0000) else: pycom.rgbled(0x00FF00) # timer wake-up Green time.sleep(2) pycom.rgbled(0x000000) time.sleep(1) pycom.rgbled(0xFF0000) # Red time.sleep(1) pycom.rgbled(0x00FF00) # Green time.sleep(1) pycom.rgbled(0x0000FF) # Blue time.sleep(1) gc.collect() # go to sleep for 5 minutes maximum if no accelerometer interrupt happens py.setup_sleep(30) py.go_to_sleep()
from pytrack import Pytrack #from pysense import Pysense from LIS2HH12 import LIS2HH12 import pycom import time pycom.heartbeat(False) py = Pytrack() # py = Pysense() # 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 if acc.activity(): pycom.rgbled(0xFF0000) else: pycom.rgbled(0x00FF00) # timer wake-up time.sleep(0.1) # go to sleep for 5 minutes maximum if no accelerometer interrupt happens py.setup_sleep(300) py.go_to_sleep()
py = Pytrack() acc = LIS2HH12() print("") DEEP_SLEEP_SECONDS = 600 # Set deep sleep parameters py.setup_int_wake_up(True, False) # Turn off accelerometer acc.set_odr(0) # Get GPS data from pytrack board gc.collect() gps = pytrackHelper.getGPS(py, 300) if (gps[0] is not None and gps[1] is not None): # Create a list of key value pairs to be # sent by LTE to hologram dataList = [] dataList.append(("lat", gps[0])) dataList.append(("lng", gps[1])) dataList.append(("humidity", 95)) gc.collect() # Connect to LTE and send the list of data items and hologram device key lteHelper.sendData(dataList, "lQ6Gjc$n") # Go into low power sleep print("Deep sleep for %d seconds..." % (DEEP_SLEEP_SECONDS)) time.sleep(1) py.setup_sleep(DEEP_SLEEP_SECONDS) py.go_to_sleep(gps=False)
pycom.rgbled(0x00FF00) #led kleurt groen als een trilling waargenomen is. lib.store_number('cycle') elif ( py.get_wake_reason() == WAKE_REASON_PUSH_BUTTON ): #Wanneer er op de knop gedrukt wordt zal er gestuurd worden wanneer er data in het geheugen aanwezig is. if (lib.get_number('cycle') != 0): #enkel sturen wanneer er data aanwezig is. lib.setup_sigfox_and_send( setup_array() ) #methode aanroepen die het versturen voor zich neemt, krijgt de array mee die deze moet versturen. lib.reset_number('cycle') #resetten van de waarde in het geheugen elif (py.get_wake_reason() == WAKE_REASON_TIMER ): #Wanneer de timer afgelopen is alles doorsturen if (lib.get_number('cycle') != 0): #enkel sturen wanneer er data aanwezig is. lib.setup_sigfox_and_send(setup_array()) lib.reset_number('cycle') if ( lib.get_number('cycle') >= NUMBER_OF_VIBRATIONS ): #als er meer data in het geheugen aanwezig is dan de thresold: versturen van de data lib.setup_sigfox_and_send(setup_array()) lib.reset_number('cycle') #instellen van de drempelwaardes voor de accelerometer. acc.enable_activity_interrupt(TRILLINGS_DREMPEL, DUUR_DREMPEL) #instellen van de deepsleep (timer instellen) py.setup_sleep(TIME_SLEEP) py.go_to_sleep(False) #False om de gps uit te schakelen.
config.app_key, WAIT_FOR_LORA_S, debug=DEBUG) if DEBUG: pycom.rgbled(BLUE) print("Sending payload...") payload = payload_encoder.encode(battery, latitude, longitude, hdop).to_bytes(7 if fixed else 2, 'big', False) counter = pycom.nvs_get('counter') if counter is None or counter > 65535: counter = 0 datarate = select_datarate(counter) pycom.nvs_set('counter', counter + 1) client.send(payload, datarate, 2 if fixed else 3) if DEBUG: pycom.rgbled(GREEN) print("Going to sleep...") py.setup_sleep(SLEEP_TIMEOUT_S) py.go_to_sleep(gps=True) if DEBUG: pycom.rgbled(RED) print("This message should not be displayed") except Exception as ex: print("!!! Exception detected !!!", type(ex), ex) finally: if DEBUG: print("Trigger reset") sleep(1) machine.reset()