Esempio n. 1
0
 def __smart_config_setup(self):
     wl = WLAN(mode=WLAN.STA)
     wl.callback(trigger=WLAN.SMART_CONF_DONE | WLAN.SMART_CONF_TIMEOUT,
                 handler=self.__smart_config_callback)
     if pycom.wifi_ssid_sta() is not None and len(
             pycom.wifi_ssid_sta()) > 0:
         print('Trying previous AP details for 60 seconds...')
         pycom.wifi_on_boot(True, True)
         try:
             start_time = time.time()
             while not wl.isconnected() and (
                     time.time() - start_time <
                     60) and self.__smart_config:
                 time.sleep(1)
         except:
             pass
         if wl.isconnected() and self.__smart_config:
             try:
                 from pybytes_config import PybytesConfig
             except:
                 from _pybytes_config import PybytesConfig
             self.__conf = PybytesConfig().smart_config()
             self.__smart_config = False
             self.start()
     if self.__smart_config:
         wl.smartConfig()
         print("Smart Provisioning started in the background")
         print("See https://docs.pycom.io/smart for details")
Esempio n. 2
0
def features(on=None):
    if on is None:
        print("heartbeat   ", pycom.heartbeat_on_boot())
        print("lte         ", pycom.lte_modem_en_on_boot())
        try:
            print("pybytes     ", pycom.pybytes_on_boot())
        except:
            pass
        try:
            print("smart_config", pycom.smart_config_on_boot())
        except:
            pass
        print("wdt         ", pycom.wdt_on_boot())
        print("wifi        ", pycom.wifi_on_boot())
    else:
        print("configure all features as", on)
        pycom.heartbeat_on_boot(on)
        pycom.lte_modem_en_on_boot(on)
        try:
            pycom.pybytes_on_boot(on)
        except:
            pass
        try:
            pycom.smart_config_on_boot(on)
        except:
            pass
        pycom.wdt_on_boot(on)
        pycom.wifi_on_boot(on)
        features(None)
Esempio n. 3
0
def set_persistent_settings():
    _logger.info("Setting persistent settings...")
    pycom.wifi_on_boot(False)
    pycom.lte_modem_en_on_boot(False)
    pycom.heartbeat_on_boot(False)
    pycom.wdt_on_boot(True)
    pycom.wdt_on_boot_timeout(1000 * 30)
Esempio n. 4
0
def setup():
    global l76, lora
    if pycom.wifi_on_boot():  ## attempt to save battery
        pycom.wifi_on_boot(False)
    pycom.heartbeat(False)
    py = Pytrack()
    l76 = L76GNSS(py, timeout=30)
    lora = LoRa(mode=LoRa.LORAWAN)
def show_boot_flags():
    _logger.info("pycom.wifi_on_boot():         %s", pycom.wifi_on_boot())
    with CheckStep(FLAG_LTE_FW_API, suppress_exception=True):
        # These methods are not available on old firmware versions
        # If they are missing, we need to upgrade the Pycom firmware
        _logger.info("pycom.lte_modem_en_on_boot(): %s",
                     pycom.lte_modem_en_on_boot())
        _logger.info("pycom.heartbeat_on_boot():    %s",
                     pycom.heartbeat_on_boot())
        _logger.info("pycom.wdt_on_boot():          %s", pycom.wdt_on_boot())
        _logger.info("pycom.wdt_on_boot_timeout():  %s",
                     pycom.wdt_on_boot_timeout())
Esempio n. 6
0
    def __init__(self):
        super(LoPy4, self).__init__()

        # configure power pins
        from machine import Pin
        for i in self.config().get("pwr_pins"):
            log_debug("Activating power pin " + str(i) + ".")
            p = Pin("P" + str(i), mode=Pin.OUT)
            p.value(1)

        # set wifi access point
        import pycom
        pycom.wifi_on_boot(self.config().get("wifi_on_boot"))

        # check for sufficiant power
        bat = LoPy4Battery(17).voltage()
        if bat > 5:
            if bat < 10.4:
                log_warning("Battery voltage too low.")
                import machine
                machine.deepsleep(890000)
Esempio n. 7
0
    def __init__(self, config, activation=False, autoconnect=False):
        self.__frozen = globals().get('__name__') == '_pybytes'
        self.__activation = activation
        self.__custom_message_callback = None
        self.__config_updated = False
        self.__pybytes_connection = None
        self.__smart_config = False
        self.__conf = {}

        if not self.__activation:
            self.__conf = config
            pycom.wifi_on_boot(False, True)

            self.__check_dump_ca()
            self.__create_pybytes_connection(self.__conf)
            self.start(autoconnect)
            if autoconnect:
                self.print_cfg_msg()
        else:
            if (hasattr(pycom, 'smart_config_on_boot')
                    and pycom.smart_config_on_boot()):
                self.smart_config(True)
    wlan = WLAN()
    wlan.init(mode=WLAN.AP, ssid='lopy-pysense', auth=(network.WLAN.WPA2,'lopy-pysense'), channel=7,antenna=WLAN.INT_ANT) #Init Wi-Fi
    server = network.Server()                                                   #Init FTP Server
    print("Device entered into debugging mode")
    print("Please do not connect to battery")
    pycom.heartbeat(True)                                                       #Se activa el Heartbeat
    while(1):
        if py.button_pressed():
            print("Resetting")
            machine.reset()

else:                                                                           #Si viene de Boot o Hard Reset
    print('Power on or hard reset')
    sleep_time = 100                                                            #Valor por defecto de sleep_time (Minimo segun Fair Acess Policy TTN)
    data_rate = 5
    pycom.wifi_on_boot(False)                                                   # disable WiFi on boot TODO: Intentar en versiones posteriores, da un Core Error.
    pycom.heartbeat_on_boot(False)
    try:
        pycom.nvs_set('sleep_time', sleep_time)                                 #Guarda el valor por defecto de sleep_time en NVRAM
        pycom.nvs_set('data_rate', data_rate)
    except (Exception):
        print("Error: Value could not be stored")
        pass

    n = Node(sleep_time,data_rate,py)                                           #Crea una instancia de Node
    n.connect(dev_eui,app_eui, app_key)                                                 #Join LoRaWAN with OTAA

    #Envío de las lecturas
    n.send(n.readsens())
    print("Data Sent, sleeping ...")
    print('- ' * 20)
Esempio n. 9
0
    uid = binascii.hexlify(machine.unique_id()).decode("utf-8")
    name = os.uname().sysname.lower() + '-' + uid[-4:]
    print(name, uid)

    features()
    if False:
        features(True)  # turn everything on
        features(False)  # turn everything off
        # print
        import pycom
        print('heartbeat', pycom.heartbeat_on_boot())
        print('lte', pycom.lte_modem_en_on_boot())
        print('pybytes', pycom.pybytes_on_boot())
        print('smart_config', pycom.smart_config_on_boot())
        print('wdt', pycom.wdt_on_boot())
        print('wifi', pycom.wifi_on_boot())
        # off
        pycom.heartbeat_on_boot(False)
        import pycom
        pycom.lte_modem_en_on_boot(False)
        pycom.wdt_on_boot(False)
        pycom.wifi_on_boot(False)
        pycom.smart_config_on_boot(False)
        pycom.pybytes_on_boot(False)
        # on
        pycom.heartbeat_on_boot(True)
        pycom.lte_modem_en_on_boot(True)
        pycom.pybytes_on_boot(True)
        pycom.smart_config_on_boot(True)
        pycom.wdt_on_boot(True)
        pycom.wifi_on_boot(True)
Esempio n. 10
0
    # run from power cycle
    runMySense()

# go into REPL mode, wifi On
try:
    setWiFi()  # MySense.runMe() may switch it off after 60 min
except:
    pass

print(
    "No auto MySense start\nTo start MySense loop (reset config, cleanup nvs):"
)
print("  import MySense; MySense.runMe(debug=False,reset=True)")
try:
    from pycom import heartbeat, rgbled, wifi_on_boot
    from time import sleep
    if not wifi_on_boot(): wifi_on_boot(True)
    heartbeat(False)
    for x in range(3):
        rgbled(0xf96015)
        sleep_ms(100)
        rgbled(0x0)
        sleep_ms(100)
        rgbled(0x0000ff)
        sleep_ms(100)
        rgbled(0x0)
        sleep_ms(400)
    heartbeat(True)
except:
    pass
Esempio n. 11
0
    except:
        pass
    try:
        from Config import replPin  # if not in config act in old style
        if not Pin(replPin, mode=Pin.IN).value():
            print("REPL enforced, pin %s" % str(REPL))
            return True
    except:
        pass
    return REPL


from machine import wake_reason, PWRON_WAKE, RTC_WAKE
try:
    from pycom import wifi_on_boot
    if (not wifi_on_boot()) and (wake_reason()[0] == PWRON_WAKE):
        wifi_on_boot(True)  # wokeup from power cycle, reset wifi
    if ReplMode() or wifi_on_boot():
        setWiFi()  # might be switched off after 60 min
except:
    setWiFi()


def runMySense():
    import MySense
    MySense.runMe()  # should never return
    import myReset  # cold reboot or sleep forever
    myReset.myEnd()


from machine import wake_reason, PWRON_WAKE, RTC_WAKE
Esempio n. 12
0
# see the Pycom Licence v1.0 document supplied with this file, or
# available at https://www.pycom.io/opensource/licensing
#
#lopy1
from network import LoRa
import socket
import time
import utime
import ubinascii
import pycom
import machine

from loramesh import Loramesh
from Networkmesh import *

pycom.wifi_on_boot(False)
pycom.heartbeat(False)

lora = LoRa(mode=LoRa.LORA,
            region=LoRa.US915,
            tx_power=20,
            bandwidth=LoRa.BW_125KHZ,
            sf=11)
print(lora.tx_power())
#lora = LoRa(mode=LoRa.LORA, region=LoRa.US915, bandwidth=LoRa.BW_125KHZ, sf=11)
#lora = LoRa(mode=LoRa.LORA, region=LoRa.US915,frequency=903000000,tx_power=19, bandwidth=LoRa.BW_125KHZ, sf=12)
MAC = str(ubinascii.hexlify(lora.mac()))[2:-1]
print("LoRa MAC: %s" % MAC)

loram = Loramesh(lora)
mesh = NetworkMesh(loram, MAC, 1)
Esempio n. 13
0
# boot.py -- run on boot-up
from network import Bluetooth
from network import WLAN
import pycom

if pycom.wifi_on_boot() == True:
    pycom.wifi_on_boot(False)

wlan = WLAN()
wlan.deinit()

bluetooth = Bluetooth()
bluetooth.deinit()

pycom.heartbeat(False)  #disable the pycom heartbeat
Esempio n. 14
0
# boot.py -- run on boot-up
# 2019-0915 disabe wifi and wdt
# bron: https://docs.pycom.io/firmwareapi/pycom/pycom/
import micropython
import pycom
from machine import I2C

# allocate memory for exceptions...
# Pycom: https://docs.pycom.io/chapter/firmwareapi/micropython/micropython.html
micropython.alloc_emergency_exception_buf(100)

# disable WiFi on boot, i.e. no AP-netwerk on Wifi
pycom.wifi_on_boot(False)
print('Wifi AP-mode enabled: ', pycom.wifi_on_boot())

# If this flag is set, the application needs to reconfigure the WDT with a
# new timeout and feed it regularly to avoid a reset.
pycom.wdt_on_boot(False)  # no Watch Dog
print('WDT enabled: ', pycom.wdt_on_boot())

# setup i2c, use default PIN assignments (P10=SDA, P11=SCL)
# Expansion board 3.0: SCL=GPO17 ('P10'), SDA=GPO16 ('P9')
i2c = I2C(0, I2C.MASTER)
print('i2c scan:', i2c.scan())
Esempio n. 15
0
This code runs immediately after board boots up.
"""
# Add ./src to the path
import sys
sys.path.append('/flash/src')

# pylint: disable=C0413
import pycom # pylint: disable=F0401
import utime # pylint: disable=E0401
from src.device import Device

# Turn off blinking LED.
pycom.heartbeat(False) # pylint: disable=E1101
# Disable WiFi:
pycom.wifi_on_boot(False) # pylint: disable=E1101

DATA_CACHE_DURATION = 7 # days
DATA_INTERVAL = 5 # seconds
EVENTS_COUNT = 100 # max # of events stored in memory.

# Initialize Device object
DD_DEVICE = Device(
    duration=DATA_CACHE_DURATION,
    interval=DATA_INTERVAL,
    num_events=EVENTS_COUNT
    )

while True:
    DD_DEVICE.read_sensor_data() # create humidity_temp reading.
    DD_DEVICE.check_for_event() # check sensor data for event
Esempio n. 16
0
import pycom
from network import WLAN

# https://docs.pycom.io/firmwareapi/pycom/pycom.html#pycomwifionbootenable
pycom.wifi_on_boot(True)

wlan = WLAN()
wlan.init(mode=WLAN.AP, ssid='wipy-wlan', auth=(WLAN.WPA2,'www.wipy.io'), channel=7, antenna=WLAN.EXT_ANT)

# id=1 is for configuring the AP mode
wlan.ifconfig(id=1, config=('192.168.4.1', '255.255.255.0', '192.168.4.1', '8.8.8.8'))

print("done")
Esempio n. 17
0
from machine import UART
from os import dupterm
from network import Bluetooth
from pycom import heartbeat
from pycom import wifi_on_boot

uart = UART(0, baudrate=115200)
dupterm(uart)

if heartbeat() == True:
    heartbeat(False)

if wifi_on_boot() == True:
    wifi_on_boot(False)

bluetooth = Bluetooth()
bluetooth.deinit()
Esempio n. 18
0
# WLAN().deinit()
# Server().deinit()
#### changing the following needs a reset of the device to take effect!
# pybytes.smart_config(False)
# pybytes.set_config("pybytes_autostart","true")
# pycom.wifi_on_boot(False)
# pycom.wdt_on_boot(False)

print("sys.platform:", sys.platform)
print("machine.unique_id:", ubinascii.hexlify(machine.unique_id()))
print("machine.freq:", machine.freq())
print("machine.info:")
machine.info()

print("pycom.wifi_on_boot:", pycom.wifi_on_boot())
print("pycom.wdt_on_boot:", pycom.wdt_on_boot())
# print("pycom.smart_config_on_boot:", pycom.smart_config_on_boot())

sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=RCZ)
print("sigfox version:", sigfox.version())
print("sigfox ID:", ubinascii.hexlify(sigfox.id()))
print("sigfox PAC:", ubinascii.hexlify(sigfox.pac()))
print("sigfox region:", RCZ)
print("sigfox frequencies:", sigfox.frequencies())
print("sigfox rssi offset:", sigfox.rssi_offset())
# sigfox config
rcz3_config_test_mode = (
    1, 0x2ee0, 0x100
)  # ie, 1 retry, 12sec timeout, 3rd config is always ignored in R3
# rcz3_config_default = (3,   5000, 0x100) # ie, 3 retries, 5sec timeout
Esempio n. 19
0
    else:
        raise Exception("Unkown ota_slot"+ str(pycom.ota_slot()))
except:
    pass

try:
    print("smart_config_on_boot", pycom.smart_config_on_boot())
except:
    pass
try:
    print("pybytes_on_boot", pycom.pybytes_on_boot())
except:
    pass

try:
    print("wifi_on_boot", pycom.wifi_on_boot())
except:
    pass
from network import WLAN
try:
    m = pycom.wifi_mode_on_boot()
    print("wifi_mode_on_boot", m, end=" ")
    print_wifi_mode(m)
    print()
except:
    pass
try:
    print("wifi_ssid", pycom.wifi_ssid())
    print("wifi_pwd", pycom.wifi_pwd())
except:
    pass
Esempio n. 20
0
###pycom run this file when booting
###setting up interrupt pin and disable wifi on boot
from machine import Pin
import machine
import pycom

#Setting up Pin mode and Initialize interrupt
pinAlert = Pin('P10', mode=Pin.IN, pull=Pin.PULL_DOWN)
machine.pin_deepsleep_wakeup(['P10'], machine.WAKEUP_ALL_LOW, True)

#Disable Wifi to reduce power consumption
pycom.wifi_on_boot([False])
Esempio n. 21
0
# REPL duplication on UART0 for serial connection
from machine import UART
import os
uart = UART(0, 115200)
os.dupterm(uart)

# Disable heartbeat LED
from pycom import heartbeat
heartbeat(False)

# Disable WiFi radio
from pycom import wifi_on_boot
wifi_on_boot(False)
Esempio n. 22
0
#!/usr/bin/env python

import pycom

pycom.wifi_on_boot(False)
print("DEVICE [BOOT]: WiFi on Boot set to {}".format(pycom.wifi_on_boot()))
Esempio n. 23
0
if pycom.lte_modem_en_on_boot():
    print("Disabling LTE modem.")
    pycom.lte_modem_en_on_boot(False)

###############################################################################
# Disable LED heartbeat on boot                                               #
###############################################################################

if pycom.heartbeat_on_boot():
    pycom.heartbeat_on_boot(False)
    pycom.heartbeat(False)

###############################################################################
# Start of boot.py, yellow LED until it is finished                           #
###############################################################################

print("Starting boot process...")
pycom.rgbled(0x111100)

###############################################################################
# Disable automatic start of WLan device                                      #
###############################################################################

if not pycom.wifi_on_boot():
    pycom.wifi_on_boot(False)

###############################################################################
# Finished boot process                                                       #
###############################################################################

print("Boot finished.")
Esempio n. 24
0
    pwd = 'www.pycom.io'
    try:
        WLAN().scan()
    except:  # mode AP, need a compare length
        # if (pycom.wifi_ssid_ap() == ssid) and (pycom.wifi_pwd_ap() == pwd): return
        pass
    from time import sleep
    try:
        WLAN().deinit()
        sleep(1)
    except:
        pass
    pycom.wifi_ssid_ap(ssid)
    pycom.wifi_pwd_ap(pwd)
    # turn on wifi on power on
    WLAN().init(mode=WLAN.AP,
                ssid=ssid,
                auth=(WLAN.WPA2, pwd),
                channel=7,
                antenna=WLAN.INT_ANT)
    sleep(1)


try:  # MySense wifi AP
    from machine import wake_reason, RTC_WAKE
    if wake_reason()[0] != RTC_WAKE:
        if not pycom.wifi_on_boot(): pycom.wifi_on_boot(True)
        set_wifi()
except:
    pass
Esempio n. 25
0
File: main.py Progetto: rejoc/Lopy4
pycom.nvs_set('temp', 25)
pycom.nvs_set('count', 10)

print("After initial setting: temp = %s, count = %s " % (pycom.nvs_get('temp'), pycom.nvs_get('count')))


pycom.nvs_erase('temp') # Erase the given key from the NVRAM memory area.
print("After selective erase: temp = %s, count = %s " % (pycom.nvs_get('temp'), pycom.nvs_get('count')))

pycom.nvs_erase_all() # Erase the entire NVRAM memory area.
print("After full erase: temp = %s, count = %s " % (pycom.nvs_get('temp'), pycom.nvs_get('count')))

pycom.nvs_set('temp', 25)
pycom.nvs_set('count', 10)

print("Before next reboot: temp = %s, count = %s " % (pycom.nvs_get('temp'), pycom.nvs_get('count')))

'''
pycom.wifi_on_boot([enable]) # Get or set the WiFi on boot flag.
pycom.wdt_on_boot([enable]) # Enables the WDT at boot time with the timeout in ms set by the function wdt_on_boot_timeout
pycom.wdt_on_boot_timeout([timeout]) # Sets or gets the WDT on boot timeout in milliseconds. The minimum value is 5000 ms.
'''

print("system info : %s, cwd : %s" % (os.uname() , os.getcwd()))

# SD card file system acces
sd = machine.SD()
os.mount(sd, '/sd')
print("SD card files :")
print(os.listdir('/sd'))