Sigfox Downlink

Sigfox provides bidirectional communication (both uplink and downlink) for its compatible devices. When a downlink request is received at the Sigfox backend from a device, the configured downlink callback will be pushed by the Sigfox Cloud to our Platform.

The callback to be used is the same as the uplink mode (you can get from your device group settings settings), but you have to add &ack={ack} at the end of the url:

https://subscription.thethings.io/sgfx/YYYYY/XXXXXXX/?id={device}&data={data}&ack={ack}

Creating a new callback in the Sigfox backend:

Once the device sends data to the Sigfox backend, make sure to update your sigfox_parser function in your thethings.iO account cloudcode to manage the downlink case. Using the following structure:

function main(params, callback){
  // when ack is requested, this block manages the result to be send
  // for the downlink. Also ends the the function returning the downlink 
  // response body
  if (params.custom.ack === 'true') {
    var resultBidir = {};
    // Remeber that the downlinkData has a fixed length of 8 bytes (16 chars)
    resultBidir[params.deviceId] = {'downlinkData':"0011223344556677"}
    return callback(null, resultBidir);
  }
  
  // this block parses the uplink data to be stored a our Platform.
    var result = [
    {
        "key": "temperature",
        "value": parseInt('0x'+params.data.substring(0,2))
    },
    {
        "key": "rssi",
        "value": params.custom.rssi
    },
    {
        "key": "$geo",
        "value": [params.custom.lng, params.custom.lat]
    }
    ]
    callback(null, result) 
}

The object that the callback returns will be sent again to the Sigfox backend and to the device.

Note that only the downlink request will be processed when the ack field is true. If your request includes uplink information, it will not be neither parsed nor stored. As you can see, the sigfox_parser function can only be called for uplink OR downlink purposes, you cannot do both tasks with the same request using this method Feel free to contact us for more information on this topic and other methods.

If all is working ok, the response payload will be stored at the sgfx-downlink resource. Any error or problem with your code will be stored at the sgfx-error resource.

Reference

At the next links, you can find more information about how works the Downlink callbacks: