示例#1
0
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
示例#2
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)
示例#3
0
wlan.connect(SSID, auth=(WLAN.WPA2, PASS), timeout=5000)
while not wlan.isconnected():
     machine.idle()
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:
示例#4
0
from CayenneLPP import CayenneLPP

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):
        pycom.rgbled(ledColor)
        time.sleep(0.2)
        pycom.heartbeat(False)
        time.sleep(0.2)
        x += 1


print("Starting boot")
pycom.wifi_on_boot(False)
pycom.heartbeat(False)
time.sleep(2)
py = Pytrack()
li = LIS2HH12()

print("Get Wakeup reason")
reason = py.get_wake_reason()
print("Wakeup reason")
print(reason)

print("Get Mac ID ..")
dev_id = ubinascii.hexlify(machine.unique_id(), ':').decode()
print("Mac ID is ..")
print(dev_id)

print("Get Voltage ..")
voltage = py.read_battery_voltage()
print("Voltage is ..")
print(voltage)

if reason == pycoproc.WAKE_REASON_ACCELEROMETER:  # purple
    flashLed(led_purple, 2)
示例#6
0
import socket
import time
import ubinascii

py = Pytrack()
acc = LIS2HH12()

# unique id (last 4 of mac) for message
id = ubinascii.hexlify(machine.unique_id()).decode()[8:12]

# type of sensor
type = "accel"

pycom.heartbeat(False)
# checks to see if system woke up because of the Accelerometer
if py.get_wake_reason() == 1:

    #test decode
    pycom.rgbled(0xffffff)
    time.sleep(1)
    # create lora socket
    lora = LoRa(mode=LoRa.LORA,
                region=LoRa.US915,
                frequency=902000000,
                tx_power=20,
                sf=12,
                power_mode=LoRa.TX_ONLY)

    sock = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
    sock.setsockopt(socket.SOL_LORA, socket.SO_DR, 3)
示例#7
0
#heartbeat uitschakelen om de led aan te kunnen sturen.
pycom.heartbeat(False)

#instantie aanmaken van de pytrack (voor deepsleep)
#instantie aanmaken van de accelerometer.
py = Pytrack()
acc = LIS2HH12()

# 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
wakeReason = py.get_wake_reason()  #reden van wakeup opvragen

cycliInGeheugen = lib.get_number('cycle')

print(
    " Cycle: " + '{}'.format(cycliInGeheugen)
)  #uitprinten van het aantal cycli in het geheugen, voordat er een nieuwe waarde bijgeteld wordt.
print("Wakeup reason: " + str(wakeReason))  #wakeReason weergeven
time.sleep(0.5)

# 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)
示例#8
0
        if environ.temperature and environ.humidity and environ.barometric_pressure:
            env_msg = EnvironMessage(
                temperature=environ.temperature,
                humidity=environ.humidity,
                barometric_pressure=environ.barometric_pressure)
        else:
            log.error('Problem with environmental sensor')

    # Send message
    pycom.rgbled(config.LED_COLOR_OK)

    msg = gps_msg.lora() + '|' + env_msg.lora() + '|{0:.1f}'.format(
        py.read_battery_voltage())

    # Awake from Accelerometer
    if py.get_wake_reason() == WAKE_REASON_ACCELEROMETER:
        msg += '|1'  # Means awake from Accellerometer

    log.debug('LoRa message to send {}', msg)
    lora.send_str(message=msg)
    pycom.heartbeat(False)

    # Awake on Accelerometer
    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)