File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ @jorjun Anno Vvii ☉ in ♓ ☽ in ♋
3+ License: MIT
4+ Description: Web API for moisture readings: http://<your-pi-host>:8080/
5+ """
6+ from functools import partial
7+ import json
8+ import logging
9+ from aiohttp import web
10+ from grow .moisture import Moisture
11+
12+ json_response = partial (web .json_response , dumps = partial (json .dumps , default = str ))
13+ routes = web .RouteTableDef ()
14+
15+
16+ @routes .get ("/" ) # Or whatever URL path you want
17+ async def reading (request ):
18+ data = {
19+ "m1" : meter [0 ].moisture ,
20+ "m2" : meter [1 ].moisture ,
21+ "m3" : meter [2 ].moisture ,
22+ }
23+ return json_response (data )
24+
25+
26+ if __name__ == "__main__" :
27+ app = web .Application ()
28+ logging .basicConfig (level = logging .INFO )
29+ app .add_routes (routes )
30+ meter = [Moisture (_ + 1 ) for _ in range (3 )]
31+ web .run_app (
32+ app ,
33+ host = "0.0.0.0" ,
34+ port = 8080 ,
35+ access_log_format = '%s %r [%b / %Tf] "%{User-Agent}i"' ,
36+ )
You can’t perform that action at this time.
0 commit comments