Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mqtt-reciever
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammed.shibili
mqtt-reciever
Commits
e764a0cc
Commit
e764a0cc
authored
Jan 27, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
receiver try,except
parent
8106105d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
scripts/serviece/main.py
+17
-12
No files found.
scripts/serviece/main.py
View file @
e764a0cc
...
...
@@ -11,21 +11,26 @@ def on_connect(client, userdata, flags, rc):
print
(
"Connected with result code "
+
str
(
rc
))
except
Exception
as
e
:
print
(
"db connection error"
,
e
)
except
TypeError
:
pass
def
on_message
(
client
,
userdata
,
message
):
data_from_mqtt
=
json
.
loads
(
message
.
payload
.
decode
())
connection
=
sqlite3
.
connect
(
db_name
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
'''CREATE TABLE IF NOT EXISTS mqtt_data
(id INT,first_name varchar(20),last_name varchar(20))'''
)
for
data
in
data_from_mqtt
:
cursor
.
execute
(
"INSERT INTO mqtt_data VALUES (?,?,?)"
,
(
data
[
"id"
],
data
[
"first_name"
],
data
[
"last_name"
]))
cursor
.
execute
(
"SELECT * FROM mqtt_data"
)
datas
=
cursor
.
fetchall
()
for
row
in
datas
:
print
(
row
)
try
:
data_from_mqtt
=
json
.
loads
(
message
.
payload
.
decode
())
connection
=
sqlite3
.
connect
(
db_name
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
'''CREATE TABLE IF NOT EXISTS mqtt_data
(id INT,first_name varchar(20),last_name varchar(20))'''
)
for
data
in
data_from_mqtt
:
cursor
.
execute
(
"INSERT INTO mqtt_data VALUES (?,?,?)"
,
(
data
[
"id"
],
data
[
"first_name"
],
data
[
"last_name"
]))
cursor
.
execute
(
"SELECT * FROM mqtt_data"
)
datas
=
cursor
.
fetchall
()
for
row
in
datas
:
print
(
row
)
except
TypeError
:
pass
client
=
mqtt
.
Client
()
...
...
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