예제 #1
0
    def connect_sensor(self):
        self.log("Attempt to connect sensor...")

        if not self.tsense:
            self.i2c = I2C(0, I2C.MASTER, baudrate=100000)

            try:
                self.tsense = MCP9808(self.i2c)
            except Exception as e:
                self.on_error("Could not connect to temperature sensor! " +
                              str(e))
                self.tsense = None
                return False
            else:
                self.log("Sensor OK")
                # print("Temperature: {0:.2f}°C".format(self.tsense.get_temp()))

                # Set wakeup pin to temp sense interrupt pin
                self.alert_pin = Pin(self.ALERT_PIN,
                                     mode=Pin.IN,
                                     pull=Pin.PULL_UP)
                machine.pin_sleep_wakeup((self.ALERT_PIN, ),
                                         machine.WAKEUP_ALL_LOW,
                                         enable_pull=True)
                return True
        else:
            self.log("Sensor already OK")
            return True
예제 #2
0
 def deepsleep(self, ms, pins=None, mode=None, enable_pull=None):
     self.__check_init()
     import machine
     if pins is not None:
         if mode is None or type(mode) != int:
             raise ValueError('You must specify a mode as integer!')
         machine.pin_sleep_wakeup(pins, mode, enable_pull)
     self.disconnect()
     machine.deepsleep(ms)
예제 #3
0
 def set_wake_on_flash_pin(self):
     # Flash pin goes low on light detection
     if self.flash_pin() == 1:
         _logger.warning(
             "Light sensor is still triggered. Skipping wakeup to avoid an infinite wake loop."
         )
     else:
         pins = [self._flash_pin_name]
         _logger.info("Setting wakeup on %s", pins)
         machine.pin_sleep_wakeup(pins=pins, mode=machine.WAKEUP_ANY_HIGH)
예제 #4
0
    def sleep(self):
        from modules.sleep.DS3231.dep.rtc_ds3231 import RTC_DS3231

        # set time to zero
        self.rtc.time_year = 1970
        self.rtc.time_month = 1
        self.rtc.time_day = 1
        self.rtc.time_workday = 1
        self.rtc.time_hours = 0
        self.rtc.time_minutes = 0
        self.rtc.time_seconds = 0

        # Set Alarm Date
        self.rtc.alarm1_day = 1
        self.rtc.alarm1_hours = self.config().get("hours")
        self.rtc.alarm1_minutes = self.config().get("minutes")
        self.rtc.alarm1_seconds = self.config().get("seconds")

        # Set Alarm Mode (see datasheet for available modes)
        self.rtc.alarm1_mode = RTC_DS3231.AlarmMode.MATCH_DATE

        # Enable Alarm
        self.rtc.alarm1_enabled = True

        # Clear Alarm Flag (this has to be called every time after a alarm occured)
        self.rtc.alarm1_clear()

        # Enable Interrupt on Alarm
        self.rtc.interrupt_enabled = True

        # Define wakup pin
        from machine import Pin
        p = Pin('P' + str(self.config().get("pin_wake")), mode=Pin.IN)

        # Define Sleep Wakeup
        import machine
        #machine.pin_deepsleep_wakeup([p], machine.WAKEUP_ALL_LOW, True)   # on older firmware
        machine.pin_sleep_wakeup([p], machine.WAKEUP_ALL_LOW,
                                 True)  # on newer firmware

        # now we can sleep finally
        machine.deepsleep()
예제 #5
0
from network import LoRa
import socket

chrono = Timer.Chrono()

# Initialize LoRa Socket:
lora = LoRa(mode=LoRa.LORA, region=LoRa.US915)
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setblocking(False)
i = 0

import time
from machine import Pin

pir = Pin('P4', mode=Pin.IN, pull=Pin.PULL_UP)
machine.pin_sleep_wakeup([pir], machine.WAKEUP_ANY_HIGH, False)

chrono.start()
active = False
print('I woke up')
# Begin reading if SN 1 has sent a message
print('Reading..')

while chrono.read() < 20:
    if s.recv(64) == b'Ping':
        # Debugging statements
        print('Sensor Node 1 Activated')
        print('Sending confirmation to SN1')
        active = True
        break
    time.sleep(1)
예제 #6
0
accelerometer()
print("enable accelerometer interrupt")

# enable_activity_interrupt( [mG], [ms], callback)
# accelerometer_sensor.enable_activity_interrupt(8000, 200, activity_int_handler) # low sensitivty
# accelerometer_sensor.enable_activity_interrupt(2000, 200, activity_int_handler) # medium sensitivity
accelerometer_sensor.enable_activity_interrupt(
    100, 200, activity_int_handler)  # high sensitivity
# accelerometer_sensor.enable_activity_interrupt(63, 160, activity_int_handler) # ultra sensitivty

if wait(0x0A000A):  # purple
    print("button was held")
    blink(0x000a00)  # green
    print("enable pycom module to wake up from accelerometer interrupt")
    wake_pins = [Pin('P13', mode=Pin.IN, pull=Pin.PULL_DOWN)]
    machine.pin_sleep_wakeup(wake_pins, machine.WAKEUP_ANY_HIGH, True)

    print("put pycoproc to sleep and pycom module to deepsleep for",
          round(sleep_time_s / 60, 1), "minutes")
    pycoproc.setup_sleep(sleep_time_s)
    pycoproc.go_to_sleep(pycom_module_off=False,
                         accelerometer_off=False,
                         wake_interrupt=True)
    machine.deepsleep(sleep_time_s * 1000)
else:
    print("button was tapped")
    blink(0x100600)  # orange
    print("put pycoproc to sleep and turn pycom module off for",
          round(sleep_time_s / 60, 1), "minutes")
    pycoproc.setup_sleep(sleep_time_s)
    pycoproc.go_to_sleep()
예제 #7
0
파일: main.py 프로젝트: ThenTech/NIIP-Labo
        # If first boot, get settings from remote
        if WITH_SENSOR:
            i2c = I2C(0, I2C.MASTER, baudrate=100000)
            tsense = MCP9808(i2c)

            tsense.set_alert_mode(enable_alert=True,
                                  output_mode=ALERT_OUTPUT_INTERRUPT,
                                  polarity=ALERT_POLARITY_ALOW,
                                  selector=ALERT_SELECT_CRIT)
            tsense.set_alert_boundary_temp(REG_TEMP_BOUNDARY_CRITICAL,
                                           TMP_THRESHOLD / 100.0)

        alert_pin = Pin(ALERT_PIN, mode=Pin.IN, pull=Pin.PULL_UP)
        machine.pin_sleep_wakeup((ALERT_PIN, ),
                                 machine.WAKEUP_ALL_LOW,
                                 enable_pull=True)

        go_to_sleep()
    else:
        # Recover from deepsleep
        reason = machine.wake_reason()[0]

        if reason == machine.PIN_WAKE:
            print("Wake on PIN_INTERRUPT")

            if WITH_SENSOR:
                i2c = I2C(0, I2C.MASTER, baudrate=100000)
                tsense = MCP9808(i2c)

                tsense.acknowledge_alert_irq()  # Is this needed in this case?
예제 #8
0
# 1 if interrupted by PIR, 2 if timeout
wake_reason     = machine.wake_reason()[0]
# True if motion's been detected. False if not.
high            = True if machine.wake_reason()[1] != [] else False


#Wifi-sniffer
wlan.callback(trigger=WLAN.EVENT_PKT_MGMT, handler=pack_cb)
wlan.promiscuous(True)


# If awoken by PIR interrupt.
if wake_reason == 1:
    # If no motion is detected.
    if not high:
        print(0)
        machine.pin_sleep_wakeup([pir], mode=machine.WAKEUP_ANY_HIGH)
        machine.deepsleep(86400000)
    # If wifi units are nearby
    elif device_found:
        print(1)
    # If motion is detected and no wifi units are nearby.
    else:
        print(2)
    # Go to sleep for 15 minutes. Interrupts if no motion's detected.
    machine.pin_sleep_wakeup([pir], mode=machine.WAKEUP_ALL_LOW)
    machine.deepsleep(900000)
# Go to sleep for 24 hours.
machine.pin_sleep_wakeup([pir], mode=machine.WAKEUP_ANY_HIGH)
machine.deepsleep(86400000)
예제 #9
0
print("LoPy4 - Has joined!!!!!")

# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

# set the LoRaWAN socket options
DATA_RATE = 0
s.setsockopt(socket.SOL_LORA, socket.SO_DR, DATA_RATE)
s.setsockopt(socket.SOL_LORA, socket.SO_CONFIRMED, True)

print('========== Starting Serial UART configuration ===========')
# Configure second UART bus on pins P3(TX1) and P4(RX1)
uart = machine.UART(1,
                    baudrate=19200,
                    bits=8,
                    parity=None,
                    stop=1,
                    pins=('P3', 'P4'))

print('========== Starting PIN wakeup configuration ============')
#p_in = Pin('P10', mode=Pin.OUT, pull=None, alt=-1)
machine.pin_sleep_wakeup(['P4'], machine.WAKEUP_ALL_LOW, False)
#machine.enable_irq()

pycom.heartbeat(False)

time.sleep(5)

machine.main('main.py')
print('========== Starting main.py ==========')