From c0ea6bad60505a6076f33eec181cc89f544e747b Mon Sep 17 00:00:00 2001 From: Peter Hinch Date: Mon, 5 Sep 2016 10:41:24 +0100 Subject: [PATCH] ESP8266 conn.py added --- ESP8266/conn.py | 23 +++++++++++++++++++++++ README.md | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 ESP8266/conn.py diff --git a/ESP8266/conn.py b/ESP8266/conn.py new file mode 100644 index 0000000..5d0f0ab --- /dev/null +++ b/ESP8266/conn.py @@ -0,0 +1,23 @@ +# Connect in station mode. Use saved parameters if possible to save flash wear + +import network +import utime + +use_default = True +ssid = 'my_ssid' +pw = 'my_password' + +sta_if = network.WLAN(network.STA_IF) +if use_default: + secs = 5 + while secs >= 0 and not sta_if.isconnected(): + utime.sleep(1) + secs -= 1 + +# If can't use default, use specified LAN +if not sta_if.isconnected(): + sta_if.active(True) + sta_if.connect(ssid, pw) + while not sta_if.isconnected(): + utime.sleep(1) + diff --git a/README.md b/README.md index 0c85c68..2c22666 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,8 @@ the same topic. Measures the round-trip delay. Adapt to suit your server address QOS (quality of service, 0 and 1 are supported). After 100 messages reports maximum and minimum delays. +conn.py Connect in station mode using saved connection details where possible + ## Rotary Incremental Encoder Classes for handling incremental rotary position encoders. Note that the Pyboard timers can