Single sawtooth signal

The characteristics of sawtooth signals (dynamic, slowly oscillating) are convenient to generate measurement sensor readings and publish telemetry data without having any hardware in place.

Sawtooth signal with MQTT


The following examples depend on mosquitto_pub usually contained in the mosquitto-clients distribution package or similar:

# Setup "mosquitto_pub"
aptitude install mosquitto-clients


Let’s define a an example sensor emitting a single sawtooth signal:

# Define an example sensor emitting a single sample of a sawtooth signal in JSON format
sensor() { echo "{\"sawtooth\": $(date +%-S)}"; }

Check if the sensor works properly:

# Read sensor value
{"sawtooth": 42}

# Verify it's actually JSON
sensor | python -mjson.tool
    "sawtooth": 42


Get real and actually transmit sensor values to Kotori by publishing them to the MQTT bus:

# Where to send data to
export MQTT_TOPIC=mqttkit-1/testdrive/area-42/node-1

# Define the transmission command to send telemetry data to the "testdrive" network
transmitter() { mosquitto_pub -h $MQTT_BROKER -t $MQTT_TOPIC/data.json -l; }

# Acquire and transmit a single sensor reading
sensor | transmitter

Periodic transmitter

“hands-free”, periodic dry-dock measurements:

measure() { sensor | transmitter; }
loop() { while true; do measure; echo -n .; sleep 1; done; }

Start publishing:



Sawtooth signal made from oscillating value of current second.

In /var/log/kotori/kotori.log, you should see things like:

2016-05-27T03:03:58+0200 [            ] INFO: [mqttkit-1   ] transactions: 1.00 tps

Sawtooth signal with HTTP

Same as above for MQTT, but with slightly changed transmitter.


This example depends on HTTPie:

aptitude install httpie


# Define transmitter
transmitter() { http POST http://localhost:24642/api/$DEVICE_TOPIC/data; }


Sawtooth signal made from oscillating value of the current second.

Multiple sawtooth signals

A more advanced sensor might be:

# Let's define multiple sawtooth signals, also derived from current time
sensor() { jo second=$(date +%-S) minute=$(date +%-M) hour=$(date +%-H) day=$(date +%-d) month=$(date +%-m); }

Check if the sensor works properly:

# Read sensor values
sensor | python -mjson.tool
    "day": 27,
    "hour": 2,
    "minute": 37,
    "month": 5,
    "second": 45

Restart transmitting:



Whole date of second, minute, hour, day and month.