-
Notifications
You must be signed in to change notification settings - Fork 0
/
bpm2api.py
53 lines (32 loc) · 952 Bytes
/
bpm2api.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
import json
import pulse_sensor
import network
import urequests
import network
import time
# create WiFi station interface
sta_if = network.WLAN(network.STA_IF)
# activate station interface and connect to WiFi network
sta_if.active(True)
sta_if.connect("SSID", "Password")
# wait for connection
while not sta_if.isconnected():
pass
print('WiFi connection established')
# Define endpoint URL
url = "url goes here!"
# Read sensor data
while True:
pulse = pulse_sensor.read()
data = {"pulse": pulse}
# Convert data to JSON format
json_data = json.dumps(data)
#print(json_data)
# Set headers
headers = {"Content-Type": "application/json"}
# Send HTTP POST request with data and headers
response = urequests.post(url, data=json_data)
# Print response
print(response.status_code)
print(response.text)
time.sleep(10)