コード例 #1
0
def fsm_connect_any(nm: nmoperations.NM):
    disable_ap(nm)
    logging.info(
        "Attempting to connect to any open or previously connected networks")
    nm.activate_any_connection()
    logging.info("After connect any")
    wait_then_run(10, fsm_is_conn_b, [nm], True)
コード例 #2
0
def disable_ap(nm: nmoperations.NM):
    while nm.is_in_AP_mode():
        logging.info("Disabling AP mode")
        nm.disable_AP_mode()
        time.sleep(1)

    close_port_80_wlan0()
    logging.info("AP mode disabled")
コード例 #3
0
def enable_ap(nm: nmoperations.NM):
    while not nm.is_in_AP_mode():
        logging.info("Attempting to go into AP mode")
        nm.create_AP()
        time.sleep(1)

    open_port_80_wlan0()
    wait_then_run(60 * 10, fsm_monitor_ap, [nm])
コード例 #4
0
def fsm_monitor_connection(nm: nmoperations.NM):
    if nm.is_connected_to_internet():
        logging.info("monitor_connection: connected to internet")
        wait_then_run(60, fsm_monitor_connection, [nm], blocking=True)
    else:
        logging.info("monitor_connection: not connected to internet")
        enable_ap(nm)
コード例 #5
0
def fsm_is_conn_b(nm: nmoperations.NM):
    if nm.is_connected_to_internet():
        logging.info("is_conn_b: connected to internet, monitoring connection")
        fsm_monitor_connection(nm)
    else:
        logging.info(
            "is_conn_b: not connected to internet, going into AP mode")
        enable_ap(nm)
コード例 #6
0
def fsm_is_conn_a(nm: nmoperations.NM):
    if nm.is_connected_to_internet():
        logging.info("is_conn_a: connected to internet, monitoring connection")
        fsm_monitor_connection(nm)
    else:
        logging.info(
            "is_conn_a: not connected to internet, attempting to connect to any open network"
        )
        fsm_connect_any(nm)
コード例 #7
0
def forget_networks(nm: nmoperations.NM):
    logging.info("Forgetting all wireless networks")
    disable_ap(nm)
    nm.delete_all_connection()
    enable_ap(nm)
コード例 #8
0
def connect_wpa(nm: nmoperations.NM, ssid: str, passwd: str):
    logging.info("connect_wpa")
    disable_ap(nm)
    nm.add_connection_wpa(ssid, passwd)
    nm.activate_connection(ssid)
    wait_then_run(5, fsm_monitor_connection, [nm])