As described in the Telemetry Overview article, SquareOne includes default telemetry but can be easily extended for other use cases.
A local WebSocket interface (at ws://localhost:3444/) provides the interface that telemetry data can be written to (or read from). Note that as long as telemetry conforms to IPSO formatting, it will automatically appear in the system, as shown below.
As an example, below is a Python script that imitates a sensor, reporting a reading every 5 minutes incrementing from 0 to 50 (and then resetting). Running this code on a device will yield the following telemetry:
Example Code
# Example of sending custom data from a device via the SquareOne agent # # Implement a dummy sensor that will send an increasing sensor value every 5 minutes, starting # at 0, increasing by 1 every reading until 50 is reached, when it starts again at 0 # # You may need to install the python websocket library using something similar to: # pip install websocket-client # from websocket import create_connection import json import time ws = 0 ### SquareOne transmission functions def topicPublish(topic, data): outStr = topic outStr += "\n" outStr += json.dumps(data) print("Sending data: "+ outStr) ws.send(outStr) ########################################################### descriptionSent = False sensorValue = 0 while True: # Open the websocket connection to the SquareOne edge client ws = create_connection("ws://localhost:3444/") # Send the sensor data up to the cloud print("Sending sensor data ", sensorValue) # If this is the first time we are sending data, also send a description. if not descriptionSent: topicPublish("/telemetry/POST/50/0/0/10400/0", { "correlationId":0, "messageId":0, "status":200, "data": { "5700": sensorValue, "5750": "Dummy Sensor Value" } }) descriptionSent = True else: topicPublish("/telemetry/POST/50/0/0/10400/0", { "correlationId":0, "messageId":0, "status":200, "data": { "5700": sensorValue } }) ws.close() print("Websocket connection closed") sensorValue += 1
if sensorValue > 50: sensorValue = 0
# Wait before sending the next sensor value
time.sleep(60 * 5)