Compare commits
1 Commits
main
...
simple-web
| Author | SHA1 | Date | |
|---|---|---|---|
| 0609aaef55 |
@@ -1,6 +1,9 @@
|
|||||||
import rp2
|
import asyncio
|
||||||
import network
|
import network
|
||||||
import ubinascii
|
import ubinascii
|
||||||
|
import rp2
|
||||||
|
|
||||||
|
from mfrc522 import MFRC522
|
||||||
from microdot import Microdot
|
from microdot import Microdot
|
||||||
|
|
||||||
rp2.country('DE')
|
rp2.country('DE')
|
||||||
@@ -21,6 +24,35 @@ print(f" essid: {wlan.config('essid')}")
|
|||||||
print(f" txpower: {wlan.config('txpower')}")
|
print(f" txpower: {wlan.config('txpower')}")
|
||||||
print(f"ifconfig: {wlan.ifconfig()}")
|
print(f"ifconfig: {wlan.ifconfig()}")
|
||||||
|
|
||||||
|
|
||||||
|
def uid_to_string(uid: list):
|
||||||
|
return '0x' + ''.join(f'{i:02x}' for i in uid)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async def get_tag_uid(reader: MFRC522, poll_interval_ms: int = 50) -> list:
|
||||||
|
'''
|
||||||
|
The maximum measured delay with poll_interval_ms=50 and a reader with tocard_retries=5 is
|
||||||
|
15.9 ms:
|
||||||
|
delay (min / max / avg) [µs]: (360 / 15945 / 1.892923e-06)
|
||||||
|
|
||||||
|
The maximum measured delay dropped to 11.6 ms by setting tocard_retries=1:
|
||||||
|
delay (min / max / avg) [µs]: (368 / 11696 / 6.204211e-06)
|
||||||
|
'''
|
||||||
|
while True:
|
||||||
|
reader.init()
|
||||||
|
|
||||||
|
# For now we omit the tag type
|
||||||
|
(stat, _) = reader.request(reader.REQIDL)
|
||||||
|
if stat == reader.OK:
|
||||||
|
(stat, uid) = reader.SelectTagSN()
|
||||||
|
if stat == reader.OK:
|
||||||
|
print(f"uid={uid_to_string(uid)}")
|
||||||
|
return uid
|
||||||
|
|
||||||
|
await asyncio.sleep_ms(poll_interval_ms)
|
||||||
|
|
||||||
|
|
||||||
app = Microdot()
|
app = Microdot()
|
||||||
|
|
||||||
|
|
||||||
@@ -35,4 +67,16 @@ async def index(request):
|
|||||||
print(f" cookies: {request.cookies}")
|
print(f" cookies: {request.cookies}")
|
||||||
return "TonberryPico says 'Hello World!'"
|
return "TonberryPico says 'Hello World!'"
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/nfc')
|
||||||
|
async def blafasel(request):
|
||||||
|
print("/nfc")
|
||||||
|
|
||||||
|
reader = MFRC522(spi_id=1, sck=10, miso=12, mosi=11, cs=13, rst=9, tocard_retries=10)
|
||||||
|
task = asyncio.create_task(get_tag_uid(reader))
|
||||||
|
|
||||||
|
uid = await task
|
||||||
|
|
||||||
|
return f"result={uid_to_string(uid)}"
|
||||||
|
|
||||||
app.run(port=80)
|
app.run(port=80)
|
||||||
|
|||||||
Reference in New Issue
Block a user