In this device_postdata.py test, reference the PcbSn corresponding to your physical IoT device. On line 27 put in your device's PcbSN. That's how iot.edglab.com knows your device or board from any other. In lines 69 and 70, change the test data to be anything you want.

Code Example

#!/usr/bin/python3
# Python 3.9.2 or above
#
# device_postdata.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 © 2021-2023 Engineering Design Group, LLC. You have the right to copy and use this code.
#
# <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):

    #====================================================================================================
    #Package any data to be recorded
    #Packaged Data contains a dictionary of dataList, includes the device ID
    #Some needed fields will be populated automatically by the DB
    #====================================================================================================

    packagedData = {
        'pcbSn':str('your_device_PcbSN'),
        'timeSent':str(datetime.now().isoformat()),
        "dataList": {
            'tempC':str(deviceData['temp']),
            'humidity':str(deviceData['humidity']),
            'numberObjects':'as many as you like',
            'types':'only simple types expressed as strings'
            }
    }

    return packagedData

def API_postData(packagedData):

    #generate URL for POST request
    baseUrl = "<https://iot.edglab.com>"
    endpointAddress = "/api/boarddata"
    dataUrl = baseUrl + endpointAddress

    #generate header (auth token is not required)
    header = {
        "Content-Type": "application/json"
    }

    # debug statements below
    #print(dataUrl)
    #print(header)
    #print(json.dumps(packagedData))

    #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()