ThingsBoard
Receive your device data in ThingsBoard through an HTTP integration and a data converter.
This guide shows how to receive CeresGate's forwarded device data in ThingsBoard. It uses the HTTP Integration of ThingsBoard PE (Professional Edition); menu names may differ slightly between ThingsBoard versions.
How it works
CeresGate → HTTP POST → ThingsBoard HTTP Integration → uplink data converter → the device's telemetry
- For every message a device uploads, CeresGate sends
{"IMSI": …, "Payload": …}to the integration's URL with an HTTPPOST, with the adapter'susernameandpasswordas headers (see Forwarding format). - The integration uses those two headers to check that the request comes from your CeresGate adapter, then passes it to the uplink data converter.
- The converter turns the content into ThingsBoard's format: the IMSI as the device name and the decoded data as telemetry. ThingsBoard creates the device the first time it sends data.
- When ThingsBoard answers HTTP 200, the forwarding logs show "Forwarded".
1. Create an uplink data converter
- In ThingsBoard's sidebar, choose "Integrations center" → "Data converters" and add a converter.
- Choose type Uplink, any name (for example
CeresGate uplink), and JavaScript as the language. - Paste the example below into the Decoder function and save.
Converter example
// CeresGate -> ThingsBoard uplink data converter (JavaScript decoder).
// CeresGate POSTs: {"IMSI": "<15 digits>", "Payload": "<hex string>"}
// payload: the request body as an array of bytes; metadata: integration metadata.
function decodeToString(bytes) {
return String.fromCharCode.apply(String, bytes);
}
// Hex string → UTF-8 text. Returns null if the bytes are not valid UTF-8
// (for example binary data), so the caller can keep the hex as-is.
function hexToUtf8(hex) {
if (!hex) {
return "";
}
try {
return decodeURIComponent(hex.replace(/../g, "%$&"));
} catch (e) {
return null;
}
}
function parseJsonObject(text) {
try {
var value = JSON.parse(text);
return (value !== null && typeof value === "object" && !Array.isArray(value)) ? value : null;
} catch (e) {
return null;
}
}
var message = JSON.parse(decodeToString(payload));
var text = hexToUtf8(message.Payload);
var values = text === null ? null : parseJsonObject(text);
var telemetry;
if (values !== null) {
// The device sent a JSON object: each key becomes a telemetry key.
// If your device wraps its readings, e.g. {"D": [{...}]}, use:
// telemetry = values.D[0];
telemetry = values;
} else if (text !== null) {
telemetry = { raw: text }; // plain text
} else {
telemetry = { raw_hex: message.Payload }; // binary data
}
return {
deviceName: message.IMSI,
deviceType: "ceresgate-device",
attributes: {
IMSI: message.IMSI,
integrationName: metadata["integrationName"]
},
telemetry: telemetry
};
This example:
- Data that is a JSON object (for example
{"temp": 25.1, "battery": 87}): each key becomes a telemetry key. - Data wrapped in a field (for example
{"D": [{"temp": 25.1}]}): changetelemetry = values;totelemetry = values.D[0];, adjusted to your format. - Data that isn't JSON (for example the plain text
hello udp :0): stored as the telemetry keyraw, so the conversion doesn't fail. - Binary data (not valid UTF-8 text): the hex string is kept as-is in
raw_hex; parse it according to your device's format. - Decodes as UTF-8, so text such as Chinese comes out right.
- Sets the device type (
deviceType) toceresgate-device, which you can change; the IMSI and the integration's name are also stored as device attributes.
Before saving, you can try it with "Test decoder function" in the converter editor: enter something CeresGate would send, for example
{"IMSI": "001013453258396", "Payload": "7b2274656d70223a32352e317d"}
The output's telemetry should be {"temp": 25.1}.
2. Create an HTTP integration
- Choose "Integrations center" → "Integrations", add an integration and choose type HTTP.
- For the uplink data converter, choose the converter from step 1.
- Turn on Enable security and add two key-value pairs of your choice to the headers filter:
username= a user name you choosepassword= a password you choose
- After saving, copy the integration's HTTP endpoint URL, which looks like:
https://thingsboard.example.com/api/v1/integrations/http/3f2a9c1e-7b4d-4e8a-9c0f-1d2e3f4a5b6c
ThingsBoard must be reachable from the internet for CeresGate to deliver to it.
3. Create the adapter in CeresGate
In the portal's sidebar, choose "Adapter settings" and add a ThingsBoard adapter:
| Field | Enter |
|---|---|
| Name | Anything that helps you recognise it |
| httpurl | The HTTP endpoint URL copied in step 2 |
| username | The username value from the headers filter in step 2 |
| password | The password value from the headers filter in step 2 |
Then, in the Adapter column of the device list, choose this adapter for your devices.
4. Check that data arrives
- Let the device send a message.
- The CeresGate portal's "Forwarding logs" should show "Forwarded" and HTTP 200.
- In ThingsBoard's "Devices", a device named after the IMSI appears, and its "Latest telemetry" tab shows the converted data.
If no data shows up, the "Events" tabs of the integration and the converter show what was received and any errors; turning on debug mode shows every message's input and output. Turn it off when you're done.
When forwarding fails
- HTTP 403: the adapter's username and password don't match the headers filter.
- HTTP 404: the httpurl is wrong, or the integration isn't enabled.
- HTTP 500: usually an error in the converter's code. The forwarding logs only say "ThingsBoard returned an internal error without a readable message"; the details (such as the failing line) are in the converter's Events. A common cause is the device sending content the converter doesn't expect.
For other cases, see Forwarding logs and troubleshooting.