Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
IoT-Weather Station
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
norbert.dajnowski
IoT-Weather Station
Commits
4fe8e5bf
Commit
4fe8e5bf
authored
Jan 04, 2021
by
norbert.dajnowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Python Weather Station Server
parent
61bc8ef0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
weather-station-server.py
weather-station-server.py
+88
-0
No files found.
weather-station-server.py
0 → 100644
View file @
4fe8e5bf
import
logging
import
asyncio
import
platform
import
sys
from
time
import
sleep
import
urllib
import
urllib.request
from
bleak
import
BleakClient
from
bleak
import
_logger
as
logger
CHARACTERISTIC_UUID
=
"0000ffe1-0000-1000-8000-00805f9b34fb"
baseURL
=
'https://api.thingspeak.com/update?api_key=N4DJDAJ1LN59PKQJ&field1='
async
def
thingspeakWrite
():
with
urllib
.
request
.
urlopen
(
baseURL
+
temp
+
"&field2="
+
humidity
+
"&field3="
+
pressure
+
"&field4="
+
CO
+
"&field5="
+
light
+
"&field6="
+
Alcohol
)
as
f
:
f
.
read
()
f
.
close
()
def
notification_handler
(
sender
,
data
):
global
humidity
global
temp
global
pressure
global
light
global
CO
global
Alcohol
global
CO2
try
:
text
=
str
(
data
)
text
=
text
.
rstrip
(
")'"
)
text
=
text
.
lstrip
(
"bytearray(b'"
)
if
"Humidity"
in
text
:
text
=
text
.
rstrip
(
"
%
"
)
humidity
=
text
.
lstrip
(
"Humidity: "
)
elif
"Temp"
in
text
:
text
=
text
.
rstrip
(
"C"
)
temp
=
text
.
lstrip
(
"Temp: "
)
elif
"Pressure"
in
text
:
text
=
text
.
rstrip
(
"Pa"
)
pressure
=
text
.
lstrip
(
"Pressure: "
)
elif
"Light"
in
text
:
text
=
text
.
rstrip
(
"V"
)
light
=
text
.
lstrip
(
"Light: "
)
elif
"CO1"
in
text
:
text
=
text
.
rstrip
(
"PPM"
)
CO
=
text
.
lstrip
(
"CO1: "
)
elif
"Alcohol"
in
text
:
text
=
text
.
rstrip
(
"PPM"
)
Alcohol
=
text
.
lstrip
(
"Alcohol: "
)
finally
:
print
(
text
)
async
def
run
(
address
):
async
with
BleakClient
(
address
)
as
client
:
while
True
:
x
=
await
client
.
is_connected
()
try
:
await
client
.
start_notify
(
CHARACTERISTIC_UUID
,
notification_handler
)
await
asyncio
.
sleep
(
15
)
await
thingspeakWrite
()
finally
:
await
client
.
stop_notify
(
CHARACTERISTIC_UUID
)
if
__name__
==
"__main__"
:
import
os
os
.
environ
[
"PYTHONASYNCIODEBUG"
]
=
str
(
1
)
address
=
(
"64:69:4E:80:2A:46"
)
loop
=
asyncio
.
get_event_loop
()
loop
.
run_until_complete
(
run
(
address
))
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