Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
co2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nikita Yurishev
co2
Commits
228c9a91
Commit
228c9a91
authored
Jul 30, 2024
by
Nikita Yurishev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added influxWriter
parent
79b153f3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
6 deletions
+43
-6
co2.py
co2.py
+8
-6
influxWriter.py
influxWriter.py
+35
-0
No files found.
co2.py
View file @
228c9a91
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
import
os
import
logging
as
log
import
hid
import
time
import
sys
import
socket
#для hostname
import
socket
from
send_data_to_influxdb
import
InfluxWriter
CO2_USB_MFG
=
'Holtek'
CO2_USB_PRD
=
'USB-zyTemp'
...
...
@@ -46,6 +46,8 @@ class ZyTemp():
self
.
_magic_word
=
[((
w
<<
4
)
&
0xFF
)
|
(
w
>>
4
)
for
w
in
bytearray
(
_CO2MON_MAGIC_WORD
)]
self
.
_magic_table
=
_CO2MON_MAGIC_TABLE
self
.
_magic_table_int
=
list_to_longint
(
_CO2MON_MAGIC_TABLE
)
self
.
influx_writer
=
InfluxWriter
()
# Создаем объект для работы с InfluxDB
if
decrypt
:
self
.
h
.
send_feature_report
(
self
.
_magic_table
)
...
...
@@ -59,9 +61,9 @@ class ZyTemp():
values
[
key
]
=
value
if
all
(
value
is
not
None
for
value
in
values
.
values
()):
#hostname
hostname
=
socket
.
gethostname
(
)
print
(
f
"{hostname}: {values}"
)
sensor_id
=
socket
.
gethostname
()
print
(
f
"{sensor_id}: {values}"
)
self
.
influx_writer
.
write_data
(
sensor_id
,
values
)
# Записываем данные в InfluxDB
sys
.
exit
(
0
)
def
run_once
(
self
,
decrypt
=
False
):
...
...
influxWriter.py
0 → 100644
View file @
228c9a91
# -*- coding: utf-8 -*-
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"
# Подключение к InfluxDB
self
.
client
=
InfluxDBClient
(
host
=
'localhost'
,
port
=
8086
,
username
=
self
.
INFLUXDB_USER
,
password
=
self
.
INFLUXDB_PASSWORD
,
database
=
self
.
INFLUXDB_DB
)
def
write_data
(
self
,
sensor_id
,
values
):
json_body
=
[
{
"measurement"
:
"sensor_data"
,
"tags"
:
{
"sensor_id"
:
sensor_id
},
"time"
:
int
(
time
.
time
()
*
1000
),
# Время в миллисекундах
"fields"
:
values
}
]
self
.
client
.
write_points
(
json_body
,
database
=
self
.
INFLUXDB_DB
)
def
__del__
(
self
):
self
.
client
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment