示例#1
0
文件: M5GO.py 项目: tebanski/M5GO
def main_enter_start(obj):
    lcd.setColor(lcd.WHITE, lcd.BLACK)
    lcd.setCursor(0, 0)
    network.WLANcallback(None)
    mainstate.stop()
    if not exists('main.py'):
        if exists('_main.py'):
            os.rename('_main.py', 'main.py')
    gc.collect()
示例#2
0
import network, utime

start_time = utime.ticks_ms()

# ----------------------------------------------------------
# Define callback function used for monitoring wifi activity
# ----------------------------------------------------------
def wifi_cb(info):
    if (info[2]):
        msg = ", info: {}".format(info[2])
    else:
        msg = ""
    print("{} [WiFi] event: {} ({}){}".format(utime.ticks_diff(utime.ticks_ms(), start_time), info[0], info[1], msg))

# Enable callbacks
network.WLANcallback(wifi_cb)

# --------------------------------------------------------------------
# Create two WLAN objects
# one will be used in STA (Station) mode, one in AP (acces point mode)
# --------------------------------------------------------------------
print("\n=== Create WLAN instance objects ===\n")
sta_if = network.WLAN(network.STA_IF)
ap_if = network.WLAN(network.AP_IF)

# Start STA WiFi interface
print("\n=== Activate STA ===================\n")
sta_if.active(True)

# Connect to access point
print("\n=== Connect to access point ========\n")
示例#3
0
文件: M5GO.py 项目: tebanski/M5GO

def wlan_evnet_cb(info):
    print("[WiFi] event: {} ({})".format(info[0], info[1]))
    if (info[2]):
        print("        info: {}".format(info[2]))
    event = info[0]
    if event == 7:  # Station got IP from connected AP
        import m5go_cloud
        m5go_cloud.mqtt.start()
    elif event == 15:  # Station connected to soft-AP
        lcd.image(0, 0, '/flash/img/4-2.jpg')
        lcd.qrcode('http://192.168.4.1', 126, 46, 175)


network.WLANcallback(wlan_evnet_cb)


def read_wificonfig():
    ssid = ''
    password = ''
    data = ''
    try:
        with open('wificonfig.json') as f:
            data = json.loads(f.read())
        ssid = data['wifi']['ssid']
        password = data['wifi']['password']
    except:
        return ['', '']
    else:
        return [ssid, password]
示例#4
0
文件: M5GO.py 项目: shaxser/M5GO
def main_enter_start(obj):
  lcd.setColor(lcd.WHITE, lcd.BLACK)
  lcd.setCursor(0, 0)
  network.WLANcallback(None)
  mainstate.stop()
  gc.collect()