-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.py
54 lines (42 loc) · 1.46 KB
/
send.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import network
import urequests
import ujson
import time
SERVER_URL = "http://192.168.100.197:8000/api"
def send_data(data):
result = str()
try:
headers = {"Content-Type": "application/json"}
# POSTリクエスト送信
response = urequests.post(f"{SERVER_URL}/send-data", headers=headers, data=ujson.dumps(data))
# レスポンス確認
if response.status_code == 200:
result = response.text
print(result)
else:
print("Failed to download the file. Status code:", response.status_code)
response.close()
except Exception as e:
print("Failed to send data:", e)
def send_start_time():
result = str()
data = {"message": "start"}
try:
headers = {"Content-Type": "application/json"}
# POSTリクエスト送信
response = urequests.post(f"{SERVER_URL}/get-start-time", headers=headers, data=ujson.dumps(data))
# レスポンス確認
if response.status_code == 200:
result = response.text
print(result)
else:
print("Failed to send start time Status code:", response.status_code)
response.close()
except Exception as e:
print("Failed to send data:", e)
# メイン処理
def main(data):
# 送信するデータを定義
send_info = {"jikken": "ari_yamamoto", "data": data}
print(send_info)
send_data(send_info)