Basic example with HTTP#
Introduction#
In this example, we will configure an example application with Kotori based on the MQTTKit application communication style. We will use HTTP as communication protocol and JSON as data serialization format. It builds upon the Basic example with MQTT.
To read about all available options for HTTP data acquisition, please follow up at HTTP.
Configure Kotori application#
Add this snippet to
/etc/kotori/apps-enabled/amazonas.ini
and edit:realm = amazonas source = http:/api/amazonas/... target = mqtt:/amazonas/...
Take a look at etc/examples/forwarders/http-api-generic.ini
as a configuration blueprint.
1; ------------------------------------------
2; Family: Protocol forwarder
3; About: Versatile protocol forwarder components for bridging the gap between
4; different data sinks, bus systems and serialization formats.
5; ------------------------------------------
6; Name: HTTP-to-MQTT protocol forwarder, generic
7; About: Suitable for data acquisition via HTTP POST/PUT requests.
8; Channel: Transport: HTTP, MQTT; Format: JSON, x-www-form-urlencoded
9; See also: https://getkotori.org/docs/handbook/forwarders/http-to-mqtt.html
10; https://getkotori.org/docs/handbook/acquisition/protocol/http.html
11; ------------------------------------------
12; Description:
13;
14; - Listen to HTTP POST or PUT requests
15; - Receive payloads formatted as JSON or in urlencoded format
16; - Forward payloads to the MQTT bus
17;
18; Manual: Please specify forwarding source and target parameters in URI format.
19; The MQTT topic path is derived from the HTTP URI path by interpolating
20; the appropriate part of the context URI.
21;
22; Example: In the example below, given the "address" part of the resource URI
23; is "testdrive/area-42/node-1", data sent to the full URI
24;
25; /api/mqttkit-1/testdrive/area-42/node-1/data
26;
27; will be republished to the MQTT topic
28;
29; mqttkit-1/testdrive/area-42/node-1/data.json
30;
31; ------------------------------------------
32
33
34[mqttkit-1.http-api-generic]
35enable = true
36
37type = application
38application = kotori.io.protocol.forwarder:boot
39
40realm = mqttkit-1
41source = http:/api/mqttkit-1/{address:.*}/{slot:(data|event)} [POST]
42target = mqtt:/mqttkit-1/{address}/{slot}.json
Watch Kotori logfile:
tail -F /var/log/kotori/kotori.log
Restart Kotori:
systemctl restart kotori
Send sample telemetry packet#
CHANNEL_URI=http://localhost:24642/api/amazonas/ecuador/cuyabeno/1/data
echo '{"temperature": 42.84, "humidity": 83.1}' | curl --request POST --header 'Content-Type: application/json' --data @- $CHANNEL_URI
Watch telemetry data#
Access Grafana by navigating to http://kotori.example.org:3000/ and logging in with
admin/admin
.Navigate to the dashboard just created by submitting telemetry data http://kotori.example.org:3000/dashboard/db/amazonas-ecuador.
Troubleshooting#
If you experience problems or don’t see any data in Grafana, please follow up with Troubleshooting.