SignalSQL

Hardware modules

Modules serve two roles in SignalSQL: some are drivers that interface the engine with a specific electrical interface or protocol, and others implement algorithms or logical functions. Each module presents itself as one or more tables; the signals it exposes show up in the built-in INPUT/OUTPUT tables, and you enable or disable modules through the MODULES table.

The bundled modules are OWSERVER, GPIO, PID, SLOW_PWM, and LOGGER, statically linked into the engine. To add hardware beyond these, SignalSQL runs out-of-process drivers you declare in the config file — no recompiling.

OWSERVER — 1-wire

Connects SignalSQL to a one-wire server (owserver, from OWFS). Add a connection by inserting a row into the OWSERVER table with the server’s host:

CREATE TABLE OWSERVER (
    ID INT AUTO_INCREMENT PRIMARY KEY,  -- The id of the OWSERVER record
    Host VARCHAR(255),                  -- IP address or hostname owserver runs on
    Port INT,                           -- Port. If NULL or zero, the default 4304 is used
    Status VARCHAR(255)                 -- Connection status:
                                        -- INIT|CONNECTING|CONNECTED|ERROR
);

Once connected, SignalSQL queries the owserver for all attached devices and adds a row to the OWDEVICE table for each:

CREATE TABLE OWDEVICE (
    ID VARCHAR(255) PRIMARY KEY,        -- The physical id of this device
    OwServer INT,                       -- The id of the OWSERVER for this device
    Type VARCHAR(255)                   -- Device type:
                                        -- SERIAL_NUMBER|SWITCH|THERMOMETER|
                                        -- AD_CONVERTER|BATTERY_MONITOR|RTC
);
  • ID is the unique physical ID reported by the unit.
  • OwServer references a row in OWSERVER.
  • Type describes the device.

Most devices in OWDEVICE are also represented in INPUT or OUTPUT, where the row Name takes the form owdevice:{id} — so a thermometer becomes a readable INPUT signal you can reference with =INPUT/owdevice:{id}/Value.

PID — closed-loop control

Implements the PID (Proportional-Integral-Derivative) control algorithm: it holds a process at a setpoint by continuously adjusting an output to minimise the error between the setpoint and the measured value.

CREATE TABLE PID (
    ID INT AUTO_INCREMENT PRIMARY KEY,  -- The id of this PID instance
    INPUT double REFERENCE,             -- The input signal
    SETPOINT double REFERENCE,          -- The desired value
    Kp double,                          -- The proportional gain
    Ki double,                          -- The integral gain
    Kd double,                          -- The derivative gain
    Direction TINY,                     -- Direction of the output
    OUTPUT double REFERENCE             -- The output of the PID algorithm
);

The output is Kp·P + Ki·I + Kd·D, where P responds to the present error, I eliminates sustained steady-state error, and D dampens the response to prevent overshoot. Tuning Kp/Ki/Kd trades off stability, responsiveness, and overshoot.

INPUT, SETPOINT, and OUTPUT are reference columns — they point at rows in other tables — so a loop is composed entirely from existing signals:

INSERT INTO PID (INPUT, SETPOINT, Kp, Ki, Kd, Direction, OUTPUT)
VALUES (
    '=INPUT/owdevice:28.F049AF040000/Value',   -- measured temperature
    '=setpoints/hlt/Value',                    -- your target row
    2.0, 0.5, 1.0, 1,
    '=OUTPUT/owdevice:12.574B7D000000/Value'   -- element / relay
);

LOGGER — sampling to a table

Periodically samples a referenced value and records it, so you can build history and charts (point Grafana at the resulting table). Configure a logger by inserting a row naming what to sample and how often:

-- id, name, interval (ms), ..., source reference
INSERT INTO logger VALUES (1, 'hlt', 1000, 3, '=INPUT/owdevice:28.F049AF040000/Value');

GPIO — digital I/O

Reads digital inputs and drives digital outputs on the host’s GPIO pins (for example, Raspberry Pi). The pins it manages appear as digital (Type = 'D') signals in the INPUT and OUTPUT tables, where you read or drive them like any other signal.

SLOW_PWM — time-proportioned output

Turns a continuous 0–100% control value into a slow on/off duty cycle, so a plain relay or solid-state relay can modulate power to a resistive load like a heating element. It time-proportions the output over a sample window — a higher percentage keeps the output on for a larger fraction of each window. Point it at a control value (for example a PID output) as its input and at a digital OUTPUT signal as its output.

Custom hardware: out-of-process drivers

Beyond the built-in modules, you can add hardware by configuration with an out-of-process driver. A driver is a separate program that connects to the engine and presents itself as a virtual SQL table; its rows publish into INPUT, so a =driver/row/column reference resolves to a live reading exactly as a built-in module does. Because a driver runs in its own process, a slow or crashing driver can’t stall or crash the engine.

Declare each driver in its own [Driver <name>] section of the config file:

[Driver relays]
Exec    = serialdrv
Args    = --config relayboard.conf
Enabled = true
OptionMeaning
ExecThe driver executable. A bare name (no path) is resolved next to the engine binary in bin/, so a shipped driver needs no path; an explicit relative or absolute path is used as-is.
ArgsExtra command-line arguments passed to it (whitespace-separated).
Enabledtrue (default) spawns the driver at startup; false declares it without starting it.

The driver runs with the config file’s directory as its working directory, so a relative --config relayboard.conf resolves next to signalsql.conf — where the shipped driver sample configs are installed.

SignalSQL supervises declared drivers: it launches them at startup, restarts a crashed driver with backoff, and reaps one that has gone silent. When a driver disconnects its table and published INPUT rows are removed, so nothing serves stale values. Tuning options (DriverPort, DriverPing, DriverDead) live in the [Server] section.

Actuator writes

A driver column declared as an output is written by a SQL UPDATE: updating it sends the new value to the device — the write half of a control loop. So the same UPDATE relays SET relay1 = 1 that changes a row also switches the physical relay.

Serial devices (RS232)

SignalSQL ships a generic, data-driven serial driver — serialdrv — for the common case of relay boards and simple serial sensor modules. It binds a serial device to a SQL table entirely from a config file: no scripting, no compiling, and one binary serves many devices — each device is just another config file. The serialdrv binary installs next to the engine in bin/, with a ready-to-edit sample relayboard.conf beside the main config file:

  • Linux: /etc/opt/signalsql/relayboard.conf
  • Windows: C:\ProgramData\Centlake\SignalSQL\etc\relayboard.conf

Point a [Driver] section at it to bring it online, then restart the service:

# signalsql.conf
[Driver relayboard]
Exec = serialdrv                 ; a bare name is found next to the engine binary
Args = --config relayboard.conf  ; resolved in the config dir, where the sample installs

The device config file

INI-style, one file per device. A minimal relay board:

[serial]
port = COM3          ; /dev/ttyUSB0 on Linux
baud = 9600

[table]
name = relays        ; the SQL table this device presents
key  = board1        ; the row identity (column 0)

[output relay1]      ; one OUTPUT column per channel
on   = A0 01 01 A2   ; whitespace-separated hex to switch it on
off  = A0 01 00 A1   ; ...and off

[output relay2]
on   = A0 02 01 A3
off  = A0 02 00 A2

This presents the table main.relays with a Name identity column and two actuator columns. Drive the relays over the MySQL protocol:

UPDATE relays SET relay1 = 1 WHERE Name = 'board1';   -- sends A0 01 01 A2
UPDATE relays SET relay1 = 0 WHERE Name = 'board1';   -- sends A0 01 00 A1

A written value is truthy → on, zero or NULL → off, so 1/0, TRUE/FALSE, or any nonzero number all work. Each channel is a column, so an 8-relay board is one row with eight [output] sections and a single UPDATE can switch several at once. Because the on/off byte strings are listed literally, any checksum they carry (here A2 = A0 + 01 + 01) is already baked in — there is nothing else to compute.

Where the port lives

The port value selects one of three backends:

port =Talks to
COM3 / /dev/ttyUSB0a real serial port (8N1)
tcp:host:porta networked serial device server (ser2net, Moxa/USR converters, …)
file:<path>a dry-run sink — appends the wire bytes to a file instead of a real port (write-only), handy for checking exactly what an UPDATE sends

Reading device state back

A device you can query is described with [input <name>] sections. Each poll interval the driver sends query, matches the reply against the response regex, and streams capture group 1 back as a live reading on a column you can SELECT:

[input temp]
type     = double            ; double (default) | int | bool
poll     = 1000              ; ms between polls
query    = "READ\r"          ; bytes to send (C escapes: \r \n \t \xHH)
response = TEMP=([0-9.]+)     ; regex; capture group 1 is the value
# map    = on=1, off=0       ; optional: map matched text to a value
SELECT temp FROM relays WHERE Name = 'board1';   -- the last polled reading

A board can mix [output] and [input] sections — each becomes a column on the same row. Inputs need a readable backend (a real port or tcp:; the file: sink is write-only). If a poll gets no matching reply, the previous value stays in place.

The driver reads its config when SignalSQL spawns it, so restart the service after editing a device config.