-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_rpc.py
39 lines (34 loc) · 1.1 KB
/
send_rpc.py
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
27
28
29
30
31
32
33
34
35
36
37
38
import os
import json
import time
import requests
TIME=5
DEVICE_ID = "9dd9bca0-809f-11eb-950e-efef5c07c810"
JWT_TOKEN = ""
BASE = 'https://thingsboard.e-yantra.org/api'
if __name__ == "__main__":
response = requests.post(f'{BASE}/auth/login', json={
'username': "[email protected]",
'password': "150rupyadega"
})
response_json = response.json()
JWT_TOKEN = response_json["token"]
with open('rpc.json') as fp:
rpc_list = json.load(fp)
for req in rpc_list:
try:
response = requests.post(f'{BASE}/plugins/rpc/oneway/{DEVICE_ID}',
json=req,
headers={
'X-Authorization': f'Bearer {JWT_TOKEN}',
})
print(response)
if response.status_code // 100 == 2:
print(f'{req} successfully sent.')
else:
print(f'Failed {response.json()}')
except requests.exceptions.RequestException as e:
# print(response.json())
print(f'Problem in sending request: {req}')
print(e)
time.sleep(TIME)