Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
Mqtt2Influxdb
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Wetterstation
Mqtt2Influxdb
Commits
1d08ccc4
Commit
1d08ccc4
authored
5 years ago
by
Dennis Eisold
Browse files
Options
Downloads
Patches
Plain Diff
Update mqtt2influx.py
parent
5e425682
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
mqtt2influx.py
+5
-4
5 additions, 4 deletions
mqtt2influx.py
with
5 additions
and
4 deletions
mqtt2influx.py
+
5
−
4
View file @
1d08ccc4
...
@@ -28,9 +28,10 @@ def on_connect(client, userdata, flags, rc):
...
@@ -28,9 +28,10 @@ def on_connect(client, userdata, flags, rc):
def
on_message
(
client
,
userdata
,
msg
):
def
on_message
(
client
,
userdata
,
msg
):
loaded_json
=
json
.
loads
(
msg
.
payload
.
decode
(
"
utf-8
"
))
loaded_json
=
json
.
loads
(
msg
.
payload
.
decode
(
"
utf-8
"
))
if
(
"
wetterstation
"
in
msg
.
topic
and
"
SENSOR
"
in
msg
.
topic
):
if
(
msg
.
topic
.
split
(
config
[
mqtt_server
][
'
subscribe
'
].
split
(
"
#
"
)[
0
])[
0
]
in
msg
.
topic
and
"
SENSOR
"
in
msg
.
topic
):
print
(
"
write to influxDB: wetterstation
"
)
print
(
"
write to influxDB:
"
+
config
[
influx_server
][
'
database
'
])
print
(
"
Sensor:
"
+
msg
.
topic
.
split
(
"
/wetterstation/
"
)[
1
].
split
(
"
/SENSOR
"
)[
0
])
client
=
msg
.
topic
.
split
(
config
[
mqtt_server
][
'
subscribe
'
].
split
(
"
#
"
)[
0
])[
1
].
split
(
"
/SENSOR
"
)[
0
]
print
(
"
Sensor:
"
+
client
)
for
key
in
loaded_json
.
keys
():
for
key
in
loaded_json
.
keys
():
if
(
"
Unit
"
not
in
key
and
"
Time
"
not
in
key
):
if
(
"
Unit
"
not
in
key
and
"
Time
"
not
in
key
):
...
@@ -46,7 +47,7 @@ def on_message(client, userdata, msg):
...
@@ -46,7 +47,7 @@ def on_message(client, userdata, msg):
json_body
=
[{
json_body
=
[{
"
measurement
"
:
"
Sensors
"
,
"
measurement
"
:
"
Sensors
"
,
"
tags
"
:
{
"
tags
"
:
{
"
client
"
:
msg
.
topic
.
split
(
"
/wetterstation/
"
)[
1
].
split
(
"
/SENSOR
"
)[
0
]
,
"
client
"
:
client
,
"
sensor
"
:
key
"
sensor
"
:
key
},
},
"
fields
"
:
fields
"
fields
"
:
fields
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment