Commit 489ac07d authored by Nikita Yurishev's avatar Nikita Yurishev

added new connection logic

parent 228c9a91
[InfluxDB]
url = http://localhost:8086
database = co2
username = admin
password = 6wp9fCi0zSjTDISXFWg4
\ No newline at end of file
# -*- coding: utf-8 -*-
import configparser
from influxdb import InfluxDBClient
import time
class InfluxWriter:
def __init__(self):
self.INFLUXDB_URL = "http://localhost:8086"
self.INFLUXDB_DB = "co2"
self.INFLUXDB_USER = "your_username"
self.INFLUXDB_PASSWORD = "your_password"
# Чтение конфигурации из файла config.ini
config = configparser.ConfigParser()
config.read('config.ini')
self.INFLUXDB_URL = config.get('influxdb', 'url')
self.INFLUXDB_DB = config.get('influxdb', 'database')
self.INFLUXDB_USER = config.get('influxdb', 'username')
self.INFLUXDB_PASSWORD = config.get('influxdb', 'password')
# Подключение к InfluxDB
self.client = InfluxDBClient(
host='localhost',
port=8086,
host=self.INFLUXDB_URL.split(':')[1].strip('/'),
port=int(self.INFLUXDB_URL.split(':')[2]),
username=self.INFLUXDB_USER,
password=self.INFLUXDB_PASSWORD,
database=self.INFLUXDB_DB
......@@ -25,7 +30,7 @@ class InfluxWriter:
"tags": {
"sensor_id": sensor_id
},
"time": int(time.time() * 1000), # Время в миллисекундах
"time": int(time.time() * 1000),
"fields": values
}
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment