Send device requests and events to your web service
Delivering events and requests to your cloud environment
Last updated
Delivering events and requests to your cloud environment
Last updated
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.
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.
Open the network you created in the Blecon Console.
Navigate to the Integrations tab, and add a Webhook integration
In the URL field, enter your unique URL that you copied above.
Tick both Select Events checkboxes, to capture all event types
Click Save to add the integration
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
:
Here is a snippet of the data:
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
The web endpoint will receive an event similar to this:
If you included a request data type, the network adds a converted_payload
field, which contains the decoded payload.
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.
In the popup, set the response content type to application/json
In the popup, set the body to {"payload":"676f7420697421"}
Rerun the request from the CLI and you will see the response displayed.
Below is sample code in various languages to encode binary data as a hexadecimal string suitable for responding to devices.
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