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()
# currently moving, wait between next GPS send time.sleep(30) send_data_lorawan() elif wakeup == WAKE_REASON_TIMER: # increment counter pulse = pycom.nvs_get('count') if pulse == None: pulse = 0 print("Wakeup Timer count: " + str(pulse)) pulse += 1 if pulse == config.COUNT_CYCLES: pulse = 0 print("--SEND TIMER") # Try to acquire GPS time.sleep(30) send_data_lorawan() pycom.nvs_set('count', pulse) # Save LoRaWAN states before deepsleep lora.nvram_save() # Enable activity and disable inactivity interrupts, using the default callback handler py.setup_int_wake_up(True, False) # enable the activity/inactivity interrupts # set the accelereation threshold to 200mG and the min duration to 100ms acc.enable_activity_interrupt(1000, 200) print("Go Deep Sleep") time.sleep(0.2) # go to sleep for 5 minutes maximum if no accelerometer interrupt happens py.setup_sleep(config.SLEEP_TIMER) py.go_to_sleep()
if failureCount > 5: bt.stop_scan() bt.start_scan(-1) failureCount = 0 time.sleep(0.50) wdt.feed() # # GO TO SLEEP # # print("set to 1 before sleep") # p_out.value(1) # p_out.hold(True) # time.sleep(1) # py.setup_sleep(60*6) try: print(a) print('print a success') except: print('print a failed') wdt.feed() print("go to sleep") time.sleep(1) py.setup_sleep(5) py.go_to_sleep()
import os import time import utime import gc from pytrack import Pytrack import pycom from machine import Pin gc.enable() py = Pytrack() pycom.heartbeat(False) # pycom.heartbeat(True) p_out = Pin('P20', mode=Pin.OUT) if not p_out.hold(): print("not on hold") p_out.value(1) else: print("on hold") p_out.hold(False) p_out.toggle() p_out.hold(True) print("performed hold") if p_out.value(): pycom.rgbled(0x007f7f) else: pycom.rgbled(0x007f00) py.setup_sleep(3) py.go_to_sleep()
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 coordHex = (hex(int(coord[0] * 100000))[2:] + hex(int(coord[1] * 100000))[2:] ) # 5 dec places is plenty accurate. (4 is still good) messageToSend = coordHex bytesToSend = 0 lastCount = 0 while bytesToSend < len(messageToSend): bytesToSend = bytesToSend + 12 s.send(str(messageToSend[lastCount:bytesToSend])) lastCount = bytesToSend sigfoxCounter = sigfoxCounter + 1 print("Sigfox messages sent: ", sigfoxCounter) time.sleep(5) # let everything go through # go to sleep for 24 hours maximum if no accelerometer interrupt happens print("Last Sleep length: ", asleepTime, "seconds") print("Going to sleep...") py.setup_sleep(maxSleep) 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)
import time py = Pytrack() #py = Pysense() # 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())) 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) acc = LIS2HH12() # enable activity and also inactivity interrupts, using the default callback handler py.setup_int_wake_up(True, True) # set the acceleration threshold to 2000mG (2G) and the min duration to 200ms acc.enable_activity_interrupt(2000, 200) # go to sleep for 5 minutes maximum if no accelerometer interrupt happens py.setup_sleep(60) py.go_to_sleep()
time.sleep(2) # <- emm, not sure why I have this..will clean up soon.. print("setup done, send message") print("first check coords, print lat and lon here") print(lat, lon) # lat and lon are floating points, this will not be supported in the TTN HTTP API integration, if you want to decode the payload... # convert to array of bytes in function convert_latlon gps_array = convert_latlon(lat, lon) print("converted array is..") print(gps_array) # Send coordinates s.send( gps_array ) # <- sent as array of bytes, we then can decode as appropriate in TTN payload configuration.. print("sent message, wait for 10 secs") time.sleep( 10 ) # <- delay to ensure message sent before going to sleep, improve this... # Deep Sleep # Since this project uses the Pytracker shield, there is no need to use the sleep shield. When using the Pytracker shield, deep sleep is achived # using py.go_to_sleep. Hence make sure the correct library is used !!! See lib folder. print("now sleep 120 seconds..") py.setup_sleep( 120 ) # deep sleep for 120 seconds, change this to suit your own needs and respect TTN fair usage policy. py.go_to_sleep()
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()
if config.DEEPSLEEP_AWAKE_ON_ACCELEROMETER: # Disable 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(config.ACCELEROMETER_THRESHOLD, config.ACCLEROMETER_DURATION_MS) # Go to sleep if config.DEEPSLEEP_ENABLED: log.info('Start sleeping for {} seconds', config.DEEPSLEEP_IN_SECONDS) time.sleep(2) # So everything can finish # Sleep py.setup_sleep(config.DEEPSLEEP_IN_SECONDS) py.go_to_sleep() except Exception as e: pycom.rgbled(config.LED_COLOR_ERROR) log.error('Unexpected error {}', e) time.sleep(5) # Wait for 5secs before reset machine.reset() # Reset device