POST /api/boarddata
URL requires a header and body with the following format (Items in bold are required):
{
"**pcbSn**": *board PCB SN,
"timeSent": *current time in iso format,
"**dataObjects**": [
{
"**rawData**": [
{
"**dataType**": *type (int, string, etc.),
"**dataName**": *name of data being tracked,
"**data**": *data value
}
]
},
{
"**rawData**": [
{
"**dataType**": *type (int, string, etc.),
"**dataName**": *name of data being tracked,
"**data**": *data value
}
]
}
]
}
Python example to post Device Data:
#!/usr/bin/python3
#
# Post_Data.py
#
# This example showcases posting a temperature reading through the API
# Note that data here is synthetic, and is normally measured by an IoT device.
#
# Copyright (c) 2021-2023 Engineering Design Group, LLC. All Rights Reserved.
#
# <variable_name> represents value specific to user
import requests
import json
from datetime import datetime
#Note: All data in the following structure is required, with the exception of the vendor SN
def createPostData(deviceData):
#===================================================================================
#rawData is a list consisting of dicts
#each dict will contain the type, name and value for a piece of data
#===================================================================================
rawData = []
#iterate through devicedata, format each piece of data and insert into rawData list
for data in deviceData:
subRawData = {'DataType':str(type(deviceData[data])),
'DataName':str(data),
'Data':str(deviceData[data])
}
rawData.append(subRawData)
#===================================================================================
#create data object
#data Object describes properties of the board, as well as which subsection of the board used
#this could mean certain sensors within the board
#could also mean specific run modes that have differing data structrues (ex. Monitor mode vs Run mode)
#All key/data pairs except Rawdata are optional
#===================================================================================
dataObject = {"RawData":rawData,
"ObjectEnum":<Enum>,
#used so user can assign indexes to certain device sensors/functions
"ObjectType":"Time/Temp Sensor",
#a name to pair with the object enumeration
"ObjectSn": <Device_Sn>,
#SN of the device provided by device manufacturer
"ObjectMnfg":"Temp_Company", #Name of device manufacturer
"ObjectMn":"Part no" #Name of device (according to manufacturer
}
#===================================================================================
#Package any dataObjects sent
#Packaged Data contains metadatae of the dataObjects, includes the device ID, company, user, and device Group
#Several of these fields will be populated automatically by the DB
#===================================================================================
packagedData = {'PcbSn':str('4b2dd454-5cf6-417e-9db7-1fd0bbcbeeef'),
'TimeSent':str(datetime.now().isoformat()),
'DataObjects':[dataObject]
}
return packagedData
def API_postData(packagedData):
#generate URL for POST request
baseUrl = <API_URL>
endpointAddress = "/api/boarddata"
dataUrl = baseUrl + endpointAddress
#generate header (auth token is not required)
header = {
"Content-Type": "application/json"
}
#send Data to API through POST request
response = requests.post(dataUrl,
headers = header,
data = json.dumps(packagedData),
verify = True)
print("Post Data: ", response)
return response
def main():
#simulate example data provided by IoT device
device_data = {
'temp':23.4,
'humidity':'58.4%'
}
print("Packaging device data...")
#package the device Data into a format the API recognizes
packaged_data = createPostData(device_data)
print("Posting data to API...")
#post the packaged data to the API
data = API_postData(packaged_data)
if __name__ == "__main__":
main()