changeset 0:a9fccf3bacb3

Start
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Sun, 04 Oct 2015 16:45:40 +0200
parents
children 5536c5501402
files blink.py conn1-flash.jpg conn1.jpg conn2.jpg connect.py http_get.py nc.py nc_select.py notes.txt send.py server.py usb2ttl.jpg
diffstat 12 files changed, 148 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blink.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,8 @@
+import pyb
+
+pin = pyb.Pin(4, pyb.Pin.OUT_PP)
+for i in range(10):
+    pin.value(1)
+    pyb.delay(500)
+    pin.value(0)
+    pyb.delay(500)
Binary file conn1-flash.jpg has changed
Binary file conn1.jpg has changed
Binary file conn2.jpg has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/connect.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,4 @@
+import pyb
+
+wlan = pyb.network.WLAN()
+wlan.connect('your-ssid', 'your-password')
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/http_get.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,7 @@
+import esp
+
+socket = esp.socket()
+socket.onrecv(print)
+socket.connect(('207.58.139.247', 80)
+socket.send('GET /testwifi/index.html HTTP/1.0\r\n\r\n')
+socket.close()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nc.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,37 @@
+import select
+import socket
+import sys
+
+def console(sock):
+    sock.setblocking(False)
+    poll = select.poll()
+    poll.register(sock, select.POLLIN)
+    poll.register(sys.stdin, select.POLLIN)
+    while True:
+        for ready, event in poll.poll():
+            if ready == sock.fileno():
+                while True:
+                    try:
+                        buffer = sock.recv(4096)
+                    except IOError:
+                        break
+                    if not buffer:
+                        return
+                    sys.stdout.write(buffer)
+            else:
+                sock.sendall(sys.stdin.readline())
+
+if __name__ == '__main__':
+    if len(sys.argv) == 2:
+        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        server.bind(('0.0.0.0', int(sys.argv[1])))
+        server.listen(1)
+        sock, address = server.accept()
+        print "Connection from {}.".format(address)
+    elif len(sys.argv) == 3:
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        sock.connect((sys.argv[1], int(sys.argv[2])))
+        print "Connected to {}:{}.".format(*sock.getpeername())
+    else:
+        print "Usage: {} [address] port".format(sys.argv[0])
+    console(sock)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nc_select.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,34 @@
+import select
+import socket
+import sys
+
+def console(sock):
+    sock.setblocking(False)
+    while True:
+        for ready in select.select([sys.stdin, sock], [], [])[0]:
+            if ready == sock:
+                while True:
+                    try:
+                        buffer = sock.recv(4096)
+                    except IOError:
+                        break
+                    if not buffer:
+                        return
+                    sys.stdout.write(buffer)
+            else:
+                sock.sendall(sys.stdin.readline())
+
+if __name__ == '__main__':
+    if len(sys.argv) == 2:
+        server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        server.bind(('0.0.0.0', int(sys.argv[1])))
+        server.listen(1)
+        sock, address = server.accept()
+        print "Connection from {}.".format(address)
+    elif len(sys.argv) == 3:
+        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+        sock.connect((sys.argv[1], int(sys.argv[2])))
+        print "Connected to {}:{}.".format(*sock.getpeername())
+    else:
+        print "Usage: {} [address] port".format(sys.argv[0])
+    console(sock)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/notes.txt	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,32 @@
+* What is ESP8266
+    * an xtensa microcontroller chip
+    * system on a chip
+    * cheap
+    * programmable
+    * AT commands, C++, Arduino, JavaScript, Lua, Micropython, other
+    * family of modules ESP-01 -- ESP-13
+* What's on board
+    * Network
+        * station/soft AP/scan
+        * tcp/ip sockets
+    * GPIO
+        * 9 digital input/output
+        * timers and pwm
+        * analog pin
+        * serial, spi, i2s, i2c
+    * sleep modes
+    * 3.3V, ~300mA
+* Connecting and boot modes
+* Compiling the firmware
+https://learn.adafruit.com/building-and-running-micropython-on-the-esp8266/overview
+* Download firmware
+https://bitbucket.org/thesheep/esp8266upy/downloads/firmware-combined.bin
+https://bitbucket.org/thesheep/esp8266upy/downloads/esptool.py
+* Flash
+python esptool.py --port /dev/ttyUSB0 write_flash 0x0 firmware-combined.bin
+screen /dev/ttyUSB0 115200
+print("Hello world!")
+* Blink a LED
+* Connect to Network
+* Send HTTP request
+* Listen for bytes
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/send.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,16 @@
+import socket
+import sys
+
+sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+sock.connect((sys.argv[1], int(sys.argv[2])))
+sock.setblocking(False)
+while True:
+    sock.sendall(sys.stdin.readline())
+    while True:
+        try:
+            buffer = sock.recv(4096)
+        except IOError:
+            break
+        if not buffer:
+            sys.exit()
+        sys.stdout.write(buffer)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server.py	Sun Oct 04 16:45:40 2015 +0200
@@ -0,0 +1,10 @@
+import esp
+
+def recv(socket, data):
+    print(data)
+
+socket = esp.socket()
+socket.onconnect(lambda s: s.onrecv(recv))
+socket.bind(('0.0.0.0', 2323))
+socket.listen(1)
+socket.close()
Binary file usb2ttl.jpg has changed