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
5bf5389b
Commit
5bf5389b
authored
Jul 22, 2024
by
Nikita Yurishev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deleted wrote to log file logic
parent
c7499761
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
25 deletions
+1
-25
co2.py
co2.py
+1
-25
No files found.
co2.py
View file @
5bf5389b
...
...
@@ -18,8 +18,6 @@ l = log.getLogger('zytemp')
_CO2MON_MAGIC_WORD
=
b
'Htemp99e'
_CO2MON_MAGIC_TABLE
=
(
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
)
LOG_FILE
=
'co2data.log'
def
list_to_longint
(
x
):
return
sum
([
val
<<
(
i
*
8
)
for
i
,
val
in
enumerate
(
x
[::
-
1
])])
...
...
@@ -60,22 +58,10 @@ class ZyTemp():
def
update
(
self
,
key
,
value
,
values
):
values
[
key
]
=
value
# Проверяем, если обе переменные имеют значения
if
all
(
value
is
not
None
for
value
in
values
.
values
()):
# Запись значений в лог-файл с меткой времени
try
:
with
open
(
LOG_FILE
,
'a'
)
as
f
:
timestamp
=
time
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
f
.
write
(
f
"{timestamp} - {values}
\n
"
)
l
.
debug
(
f
"Successfully wrote data to {LOG_FILE}"
)
except
Exception
as
e
:
l
.
error
(
f
"Failed to write data to {LOG_FILE}: {e}"
)
print
(
values
)
# Выход после записи в лог
sys
.
exit
(
0
)
#Функция получения данных с детектора
def
run_once
(
self
,
decrypt
=
False
):
while
True
:
try
:
...
...
@@ -101,7 +87,6 @@ class ZyTemp():
continue
if
r
[
3
]
!=
sum
(
r
[
0
:
3
])
&
0xff
:
# l.error(f'Checksum error')
continue
m_type
=
r
[
0
]
...
...
@@ -149,14 +134,8 @@ def get_hiddev():
return
h
if
__name__
==
"__main__"
:
log
.
basicConfig
(
level
=
log
.
DEBUG
)
# Проверка на наличие файла co2data.log, создание при отсутствии
if
not
os
.
path
.
exists
(
LOG_FILE
):
with
open
(
LOG_FILE
,
'w'
)
as
f
:
f
.
write
(
"CO2 and Temperature data log
\n
"
)
hiddev
=
get_hiddev
()
if
hiddev
is
None
:
sys
.
exit
(
1
)
...
...
@@ -164,8 +143,5 @@ if __name__ == "__main__":
zytemp
=
ZyTemp
(
hiddev
)
zytemp
.
run_once
()
# Вывод значений переменных temperature и co2 в консоль
temperature
=
zytemp
.
values
.
get
(
'Temperature'
,
'N/A'
)
co2
=
zytemp
.
values
.
get
(
'CO2'
,
'N/A'
)
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