Skip to content

Commit a6cdf14

Browse files
authored
GitHub Pages improvements (#1)
* Use fixed theme in advance of pages-themes/primer#89 * add sitemap plugin * bare URLs don't work on GitHub Pages :(
1 parent 011f99a commit a6cdf14

File tree

2 files changed

+68
-19
lines changed

2 files changed

+68
-19
lines changed

README.md

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
# pi-pico-serial-web-api
1+
# [pi-pico-serial-web-api](https://chabala.github.io/pi-pico-serial-web-api/)
22

33
Web interface & API for an RS-232 controlled device (a Sharp AQUOS TV).
44

55
Update: This project won the [third place prize in WIZnet's Ethernet HAT Contest 2022](
66
https://web.archive.org/web/20220511160854/https://maker.wiznet.io/wiznet-ethernet-hat-contest-winners/).
77

8+
<div style="text-align: right">
9+
<a href="https://github.com/chabala/pi-pico-serial-web-api/">GitHub repository for this page</a> /
10+
<a href="https://chabala.github.io/">Up to the root page</a>
11+
</div>
12+
813
## Abstract
914

1015
A Raspberry Pi Pico with hardwired Ethernet seems like the perfect platform to add web APIs to serial
@@ -56,10 +61,10 @@ just enough for this kind of project, and no more.
5661

5762
Step zero in any project should be a search to see if anyone else has already done the work. I
5863
searched GitHub for other projects that were trying to interface with Sharp TVs and found these:
59-
* https://github.com/partouf/AquosComm [Pascal, 2009]
60-
* https://github.com/bwkeller/pyaquos [Python, 2012]
61-
* https://github.com/p4ddy1/aquoscontrol [Go, 2017]
62-
* https://github.com/neerlent/aquostv_serial [Python, 2019]
64+
* [https://github.com/partouf/AquosComm](https://github.com/partouf/AquosComm) [Pascal, 2009]
65+
* [https://github.com/bwkeller/pyaquos](https://github.com/bwkeller/pyaquos) [Python, 2012]
66+
* [https://github.com/p4ddy1/aquoscontrol](https://github.com/p4ddy1/aquoscontrol) [Go, 2017]
67+
* [https://github.com/neerlent/aquostv_serial](https://github.com/neerlent/aquostv_serial) [Python, 2019]
6368

6469
These all target running software on a full computer rather than a microcontroller, but at least
6570
some were also trying to integrate with home automation software. It's always good to see what's
@@ -76,9 +81,9 @@ could connect a common USB-to-serial adapter to it.
7681
### Selecting a software platform
7782

7883
Possible software toolkits available for the Pi Pico and clones:
79-
* C/C++ and/or assembly - https://github.com/raspberrypi/pico-sdk
80-
* MicroPython - https://github.com/micropython/micropython
81-
* CircuitPython - https://github.com/adafruit/circuitpython
84+
* C/C++ and/or assembly - [https://github.com/raspberrypi/pico-sdk](https://github.com/raspberrypi/pico-sdk)
85+
* MicroPython - [https://github.com/micropython/micropython](https://github.com/micropython/micropython)
86+
* CircuitPython - [https://github.com/adafruit/circuitpython](https://github.com/adafruit/circuitpython)
8287

8388
My C++ is very rusty, so one of the Python variants seemed like a good place to start. CircuitPython is a
8489
fork of MicroPython with an emphasis on ease of use for beginners, and is backed by Adafruit to ensure
@@ -125,28 +130,35 @@ CircuitPython.
125130
Googled the error, but the results are people using CircuitPython on Raspberry Pi (not Pi Pico)
126131
being advised to install `adafruit_blinka`, which is an abstraction layer that I should not need.
127132

128-
I started poking around in the issues on https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k
129-
and found https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/pull/49 which links to
130-
https://gist.github.com/anecdata/3c6f37c05a91f7b769dad7517bfe3aa1 which is example code that works
133+
I started poking around in the issues on [https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k](
134+
https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k)
135+
and found [https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/pull/49](
136+
https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/pull/49) which links to
137+
[https://gist.github.com/anecdata/3c6f37c05a91f7b769dad7517bfe3aa1](
138+
https://gist.github.com/anecdata/3c6f37c05a91f7b769dad7517bfe3aa1) which is example code that works
131139
fine.
132140

133141
Looking back at the WIZnet Getting Started guide, it seems they may have intended
134-
https://github.com/Wiznet/RP2040-HAT-CircuitPython/blob/master/examples/Network/W5x00_Ping_Test.py
142+
[https://github.com/Wiznet/RP2040-HAT-CircuitPython/blob/master/examples/Network/W5x00_Ping_Test.py](
143+
https://github.com/Wiznet/RP2040-HAT-CircuitPython/blob/master/examples/Network/W5x00_Ping_Test.py)
135144
as initial example code. It's very similar to the working gist. Of interest though, they
136145
both use different pins for the reset pin. The WIZnet example is correctly using `GP20`, but using
137146
that pin in the gist's code causes it to fail to initialize. This turns out to be a bug in the
138-
driver library, and I opened https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/issues/51
147+
driver library, and I opened [https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/issues/51](
148+
https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k/issues/51)
139149
to fix it.
140150

141151
Tested web server example code from
142-
https://github.com/Wiznet/RP2040-HAT-CircuitPython/blob/master/examples/HTTP/Webserver/W5x00_WebServer.py
152+
[https://github.com/Wiznet/RP2040-HAT-CircuitPython/blob/master/examples/HTTP/Webserver/W5x00_WebServer.py](
153+
https://github.com/Wiznet/RP2040-HAT-CircuitPython/blob/master/examples/HTTP/Webserver/W5x00_WebServer.py)
143154
which works and shows the basics of URL routing.
144155

145156
At this point I've gotten network functionality working, and I want to test the serial end of things.
146157
Based on some conversation on the [Adafruit Discord](http://adafru.it/discord), while the Pi Pico
147158
hardware supports USB host mode, CircuitPython itself does not yet. There is work underway in the
148159
USB stack (TinyUSB), and preliminary work on the CircuitPython API for it:
149-
https://github.com/tannewt/circuitpython/tree/usb_host but nothing ready for use.
160+
[https://github.com/tannewt/circuitpython/tree/usb_host](
161+
https://github.com/tannewt/circuitpython/tree/usb_host) but nothing ready for use.
150162

151163
My option for using the USB serial adapter in the near term may only be to implement the USB host
152164
logic myself in C, which is more than I bargained for. As a result, I ordered a [Waveshare
@@ -177,7 +189,36 @@ https://en.wikipedia.org/wiki/HATEOAS) style, and learned how to handle GET and
177189
with it. It should be easier to follow that pattern and start flushing out the serial TV control
178190
endpoint now without making a mess of it.
179191

180-
https://github.com/chabala/pi-pico-serial-web-api/blob/e81f4f882127e0290d8b4310b3c9e9d4933914b9/CIRCUITPY/code.py#L69-L93
192+
From: [https://github.com/chabala/pi-pico-serial-web-api/blob/e81f4f882127e0290d8b4310b3c9e9d4933914b9/CIRCUITPY/code.py#L69-L93](
193+
https://github.com/chabala/pi-pico-serial-web-api/blob/e81f4f882127e0290d8b4310b3c9e9d4933914b9/CIRCUITPY/code.py#L69-L93)
194+
195+
```python
196+
@web_app.route("/led/", ["GET", "POST"])
197+
def led(request):
198+
print(f"\n{request.method} {request.path}")
199+
set_value = None
200+
if request.method == "GET":
201+
set_value = request.query_params.get('set')
202+
elif request.method == "POST":
203+
post_params = request.__parse_query_params(request.body.getvalue())
204+
request.body.close()
205+
set_value = post_params.get('set')
206+
if set_value is not None:
207+
if set_value == 'toggle':
208+
user_led.value = not user_led.value
209+
else:
210+
user_led.value = True if set_value == 'on' else False
211+
status = 'on' if user_led.value else 'off'
212+
return "200 OK", [], [html_doc("User LED status", f"""LED is {status}<br><br>
213+
<form action="/led/" method="post">
214+
Actions:<br>
215+
<input type="radio" id="on" name="set" value="on"><label for="on"> turn LED on</label><br>
216+
<input type="radio" id="off" name="set" value="off"><label for="off"> turn LED off</label><br>
217+
<input type="radio" id="toggle" name="set" value="toggle"><label for="toggle"> toggle LED state</label><br>
218+
<button type="submit">Submit</button>
219+
</form><br><br>
220+
<a href="/" id="root">Back to root</a>""")]
221+
```
181222

182223
![LED interface screenshot](documentation/ui-screenshots/led-interface.png "LED interface screenshot")
183224

@@ -259,6 +300,7 @@ The `/led/` and `/serial/` endpoints were already shown above.
259300
* The `/tv/power/` endpoint:
260301

261302
![power](documentation/ui-screenshots/tv-power.png "power")
303+
262304
![power status](documentation/ui-screenshots/tv-power-status.png "power status")
263305

264306
Interacting with any of the commands will return to the same page, but the response from the
@@ -268,7 +310,9 @@ level of the API structure.
268310
* The `/tv/volume/` endpoint:
269311

270312
![volume set](documentation/ui-screenshots/tv-volume-set.png "volume set")
313+
271314
![volume status](documentation/ui-screenshots/tv-volume-status.png "volume status")
315+
272316
![mute status](documentation/ui-screenshots/tv-mute-status.png "mute status")
273317

274318
* The `/tv/input/` endpoint:
@@ -366,9 +410,9 @@ final product out of it.
366410

367411
All project code is MIT licensed. Adafruit library code is present as a convenience, but it retains
368412
its own license(s), refer to the library repositories for more detail:
369-
* https://github.com/adafruit/Adafruit_CircuitPython_Requests
370-
* https://github.com/adafruit/Adafruit_CircuitPython_WSGI
371-
* https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k
413+
* [https://github.com/adafruit/Adafruit_CircuitPython_Requests](https://github.com/adafruit/Adafruit_CircuitPython_Requests)
414+
* [https://github.com/adafruit/Adafruit_CircuitPython_WSGI](https://github.com/adafruit/Adafruit_CircuitPython_WSGI)
415+
* [https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k](https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k)
372416

373417
This repository contains a reproduction of a single page of a manual, presumed to be under copyright
374418
by SHARP ELECTRONICS CORPORATION. I assert fair use for including it.

_config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
google_analytics: G-CB7P776F76
2+
remote_theme: chabala/primer@update-google-analytics
3+
plugins:
4+
- jekyll-remote-theme
5+
- jekyll-sitemap

0 commit comments

Comments
 (0)