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
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
; ------------------------------------------
; Family:   Protocol forwarder
; About:    Versatile protocol forwarder components for bridging the gap between
;           different data sinks, bus systems and serialization formats.
; ------------------------------------------
; Name:     HTTP-to-MQTT protocol forwarder, generic
; About:    Suitable for data acquisition via HTTP POST/PUT requests.
; Channel:  Transport: HTTP, MQTT; Format: JSON, x-www-form-urlencoded
; See also: https://getkotori.org/docs/handbook/forwarders/http-to-mqtt.html
;           https://getkotori.org/docs/handbook/acquisition/protocol/http.html
; ------------------------------------------
; Description:
;
;         - Listen to HTTP POST or PUT requests
;         - Receive payloads formatted as JSON or in urlencoded format
;         - Forward payloads to the MQTT bus
;
; Manual:   Please specify forwarding source and target parameters in URI format.
;           The MQTT topic path is derived from the HTTP URI path by interpolating
;           the appropriate part of the context URI.
;
; Example:  In the example below, given the "address" part of the resource URI
;           is "testdrive/area-42/node-1", data sent to the full URI
;
;               /api/mqttkit-1/testdrive/area-42/node-1/data
;
;           will be republished to the MQTT topic
;
;               mqttkit-1/testdrive/area-42/node-1/data.json
;
; ------------------------------------------


[mqttkit-1.http-api-generic]
enable          = true

type            = application
application     = kotori.io.protocol.forwarder:boot

realm           = mqttkit-1
source          = http:/api/mqttkit-1/{address:.*}/{slot:(data|event)} [POST]
target          = 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

Troubleshooting

If you experience problems or don’t see any data in Grafana, please follow up with Troubleshooting.