Developer
Ask a QuestionBlecon WebsiteBlecon Console
  • Learn Blecon
    • Introduction
    • Blecon Modems
      • Device Identity and Network Security
      • Modem Firmware vs Modem Library
      • Using the Modem
      • Communicating with the cloud
      • Sending data from the cloud to a device
    • Blecon Hotspots
    • Blecon Networks
      • Blecon Accounts
      • Registering devices
        • The Blecon Scanner
        • Blecon Scanner Developer Guide
      • Blecon Events
      • Cloud Integrations
  • Cloud Integrations
    • Webhook
    • AWS S3
    • AWS SQS
    • AWS EventBridge
    • Memfault
  • Getting Started Guides
    • Getting started index
    • Install the Blecon Modem Firmware
    • Set up a Blecon Hotspot
    • Use Blecon from your computer with the Blecon CLI
    • Create a Network and register a device
    • Send device requests and events to your web service
    • Use Blecon from a Development Board
    • Use the Blecon Modem from an MCU
  • Device Guides
    • KKM S5-BCN
  • Development Board Guides
    • Supported Development Boards
    • Ezurio DVK-BL54L15
    • Fanstel EV-BM15C
    • InsightSiP ISP2454-LX-EB
    • Nordic nRF52840DK
    • Nordic nRF54L15DK
    • Minew ME54BE01
    • Panasonic PAN-B511 EVB
    • Raytac AN54L15Q-DB
    • u-Blox EVK-NORA-B20
  • Modem Reference
    • Modem Firmware Releases
      • nRF54L15 DK
      • nRF52840 Dongle
      • nRF52840 DK
    • CLI Releases
    • SDK Releases
    • Modem API Reference
    • Modem Protocol Reference
      • Request Frames
      • Command Protocol
      • UART Transport
    • Guides and best practices
      • Retrieve a device's identity
  • Cloud Reference
    • Configuration API
    • Advanced event routing
  • Hotspot Reference
    • Blecon Hub
Powered by GitBook

Get Support

  • Ask a question
On this page
  • Set up a reciever endpoint
  • Configure an Integration
  • Send a request
  • Sending a request with a structured data type
  • Receiving events at your Event Route URL
  • Sending back a response
  • Next Steps
  1. Getting Started Guides

Send device requests and events to your web service

Delivering events and requests to your cloud environment

PreviousCreate a Network and register a deviceNextUse Blecon from a Development Board

Last updated 2 months ago

For data from Blecon devices to be delivered to your cloud application, you will need to configure an that delivers events to the desired destination,

Everything that happens on Blecon is an . Events are produced when devices send requests and messages and when other things happen, like when the network spots one of your devices.

This guide will show you how to set up a Webhook Integration to capture requests and forward the result on an external web endpoint.

Set up a reciever endpoint

First, you will need to set up a web endpoint for the Blecon service to send events to. For this example we will use to quickly create a temporary endpoint for testing.

When you visit , you will see the unique URL that has been created for you:

Click on the URL to copy it to the clipboard. You will use this URL for your event route.

Configure an Integration

  1. Open the network you created in the Blecon Console.

  2. Navigate to the Integrations tab, and add a Webhook integration

  3. In the URL field, enter your unique URL that you copied above.

  4. Tick both Select Events checkboxes, to capture all event types

  5. Click Save to add the integration

Send a request

If you are using the Blecon CLI use the request subcommand with a payload. In the example below, we send a 4-byte message with values 4b 1e c0 17 :

$ ./blecon-cli request 4b1ec017
Waiting for connection...
Connected
Terminating connection
Response:

Here is a snippet of the data:

"device_id": "64c89eef-9dc1-427d-add0-d98b598adac4",
"payload": "4b1ec017",

Sending a request with a structured data type

Device requests can optionally include a request data type. On the CLI, this is specified using the -x option. If the request data type is application/json the Blecon network will decode the binary data and pass it to your web endpoint.

For example, if you make the request:

./blecon-cli request -t '{ "my message" : "hello cloud!" }' -x application/json

Note that on some terminals you need to quote the command differently. On Windows Command Prompt, try:

blecon-cli request -t "{ \"my message\" : \"hello cloud!\" }" -x application/json

Receiving events at your Event Route URL

The web endpoint will receive an event similar to this:

"device_id": "64c89eef-9dc1-427d-add0-d98b598adac4",
"payload": "7b226d79206d657373616765223a2268656c6c6f20636c6f756421227d",
"converted_payload": {
        "my message": "hello cloud!"
},

If you included a request data type, the network adds a converted_payload field, which contains the decoded payload.

Sending back a response

You will notice that the CLI command still outputs a blank response. Also, if you check the "Recent Events" for your network, you will see a device.request_failed error.

  1. In the popup, set the response content type to application/json

  2. In the popup, set the body to {"payload":"676f7420697421"}

  1. Rerun the request from the CLI and you will see the response displayed.

Generating hexadecimal-encoded strings

Below is sample code in various languages to encode binary data as a hexadecimal string suitable for responding to devices.

// Encoding a text string
Buffer.from('example text', 'utf8').toString('hex');

// Encoding binary data
data = [ 0xaa, 0xbb, 0xcc, 0xdd ];
Buffer.from(data).toString('hex');
# Encoding text
'example text'.encode('utf-8').hex()

# Encoding binary data
data = b'\xaa\xbb\xcc\xdd'
data.hex()
// encoding text
bin2hex("example text");

// encoding binary data
$data = pack("C*", 0xaa, 0xbb, 0xcc, 0xdd);
bin2hex($data);

Next Steps

Now that an event route is configured, requests sent from the device will be routed to your unique URL at .

You will see your request appear on the sidebar at . When you click on the incoming request you can see your payload in the Raw Data window.

This is because your web integration isn't sending a properly formatted response to the request. Requests are the only event type that require a response. Other events like one-way device do not.

Let's fix that now by configuring a response. Like payloads from devices, responses back to the device are sent as bytes encoded as a . We will send the following 7-byte response: 67 6f 74 20 69 74 21

In , click "Edit" in the toolbar at the top of the page

Read more about and their format

https://webhook.site
https://webhook.site
messages
https://webhook.site
events
hexadecimal string
integration
Event
https://webhook.site
https://webhook.site
Configuration for https://webhook.site URL response