コード例 #1
0
    def testStart(self):
        network.DEBUG_RESET()
        WifiManager.config_file = 'test/networks_fallback.json'
        WifiManager.start_managing()
        loop = asyncio.get_event_loop()

        async def tester():
            print("Time's up")

        # TODO: Tests here
        loop.run_until_complete(tester())
コード例 #2
0
ファイル: board.py プロジェクト: flokain/Smart-Cube
    def __init__(self, device):
        # Set all pins to OUT m od
        log.debug("initalizing board %s", device)
        if hasattr(machine, "Pin"):
            for p, d in self.pins.items():
                machine.Pin(p, machine.Pin.OUT)

        log.debug("free memory: %s", gc.mem_free())
        WifiManager.start_managing()
        log.debug("Wifi config loaded")
        log.debug("free memory: %s", gc.mem_free())
コード例 #3
0
 def test_fallback_ap(self):
     network.DEBUG_RESET()
     interface = network.WLAN(network.STA_IF)
     host = network.WLAN(network.AP_IF)
     interface.scan_results = sample_scans.scan3()
     WifiManager.config_file = 'test/networks_fallback.json'
     WifiManager.setup_network()
     # Checks on the client
     self.assertTrue(not interface.isconnected())
     self.assertTrue(interface.DEBUG_CONNECTED_SSID is None)
     self.assertTrue(interface.DEBUG_CONNECTED_BSSID is None)
     # Checks on th AP
     self.assertTrue(host.active())
     self.assertTrue(host.config_dict['essid'] == "Micropython-Dev")
コード例 #4
0
 def test_fallback_choose_best(self):
     network.DEBUG_RESET()
     interface = network.WLAN(network.STA_IF)
     host = network.WLAN(network.AP_IF)
     interface.scan_results = sample_scans.scan2()
     WifiManager.config_file = 'test/networks_fallback.json'
     WifiManager.setup_network()
     # Checks on the client
     self.assertTrue(interface.isconnected())
     self.assertTrue(interface.DEBUG_CONNECTED_SSID == "HomeNetwork")
     self.assertTrue(
         interface.DEBUG_CONNECTED_BSSID == b'\x90r@\x1f\xf0\xe4')
     # Checks on th AP
     self.assertTrue(not host.active())
コード例 #5
0
 def test_never_ap(self):
     network.DEBUG_RESET()
     interface = network.WLAN(network.STA_IF)
     host = network.WLAN(network.AP_IF)
     interface.scan_results = sample_scans.scan1()
     WifiManager.config_file = 'test/networks_always.json'
     WifiManager.setup_network()
     # Checks on the client
     self.assertTrue(interface.isconnected())
     self.assertTrue(interface.DEBUG_CONNECTED_SSID == "HomeNetwork")
     self.assertTrue(
         interface.DEBUG_CONNECTED_BSSID == b'\x90r@\x1f\xf0\xe4')
     # Checks on th AP
     self.assertTrue(host.active())
     self.assertTrue(host.config_dict['essid'] == "Micropython-Dev")
コード例 #6
0
 def __init__(self, primary_wifi_ssid, primary_wifi_key,
              backup_ssid_to_keys):
     if NetworkManager._instance is not None:
         raise Exception("This class is a singleton. Please use"
                         "get_instance() to get a class object.")
     self.wifi_manager = WifiManager.get_instance(primary_wifi_ssid,
                                                  primary_wifi_key,
                                                  backup_ssid_to_keys)
     NetworkManager._instance = self
コード例 #7
0
 def __init__(self, ap_name='MicroWifi', ap_password=''):
     self.web_server = WebServer()
     self.wifi_man = WifiManager(ap_name=ap_name, ap_password=ap_password)
     # setup web server routes
     self.setup_routes(self.web_server, self.wifi_man)
コード例 #8
0
class MicroWifi:
    def __init__(self, ap_name='MicroWifi', ap_password=''):
        self.web_server = WebServer()
        self.wifi_man = WifiManager(ap_name=ap_name, ap_password=ap_password)
        # setup web server routes
        self.setup_routes(self.web_server, self.wifi_man)

    def start(self):
        # try to auto connect
        self.wifi_man.auto_connect()
        if self.wifi_man.is_access_point_mode():
            # start our web server to allow the user to configure the device
            self.web_server.start()

    def stop(self):
        try:
            self.web_server.stop()
        except Exception as exc:
            print('Error stopping {}'.format(exc))

    def setup_routes(self, server, wifi_manager):
        @server.route("/")
        def home(client, request):
            try:
                html = ""
                try:
                    with open('www/index.html') as f:
                        html = f.read()
                except OSError:
                    pass
                server.send_response(client, html)
            except Exception as exc:
                print('Error in home route {}'.format(exc))

        @server.route("/scan")
        def scan(client, request):
            try:
                network_ssids = [
                    network[0] for network in wifi_manager.access_point_scan()
                ]
                payload = {'networks': network_ssids}
                server.send_response(client,
                                     json.dumps(payload),
                                     content_type='application/json')
            except Exception as exc:
                print('Error in scan route {}'.format(exc))

        @server.route("/connect", 'POST')
        def connect(client, request):
            params = server.get_form_data(request)
            ssid = params.get('ssid')
            password = params.get('password')
            # try to connect to the network
            status = wifi_manager.connect(ssid, password)
            payload = {
                'status':
                status,
                'msg':
                'Successfully connected to {}'.format(ssid)
                if status else 'Error connecting to {}'.format(ssid)
            }
            server.send_response(client,
                                 json.dumps(payload),
                                 content_type='application/json')
コード例 #9
0
from qsostate import Qsostate

from  mopp import Moppm32

from callsign import CallGenerator




if  sys.platform == 'esp8266':

    import roger

    from wifi_manager import WifiManager

    WifiManager.setup_network()

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

SERVER_IP = "0.0.0.0"
UDP_PORT = 7373
CLIENT_TIMEOUT = 300
MAX_CLIENTS = 10
KEEPALIVE = 10
DEBUG = False

# map the states to action functions          
# map the states to action functions          


action = {
コード例 #10
0
np = neopixel.NeoPixel(machine.Pin(15), 1, bpp=3)


# one neopixel led
def pixel(r=0, g=0, b=0):
    np[0] = (r, g, b)
    np.write()


# code red
pixel(0, 0, 32)

# wireless networking
from wifi_manager import WifiManager
# https://github.com/mitchins/micropython-wifimanager#asynchronous-usage-event-loop
log.info(WifiManager.start_managing())

# code green
pixel(0, 32, 0)

# initiate sensor bus
from machine import I2C, Pin
# frequency high, updates lots
# datasheet of 'gy-91' states 400000 as maximum but it's running fine at 800000
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000)
log.debug(i2c)

import ujson


# inhale json
コード例 #11
0
import machine
import gc
from wifi_manager import WifiManager

gc.collect()

wlan = WifiManager()

if wlan.check_connection():
    print("We're good to go!")
else:
    print("Something went wrong! Let's reboot and try again.")
    machine.reset()

gc.collect()
コード例 #12
0
ファイル: main.py プロジェクト: 1wq2/InPD
#!/usr/bin/env python

from wifi_manager import WifiManager
import subprocess

if __name__ == '__main__':
    import sys

    from PyQt5.QtWidgets import QApplication

    app = QApplication(sys.argv)

    dev_manager = WifiManager()
    dev_manager.show()

sys.exit(app.exec_())