Commit afc05fff by rakesh.pv

modification done

parent a5ad958b
...@@ -7,15 +7,15 @@ mqtt_client = mqtt.Client() ...@@ -7,15 +7,15 @@ mqtt_client = mqtt.Client()
mqtt_client.connect(MQTT_HOST, MQTT_PORT) mqtt_client.connect(MQTT_HOST, MQTT_PORT)
# #
no_of_doctor = int(input(" enter the number of doctor [ mqtt topic ]")) no_of_doctor = int(input(" enter the number of doctor [ mqtt topic ]"))
c = 0 count = 0
def assign_doctor_to_patient(patient_id): def assign_doctor_to_patient(patient_id):
try: try:
global c global count
c = (c + 1) count = (count + 1)
doctor_topic = "doctor" + str(c) doctor_topic = "doctor" + str(count)
r.set(patient_id, doctor_topic) r.set(patient_id, doctor_topic)
print(patient_id, " assigned to ", doctor_topic) print(patient_id, " assigned to ", doctor_topic)
......
import json import json
import paho.mqtt.client as mqtt
from scripts.config.mqtt_connection import MQTT_TOPIC, MQTT_HOST, MQTT_PORT
from scripts.core.handlers.store_patient_details_in_redis import insert_data_redis from scripts.core.handlers.store_patient_details_in_redis import insert_data_redis
# from scripts.core.handlers.assign_doctor_to_patient import send_patient_details
def insert_new_data(): def insert_new_data():
patient_name = input("enter patient name") patient_name = input("enter patient name")
patient_id = int(input("enter patient id")) patient_id = int(input("enter patient id"))
...@@ -29,7 +28,15 @@ def insert_new_data(): ...@@ -29,7 +28,15 @@ def insert_new_data():
print(" data that will be published to broker is :\n\n", "patiend id :\n", patient_id, "\npatient description \n\n", print(" data that will be published to broker is :\n\n", "patiend id :\n", patient_id, "\npatient description \n\n",
json.dumps(data_to_be_sent)) json.dumps(data_to_be_sent))
# -> scripts.core.handlers.store_patient_details_in_redis Mqtt_msg = json.dumps(data_to_be_sent)
insert_data_redis(patient_id, json.dumps(data_to_be_sent)) insert_data_redis(patient_id, json.dumps(data_to_be_sent))
Mqtt_msg = json.dumps(entire_data)
return Mqtt_msg return Mqtt_msg
def publish_to_mqtt(x):
mqttc = mqtt.Client()
mqttc.connect(MQTT_HOST, MQTT_PORT)
mqttc.publish(MQTT_TOPIC, x)
mqttc.loop_forever()
from scripts.config.mqtt_connection import MQTT_TOPIC, MQTT_HOST, MQTT_PORT
from scripts.config.redis_connection import r from scripts.config.redis_connection import r
from scripts.core.handlers.assign_doctor_to_patient import assign_doctor_to_patient from scripts.core.handlers.assign_doctor_to_patient import assign_doctor_to_patient
...@@ -22,6 +25,5 @@ def check_patient_id(patient_id): ...@@ -22,6 +25,5 @@ def check_patient_id(patient_id):
def insert_data_redis(patient_id, x): def insert_data_redis(patient_id, x):
# -> scripts.core.handlers.check_patient_visited
check_patient_id(patient_id) check_patient_id(patient_id)
# -> scripts.core.handlers.check_patient_visited
import paho.mqtt.client as mqtt
from fastapi import FastAPI
from scripts.config.mqtt_connection import MQTT_HOST, MQTT_PORT, MQTT_TOPIC from fastapi import FastAPI, APIRouter
from scripts.core.handlers.create_new_patient_data import insert_new_data
from scripts.config.mqtt_connection import MQTT_TOPIC, MQTT_HOST, MQTT_PORT
from scripts.core.handlers.create_new_patient_data import insert_new_data, publish_to_mqtt
app = FastAPI() app = FastAPI()
router = APIRouter(
prefix='/test',
tags=['task']
)
@app.get("/") @app.get("/")
def index(): def index():
...@@ -15,24 +21,7 @@ def index(): ...@@ -15,24 +21,7 @@ def index():
# ->scripts.core.handlers.create_new_patient_data # ->scripts.core.handlers.create_new_patient_data
@app.get("/consulation/") @app.get("/consulation/")
def consult_doctor(): def consult_doctor():
x = insert_new_data() x=insert_new_data()
publish_to_mqtt(x)
def on_publish(client, userdata, mid):
print("Message Published...")
def on_connect(client, userdata, flags, rc):
client.subscribe(MQTT_TOPIC)
client.publish(MQTT_TOPIC, x)
def on_message(client, userdata, msg):
print(msg.topic)
print(msg.payload)
client.disconnect()
mqttc = mqtt.Client()
mqttc.on_publish = on_publish
mqttc.on_connect = on_connect
mqttc.on_message = on_message
mqttc.connect(MQTT_HOST, MQTT_PORT)
mqttc.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