Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kl_task7_MQTTreceiver
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
arun.uday
kl_task7_MQTTreceiver
Commits
c4ca5413
Commit
c4ca5413
authored
Feb 02, 2023
by
arun.uday
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit3
parent
7583b00c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
14 deletions
+45
-14
app.py
+3
-3
conf/applications.conf
+9
-0
scripts/config/application_config.py
+8
-0
scripts/core/handlers/operations_db.py
+8
-8
scripts/services/receiver_app_services_run.py
+3
-3
scripts/utilis/db_queries.py
+14
-0
No files found.
app.py
View file @
c4ca5413
import
uvicorn
from
scripts.config.application_config
import
uvicorn_host
,
uvicorn_port
from
scripts.config.application_config
import
uvicorn_host
,
uvicorn_port
,
uvicorn_app
# starting the application
if
__name__
==
"__main__"
:
print
(
"
Fast API
task"
)
uvicorn
.
run
(
"scripts.services.receiver_app_services_run:app"
,
host
=
uvicorn_host
,
port
=
int
(
uvicorn_port
))
print
(
"
MQTT
task"
)
uvicorn
.
run
(
uvicorn_app
,
host
=
uvicorn_host
,
port
=
int
(
uvicorn_port
))
conf/applications.conf
View file @
c4ca5413
...
...
@@ -15,3 +15,11 @@ requests = 60
[
uvicorn
]
uvicorn_host
=
127
.
0
.
0
.
1
uvicorn_port
=
8001
uvicorn_app
=
scripts
.
services
.
receiver_app_services_run
:
app
[
db
]
db_name
=
user_details
.
db
db_table
=
details
[
encode
]
encode
=
utf
-
8
\ No newline at end of file
scripts/config/application_config.py
View file @
c4ca5413
...
...
@@ -20,9 +20,17 @@ request_no = config.get("mqtt", "requests")
# uvicorn
uvicorn_host
=
config
.
get
(
"uvicorn"
,
"uvicorn_host"
)
uvicorn_port
=
config
.
get
(
"uvicorn"
,
"uvicorn_port"
)
uvicorn_app
=
config
.
get
(
"uvicorn"
,
"uvicorn_app"
)
# file name
file_name_csv
=
config
.
get
(
"file"
,
"file_name_csv"
)
file_name_json
=
config
.
get
(
"file"
,
"file_name_json"
)
full_path_csv
=
base_path
+
sub_path
+
file_name_csv
full_path_json
=
base_path
+
sub_path
+
file_name_json
# db name
db_name
=
config
.
get
(
"db"
,
"db_name"
)
db_table
=
config
.
get
(
"db"
,
"db_table"
)
# encode
utf_encode
=
config
.
get
(
"encode"
,
"encode"
)
scripts/
utili
s/operations_db.py
→
scripts/
core/handler
s/operations_db.py
View file @
c4ca5413
import
sqlite3
from
scripts.config.application_config
import
db_name
,
db_table
from
scripts.utilis.db_queries
import
DbQueries
class
SqliteOperations
:
def
__init__
(
self
):
# connecting to the database
self
.
conn
=
sqlite3
.
connect
(
'user_details.db'
)
self
.
conn
=
sqlite3
.
connect
(
db_name
)
def
create_db
(
self
):
try
:
# creating the table
self
.
conn
.
execute
(
'''CREATE TABLE IF NOT EXISTS details
(ID INT PRIMARY KEY NOT NULL,
FIRSTNAME TEXT NOT NULL,
LASTNAME TEXT NOT NULL);'''
)
self
.
conn
.
execute
(
DbQueries
()
.
create_table
)
self
.
conn
.
close
()
except
Exception
as
e
:
print
(
e
)
...
...
@@ -20,7 +20,7 @@ class SqliteOperations:
def
insert_db
(
self
,
frames
):
try
:
# inserting data to table
frames
.
to_sql
(
'details'
,
self
.
conn
,
if_exists
=
'replace'
)
frames
.
to_sql
(
db_table
,
self
.
conn
,
if_exists
=
'replace'
)
self
.
conn
.
commit
()
except
Exception
as
e
:
print
(
e
)
...
...
@@ -30,8 +30,8 @@ class SqliteOperations:
# Create a cursor
cursor
=
self
.
conn
.
cursor
()
# Execute a SELECT statement to fetch data from the "detai
sl
" table
cursor
.
execute
(
"SELECT * FROM details"
)
# Execute a SELECT statement to fetch data from the "detai
ls
" table
cursor
.
execute
(
DbQueries
()
.
select
)
return
cursor
except
Exception
as
e
:
print
(
e
)
scripts/services/receiver_app_services_run.py
View file @
c4ca5413
...
...
@@ -3,9 +3,9 @@ from fastapi import FastAPI
import
json
import
pandas
as
pd
from
scripts.config.application_config
import
topic_name
,
mqtt_host
,
port
,
request_no
from
scripts.config.application_config
import
topic_name
,
mqtt_host
,
port
,
request_no
,
utf_encode
from
scripts.core.handlers.display_data
import
display_fetched_data
from
scripts.
utili
s.operations_db
import
SqliteOperations
from
scripts.
core.handler
s.operations_db
import
SqliteOperations
# This is the Subscriber
...
...
@@ -22,7 +22,7 @@ def receiver():
def
on_message
(
client_name
,
userdata
,
msg
):
print
(
client_name
,
" "
,
userdata
)
# decoding the msg to string
payload_decoded
=
msg
.
payload
.
decode
(
'utf-8'
)
payload_decoded
=
msg
.
payload
.
decode
(
utf_encode
)
json_data
=
json
.
loads
(
payload_decoded
)
# decoded msg to list
data_list
=
list
(
json_data
.
values
())
...
...
scripts/utilis/db_queries.py
0 → 100644
View file @
c4ca5413
# database queries
from
scripts.config.application_config
import
db_table
class
DbQueries
:
def
__init__
(
self
):
# table creation
self
.
create_table
=
'''CREATE TABLE IF NOT EXISTS details
(ID INT PRIMARY KEY NOT NULL,
FIRSTNAME TEXT NOT NULL,
LASTNAME TEXT NOT NULL);'''
# table selection
self
.
select
=
"SELECT * FROM "
+
db_table
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