mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 22:48:16 +01:00
separate influxdb write to async routine (test)
This commit is contained in:
parent
c4333d2cab
commit
9a8b0ca30f
5 changed files with 21 additions and 13 deletions
|
@ -1,3 +1,3 @@
|
||||||
__version__ = "4.1.7.a4"
|
__version__ = "4.1.7.a5"
|
||||||
__codename__ = "Groundhog Day"
|
__codename__ = "Groundhog Day"
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from time import strftime, localtime
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import zipfile
|
import zipfile
|
||||||
import base64
|
import base64
|
||||||
import urllib3
|
from urllib3 import Timeout, PoolManager
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from cbpi.api import *
|
from cbpi.api import *
|
||||||
from cbpi.api.config import ConfigType
|
from cbpi.api.config import ConfigType
|
||||||
|
@ -46,16 +46,20 @@ class LogController:
|
||||||
|
|
||||||
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
|
formatted_time = strftime("%Y-%m-%d %H:%M:%S", localtime())
|
||||||
self.datalogger[name].info("%s,%s" % (formatted_time, str(value)))
|
self.datalogger[name].info("%s,%s" % (formatted_time, str(value)))
|
||||||
|
|
||||||
if self.influxdb == "Yes":
|
if self.influxdb == "Yes":
|
||||||
|
## Write to influxdb in an asyncio task
|
||||||
|
self._task = asyncio.create_task(self.log_influx(name,value))
|
||||||
|
|
||||||
|
async def log_influx(self, name:str, value:str):
|
||||||
self.influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", "No")
|
self.influxdbcloud = self.cbpi.config.get("INFLUXDBCLOUD", "No")
|
||||||
self.influxdbaddr = self.cbpi.config.get("INFLUXDBADDR", None)
|
self.influxdbaddr = self.cbpi.config.get("INFLUXDBADDR", None)
|
||||||
#self.influxdbport = self.cbpi.config.get("INFLUXDBPORT", None)
|
|
||||||
self.influxdbname = self.cbpi.config.get("INFLUXDBNAME", None)
|
self.influxdbname = self.cbpi.config.get("INFLUXDBNAME", None)
|
||||||
self.influxdbuser = self.cbpi.config.get("INFLUXDBUSER", None)
|
self.influxdbuser = self.cbpi.config.get("INFLUXDBUSER", None)
|
||||||
self.influxdbpwd = self.cbpi.config.get("INFLUXDBPWD", None)
|
self.influxdbpwd = self.cbpi.config.get("INFLUXDBPWD", None)
|
||||||
self.influxdbmeasurement = self.cbpi.config.get("INFLUXDBMEASUREMENT", "measurement")
|
self.influxdbmeasurement = self.cbpi.config.get("INFLUXDBMEASUREMENT", "measurement")
|
||||||
|
|
||||||
id = name
|
id = name
|
||||||
|
timeout = Timeout(connect=5.0, read=None)
|
||||||
try:
|
try:
|
||||||
sensor=self.cbpi.sensor.find_by_id(name)
|
sensor=self.cbpi.sensor.find_by_id(name)
|
||||||
if sensor is not None:
|
if sensor is not None:
|
||||||
|
@ -68,7 +72,7 @@ class LogController:
|
||||||
self.influxdburl=self.influxdbaddr + "/api/v2/write?org=" + self.influxdbuser + "&bucket=" + self.influxdbname + "&precision=s"
|
self.influxdburl=self.influxdbaddr + "/api/v2/write?org=" + self.influxdbuser + "&bucket=" + self.influxdbname + "&precision=s"
|
||||||
try:
|
try:
|
||||||
header = {'User-Agent': name, 'Authorization': "Token {}".format(self.influxdbpwd)}
|
header = {'User-Agent': name, 'Authorization': "Token {}".format(self.influxdbpwd)}
|
||||||
http = urllib3.PoolManager()
|
http = PoolManager(timeout=timeout)
|
||||||
req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
|
req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("InfluxDB cloud write Error: {}".format(e))
|
logging.error("InfluxDB cloud write Error: {}".format(e))
|
||||||
|
@ -78,7 +82,7 @@ class LogController:
|
||||||
self.influxdburl= self.influxdbaddr + '/write?db=' + self.influxdbname
|
self.influxdburl= self.influxdbaddr + '/write?db=' + self.influxdbname
|
||||||
try:
|
try:
|
||||||
header = {'User-Agent': name, 'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic %s' % self.base64string.decode('utf-8')}
|
header = {'User-Agent': name, 'Content-Type': 'application/x-www-form-urlencoded','Authorization': 'Basic %s' % self.base64string.decode('utf-8')}
|
||||||
http = urllib3.PoolManager()
|
http = PoolManager(timeout=timeout)
|
||||||
req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
|
req = http.request('POST',self.influxdburl, body=out.encode(), headers = header)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("InfluxDB write Error: {}".format(e))
|
logging.error("InfluxDB write Error: {}".format(e))
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: cbpi4
|
Name: cbpi4
|
||||||
Version: 4.1.2
|
Version: 4.1.7a4
|
||||||
Summary: CraftBeerPi4 Brewing Software
|
Summary: CraftBeerPi4 Brewing Software
|
||||||
Home-page: http://web.craftbeerpi.com
|
Home-page: http://web.craftbeerpi.com
|
||||||
Author: Manuel Fritsch / Alexander Vollkopf
|
Author: Manuel Fritsch / Alexander Vollkopf
|
||||||
|
@ -14,14 +14,14 @@ License-File: LICENSE
|
||||||
|
|
||||||
# CraftBeerPi 4
|
# CraftBeerPi 4
|
||||||
|
|
||||||
[![Build](https://github.com/avollkopf/craftbeerpi4/actions/workflows/build.yml/badge.svg)](https://github.com/avollkopf/craftbeerpi4/actions/workflows/build.yml)
|
[![Build](https://github.com/PiBrewing/craftbeerpi4/actions/workflows/build.yml/badge.svg)](https://github.com/PiBrewing/craftbeerpi4/actions/workflows/build.yml)
|
||||||
[![GitHub license](https://img.shields.io/github/license/avollkopf/craftbeerpi4)](https://github.com/avollkopf/craftbeerpi4/blob/master/LICENSE)
|
[![GitHub license](https://img.shields.io/github/license/PiBrewing/craftbeerpi4)](https://github.com/PiBrewing/craftbeerpi4/blob/master/LICENSE)
|
||||||
![GitHub issues](https://img.shields.io/github/issues-raw/avollkopf/craftbeerpi4)
|
![GitHub issues](https://img.shields.io/github/issues-raw/PiBrewing/craftbeerpi4)
|
||||||
![PyPI](https://img.shields.io/pypi/v/cbpi4)
|
![PyPI](https://img.shields.io/pypi/v/cbpi4)
|
||||||
![Happy Brewing](https://img.shields.io/badge/CraftBeerPi%204-Happy%20Brewing-%23FBB117)
|
![Happy Brewing](https://img.shields.io/badge/CraftBeerPi%204-Happy%20Brewing-%23FBB117)
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://github.com/avollkopf/craftbeerpi4-ui/blob/main/cbpi4gui/public/logo192.png?raw=true" alt="CraftBeerPi Logo"/>
|
<img src="https://github.com/PiBrewing/craftbeerpi4-ui/blob/main/cbpi4gui/public/logo192.png?raw=true" alt="CraftBeerPi Logo"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
CraftBeerPi 4 is an open source software solution to control the brewing and
|
CraftBeerPi 4 is an open source software solution to control the brewing and
|
||||||
|
@ -50,6 +50,6 @@ For a more detailed description of a development setup without the _development
|
||||||
### Contributors
|
### Contributors
|
||||||
Thanks to all the people who have contributed
|
Thanks to all the people who have contributed
|
||||||
|
|
||||||
[![contributors](https://contributors-img.web.app/image?repo=avollkopf/craftbeerpi4)](https://github.com/avollkopf/craftbeerpi4/graphs/contributors)
|
[![contributors](https://contributors-img.web.app/image?repo=PiBrewing/craftbeerpi4)](https://github.com/PiBrewing/craftbeerpi4/graphs/contributors)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -158,6 +158,10 @@ cbpi/extension/onewire/__pycache__/__init__.cpython-310.pyc
|
||||||
cbpi/extension/onewire/__pycache__/__init__.cpython-311.pyc
|
cbpi/extension/onewire/__pycache__/__init__.cpython-311.pyc
|
||||||
cbpi/extension/onewire/__pycache__/__init__.cpython-37.pyc
|
cbpi/extension/onewire/__pycache__/__init__.cpython-37.pyc
|
||||||
cbpi/extension/onewire/__pycache__/__init__.cpython-39.pyc
|
cbpi/extension/onewire/__pycache__/__init__.cpython-39.pyc
|
||||||
|
cbpi/extension/timer/__init__.py
|
||||||
|
cbpi/extension/timer/config.yaml
|
||||||
|
cbpi/extension/timer/__pycache__/__init__.cpython-311.pyc
|
||||||
|
cbpi/extension/timer/__pycache__/__init__.cpython-39.pyc
|
||||||
cbpi/http_endpoints/__init__.py
|
cbpi/http_endpoints/__init__.py
|
||||||
cbpi/http_endpoints/http_actor.py
|
cbpi/http_endpoints/http_actor.py
|
||||||
cbpi/http_endpoints/http_config.py
|
cbpi/http_endpoints/http_config.py
|
||||||
|
|
|
@ -7,7 +7,7 @@ aiohttp-session==2.12.0
|
||||||
aiohttp-swagger==1.0.16
|
aiohttp-swagger==1.0.16
|
||||||
aiojobs==1.1.0
|
aiojobs==1.1.0
|
||||||
aiosqlite==0.17.0
|
aiosqlite==0.17.0
|
||||||
cryptography==36.0.1
|
cryptography==40.0.0
|
||||||
requests==2.28.1
|
requests==2.28.1
|
||||||
voluptuous==0.13.1
|
voluptuous==0.13.1
|
||||||
pyfiglet==0.8.post1
|
pyfiglet==0.8.post1
|
||||||
|
|
Loading…
Reference in a new issue