ChirpStack Learning Notes 2.8 Application Integration InfluxDB

Article Directory

Preface

To visualize the indicators of nodes and gateways in LoRaWAN systems, ChirpStack introduced Granfana .Granfana now supports a variety of databases, most typically temporal databases InfluxDB.

ChirpStack can be used in Configuration in Application Integration to store data sent and received to InfluxDB And then visualize it with Granfana.

Turn over in the Forum This feature was released by Brother B in May 18 And it seemed happy at the time, which was really a great feature.

Write down how to use InfluxDB in this note and grafana in the next.

Young hands have recently been learning about the ChirpStack project, which should be the most influential LoRaWAN server open source project.It is a good learning material because of its rich components and readable code.Learn more about notes, Click here to view.

1 Functional description

measurement of upstream and downstream data

Naming format for measurement s

All measurements are using the field names from the object element, joined by an underscode (_) in case the object element is nested. Payload data is prefixed by device_frmpayload_data.

All measurements names connect several elements of an object with underscores.The Payload data is prefixed with device_frmpayload_data and requires that Payload be in JSON format before storing it in InfluxDB with the key: object.

Payload example:

{
    "object": {
        "temperature_sensor": {
            "1": 23.5
        }
    }
}

This sample measurements will be named device_frmpayload_data_temperature_sensor_1.

Tags for measurements

Each measurements has the following tag s:

  • application_name
  • device_name
  • dev_eui
  • f_port (LoRaWAN port used for uplink)

measurement of other classes

In addition to the core upstream and downstream data, ChirpStack supports the recording of several types of data:

  • Device upstream meta-data, in order to monitor data such as spread spectrum factor, channel, etc., each upstream data is recorded to a measurement named device_uplink.value is fixed to 1.
  • Device battery level, obtained from mac command DevStatusAns
  • Device margin status, obtained from the mac command DevStatusAns

2 Specific operations

2.1 Initialize and start the InfluxDB container

# mkdir InfluxDB
# cd InfluxDB/
# sudo docker run --rm\
      -e INFLUXDB_DB=db0 -e INFLUXDB_ADMIN_ENABLED=true \
      -e INFLUXDB_ADMIN_USER=admin -e INFLUXDB_ADMIN_PASSWORD=supersecretpassword \
      -e INFLUXDB_USER=telegraf -e INFLUXDB_USER_PASSWORD=secretpassword \
      -v $PWD:/var/lib/influxdb \
      influxdb /init-influxdb.sh
# docker run --name=influxdb -d -p 8086:8086 -v $PWD:/var/lib/influxdb influxdb
# 

This initializes the db0 database and adds the user telegraf.See the tutorial for detailed InfluxDB operations InfluxDB Basic Concepts and Operations.

2.2 webui Configuration InfluxDB

Note that the IP in API endpoint (write) must remember to process that I have run the InfluxDB container on the same host machine, cannot use the default localhost, and must be configured as the address of the Docker bridge so that the AS container can communicate with the InfluxDB container through the host address.

# ip a
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:5f:e8:7c:be brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

I have a detailed record of this in my next note.

2.3 Device Report Data

Operating devices report data, I use 2.7 Use of JS codec functions Same program, the reported data is coded and decoded out of a temperature object.

3 Results

After the device data is reported, AS's log is printed as follows:

time="2020-02-07T11:29:23Z" level=info msg="device updated" dev_eui=1219000000000003
time="2020-02-07T11:29:23Z" level=info msg="finished unary call with code OK" grpc.code=OK grpc.method=HandleUplinkData grpc.request.deadline="2020-02-07T11:29:24Z" grpc.service=as.ApplicationServerService grpc.start_time="2020-02-07T11:29:23Z" grpc.time_ms=4.927 peer.address="192.168.64.5:53871" span.kind=server system=grpc
time="2020-02-07T11:29:23Z" level=info msg="integration/mqtt: publishing message" qos=0 topic=application/2/device/1219000000000003/rx
time="2020-02-07T11:29:23Z" level=info msg="integration/influxdb: uplink measurements written" dev_eui=1219000000000003

We log in to InfluxDB to see the measurements.

device_frmpayload_data

Because the object I uploaded is "object": {"temperature": 104}, the corresponding measurements are: device_frmpayload_data_temperature.

> use db0
Using database db0
> SELECT * FROM device_frmpayload_data_temperature
name: device_frmpayload_data_temperature
time                application_name dev_eui          device_name f_port value
----                ---------------- -------          ----------- ------ -----
1581074823742000000 demoapp          1219000000000003 ths_001     5      104
1581074843739000000 demoapp          1219000000000003 ths_001     5      104
1581074863740000000 demoapp          1219000000000003 ths_001     5      104
1581074883739000000 demoapp          1219000000000003 ths_001     5      104
1581074903742000000 demoapp          1219000000000003 ths_001     5      104
1581074923740000000 demoapp          1219000000000003 ths_001     5      104
1581074943744000000 demoapp          1219000000000003 ths_001     5      104
1581074963741000000 demoapp          1219000000000003 ths_001     5      104
1581074983740000000 demoapp          1219000000000003 ths_001     5      104
1581075003741000000 demoapp          1219000000000003 ths_001     5      104
1581075023754000000 demoapp          1219000000000003 ths_001     5      104
1581075043742000000 demoapp          1219000000000003 ths_001     5      104

device_uplink

> SELECT * FROM device_uplink
name: device_uplink
time                application_name dev_eui          device_name dr f_cnt frequency rssi snr  value
----                ---------------- -------          ----------- -- ----- --------- ---- ---  -----
1581074823742000000 demoapp          1219000000000003 ths_001     4  0     470300000 -113 -4.3 1
1581074843739000000 demoapp          1219000000000003 ths_001     4  1     470300000 -113 -4.3 1
1581074863740000000 demoapp          1219000000000003 ths_001     4  2     470300000 -113 -4.3 1
1581074883739000000 demoapp          1219000000000003 ths_001     4  3     470300000 -113 -4.3 1
1581074903742000000 demoapp          1219000000000003 ths_001     4  4     470300000 -113 -4.3 1
1581074923740000000 demoapp          1219000000000003 ths_001     4  5     470300000 -113 -4.3 1
1581074943744000000 demoapp          1219000000000003 ths_001     4  6     470300000 -113 -4.3 1
1581074963741000000 demoapp          1219000000000003 ths_001     4  7     470300000 -113 -4.3 1
1581074983740000000 demoapp          1219000000000003 ths_001     4  8     470300000 -113 -4.3 1
1581075003741000000 demoapp          1219000000000003 ths_001     4  9     470300000 -113 -4.3 1
1581075023754000000 demoapp          1219000000000003 ths_001     4  10    470300000 -113 -4.3 1
1581075043742000000 demoapp          1219000000000003 ths_001     4  11    470300000 -113 -4.3 1
> 

END

239 original articles published, 228 approved, 800,000 visits+
His message board follow

Tags: InfluxDB Docker Mac Database

Posted on Sat, 08 Feb 2020 00:22:26 -0800 by Mirge