Revert "Example moisture-reading web API (aiohttp)"

This reverts commit dfa1e464ec.
This commit is contained in:
jorjun
2023-01-19 15:45:44 +00:00
committed by Phil Howard
parent acbff3e98d
commit 90c351e6e3
2 changed files with 39 additions and 93 deletions

View File

@@ -63,7 +63,6 @@ py3deps =
python3-spidev python3-spidev
python3-numpy python3-numpy
python3-rpi.gpio python3-rpi.gpio
python3-aiohttp
commands = commands =
printf "Setting up i2c and SPI..\n" printf "Setting up i2c and SPI..\n"
raspi-config nonint do_spi 0 raspi-config nonint do_spi 0

View File

@@ -1,53 +0,0 @@
"""
@jorjun Anno Vvii ☉ in ♓ ☽ in ♋
License: MIT
Description: Web API for moisture readings: //:8080/api/moisture/
"""
from functools import partial
import json
import logging
from aiohttp import web
from grow.moisture import Moisture
# Test class
#class Moisture():
#def __init__(self, channel):
#self.channel = channel
#@property
#def moisture(self):
#return self.channel *3
json_response = partial(web.json_response, dumps=partial(json.dumps, default=str))
routes = web.RouteTableDef()
@routes.get("/api/moisture/")
async def reading(request):
data = {
"m1": meter[0].moisture,
"m2": meter[1].moisture,
"m3": meter[2].moisture,
}
return json_response(data)
if __name__ == "__main__":
app = web.Application()
logging.basicConfig(level=logging.INFO)
app.add_routes(routes)
meter = [Moisture(_+1) for _ in range(3)]
web.run_app(
app,
host="0.0.0.0",
port=8080,
access_log_format='%s %r [%b / %Tf] "%{User-Agent}i"',
)