-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_set_temperature.py
More file actions
executable file
·26 lines (23 loc) · 1.24 KB
/
test_set_temperature.py
File metadata and controls
executable file
·26 lines (23 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/python3
# Importing required packages
import argparse
import requests
import json
# command line arguments
parser = argparse.ArgumentParser(prog='test_set_temperature.py',
description='Set the detector temperature by sending a request to the API server.')
parser.add_argument('-i', '--ip_address', type=str, default='150.204.240.129', help='The IP address the server is running on.')
parser.add_argument('-p', '--port_number', type=int, default=5100, help='The port number the server is running on.')
parser.add_argument('-t', '--temperature', type=int, default=-60, help='The temperature set-point to attain in degrees centigrade.')
args = parser.parse_args()
# Composing a payload for API
payload = {'temperature' : args.temperature }
# Defining content type for our payload
headers = {'Content-type': 'application/json'}
# Compose the API endpoint URL
urlname = "http://" + str(args.ip_address) + ":" + str(args.port_number) + "/setTemperature"
print ("Invoking end-point: ", urlname, " with payload:", json.dumps(payload))
# Sending a post request to the server (API) and receiving a reply
response = requests.post(url=urlname , data=json.dumps(payload), headers=headers)
# Printing out the response of API
print(response.text)