Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Snippet to send vitals data
''' API CALL To SEND Data '''
import requests
class Client_Device(object):
BASE_URL = 'http://92.168.10.12:8000/api/' #change to your IP address as needed
def send_temperature(self, id, temperature):
url = self.BASE_URL + 'temperature' # Set destination URL here
post_fields = {'patient_id': id, 'temperature': temperature} # Set POST fields here
response = requests.post(url, post_fields)
if response.json():
print("Temperature Stored. data: ")
print(post_fields)
else:
print("Temperature Storing Failed! data: ")
print(post_fields)
def send_bpm(self, id, bpm):
url = self.BASE_URL + 'bpm' # Set destination URL here
post_fields = {'patient_id': id, 'bpm': bpm} # Set POST fields here
response = requests.post(url, post_fields)
if response.json():
print("BPM Stored. data: ")
print(post_fields)
else:
print("BPM Storing Failed! data: ")
print(post_fields)
def send_oximeter(self, id, oximeter):
url = self.BASE_URL + 'oximeter' # Set destination URL here
post_fields = {'patient_id': id, 'oximeter': oximeter} # Set POST fields here
response = requests.post(url, post_fields)
if response.json():
print("OXI-meter Stored. data: ")
print(post_fields)
else:
print("OXI-meter Storing Failed! data: ")
print(post_fields)
def alert_emergency(self, id):
url = self.BASE_URL + 'emergency/' + id.__str__() # Set destination URL here
response = requests.get(url)
response = response.json()
''' Response will return true or false '''
''' Response will return false if id doesn't exist '''
print(response.get('status') )
def recieve_char(self, id):
url = self.BASE_URL + 'char/' + id.__str__() # Set destination URL here
response = requests.get(url)
response = response.json()
''' Response will return true or false '''
''' Response will return false if id doesn't exist '''
print(response.get('char'))
device_1 = Client_Device()
device_1.send_temperature(5, 102)
device_1.send_bpm(5, 120)
device_1.send_oximeter(5, 95)
''' This will be in constant loop to receive alert for emergency or char '''
print("starting Check Thread")
import sched, time
s = sched.scheduler(time.time, time.sleep)
def checkstates_10_secs(sc):
device_1.recieve_char(9)
device_1.alert_emergency(9)
s.enter(10, 1, checkstates_10_secs, (sc,))
s.enter(10, 1, checkstates_10_secs, (s,))
s.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.