External systems and individual IoT devices (hereafter collectively called "devices") can send condition reports to the withthegrid application. Devices identify themselves with a client certificate or a token. This documentation is about access with a token. Devices with a token can interact with the platform by sending:
As developer, you can create a token in your connectivity environment under "Device authentication", "Webhook access". The URL containing the token as shown in the application can be modified as long as it still adheres to the requirements above and the token is present:
t
x-wtg-token
2050
The withthegrid server inspects the incoming request and tries to look up the token. If that is found, the identifier function belonging to that token is run, with the incoming request as parameter. The identifier function is then expected to return the device type hashId and a identifier that uniquely identifies the device among all devices in the connectivity environment.
The identifier function should:
handle
handle(args: Arguments): Result
When the identifier function throws an error or when the return is conform the signature, the request will be rejected with a 502
status code.
When the device type is not known by the application, the request will be rejected with a 404
status code. Otherwise:
502
status code./**
* This identifier assumes that the device presents its identifier in the x-mcu-id
* header and determines its own device type through the x-device-type-hash-id header
*/
function handle(args: Arguments): Result {
const deviceIdentifier = args.request.headers['x-mcu-id'];
if (typeof deviceIdentifier !== 'string') {
throw new Error('x-mcu-id header is not available');
}
const deviceTypeHashId = args.request.headers['x-device-type-hash-id'];
if (typeof deviceTypeHashId !== 'string') {
throw new Error('x-device-type-hash-id header is not available');
}
return {
deviceTypeHashId,
deviceIdentifier,
};
}
You can inspect activity on this identifier function by going to "Activity" in the connectivity environment and filtering "Type" on "Handle incoming request" and "Webhook" on the name given to the webhook.