Commit 151e1270 by arun.uday

v1

parents
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (task9receiverredis)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="530f9a40-4e97-41f4-9693-adc3b4faba7d" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Python Script" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2L7agoVWktk1eKoSJUoOaB0Tdf5" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;last_opened_file_path&quot;: &quot;E:/KL projects/task9receiverredis&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;project.propVCSSupport.DirectoryMappings&quot;
}
}</component>
<component name="RunManager">
<configuration name="app" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="redis receiver" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="E:\KL projects\task9receiverredis\venv\Scripts\python.exe" />
<option name="SDK_NAME" value="Python 3.9 (task9receiverredis)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/app.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="530f9a40-4e97-41f4-9693-adc3b4faba7d" name="Changes" comment="" />
<created>1675224688329</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1675224688329</updated>
</task>
<servers />
</component>
</project>
\ No newline at end of file
import uvicorn
from scripts.config.applications_config import uvicorn_host, uvicorn_port
# starting the application
if __name__ == "__main__":
print("redis MQTT task")
uvicorn.run("scripts.services.receiver_app_run:app", host=uvicorn_host, port=int(uvicorn_port))
[path]
base_path = scripts/
sub_path = temp/
[mqtt]
topic = receptionist
mqtt_host = 192.168.0.220
port = 1883
requests = 60
[uvicorn]
uvicorn_host = 127.0.0.1
uvicorn_port = 8001
# database servers
[connection]
mongodb = mongodb://localhost:27017
[redis_db]
redis_host = 127.0.0.1
import configparser
config = configparser.RawConfigParser()
config.read("conf/application.conf")
# path
base_path = config.get("path", 'base_path')
sub_path = config.get("path", "sub_path")
# mqtt
topic_name = config.get("mqtt", "topic")
mqtt_host = config.get("mqtt", "mqtt_host")
port = config.get("mqtt", "port")
request_no = config.get("mqtt", "requests")
# db connection
client_connect = config.get("connection", "mongodb")
# uvicorn
uvicorn_host = config.get("uvicorn", "uvicorn_host")
uvicorn_port = config.get("uvicorn", "uvicorn_port")
# redis
redis_host = config.get("redis_db", "redis_host")
# connecting to the redis
import redis
from scripts.config.applications_config import redis_host
conn = redis.Redis(redis_host)
# get the doctor topics to subscribe
def read_doctors(conn, client_name):
no_doctors = conn.get("Doctors")
doctors_list = []
for doctors in range(0, int(no_doctors)):
tup_doctors = ('doctor' + str(doctors), 0)
doctors_list.append(tup_doctors)
client_name.subscribe(doctors_list)
import paho.mqtt.client as mqtt
from fastapi import FastAPI
from scripts.config.applications_config import mqtt_host, port, request_no
from scripts.core.engine.redis_db import conn
from scripts.core.handlers.reading_doctors import read_doctors
# This is the Subscriber
app = FastAPI()
# subscribing to the doctor topics and getting the messages
@app.get("/")
def receiver():
# subscribe to the doctor topics
def on_connect(client_name, userdata, flags, rc):
print(userdata, " ", flags)
print("Connected with result code " + str(rc))
read_doctors(conn, client_name)
# printing the messages
def on_message(client_name, userdata, msg):
print(client_name, " ", userdata)
# decoding the msg to string
payload_decoded = msg.payload.decode('utf-8')
print(msg.topic, "assigned to", payload_decoded)
# creating the paho client for mqtt
client = mqtt.Client()
client.connect(mqtt_host, int(port), int(request_no))
client.on_connect = on_connect
client.on_message = on_message
client.loop_forever()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment