When you want to get data from your device over an LPWAN network (such as LoRaWAN), you cannot use a plain JSON format over HTTP(S) or MQTT. Given their constrained nature, LPWAN networks expect that your device sends over a binary payload. The payload should be as compact as possible to minimise the Time-on-Air and reduce power consumption for battery-operated devices.
This guide will help you to encode and decode different types of data in as few bytes as possible, using JavaScript.
The goal of the conversion is to translate the state which device reports in binary payload into a format understandable to AllThingsTalk Platform.
For example, a device reports its battery and force states like this:
| Example payload: 1B 5D | ||
| Byte | Hex | |
|---|---|---|
| 0 | 1B | Set force to 27 |
| 1 | 5D | Set battery to 93 |
The device state in AllThingsTalk should look like this:
{
"force": {
"value": 27
},
"battery": {
"value": 93
}
}
Ultimately, you should write a JavaScript conversion which:
force battery.You can provide a conversion for uplink messages, and optionally another conversion for downlink messages. You set them in the Payload formats settings of the device: choose JavaScript conversion, paste the uplink code under Converting uplink and, if you need one, the downlink code under Converting downlink.

When you save a conversion, the platform checks it, as described in Checks when you save, and applies it to the device. From then on, every payload will be processed by the conversion. This works for devices on an LPWAN network and also for devices that send a binary payload over MQTT or with the HTTP API; see Data formats.
The Debug tab shows both successful and unsuccessful conversions.

The sections below show how to write an uplink conversion step by step: the function and its input, the result it must return, how to send several readings with their own times in one message, how to deal with payloads you did not expect, the limits that apply, and how to test a conversion before you save it. The Elsys example near the end of this guide puts it together for a real device, and the last section covers downlink conversions.
An uplink conversion is a JavaScript function named converter. The platform calls it once for every message your device sends, passes it the payload of that message, and stores the readings it returns in the assets of your device.
A converter takes one argument or two:
function converter(code) { ... }
function converter(code, timestamp) { ... }
Both forms work. Use the second one when you need the moment the message arrived; see Using the arrival time.
The declaration has to follow these rules:
function converter(...). A function assigned to a variable, as in var converter = function (code) {...}, is refused when you save.code. The second parameter may have any name, such as timestamp or receivedAt.timestamp = 0, and do not use a rest parameter such as ...args.converter only once.If a rule is broken, the save fails with Invalid converter function definition. Make sure that you use function converter(code) as a declaration. The message names only the form with one parameter, but it applies to both forms.
Write the converter in ES5 JavaScript, plus let and const. Arrow functions (=>), template literals (text between backticks) and for...of are refused when you save, although Node.js and browsers accept them; see JavaScript you can use.
Here is a complete converter with one parameter. The device sends 3 bytes: a temperature in tenths of a degree Celsius as a signed 16-bit number, then the relative humidity in percent:
function converter(code) {
// Payload: 3 bytes. Bytes 0-1: temperature, int16, 0.1 degC. Byte 2: humidity, %.
if (code.length !== 6) {
return "[]";
}
var t = parseInt(code.substr(0, 4), 16);
if (t > 0x7FFF) {
t = t - 0x10000;
}
var h = parseInt(code.substr(4, 2), 16);
return JSON.stringify({
temperature: { value: t / 10 },
humidity: { value: h }
});
}
For the payload 00e229 this returns the text {"temperature":{"value":22.6},"humidity":{"value":41}}, and for ff9c50 it returns {"temperature":{"value":-10},"humidity":{"value":80}}. A payload of any other length is not one this device sends, so the converter returns "[]", which stores nothing. Why it does not throw an error there is explained in Checks when you save.
code is the payload as text: hexadecimal digits in lowercase, two per byte, without spaces and without a 0x prefix. If your device sends the four bytes AB CD 0F 00, code is "abcd0f00". A message with an empty payload is not passed to your converter.
Most converters start by turning this text into a list of byte values. The platform has no Buffer or atob, so use a small loop at the start of your converter function:
var bytes = [];
for (var i = 0; i + 1 < code.length; i += 2) {
bytes.push(parseInt(code.substr(i, 2), 16));
}
// "abcd0f00" becomes [171, 205, 15, 0]
After the loop, bytes[0] is the first byte, as a number from 0 to 255, and bytes.length is the number of bytes in the payload.
Devices pack their numbers into one or more bytes. A 16-bit number takes two bytes: in big endian order the most significant byte comes first, in little endian order it comes last. A signed number uses its highest bit to mark negative values, so the same two bytes can mean two different numbers. Take this example payload:
| Example payload: FF 9C 94 27 BA 57 | ||
| Byte | Hex | |
|---|---|---|
| 0-1 | FF 9C | temperature in 0.1 °C, signed 16-bit, big endian: -100, so -10.0 °C |
| 2-3 | 94 27 | pressure in 0.1 hPa, unsigned 16-bit, little endian: 0x2794 = 10132, so 1013.2 hPa |
| 4 | BA | signal in dBm, signed 8-bit: 186 - 256 = -70 |
| 5 | 57 | battery in %, unsigned 8-bit: 87 |
The bytes FF 9C read as an unsigned number give 65436. Because the highest bit is set, the signed value is 65436 - 65536 = -100. These helper functions read the common cases. They are declared inside converter; Code before the function explains where helpers may go:
function converter(code) {
function toBytes(hex) {
var out = [];
for (var i = 0; i + 1 < hex.length; i += 2) {
out.push(parseInt(hex.substr(i, 2), 16));
}
return out;
}
function uint8(b, i) { return b[i]; }
function int8(b, i) { return b[i] > 127 ? b[i] - 256 : b[i]; }
function uint16BE(b, i) { return (b[i] << 8) | b[i + 1]; }
function int16BE(b, i) { var v = uint16BE(b, i); return v > 32767 ? v - 65536 : v; }
function uint16LE(b, i) { return b[i] | (b[i + 1] << 8); }
function int16LE(b, i) { var v = uint16LE(b, i); return v > 32767 ? v - 65536 : v; }
var b = toBytes(code);
if (b.length !== 6) {
return "[]";
}
return JSON.stringify({
temperature: { value: int16BE(b, 0) / 10 },
pressure: { value: uint16LE(b, 2) / 10 },
signal: { value: int8(b, 4) },
battery: { value: uint8(b, 5) }
});
}
For the payload ff9c9427ba57 this converter returns {"temperature":{"value":-10},"pressure":{"value":1013.2},"signal":{"value":-70},"battery":{"value":87}}.
For 32-bit numbers, keep in mind that the bitwise operators of JavaScript work on signed 32-bit numbers, so 0xFF << 24 is negative. Add >>> 0 to get an unsigned result. Floating-point numbers are read with a DataView. Like the helpers above, declare these inside converter:
function uint32BE(b, i) { return ((b[i] << 24) | (b[i + 1] << 16) | (b[i + 2] << 8) | b[i + 3]) >>> 0; }
function int32BE(b, i) { return (b[i] << 24) | (b[i + 1] << 16) | (b[i + 2] << 8) | b[i + 3]; }
function float32BE(b, i) {
var view = new DataView(new ArrayBuffer(4));
for (var k = 0; k < 4; k++) {
view.setUint8(k, b[i + k]);
}
return view.getFloat32(0, false); // getFloat32(0, true) for little endian
}
The bytes FF 00 00 01 give 4278190081 as an unsigned and -16777215 as a signed 32-bit number, and the bytes 41 B4 00 00 give the float 22.5.
The converter must return text: a JSON object with one property per asset. The name of the property is the name of the asset, and its value is an object with the reading’s value and, optionally, its time at:
{
"temperature": {"value": 22.6, "at": "2026-11-19T09:45:00.000Z"},
"humidity": {"value": 41}
}
Build the result as a JavaScript object and turn it into text with JSON.stringify, as the examples above do. A reading without at gets the time the message arrived (for LoRaWAN, the time the network server gives; see Using the arrival time); the next sections show when and how to give a time of your own. To return several readings of the same asset in one message, return an array instead; see Several readings in one message.
These are the most common mistakes, and what they cause:
JSON.stringify: the save is refused with Invalid converter function definition. Make sure that your function returns string type.JSON.stringify({temperature: 22.6}): the save is accepted, but every message fails with Wrong model returned! in the Debug tab."22.6 C": the save is accepted, but every message fails. The Debug tab then reports the conversion as unavailable and adds Input should be a dict or list.; the cause is the result of your converter, not an outage.return on one of the paths through your function: every message that takes that path fails. If the sample payload used when you save takes it, the save is refused with the “returns string type” message above.A converter that saves without an error can still fail on every message. The test in Testing your conversion catches these mistakes before you save.
The value of a reading must fit the profile of its asset:
22.6. Text that holds a number, such as "22.6", is accepted too. Other text, true and null are refused.23.7 is stored as 23.true or false. A number is accepted too: greater than 0 counts as true, anything else as false. The texts "true" and "false" are accepted as well.latitude and longitude, and optionally altitude.In the result, a location reading looks like this:
{"location": {"value": {"latitude": 51.2194, "longitude": 4.4025}}}
If the profile sets a minimum and a maximum, or a list of allowed values, a value outside them is refused as well. A value that does not fit drops only that one reading; the other readings of the message are stored. The Debug tab then shows a note such as Received value 'warm' for asset 'temperature' is not a number. or Received value '150' for asset 'humidity' does not fit within specified value range.
NaN and Infinity are not valid JSON: JSON.stringify turns them into null, which a number asset refuses. They usually come from reading past the end of the payload or from a division by zero.
The property names in your result must be exactly the names of assets that exist on the device; the platform does not create assets for you. A reading for a name the device does not have is dropped, and no note about it appears in the Debug tab, although the line of the conversion there still lists it. If none of the names match an asset, nothing is stored.
For example, a device with the assets temperature and humidity, whose converter returns
{"temp": {"value": 22.6}, "humidity": {"value": 41}}
stores only the humidity. Create the assets first, and use exactly the same names in the converter.
Make converter the first function in your code. Before it, do not write another named function, and do not write the word function followed by another word, not even in a comment or a text string, such as // This function decodes the payload; the save then fails with the declaration message. Comments, "use strict"; and declarations such as var SCALE = 10; are fine. Helper functions go inside converter, or after it:
// Uplink conversion for the fridge logger, version 3.
"use strict";
var SCALE = 10;
function converter(code) {
if (code.length !== 4) {
return "[]";
}
return JSON.stringify({ temperature: { value: signed16(parseInt(code, 16)) / SCALE } });
}
function signed16(v) {
return v > 32767 ? v - 65536 : v;
}
When you save a conversion, the platform checks the code and runs the converter once on a sample payload, 0100e202290400270506060308070d62. Nothing from this run is stored. If something is wrong, the save fails with one of these messages:
| Message | What to fix |
|---|---|
JavaScript code is not valid. |
The code uses JavaScript the platform does not accept (see JavaScript you can use), uses eval, or throws an error outside the converter function. |
Invalid converter function definition. Make sure that you use function converter(code) as a declaration. |
The declaration breaks a rule in The converter function or Code before the function. |
Invalid converter function definition. Make sure that your function returns string type. |
On the sample payload, the converter returned an object, a number or nothing instead of text. |
The converter threw an error on the sample payload: followed by the error |
The converter threw an error on the sample payload. Return "[]" for payloads you do not recognise instead; see below. |
Conversion time too long. or Conversion used too much memory. |
The converter went over a limit. |
The sample payload is most likely not in the format of your device, so your converter must not throw an error on it. Return "[]" for payloads you do not recognise, as the examples in this guide do. This converter throws for every payload that is not 3 bytes long:
function converter(code) {
if (code.length !== 6) {
throw new Error("Expected 3 bytes, got " + code.length / 2);
}
return JSON.stringify({ temperature: { value: parseInt(code.substr(0, 4), 16) / 10 } });
}
It cannot be saved, because the save fails with:
The converter threw an error on the sample payload: Uncaught Error: Expected 3 bytes, got 16 at undefined:3:8
If your format has no byte that says what kind of frame it is, read Ignore or throw before you add a throw.
Declare a second parameter to receive the moment the message arrived:
function converter(code, timestamp) { ... }
timestamp is a whole number: the number of milliseconds since 1 January 1970, 00:00 UTC. It is not in seconds. new Date(timestamp) turns it into a date, and new Date(timestamp).toISOString() into text such as "2026-11-19T10:00:00.000Z".
Which moment it stands for depends on how the message reaches AllThingsTalk:
received_at from The Things Network or ts from LORIOT. If the network server gives no time, the moment AllThingsTalk received the message.A reading that you return without at is stored at this same moment. So you only need timestamp when a reading’s time differs from it, usually because the device tells you how old a measurement is. This converter receives a temperature and the age of that measurement in minutes:
function converter(code, timestamp) {
// 3 bytes: temperature (signed 16-bit, 0.1 degrees Celsius), then the age of the measurement in minutes.
if (code.length !== 6) {
return "[]";
}
var t = parseInt(code.substr(0, 4), 16);
if (t > 32767) {
t = t - 65536;
}
var ageMinutes = parseInt(code.substr(4, 2), 16);
return JSON.stringify({
temperature: { value: t / 10, at: new Date(timestamp - ageMinutes * 60000).toISOString() }
});
}
For the payload 00e20f and the timestamp 1795082400000 (19 November 2026, 10:00:00 UTC), the temperature 22.6 was measured 15 minutes earlier, and the converter returns {"temperature":{"value":22.6,"at":"2026-11-19T09:45:00.000Z"}}.
A converter with only the code parameter never receives the timestamp. You can add the second parameter to an existing converter at any time.
If the device sends a clock time instead of an age, use that time: a device time in seconds since 1970 becomes new Date(seconds * 1000).toISOString(). You can also give the seconds directly as at; see Formats of the time.
Some devices collect several measurements and send them together: a logger that reports every hour what it measured every 10 minutes, or a tracker that keeps its positions while it has no coverage. For such devices, return an array with one object per moment, holding the readings taken at that moment. Every object has the same form as the single result above, and every reading can carry its own at:
[
{"temperature": {"value": 4.2, "at": "2026-11-19T09:40:00.000Z"}, "humidity": {"value": 81, "at": "2026-11-19T09:40:00.000Z"}},
{"temperature": {"value": 3.9, "at": "2026-11-19T09:50:00.000Z"}, "humidity": {"value": 80, "at": "2026-11-19T09:50:00.000Z"}}
]
Every reading that the platform accepts is stored in the history of its asset. A single object can also give each asset its own at, but it can name each asset only once. You need an array when the same asset has more than one reading in a message.
An array may hold at most 256 entries and 2000 readings in total. If it holds more, the whole message is refused and nothing is stored; the Debug tab shows Too many entries: 257 entries (at most 256). or Too many readings: 2001 readings (at most 2000). A single object has no such limit.
A device behind a gateway that sends its payload with the HTTP API route PUT /gateway/{id}/device/{deviceName}/state cannot use an array: there, the converter must return a single object.
Converters written for an earlier version of the platform may return another list form, [{"at": "2026-11-19T09:40:00.000Z", "states": [{"assetName": "temperature", "value": 4.2}]}]. This form still works: every reading in states gets the at of its entry. Use the form above for new converters.
In short, the rules for the times of readings are:
at, preferably as new Date(milliseconds).toISOString().at is stored at the arrival time. Several readings of one asset without at are stored 1 millisecond apart.The sections below explain each rule.
The device in this example is a fridge logger. It measures temperature and humidity every 10 minutes, and sends its last three measurements in one message, each with its age:
| Example payload: 10 03 04 B0 00 2A 51 02 58 00 27 50 00 00 FF FB 4F | ||
| Byte | Hex | |
|---|---|---|
| 0 | 10 | Frame type: history |
| 1 | 03 | Number of records: 3 |
| 2-3 | 04 B0 | Record 1: age 1200 seconds (20 minutes) |
| 4-5 | 00 2A | Record 1: temperature 42, so 4.2 °C |
| 6 | 51 | Record 1: humidity 81 % |
| 7-8 | 02 58 | Record 2: age 600 seconds (10 minutes) |
| 9-10 | 00 27 | Record 2: temperature 39, so 3.9 °C |
| 11 | 50 | Record 2: humidity 80 % |
| 12-13 | 00 00 | Record 3: age 0 seconds |
| 14-15 | FF FB | Record 3: temperature -5, so -0.5 °C |
| 16 | 4F | Record 3: humidity 79 % |
The converter turns the payload into bytes, checks that it is a history frame of the right length, and computes the time of each record as the arrival time minus the record’s age:
function converter(code, timestamp) {
// Fridge logger, history frame (big endian):
// byte 0 frame type, 0x10
// byte 1 number of records, N
// then N records of 5 bytes each:
// bytes 0-1 age of the record in seconds when the message was sent (unsigned 16-bit)
// bytes 2-3 temperature in 0.1 degrees Celsius (signed 16-bit)
// byte 4 relative humidity in % (unsigned 8-bit)
var bytes = [];
for (var i = 0; i + 1 < code.length; i += 2) {
bytes.push(parseInt(code.substr(i, 2), 16));
}
if (bytes.length < 2 || bytes[0] !== 0x10) {
return "[]";
}
var n = bytes[1];
if (bytes.length !== 2 + 5 * n) {
throw new Error("History frame with " + n + " records needs " + (2 + 5 * n) + " bytes, got " + bytes.length);
}
function u16(p) {
return (bytes[p] << 8) | bytes[p + 1];
}
function s16(p) {
var v = u16(p);
return v > 32767 ? v - 65536 : v;
}
var readings = [];
for (var r = 0; r < n; r++) {
var o = 2 + 5 * r;
var at = new Date(timestamp - u16(o) * 1000).toISOString();
readings.push({
temperature: { value: s16(o + 2) / 10, at: at },
humidity: { value: bytes[o + 4], at: at }
});
}
return JSON.stringify(readings);
}
A payload that does not start with 10 is not a history frame, so the converter returns "[]"; this includes the sample payload used when you save. A history frame whose length does not match its number of records is broken, so the converter throws an error that says why.
For a message that arrives at 10:00:00 UTC on 19 November 2026, the converter returns the following text, shown here over several lines and with spaces for reading:
[
{"temperature": {"value": 4.2, "at": "2026-11-19T09:40:00.000Z"}, "humidity": {"value": 81, "at": "2026-11-19T09:40:00.000Z"}},
{"temperature": {"value": 3.9, "at": "2026-11-19T09:50:00.000Z"}, "humidity": {"value": 80, "at": "2026-11-19T09:50:00.000Z"}},
{"temperature": {"value": -0.5, "at": "2026-11-19T10:00:00.000Z"}, "humidity": {"value": 79, "at": "2026-11-19T10:00:00.000Z"}}
]
All six readings are stored in the history of the two assets:
| Time (UTC) | temperature | humidity |
|---|---|---|
| 09:40:00 | 4.2 | 81 |
| 09:50:00 | 3.9 | 80 |
| 10:00:00 | -0.5 | 79 |
The current state of temperature becomes -0.5 and that of humidity becomes 79, both at 10:00:00, because these are the newest readings.
Many devices measure at a fixed interval and do not send a time or an age for each measurement. The device in this example measures the temperature every 15 minutes and sends its last measurements together, oldest first. The last one is measured when the message is sent:
| Example payload: 04 00 E2 00 DD 00 D7 FF F6 | ||
| Byte | Hex | |
|---|---|---|
| 0 | 04 | Number of measurements: 4 |
| 1-2 | 00 E2 | temperature 226, so 22.6 °C, measured 45 minutes before the message |
| 3-4 | 00 DD | temperature 221, so 22.1 °C, 30 minutes before |
| 5-6 | 00 D7 | temperature 215, so 21.5 °C, 15 minutes before |
| 7-8 | FF F6 | temperature -10, so -1.0 °C, measured when the message was sent |
The newest measurement, the last one, gets the arrival time, and every measurement before it 15 minutes less:
function converter(code, timestamp) {
// Payload (big endian):
// byte 0 number of measurements, N
// then N temperatures of 2 bytes each, in 0.1 degrees Celsius (signed 16-bit), oldest first
// The device measures every 15 minutes; it takes the last measurement when it sends the message.
var INTERVAL = 15 * 60 * 1000; // 15 minutes in milliseconds
var bytes = [];
for (var i = 0; i + 1 < code.length; i += 2) {
bytes.push(parseInt(code.substr(i, 2), 16));
}
var n = bytes[0];
if (bytes.length !== 1 + 2 * n) {
return "[]"; // this format has no frame type, so ignore what does not fit instead of throwing
}
var readings = [];
for (var r = 0; r < n; r++) {
var v = (bytes[1 + 2 * r] << 8) | bytes[2 + 2 * r];
if (v > 32767) {
v = v - 65536;
}
var at = new Date(timestamp - (n - 1 - r) * INTERVAL).toISOString();
readings.push({ temperature: { value: v / 10, at: at } });
}
return JSON.stringify(readings);
}
For the payload 0400e200dd00d7fff6, arriving at 10:00:00 UTC on 19 November 2026, it returns:
[{"temperature":{"value":22.6,"at":"2026-11-19T09:15:00.000Z"}},{"temperature":{"value":22.1,"at":"2026-11-19T09:30:00.000Z"}},{"temperature":{"value":21.5,"at":"2026-11-19T09:45:00.000Z"}},{"temperature":{"value":-1,"at":"2026-11-19T10:00:00.000Z"}}]
All four readings are stored in the history of temperature, and -1 at 10:00:00 becomes its current state.
A door sensor sends its battery level and the door events since its last message: byte 0 is the frame type 20, byte 1 the battery level in percent, byte 2 the number of events, and then 3 bytes per event, the age of the event in seconds followed by 1 for opened or 0 for closed:
function converter(code, timestamp) {
// Door sensor report:
// byte 0 frame type, 0x20
// byte 1 battery level in %
// byte 2 number of door events, M
// then M events of 3 bytes each:
// bytes 0-1 age of the event in seconds (unsigned 16-bit, big endian)
// byte 2 1 = opened, 0 = closed
var b = [];
for (var i = 0; i + 1 < code.length; i += 2) {
b.push(parseInt(code.substr(i, 2), 16));
}
if (b.length < 3 || b[0] !== 0x20) {
return "[]";
}
if (b.length !== 3 + 3 * b[2]) {
throw new Error("Door report with " + b[2] + " events needs " + (3 + 3 * b[2]) + " bytes, got " + b.length);
}
var result = [{ battery: { value: b[1] } }];
for (var e = 0; e < b[2]; e++) {
var o = 3 + 3 * e;
var age = (b[o] << 8) | b[o + 1];
result.push({ door: { value: b[o + 2] === 1, at: new Date(timestamp - age * 1000).toISOString() } });
}
return JSON.stringify(result);
}
For the payload 205702012c01003c00, arriving at 10:00:00 UTC, it returns:
[{"battery":{"value":87}},{"door":{"value":true,"at":"2026-11-19T09:55:00.000Z"}},{"door":{"value":false,"at":"2026-11-19T09:59:00.000Z"}}]
The battery reading has no at, so it is stored at the arrival time, 10:00:00. The door was opened at 09:55 and closed at 09:59. Both events are stored in the history of door, and its current state is false, the newer of the two.
The at of a reading can have any of these forms. Each example in the table means 09:40:00 UTC on 19 November 2026:
at |
How it is read |
|---|---|
"2026-11-19T09:40:00.000Z" |
ISO 8601 in UTC. This is what new Date(ms).toISOString() returns. |
"2026-11-19T10:40:00+01:00" |
ISO 8601 with an offset from UTC. The offset needs a colon. |
"2026-11-19T09:40:00" |
ISO 8601 without a time zone, read as UTC. |
1795081200 |
A number below 100000000000: seconds since 1970. |
1795081200000 |
A number from 100000000000 up: milliseconds since 1970. |
"1795081200" or "1795081200000" |
Text of 10 digits is read as seconds, of 13 digits as milliseconds. |
In ISO 8601 text, a space may replace the T, and fractions of a second may have any number of digits; the platform keeps milliseconds.
Other notations are not read as times, for example an offset without a colon (+0100), a time without seconds or a date alone. Neither is any time before 1 January 2010. Checks on reading times explains what happens to such a reading. new Date(ms).toISOString() always gives a form that is read correctly.
null, an empty text and 0 count as no time: the reading is treated as if it had no at.
A reading without at gets the arrival time. If the same asset appears several times without at in one message, its readings are stored 1 millisecond apart, in the order of the array, so none of them is lost. This result
[{"temperature": {"value": 4.1}}, {"temperature": {"value": 4.2}}, {"temperature": {"value": 4.3}}]
arriving at 10:00:00 UTC is stored as 4.1 at 10:00:00.000, 4.2 at 10:00:00.001 and 4.3 at 10:00:00.002. The last one becomes the current state, so put readings without a time in the order in which they were measured, oldest first.
An asset holds one reading per moment. If a message contains two readings of the same asset with the same at, the first is stored and the second is dropped, with the note Asset 'temperature' got two readings at 2026-11-19T09:40:00Z; the first was kept. The same holds across messages: sending a reading again with the same at and a new value does not change the stored value.
Keep this in mind when some records have no usable time of their own. If you give several such records the same at, for example the arrival time, only the first of them is kept. Leave out at instead: readings without a time are kept 1 millisecond apart.
The current state of an asset is its reading with the newest time, not the last one in the array. This applies to every result, a single object as well as an array. A reading replaces the current state only if its time is later than the time of the current state. A reading that arrives late, with an older time, is stored in the history and leaves the current state alone. A reading with the same time as the current state does not replace it either.
For example, temperature has the current state 5.0 at 10:00. A message that arrives later with the reading 4.0 at 09:30 adds 4.0 to the history, and the current state stays 5.0 at 10:00.
When a converter returns an array, rules receive only the newest reading of each asset, and only if that reading is at most 15 minutes older than the arrival of the message. A message that carries only older readings fills the history without triggering rules. Live updates, such as messages on the asset feed topics, are sent for every stored reading, oldest first.
When your converter gives a reading an at, the platform compares it with the arrival time of the message, and for a time that looks wrong it writes a warning, shown as a note in the Debug tab. In these examples the message arrived at 10:00 UTC on 19 November 2026:
Reading of asset 'temperature' at 2026-11-19T11:00:00Z is in the future. For a time without a time zone, the note ends with (no timezone, read as UTC).Reading of asset 'temperature' at 2026-11-20T01:00:00Z is more than 14 hours in the future; it was skipped. This applies to a single object as well as to an array.Reading of asset 'temperature' at 2026-11-10T10:00:00Z is older than 7 days.Received at '2026-11-19T10:40:00+0100' for asset 'temperature' is not a time; the reading was skipped. In a single object the reading is stored at the arrival time instead, and the note ends with the reading was stored at the arrival time.Received at '86400' for asset 'temperature' is before 2010; the reading was skipped.These notes appear in the Debug tab as a separate entry for the message, in addition to the line of the conversion. The same entry also lists readings refused because their value does not fit the asset’s profile, and second readings with the same time. The same note is shown at most once a minute per device.
A time in the future usually means that the device sends its local time as if it were UTC. A time before 2010 usually means that the clock of the device was not set, for example after a restart. Fix the clock of the device; until then, leaving out at stores the readings at the arrival time. Keep in mind that a reading stored with a future time stays the current state until a reading with a later time arrives.
The same checks apply to the time a network server gives, which a reading without at gets.
Not every message is one your converter can decode. A device may send status frames, a firmware update may change the format, a message may arrive cut short, and when you save, your converter is run on a sample payload that is not yours at all. Decide for every case what the converter should do.
A conversion ends in one of three ways:
| Your converter | What is stored | What the Debug tab shows |
|---|---|---|
| returns readings | the readings | Parsed [...] from payload ... using JS |
returns "[]" |
nothing | Parsed [] from payload ... using JS |
throws an Error |
nothing | Nothing parsed from payload ... Errors: and your message |
Return "[]" for payloads you want to ignore: frames this converter does not handle, heartbeats, frames without records. Throw an error when a payload is in your format but cannot be right, for example when its length does not match its contents, so that the problem shows up in the Debug tab.
Throw only when you can tell that a payload is in your format. If your format has a byte that says what kind of frame it is, check that byte first, as the converter in A complete example does with 10. If it has none, any payload can look like yours: read as a number of records, the first byte of the sample payload used when you save, 01, announces one record, but the payload is 16 bytes long. A converter that throws on that cannot be saved. For such a format, return "[]" when the length does not fit, as the converter in Readings at a fixed interval does.
For the converter in A complete example, a history frame cut off after 10 bytes gives:
Nothing parsed from payload 10 03 04 B0 00 2A 51 02 58 00. Errors:
Uncaught Error: History frame with 3 records needs 17 bytes, got 10 at undefined:18:8
The line after Errors: holds your message and the place where the error was thrown: line 18, column 8 of your code (columns count from 0). More lines follow; you can ignore them.
Throw an Error object, as in throw new Error("..."). If you throw plain text, as in throw "Unknown frame", the Debug tab shows Uncaught Unknown frame at undefined:0:0, without the place in your code.
console.log prints nothing you can see. While you look for a problem, put the values you want to see in the message of an error, or test the converter on your computer as described in Testing your conversion.
If your device sends its payload with the HTTP API (PUT /device/{id}/state), a conversion that fails, or returns more readings than allowed, makes the request fail with HTTP status 400 and the error text.
JavaScript does not stop you from reading past the end of a payload: in a payload of 17 bytes, bytes[20] is undefined. Bitwise operators treat undefined as 0, so (bytes[i] << 8) | bytes[i + 1] quietly gives a wrong number. Arithmetic turns it into NaN, which JSON.stringify writes as null. A value that is undefined disappears from the JSON altogether: JSON.stringify({value: undefined}) gives {}. Check the length of the payload, as the examples in this guide do.
This version of the fridge logger converter handles every case on purpose. It also knows a heartbeat frame (type 00), and it leaves out a temperature reading when the sensor reports 7FFF, the value it uses for a failed measurement. And it throws an error for a payload that starts with 10 but is too short to hold the number of records:
function converter(code, timestamp) {
var bytes = [];
for (var i = 0; i + 1 < code.length; i += 2) {
bytes.push(parseInt(code.substr(i, 2), 16));
}
// 1. Payloads you do not want to store: return an empty list, not an error.
if (bytes[0] === 0x00) {
return "[]"; // heartbeat frame: nothing to store
}
if (bytes[0] !== 0x10) {
return "[]"; // a frame this converter does not know, such as the sample used on save
}
// 2. Your own frame, but broken: throw an Error that says what is wrong.
if (bytes.length < 2) {
throw new Error("History frame too short: " + code);
}
var n = bytes[1];
if (bytes.length !== 2 + 5 * n) {
throw new Error("History frame with " + n + " records needs " + (2 + 5 * n) + " bytes, got " + bytes.length);
}
function u16(p) {
return (bytes[p] << 8) | bytes[p + 1];
}
function s16(p) {
var v = u16(p);
return v > 32767 ? v - 65536 : v;
}
var readings = [];
for (var r = 0; r < n; r++) {
var o = 2 + 5 * r;
var at = new Date(timestamp - u16(o) * 1000).toISOString();
var record = {};
// 3. 0x7FFF means the temperature sensor failed: leave that reading out, keep the others.
if (u16(o + 2) !== 0x7FFF) {
record.temperature = { value: s16(o + 2) / 10, at: at };
}
record.humidity = { value: bytes[o + 4], at: at };
readings.push(record);
}
// 4. Always return a JSON string, also when it holds no readings.
return JSON.stringify(readings);
}
With the arrival time 10:00:00 UTC on 19 November 2026:
| Payload | Result |
|---|---|
00 |
A heartbeat: [], nothing is stored. |
0100e202290400270506060308070d62 |
A frame type this converter does not know, such as the sample payload used when you save: []. |
100104b07fff51 |
[{"humidity":{"value":81,"at":"2026-11-19T09:40:00.000Z"}}]: the failed temperature reading is left out. |
100304b0002a51025800 |
Throws History frame with 3 records needs 17 bytes, got 10. |
10 |
Throws History frame too short: 10. |
Every conversion runs within these limits:
" and \ counts as two characters. A result with 2000 ordinary readings stays far below it.A conversion that goes over the time or memory limit is stopped, and fails with Conversion time too long. or Conversion used too much memory. A longer result fails with Conversion used too much memory. as well. Error messages are cut off after 10,000 characters.
If a message rate limit applies to your account, every reading counts towards it, for all devices of the account together: a message with 50 readings counts as 50 messages. When the limit is reached, the whole message is dropped, and the Debug tab shows Rate limit of ... msg/min exceeded, current message rate is ... msg/min.
Every message is converted in a fresh environment. Variables keep no value from one message to the next, so counters, caches and remembered last values do not work. This converter returns 1 for every message:
var messages = 0;
function converter(code) {
messages = messages + 1;
return JSON.stringify({ counter: { value: messages } });
}
If the converter needs information from earlier messages, let the device include it in every message.
The platform accepts ES5 JavaScript, plus let and const. Some other newer forms work too, but stay with ES5 style so that your converter can always be saved.
These are refused when you save, with JavaScript code is not valid.: arrow functions (=>), template literals (text between backticks), class, for...of, destructuring, spread and rest (...), **, ?., ??, BigInt numbers such as 10n, a trailing comma in a function call, catch without (e), async functions and generators.
You can use Math, JSON, Date, Number, parseInt, typed arrays such as Uint8Array, DataView and Map, and methods such as Object.keys, Object.entries, Object.fromEntries, Array.prototype.includes, Array.prototype.flat, String.prototype.padStart and String.prototype.replaceAll. Methods that are not listed here may be missing: calling one makes the conversion fail with a TypeError. Check the Debug tab after you save a converter that uses such a method.
These do not exist on the platform: require, Buffer, atob, btoa, TextDecoder, fetch, setTimeout, process, Intl, structuredClone and WebAssembly. console exists, but what it prints is not shown anywhere.
Work in UTC: use Date.UTC, the getUTC... methods and toISOString(). toLocaleString ignores locales and time zones, so do not rely on it, or on the local time zone of the platform.
Put a space after & and &&, as in flags & reg and ready && notFull. Some text directly after an &, such as ® or ¬, is read as a special character, so flags® makes the save fail.
The quickest way to try a converter is to run it with Node.js, or in the developer console of your browser. Create a file test-converter.js, paste your converter at the top, exactly as you save it in AllThingsTalk, and add this code below it:
// The payloads to try, as hex text, each with the arrival time to pass in milliseconds.
var tests = [
["100304b0002a5102580027500000fffb4f", Date.UTC(2026, 10, 19, 10, 0, 0)], // months count from 0: 10 is November
["100304b0002a51025800", Date.now()],
["0100e202290400270506060308070d62", Date.now()]
];
// Checks a result the way the platform reads it.
function check(text) {
if (typeof text !== "string") {
return "ERROR: the result is of type " + typeof text + ", not a string; return JSON.stringify(...)";
}
var result;
try {
result = JSON.parse(text);
} catch (e) {
return "ERROR: not JSON text: " + text;
}
if (result === null || typeof result !== "object") {
return "ERROR: must be a JSON object or array: " + text;
}
var entries = Array.isArray(result) ? result : [result];
var count = 0;
for (var e = 0; e < entries.length; e++) {
if (entries[e] === null || typeof entries[e] !== "object" || Array.isArray(entries[e])) {
return "ERROR: entry " + e + " is not an object of readings";
}
if (Array.isArray(result) && Array.isArray(entries[e].states)) {
count += entries[e].states.length; // the older list form, {"at": ..., "states": [...]}
continue;
}
for (var name in entries[e]) {
var reading = entries[e][name];
if (reading === null || typeof reading !== "object" || !("value" in reading)) {
return "ERROR: the reading of " + name + ' must be an object with a value, such as {"value": 1}';
}
count++;
}
}
if (Array.isArray(result) && (result.length > 256 || count > 2000)) {
return "ERROR: " + result.length + " entries and " + count + " readings; the limit is 256 and 2000";
}
return "OK, " + count + " readings: " + JSON.stringify(result);
}
for (var t = 0; t < tests.length; t++) {
var outcome;
try {
outcome = check(converter(tests[t][0], tests[t][1]));
} catch (err) {
outcome = "THREW: " + (err instanceof Error ? err.message : err);
}
console.log(tests[t][0]);
console.log(" " + outcome);
}
Run it with node test-converter.js. With the converter from A complete example, it prints:
100304b0002a5102580027500000fffb4f
OK, 6 readings: [{"temperature":{"value":4.2,"at":"2026-11-19T09:40:00.000Z"},"humidity":{"value":81,"at":"2026-11-19T09:40:00.000Z"}},{"temperature":{"value":3.9,"at":"2026-11-19T09:50:00.000Z"},"humidity":{"value":80,"at":"2026-11-19T09:50:00.000Z"}},{"temperature":{"value":-0.5,"at":"2026-11-19T10:00:00.000Z"},"humidity":{"value":79,"at":"2026-11-19T10:00:00.000Z"}}]
100304b0002a51025800
THREW: History frame with 3 records needs 17 bytes, got 10
0100e202290400270506060308070d62
OK, 0 readings: []
Replace the first payloads with real ones from your device, which the Debug tab shows; write them in lowercase without spaces, as the platform passes them to your converter. Keep the last one: it is the sample payload the platform runs your converter on when you save, so it must not throw. To test in a browser instead, paste the converter and the test code into the console of its developer tools and press Enter.
Node.js and browsers accept more JavaScript than the platform, and offer objects that the platform does not have, such as Buffer. A converter that passes this test can still be refused when you save; check it against JavaScript you can use. Also, in this test variables keep their values from one payload to the next, which they do not on the platform; see Each message starts from scratch.
Once the conversion is saved, the Debug tab of the device shows a line for every message: Parsed ... using JS when the conversion succeeded, and a line with the errors when it failed, usually starting with Nothing parsed from payload. For a long result, the line shows the first 20 readings, followed by (first 20 of 25 readings) or the matching numbers. Notes about times and values appear in a separate entry, as described in Checks on reading times.
The lines shown in this guide are those of a device that sends over MQTT or with the HTTP API: the readings as your converter returned them, and the payload in capitals with spaces. For a device that sends through LoRaWAN or another network integration, the payload is shown as the text your converter received, such as 100304b0002a5102580027500000fffb4f, and a reading you returned without at is shown with the time the network server gave, if it gave one.
Elsys ERS devices monitor the indoor environment. An ERS device reports the state of all its assets in one binary payload, and that payload changes with the situation: sometimes it holds only CO2 and light readings, at other times the readings of all assets. This makes it an ideal candidate for a JavaScript conversion.
Uplink conversion
Here’s the example of the Uplink conversion:
function converter(code) {
const TYPE_TEMP = 0x01; //temp 2 bytes -3276.8°C -->3276.7°C
const TYPE_RH = 0x02; //Humidity 1 byte 0-100%
const TYPE_ACC = 0x03; //acceleration 3 bytes X,Y,Z -128 --> 127 +/-63=1G
const TYPE_LIGHT = 0x04; //Light 2 bytes 0-->65535 Lux
const TYPE_MOTION = 0x05; //No of motion 1 byte 0-255
const TYPE_CO2 = 0x06; //Co2 2 bytes 0-65535 ppm
const TYPE_VDD = 0x07; //VDD 2byte 0-65535mV
const TYPE_ANALOG1 = 0x08; //VDD 2byte 0-65535mV
const TYPE_GPS = 0x09; //3bytes lat 3bytes long binary
const TYPE_PULSE1 = 0x0A; //2bytes relative pulse count
const TYPE_PULSE1_ABS = 0x0B; //4bytes no 0->0xFFFFFFFF
const TYPE_EXT_TEMP1 = 0x0C; //2bytes -3276.5C-->3276.5C
const TYPE_EXT_DIGITAL = 0x0D; //1bytes value 1 or 0
const TYPE_EXT_DISTANCE = 0x0E; //2bytes distance in mm
const TYPE_ACC_MOTION = 0x0F; //1byte number of vibration/motion
const TYPE_IR_TEMP = 0x10; //2bytes internal temp 2bytes external temp -3276.5C-->3276.5C
const TYPE_OCCUPANCY = 0x11; //1byte data
const TYPE_WATERLEAK = 0x12; //1byte data 0-255
const TYPE_GRIDEYE = 0x13; //65byte temperature data 1byte ref+64byte external temp
const TYPE_PRESSURE = 0x14; //4byte pressure data (hPa)
const TYPE_SOUND = 0x15; //2byte sound data (peak/avg)
const TYPE_PULSE2 = 0x16; //2bytes 0-->0xFFFF
const TYPE_PULSE2_ABS = 0x17; //4bytes no 0->0xFFFFFFFF
const TYPE_ANALOG2 = 0x18; //2bytes voltage in mV
const TYPE_EXT_TEMP2 = 0x19; //2bytes -3276.5C-->3276.5C
const TYPE_EXT_DIGITAL2 = 0x1A; // 1bytes value 1 or 0
const TYPE_EXT_ANALOG_UV = 0x1B; // 4 bytes signed int (uV)
const TYPE_TVOC = 0x1C; // 2 bytes (ppb)
const TYPE_DEBUG = 0x3D; // 4bytes debug
function bin16dec(bin) {
var num = bin & 0xFFFF;
if (0x8000 & num)
num = -(0x010000 - num);
return num;
}
function bin8dec(bin) {
var num = bin & 0xFF;
if (0x80 & num)
num = -(0x0100 - num);
return num;
}
function hexToBytes(hex) {
for (var bytes = [], c = 0; c < hex.length; c += 2)
bytes.push(parseInt(hex.substr(c, 2), 16));
return bytes;
}
function DecodeElsysPayload(data) {
var obj = new Object();
var extTemp2 = [];
for (var i = 0; i < data.length; i++) {
//console.log(data[i]);
switch (data[i]) {
case TYPE_TEMP: //Temperature
var temp = (data[i + 1] << 8) | (data[i + 2]);
temp = bin16dec(temp);
obj.temperature = {value: temp / 10};
i += 2;
break
case TYPE_RH: //Humidity
var rh = (data[i + 1]);
obj.humidity = {value: rh};
i += 1;
break
case TYPE_ACC: //Acceleration
obj.acceleration = {value: {
x: bin8dec(data[i + 1]),
y: bin8dec(data[i + 2]),
z: bin8dec(data[i + 3])
}}
i += 3;
break
case TYPE_LIGHT: //Light
obj.light = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_MOTION: //Motion sensor(PIR)
obj.motion = {value: (data[i + 1])};
i += 1;
break
case TYPE_CO2: //CO2
obj.co2 = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_VDD: //Battery level
obj.vdd = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_ANALOG1: //Analog input 1
obj.analog1 = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_GPS: //gps
i++;
obj.location = {value: {
latitude: (data[i + 0] | data[i + 1] << 8 | data[i + 2] << 16 | (data[i + 2] & 0x80 ? 0xFF << 24 : 0)) / 10000,
longitude: (data[i + 3] | data[i + 4] << 8 | data[i + 5] << 16 | (data[i + 5] & 0x80 ? 0xFF << 24 : 0)) / 10000
}}
i += 5;
break
case TYPE_PULSE1: //Pulse input 1
obj.pulse1 = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_PULSE1_ABS: //Pulse input 1 absolute value
var pulseAbs = ((data[i + 1] << 24) | (data[i + 2] << 16) | (data[i + 3] << 8) | (data[i + 4])) >>> 0;
obj.pulseAbs = {value: pulseAbs};
i += 4;
break
case TYPE_EXT_TEMP1: //External temp
var temp = (data[i + 1] << 8) | (data[i + 2]);
temp = bin16dec(temp);
obj.externalTemperature = {value: temp / 10};
i += 2;
break
case TYPE_EXT_DIGITAL: //Digital input
obj.digital = {value: (data[i + 1])};
i += 1;
break
case TYPE_EXT_DISTANCE: //Distance sensor input
obj.distance = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_ACC_MOTION: //Acc motion
obj.accMotion = {value: (data[i + 1])};
i += 1;
break
case TYPE_IR_TEMP: //IR temperature
var iTemp = (data[i + 1] << 8) | (data[i + 2]);
iTemp = bin16dec(iTemp);
var eTemp = (data[i + 3] << 8) | (data[i + 4]);
eTemp = bin16dec(eTemp);
obj.irInternalTemperature = {value: iTemp / 10}
obj.irExternalTemperature = {value: eTemp / 10}
i += 4;
break
case TYPE_OCCUPANCY: //Body occupancy
obj.occupancy = {value: (data[i + 1])};
i += 1;
break
case TYPE_WATERLEAK: //Water leak
obj.waterleak = {value: (data[i + 1])};
i += 1;
break
case TYPE_GRIDEYE: //Grideye data
var ref = data[i+1];
i++;
obj.grideye = [];
for(var j = 0; j < 64; j++) {
obj.grideye[j] = ref + (data[1+i+j] / 10.0);
}
obj.grideye = {
value: obj.grideye
}
i += 64;
break
case TYPE_PRESSURE: //External Pressure
var temp = ((data[i + 1] << 24) | (data[i + 2] << 16) | (data[i + 3] << 8) | (data[i + 4])) >>> 0;
obj.pressure = {value: temp / 1000};
i += 4;
break
case TYPE_SOUND: //Sound
obj.soundPeak = {value: data[i + 1]};
obj.soundAvg = {value: data[i + 2]};
i += 2;
break
case TYPE_PULSE2: //Pulse 2
obj.pulse2 = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_PULSE2_ABS: //Pulse input 2 absolute value
obj.pulseAbs2 = {value: ((data[i + 1] << 24) | (data[i + 2] << 16) | (data[i + 3] << 8) | (data[i + 4])) >>> 0};
i += 4;
break
case TYPE_ANALOG2: //Analog input 2
obj.analog2 = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
case TYPE_EXT_TEMP2: //External temp 2
var temp = (data[i + 1] << 8) | (data[i + 2]);
temp = bin16dec(temp);
extTemp2.push(temp / 10);
obj.externalTemperature2 = {
value: extTemp2.length === 1 ? extTemp2[0] : extTemp2
}
i += 2;
break
case TYPE_EXT_DIGITAL2: //Digital input 2
obj.digital2 = {value: (data[i + 1])};
i += 1;
break
case TYPE_EXT_ANALOG_UV: //Load cell analog uV
obj.analogUv = {value: (data[i + 1] << 24) | (data[i + 2] << 16) | (data[i + 3] << 8) | (data[i + 4])};
i += 4;
break
case TYPE_TVOC:
obj.tvoc = {value: (data[i + 1] << 8) | (data[i + 2])};
i += 2;
break
default: //unknown type: stop, and keep what was decoded so far
return obj;
}
}
if (i > data.length) {
throw new Error("Elsys payload cut short: " + data.length + " bytes");
}
return obj;
}
var decoded = DecodeElsysPayload(hexToBytes(code));
if (Object.keys(decoded).length === 0) {
return "[]";
}
return JSON.stringify(decoded);
}
The converter returns "[]" when a payload holds no data it knows, and throws an error when the last value in the payload is cut short. The values of acceleration and location are objects, and that of grideye is a list, so these assets need an object or an array profile. A payload with two TYPE_EXT_TEMP2 values gives a list of both as the value of externalTemperature2, which an asset with a number profile refuses.
For the payload 0100e202290400270506060308070d62, the Debug tab shows a line like this (In the Debug tab explains how it differs for a LoRaWAN device):
Parsed {"temperature": {"value": 22.6}, "humidity": {"value": 41}, "light": {"value": 39}, "motion": {"value": 6}, "co2": {"value": 776}, "vdd": {"value": 3426}} from payload 01 00 E2 02 29 04 00 27 05 06 06 03 08 07 0D 62 using JS
Downlink conversion
Here’s the example of the downlink conversion:
function converter(code) {
var given_obj = JSON.parse(code);
var given_value = Number(given_obj[Object.keys(given_obj)[0]].value) & 0xFF;
var hex = (given_value < 16 ? "0" : "") + given_value.toString(16).toUpperCase();
return JSON.stringify({ data: "018A0300" + hex });
}
This would enable you to send a command from the actuator asset and schedule a downlink for your device. For the value 13, the Debug tab shows a line like this:
Parsed {"actuator": {"at": "2022-03-02T09:13:50.422881Z", "value": 13}} to payload 01 8A 03 00 0D using JS
The value is limited to one byte with & 0xFF, so that the payload always has two hexadecimal digits per byte. A value above 255 wraps around: 300 is sent as 2C. Without & 0xFF, a value such as 3425 would give an odd number of digits, 018A0300D61, and the command would fail when it is sent. Try a downlink converter with small and large values before you save it.
A downlink conversion is a converter function too, and follows the same rules for its declaration. Its input code is the command as JSON text, with the name of the actuator as its key, such as {"actuator": {"value": 13}}. Depending on how the command is sent, it may also carry an at, so read only its value. When you save, the platform runs the converter on a sample command for an actuator with another name and a value larger than one byte. So read the first key, as the example above does, instead of a fixed actuator name, and make sure the converter does not throw an error on that sample. If you declare a second parameter, it receives the moment of the conversion.
The converter must return text in one of two forms:
JSON.stringify({data: "018A03000D"}): the bytes to send as hexadecimal text, two digits per byte, optionally with meta for the port or a confirmed downlink, as shown below. This is the safest form."018A03000D". Spaces and capital letters are allowed, a 0x prefix is not. Hexadecimal text that can also be read as a JSON number, such as "1234" or "1E10", does not work in this form; return JSON.stringify({data: "1234"}) instead.Returning an object instead of text is accepted when you save, but then every command fails with Wrong type Converted!. Returning nothing makes the save fail with The converter returned no value (undefined). If the converter throws an error, the conversion of that command fails, and the error appears in the Debug tab.
To specify port for your downlink you can do this:
function converter(code){
var data = {data: "AA00", meta: {
port: 9
}
};
return JSON.stringify(data)
}
To specify that your downlink should be confirmed, do this:
function converter(code){
var data = {data: "AA00", meta: {
confirmed: true
}
};
return JSON.stringify(data)
}