Compare commits

...

4 Commits

Author SHA1 Message Date
Jimmy e46e1dce52 Merge branch 'master' of git.technical.kiwi:jimmy/pixeleditor 2023-12-26 22:09:20 +13:00
jimmy 682ac264d2 Add requests 2023-06-06 22:46:32 +12:00
jimmy 53e3049d8e Add sdcard driver 2023-06-06 22:46:16 +12:00
jimmy af251e7c5f On save upload to pico 2023-06-06 22:44:21 +12:00
1 changed files with 0 additions and 80 deletions

80
web.py
View File

@ -1,80 +0,0 @@
#
# This is an example of a (sub)application, which can be made a part of
# bigger site using "app mount" feature, see example_app_router.py.
#
import picoweb
import network
from time import sleep
import ulogging
import traceback
import sdcard
import uos
from ws2812b import WS2812B
ssid = 'XCHC1'
password = 'workspace'
ws = WS2812B(256, 28, 0.1)
# Assign chip select (CS) pin (and start it high)
cs = machine.Pin(13, machine.Pin.OUT)
# Intialize SPI peripheral (start with 1 MHz)
spi = machine.SPI(1,
baudrate=1000000,
polarity=0,
phase=0,
bits=8,
firstbit=machine.SPI.MSB,
sck=machine.Pin(10),
mosi=machine.Pin(11),
miso=machine.Pin(12))
# Initialize SD card
sd = sdcard.SDCard(spi, cs)
# Mount filesystem
vfs = uos.VfsFat(sd)
uos.mount(vfs, "/sd")
def connect():
#Connect to WLAN
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
i = 0
while wlan.isconnected() == False:
if i>10:
print("Failed to connect")
break
i += 1
print('Waiting for connection...')
sleep(1)
ip = wlan.ifconfig()[0]
print(f'Connected on {ip}')
return ip
ip = connect()
app = picoweb.WebApp(__name__)
@app.route("/")
def index(request, response):
size = int(request.headers[b"Content-Length"])
data = yield from request.reader.readexactly(size)
data = data.split(b'\r\n\r\n')[-1].split(b'------')[0]
for i in range(256):
offset = i * 3
green, red, blue = data[offset:offset + 3]
#print(red, green, blue)
ws.pixels_set(i, (red, green, blue))
ws.pixels_show()
yield from picoweb.start_response(response)
yield from response.awrite("HTTP/1.0 200 OK\r\n")
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=80)