Terkin-Variante für CPython / Raspberry Pi / Dragino LoRa/GPS HAT

Einleitung

Dank @tonke ist der Terkin Datenlogger nun auch auf einem Raspberry Pi lauffähig. Er verwendet einen Dragino LoRa/GPS HAT für LoRaWAN/TTN-Konnektivität sowie eine Reihe von Sensoren für einen anderen Kontext als Bienenmonitoring.

Das ganze funktioniert ähnlich wie Use LoRa/GPS HAT + RaspberryPi to set up a LoRa Node, kommt aber deutlich ausgereifter und “ready-to-go” daher.

Features

  • Sensoren: BME280, DS18x20, ADS1x15, GPSD, EPSolar, VEDirect
  • Telemetrie: MQTT over IP, CayenneLPP over LoRaWAN/TTN
4 Likes

Terkin with Dragino on Raspberry Pi 3

Setup instructions

Install distribution packages

# Install prerequisites
sudo apt install git python-virtualenv python3-virtualenv gpsd gpsd-clients curl

Configure system

This procedure should be executed as user root. So, when logged in as pi, become root by typing:

sudo su

Enable peripherals

Adjust /boot/config.txt.

Overlay parameters are only in scope until the next overlay is loaded.

# Enable I2C
dtparam=i2c_arm=on

# Second I2C
dtoverlay=i2c-gpio,bus=5,i2c_gpio_delay_us=1,i2c_gpio_sda=26,i2c_gpio_scl=20

# Pin 7 (BCM4) is used by Dragino LoRa DIO0.
# So, use Pin 40 (BCM21) for GPIO, e.g. 1-Wire Digital Temperature Sensor DS18B20.
# https://www.hackster.io/idreams/getting-started-with-lora-fd69d1
dtoverlay=w1-gpio,gpiopin=21

# Dragino Board
dtoverlay=spi0-cs,cs0_pin=25
dtparam=spi=on

# GPS PPS for feeding NTP
dtoverlay=pps-gpio,gpiopin=18

Try

touch /boot/config-auto.txt
raspi-config nonint set_config_var dtoverlay "spi0-cs,cs0_pin=25" /boot/config-auto.txt
raspi-config nonint set_config_var dtparam "i2c_arm=on,spi=on,audio=on" /boot/config-auto.txt

Configure GPSD

Adjust /etc/default/gpsd:

DEVICES="/dev/ttyS0"

:warning::warning::warning: Don’t forget the reboot here! :warning::warning::warning:

Install Terkin datalogger

This procedure should be executed as user pi again.

# Clone sources
git clone https://github.com/hiveeyes/terkin-datalogger.git
cd terkin-datalogger

# Run setup process
make setup-dragino

Configure

Create settings.py

In order to create an initial configuration, just derive it from a blueprint called settings.raspberrypi.py.

cp src/settings.raspberrypi.py src/settings.py

Edit settings.py

:arrow_right: Please read the configuration file src/settings.py carefully and adjust the different settings according to your needs. Getting everything configured properly is essential for correct operation.

Configuration sections

The settings.py configuration file is divided into four different sections.

  • Main/System
    • Duty cycle
    • Deep sleep
    • Watchdog
    • LED signalling
  • Network connectivity
    • Linux networking (Ethernet, WiFi)
    • GPRS (SIM800)
    • LoRa (SX127x)
  • Telemetry targets
    • MQTT broker and topic
    • HTTP endpoint
    • TTN account
  • Sensor domain
    • Buses: I2C and 1-Wire
    • Adapters: BME280, DS18x20, SI7021, ADS1x15, GPSD, EPSolar or VEDirect

Invoke

This starts the datalogger in daemon mode using the "terkin --daemon" command.

make run-cpython

Appendix

Test GPSD

# On one shell
service gpsd stop
sudo -u gpsd /usr/sbin/gpsd -n -N -D 256 /dev/ttyS0

# On another Shell
cgps -s

Log-Output


    2.1411 [terkin.datalogger           ] INFO   : --- cycle ---
    2.2412 [terkin.sensor.core          ] INFO   : Sending power_on to bus i2c:1
    2.3413 [terkin.datalogger           ] INFO   : Reading 3 sensor ports
    2.4414 [terkin.datalogger           ] INFO   : Reading sensor port "BME280Sensor"
    2.5415 [terkin.datalogger           ] INFO   : Reading sensor port "GpsdSensor"
    2.6416 [terkin.driver.gpsd_sensor   ] INFO   : Reading sensor GPSD
    2.7417 [terkin.datalogger           ] INFO   : Reading sensor port "GPIOZeroSensor"
    2.8417 [terkin.driver.gpiozero_sensor] INFO  : Reading sensor GPIOZero
    2.8440 [terkin.datalogger           ] INFO   : Sensor data:

           altitude.gpsd                                       691.6    Gpsd Daemon
           cputemp.rpi                                        49.926    gpiozero
           diskusage.rpi                           6.015081995941164    gpiozero
           humidity.0x76.i2c:1                     36.27984170356756    Bme280 on ic2:1 0x76
           latitude.gpsd                                      47.965    Gpsd Daemon
           loadaverage.rpi                                      0.14    gpiozero
           longitude.gpsd                                     11.432    Gpsd Daemon
           pressure.0x76.i2c:1                     931.5441805693531    Bme280 on ic2:1 0x76
           temperature.0x76.i2c:1                        22.39921875    Bme280 on ic2:1 0x76

    2.8446 [terkin.device               ] INFO   : Start curating the garbage collector
    2.8455 [terkin.device               ] INFO   : Collecting garbage
    2.8461 [terkin.device               ] INFO   : Curating the garbage collector finished. Free memory: 1000000
    2.8465 [terkin.telemetry.core       ] INFO   : Telemetry transport: MQTT over TCP over WiFi
    2.8474 [terkin.telemetry.core       ] INFO   : Connecting to MQTT broker at daq.example.org with username None. client_id=terkin.3133383631
    2.8533 [terkin.telemetry.core       ] INFO   : MQTT topic:   workbench/testdrive/area-42/rasp-03/data.json
    2.8536 [terkin.telemetry.core       ] INFO   : MQTT payload: {"temperature.0x76.i2c:1": 22.39921875, "humidity.0x76.i2c:1": 36.27984170356756, "pressure.0x76.i2c:1": 931.5441805693531, "latitude.gpsd": 47.965, "longitude.gpsd": 11.432, "altitude.gpsd": 691.6, "cputemp.rpi": "49.926", "diskusage.rpi": "6.015081995941164", "loadaverage.rpi": "0.14"}
    2.8539 [terkin.telemetry.core       ] INFO   : Connecting to MQTT broker at daq.example.org with username None
    2.9382 [terkin.telemetry.core       ] INFO   : Connecting to MQTT broker at ('10.10.1.42', 1883) succeeded
    3.0283 [terkin.telemetry.core       ] INFO   : Telemetry transport: CayenneLPP over LoRaWAN/TTN
    3.0404 [terkin.network.lora         ] INFO   : [LoRa] Waiting for connectivity
    4.0419 [terkin.network.lora         ] INFO   : [LoRa] Waiting for connectivity
    5.0435 [terkin.network.lora         ] INFO   : [LoRa] Waiting for connectivity
    6.0824 [terkin.network.lora         ] INFO   : [LoRa] Waiting for connectivity
    7.0949 [terkin.telemetry.core       ] INFO   : [LoRa] Uplink payload (hex): 056700df05684805732463
    7.0957 [terkin.telemetry.core       ] INFO   : [LoRa] Sending payload...
    7.1697 [terkin.telemetry.core       ] INFO   : [LoRa] Sent None bytes
    7.1704 [terkin.telemetry.core       ] INFO   : [LoRa] No downlink message processed
    7.1710 [terkin.datalogger           ] INFO   : Telemetry status: SUCCESS (2/2)

Picture

1 Like

Terkin 0.9.0 gibt es nun bei PyPI und läuft so auch komfortabel auf CPython los. Auch wenn der Raspberry Pi das primäre Ziel war, läuft er problemlos auch in anderen CPython 3.x Umgebungen unter Linux, macOS und WSL2.

Unabhängig vom tatsächlichen Einsatz auf einer dieser Plattformen macht das auch die Entwicklung vieler Subsysteme deutlich angenehmer, als den Code bei jedem Entwicklungszyklus neu auf ein Embedded Gerät aufspielen zu müssen.

Synopsis

pip install --user terkin
terkin --daemon --config settings.raspberrypi.py

Dokumentation

4 Likes