Hello @bongchanho,
I haven’t used matlab for a very long time now but I am pretty sure you could adapt the following script from our data acquisition format documentation to matlab format using something similar to this https://www.mathworks.com/matlabcentral/answers/499434-matlab-http-post-and-json-request
Here is the example in Python on how to use our API to push some data:
# First, install the dependencies via:
# $ pip3 install requests
import json
import time, hmac, hashlib
import requests
HMAC_KEY = "fed53116f20684c067774ebf9e7bcbdc"
API_KEY = "ei_fd83..."
# empty signature (all zeros). HS256 gives 32 byte signature, and we encode in hex, so we need 64 characters here
emptySignature = ''.join(['0'] * 64)
data = {
"protected": {
"ver": "v1",
"alg": "HS256",
"iat": time.time() # epoch time, seconds since 1970
},
"signature": emptySignature,
"payload": {
"device_name": "ac:87:a3:0a:2d:1b",
"device_type": "DISCO-L475VG-IOT01A",
"interval_ms": 10,
"sensors": [
{ "name": "accX", "units": "m/s2" },
{ "name": "accY", "units": "m/s2" },
{ "name": "accZ", "units": "m/s2" }
],
"values": [
[ -9.81, 0.03, 1.21 ],
[ -9.83, 0.04, 1.27 ],
[ -9.12, 0.03, 1.23 ],
[ -9.14, 0.01, 1.25 ]
]
}
}
# encode in JSON
encoded = json.dumps(data)
# sign message
signature = hmac.new(bytes(HMAC_KEY, 'utf-8'), msg = encoded.encode('utf-8'), digestmod = hashlib.sha256).hexdigest()
# set the signature again in the message, and encode again
data['signature'] = signature
encoded = json.dumps(data)
# and upload the file
res = requests.post(url='https://ingestion.edgeimpulse.com/api/training/data',
data=encoded,
headers={
'Content-Type': 'application/json',
'x-file-name': 'idle01',
'x-api-key': API_KEY
})
if (res.status_code == 200):
print('Uploaded file to Edge Impulse', res.status_code, res.content)
else:
print('Failed to upload file to Edge Impulse', res.status_code, res.content)
In the ECG case, it is a time serie so you won’t have any problem adapting the JSON file to send and after feel free to use any of your favorite language to post your JSON using an http request:
Here is how the JSON file should look like:
{
"protected": {
"ver": "v1",
"alg": "HS256",
"iat": 1564128599
},
"signature": "b0ee0572a1984b93b6bc56e6576e2cbbd6bccd65d0c356e26b31bbc9a48210c6",
"payload": {
"device_name": "ac:87:a3:0a:2d:1b",
"device_type": "DISCO-L475VG-IOT01A",
"interval_ms": 10,
"sensors": [
{ "name": "accX", "units": "m/s2" },
{ "name": "accY", "units": "m/s2" },
{ "name": "accZ", "units": "m/s2" }
],
"values": [
[ -9.81, 0.03, 1.21 ],
[ -9.83, 0.04, 1.27 ],
[ -9.12, 0.03, 1.23 ],
[ -9.14, 0.01, 1.25 ]
]
}
}
Regards,
Louis