summaryrefslogtreecommitdiffstatshomepage
path: root/esp8266/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'esp8266/scripts')
-rw-r--r--esp8266/scripts/apa102.py28
-rw-r--r--esp8266/scripts/dht.py32
-rw-r--r--esp8266/scripts/inisetup.py4
-rw-r--r--esp8266/scripts/neopixel.py9
-rw-r--r--esp8266/scripts/ntptime.py4
-rw-r--r--esp8266/scripts/onewire.py2
-rw-r--r--esp8266/scripts/port_diag.py12
-rw-r--r--esp8266/scripts/webrepl.py33
-rw-r--r--esp8266/scripts/webrepl_setup.py5
9 files changed, 113 insertions, 16 deletions
diff --git a/esp8266/scripts/apa102.py b/esp8266/scripts/apa102.py
new file mode 100644
index 0000000000..126448cc20
--- /dev/null
+++ b/esp8266/scripts/apa102.py
@@ -0,0 +1,28 @@
+# APA102 driver for MicroPython on ESP8266
+# MIT license; Copyright (c) 2016 Robert Foss, Daniel Busch
+
+from esp import apa102_write
+
+class APA102:
+ def __init__(self, clock_pin, data_pin, n):
+ self.clock_pin = clock_pin
+ self.data_pin = data_pin
+ self.n = n
+ self.buf = bytearray(n * 4)
+
+ self.clock_pin.init(clock_pin.OUT)
+ self.data_pin.init(data_pin.OUT)
+
+ def __setitem__(self, index, val):
+ r, g, b, brightness = val
+ self.buf[index * 4] = r
+ self.buf[index * 4 + 1] = g
+ self.buf[index * 4 + 2] = b
+ self.buf[index * 4 + 3] = brightness
+
+ def __getitem__(self, index):
+ i = index * 4
+ return self.buf[i], self.buf[i + 1], self.buf[i + 2], self.buf[i + 3]
+
+ def write(self):
+ apa102_write(self.clock_pin, self.data_pin, self.buf)
diff --git a/esp8266/scripts/dht.py b/esp8266/scripts/dht.py
new file mode 100644
index 0000000000..9a69e7e07e
--- /dev/null
+++ b/esp8266/scripts/dht.py
@@ -0,0 +1,32 @@
+# DHT11/DHT22 driver for MicroPython on ESP8266
+# MIT license; Copyright (c) 2016 Damien P. George
+
+import esp
+
+class DHTBase:
+ def __init__(self, pin):
+ self.pin = pin
+ self.buf = bytearray(5)
+
+ def measure(self):
+ buf = self.buf
+ esp.dht_readinto(self.pin, buf)
+ if (buf[0] + buf[1] + buf[2] + buf[3]) & 0xff != buf[4]:
+ raise Exception("checksum error")
+
+class DHT11(DHTBase):
+ def humidity(self):
+ return self.buf[0]
+
+ def temperature(self):
+ return self.buf[2]
+
+class DHT22(DHTBase):
+ def humidity(self):
+ return (self.buf[0] << 8 | self.buf[1]) * 0.1
+
+ def temperature(self):
+ t = ((self.buf[2] & 0x7f) << 8 | self.buf[3]) * 0.1
+ if self.buf[2] & 0x80:
+ t = -t
+ return t
diff --git a/esp8266/scripts/inisetup.py b/esp8266/scripts/inisetup.py
index 93a05bd8a7..461690b162 100644
--- a/esp8266/scripts/inisetup.py
+++ b/esp8266/scripts/inisetup.py
@@ -40,7 +40,7 @@ def setup():
with open("/boot.py", "w") as f:
f.write("""\
# This file is executed on every boot (including wake-boot from deepsleep)
-import webrepl
-webrepl.start()
+#import webrepl
+#webrepl.start()
""")
return vfs
diff --git a/esp8266/scripts/neopixel.py b/esp8266/scripts/neopixel.py
index 4818c74a3b..8aa0348680 100644
--- a/esp8266/scripts/neopixel.py
+++ b/esp8266/scripts/neopixel.py
@@ -8,7 +8,7 @@ class NeoPixel:
self.pin = pin
self.n = n
self.buf = bytearray(n * 3)
- self.pin.init(pin.OUT, pin.PULL_NONE)
+ self.pin.init(pin.OUT)
def __setitem__(self, index, val):
r, g, b = val
@@ -20,5 +20,12 @@ class NeoPixel:
i = index * 3
return self.buf[i + 1], self.buf[i], self.buf[i + 2]
+ def fill(self, color):
+ r, g, b = color
+ for i in range(len(self.buf) / 3):
+ self.buf[i * 3] = g
+ self.buf[i * 3 + 1] = r
+ self.buf[i * 3 + 2] = b
+
def write(self):
neopixel_write(self.pin, self.buf, True)
diff --git a/esp8266/scripts/ntptime.py b/esp8266/scripts/ntptime.py
index 650cc2e85b..a97e08e60d 100644
--- a/esp8266/scripts/ntptime.py
+++ b/esp8266/scripts/ntptime.py
@@ -10,10 +10,12 @@ except:
# (date(2000, 1, 1) - date(1900, 1, 1)).days * 24*60*60
NTP_DELTA = 3155673600
+host = "pool.ntp.org"
+
def time():
NTP_QUERY = bytearray(48)
NTP_QUERY[0] = 0x1b
- addr = socket.getaddrinfo('pool.ntp.org', 123)[0][-1]
+ addr = socket.getaddrinfo(host, 123)[0][-1]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(1)
res = s.sendto(NTP_QUERY, addr)
diff --git a/esp8266/scripts/onewire.py b/esp8266/scripts/onewire.py
index 4980d0af5c..686616950a 100644
--- a/esp8266/scripts/onewire.py
+++ b/esp8266/scripts/onewire.py
@@ -13,7 +13,7 @@ class OneWire:
def __init__(self, pin):
self.pin = pin
- self.pin.init(pin.OPEN_DRAIN, pin.PULL_NONE)
+ self.pin.init(pin.OPEN_DRAIN)
def reset(self):
return _ow.reset(self.pin)
diff --git a/esp8266/scripts/port_diag.py b/esp8266/scripts/port_diag.py
index fd7ee52d14..aa696b1abb 100644
--- a/esp8266/scripts/port_diag.py
+++ b/esp8266/scripts/port_diag.py
@@ -1,5 +1,7 @@
import esp
import uctypes
+import network
+import lwip
def main():
@@ -7,6 +9,7 @@ def main():
ROM = uctypes.bytearray_at(0x40200000, 16)
fid = esp.flash_id()
+ print("FlashROM:")
print("Flash ID: %x (Vendor: %x Device: %x)" % (fid, fid & 0xff, fid & 0xff00 | fid >> 16))
print("Flash bootloader data:")
@@ -15,5 +18,14 @@ def main():
print("Byte @2: %02x" % ROM[2])
print("Byte @3: %02x (Flash size: %s Flash freq: %s)" % (ROM[3], SZ_MAP.get(ROM[3] >> 4, "?"), FREQ_MAP.get(ROM[3] & 0xf)))
+ print("\nNetworking:")
+ print("STA ifconfig:", network.WLAN(network.STA_IF).ifconfig())
+ print("AP ifconfig:", network.WLAN(network.AP_IF).ifconfig())
+ print("Free WiFi driver buffers of type:")
+ for i in range(5):
+ print("%d: %d" % (i, esp.esf_free_bufs(i)))
+ print("lwIP PCBs:")
+ lwip.print_pcbs()
+
main()
diff --git a/esp8266/scripts/webrepl.py b/esp8266/scripts/webrepl.py
index 1a2c82277e..da3e70c595 100644
--- a/esp8266/scripts/webrepl.py
+++ b/esp8266/scripts/webrepl.py
@@ -10,7 +10,7 @@ listen_s = None
client_s = None
def setup_conn(port, accept_handler):
- global listen_s, client_s
+ global listen_s
listen_s = socket.socket()
listen_s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -19,11 +19,13 @@ def setup_conn(port, accept_handler):
listen_s.bind(addr)
listen_s.listen(1)
- listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
+ if accept_handler:
+ listen_s.setsockopt(socket.SOL_SOCKET, 20, accept_handler)
for i in (network.AP_IF, network.STA_IF):
iface = network.WLAN(i)
if iface.active():
print("WebREPL daemon started on ws://%s:%d" % (iface.ifconfig()[0], port))
+ return listen_s
def accept_conn(listen_sock):
@@ -49,14 +51,25 @@ def stop():
listen_s.close()
-def start(port=8266):
+def start(port=8266, password=None):
stop()
- try:
- import port_config
- _webrepl.password(port_config.WEBREPL_PASS)
+ if password is None:
+ try:
+ import port_config
+ _webrepl.password(port_config.WEBREPL_PASS)
+ setup_conn(port, accept_conn)
+ print("Started webrepl in normal mode")
+ except:
+ import webrepl_setup
+ setup_conn(port, webrepl_setup.handle_conn)
+ print("Started webrepl in setup mode")
+ else:
+ _webrepl.password(password)
setup_conn(port, accept_conn)
print("Started webrepl in normal mode")
- except:
- import webrepl_setup
- setup_conn(port, webrepl_setup.handle_conn)
- print("Started webrepl in setup mode")
+
+
+def start_foreground(port=8266):
+ stop()
+ s = setup_conn(port, None)
+ accept_conn(s)
diff --git a/esp8266/scripts/webrepl_setup.py b/esp8266/scripts/webrepl_setup.py
index 7c4068750c..d0bf8465d5 100644
--- a/esp8266/scripts/webrepl_setup.py
+++ b/esp8266/scripts/webrepl_setup.py
@@ -26,7 +26,7 @@ def getpass(stream, prompt):
stream.write("\r\n")
return passwd
passwd += c
-# stream.write("*")
+ stream.write("*")
def handle_conn(listen_sock):
cl, remote_addr = listen_sock.accept()
@@ -60,6 +60,9 @@ some boards, you may need to press reset button or reconnect power.\r
if len(passwd1) < 4:
ws.write("Password too short\r\n")
continue
+ elif len(passwd1) > 9:
+ ws.write("Password too long\r\n")
+ continue
passwd2 = getpass(ws, "Confirm password: ")
if passwd1 == passwd2:
break