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
RMotorB = Pin('GPIO8', af=0, mode=Pin.OUT)
LMotorB.low()
RMotorB.low()

# assign GPIO9 and 10 to alternate function 3 (PWM)
# These will be the pins to control speed
LMotorA = Pin('GPIO9', af=3, type=Pin.STD)
RMotorA = Pin('GPIO10', af=3, type=Pin.STD)

# Enable timer channels 3B and 4A for PWM pins
LMTimer = Timer(3, mode=Timer.PWM, width=16)
RMTimer = Timer(4, mode=Timer.PWM, width=16)
# enable channel A @1KHz with a 50% duty cycle
LMT_a = LMTimer.channel(Timer.B, freq=1000, duty_cycle=50)
RMT_a = RMTimer.channel(Timer.A, freq=1000, duty_cycle=50)

def Setup_WIFI()
wifi = WLAN(WLAN.STA)
# go for fixed IP settings
wifi.ifconfig('192.168.0.107', '255.255.255.0', '192.168.0.1', '8.8.8.8')
wifi.scan()     # scan for available netrworks
wifi.connect(ssid='mynetwork', security=2, key='mynetworkkey')
while not wifi.isconnected():
    pass
print(wifi.ifconfig())
# enable wake on WLAN
wifi.callback(wakes=Sleep.SUSPENDED)
# go to sleep
Sleep.suspend()
# now, connect to the FTP or the Telnet server and the WiPy will wake-up
Esempio n. 3
0
            channel=11,
            antenna=WLAN.INT_ANT)
wlan.ifconfig(id=1,
              config=(config.API_HOST, '255.255.255.0', '10.42.31.1',
                      '8.8.8.8'))


def _wlan_callback(trigger):
    Log.i("_wlan_callback")
    Log.i("trigger type = " + type(trigger))
    Log.i("trigger = " + trigger)


wlan.callback(
    trigger=(WLAN.EVENT_PKT_ANY | WLAN.EVENT_PKT_CTRL | WLAN.EVENT_PKT_DATA
             | WLAN.EVENT_PKT_DATA_AMPDU | WLAN.EVENT_PKT_DATA_MPDU
             | WLAN.EVENT_PKT_MISC | WLAN.EVENT_PKT_MGMT),
    handler=_wlan_callback)
############################################################################

######################### Configure FTP and Telnet #########################
server = network.Server()
server.deinit()  # disable
############################################################################

########################## Configure microWebSrv ###########################
# DOC : https://github.com/jczic/MicroWebSrv


@MicroWebSrv.route('/subscribe', 'POST')
def handlerFuncPost(httpClient, httpResponse):
Esempio n. 4
0
        device_found = True


#Variables
pin_str         = 'P18'
pir             = Pin(pin_str, mode=Pin.IN, pull=None)
device_found    = False
wlan            = WLAN(mode=WLAN.STA, antenna=WLAN.EXT_ANT)
# 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:
Esempio n. 5
0
#https://forum.pycom.io/topic/6347/wlan-smartconfig/2
from network import WLAN


def conf(msg):
    print('smart config', msg)


wlan = WLAN(mode=WLAN.STA, antenna=WLAN.INT_ANT)
if wlan.isconnected(): print('connected')
wlan.callback(trigger=WLAN.SMART_CONF_DONE, handler=conf('done'))
wlan.callback(trigger=WLAN.SMART_CONF_TIMEOUT, handler=conf('timed out'))
print('try smartConfig')
wlan.smartConfig()