← Documentation index

SPPGATE

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
CONFIGURATION
REQUESTS
REPLIES
DIAGNOSTICS
SIGNALS
FILES
EXIT STATUS
EXAMPLES
SEE ALSO
AUTHOR
COPYRIGHT

NAME

sppgate - the gateway of sapupra: receives the scans of the scan devices and hands them to the broker

SYNOPSIS

sppgate [-c|--config FILE] [-s|--syslog] [-d|--debug |-q|--quiet]
sppgate -h
|--help
sppgate -V
|--version

DESCRIPTION

sppgate receives by HTTP the codes that the scan devices read (Binary Eye on Android, AllCodeRelay on iOS), makes of each an input of the kind scan for a location label, location, or, for the label of an item, label, and publishes it on the MQTT broker for the worker, on the topic sapupra/v1/input/DEVICE. It then answers the scan device with the worker’s verdict (the title found, or why the item is set aside), or with "queued" if no verdict came within a few seconds.

It runs in the foreground, and is put in the background by the service manager: systemd on Debian (the unit sppgate.service), daemon(8) in an rc script on FreeBSD (the script sppgate). A broker out of reach is not an error: the gateway tries again every 5 seconds, and answers "Not recorded" meanwhile.

An input stays in memory until the worker’s receipt says that it is in the database; without a receipt within receipt_timeout seconds while the worker is online, it is published again, with the same identifier, which the worker records once.

OPTIONS

-c, --config FILE

The configuration file; by default /usr/local/etc/sapupra.ini (the sysconfdir of the installation).

-s, --syslog

Log to syslog, facility daemon, instead of standard error. The normal messages are logged at the level notice, the warnings at warning, the errors at err, the debugging messages at debug: the default syslog.conf of FreeBSD keeps notice and above in /var/log/messages.

-d, --debug

Log the debugging messages too: each publication and acknowledgement. On standard error each line then begins with the time, as HH:MM:SS.mmm.

-q, --quiet

Log only the warnings and the errors, not each scan.

-h, --help

Print the usage and exit.

-V, --version

Print the version and exit.

CONFIGURATION

The file is in the INI form; a value left out takes its default. A value is taken as it is written, from after the = to the end of the line, without the spaces around it: no quotes, no escapes, any character included. A comment is a line of its own, starting with ; or #.
[broker] host
, port

The broker: the address that the listener line of its configuration names, and its port; by default localhost and 1883.

[gateway] listen

The address and the port to listen on: ADDRESS:PORT, [IPV6]:PORT, or :PORT for every address; by default :8080. ADDRESS may be a name that the machine resolves (localhost, its own name): it is resolved once, at the start, and the first IPv4 address is taken, else the first; a name that does not resolve stops the program, with the reason.

[gateway] user, password

The gateway’s account at the broker. The account’s name is also the client identifier that the gateway gives the broker, which its log shows.

[gateway] wait

Seconds to wait for the broker’s acknowledgement, then for the verdict; 1 to 60, by default 3.

[gateway] receipt_timeout

Seconds before an input without receipt is published again; 5 to 3600, by default 30.

[gateway] log_level

One of quiet, normal and debug: the same as the options -q, nothing, and -d. By default normal. The option of the command line, if there is one, wins: a service can keep a quiet or a normal level in the file, and a run by hand ask for -d without touching it.

[interface] language

The language of the pages (of the one sentence that the phone shows, for the gateway): en, the default, or a language with a catalogue installed, as fr. A language without catalogue keeps the English, and the log says which file was looked for.

[locations] prefix

The start of the code of a location label; by default LOC:.

[items] prefix

The start of the code of the label of an item; by default ITM:. The gateway checks the number and its check digit: a label misread is answered 422 "Label misread, scan again" and nothing is published. It must not begin like the location prefix, nor the reverse: the program refuses to start otherwise.

REQUESTS

POST / or POST /scan

A scan, as a JSON object: from Binary Eye, with the fields content, format, timestamp, deviceId and others, sent with the request type "POST application/json"; from AllCodeRelay, with the field code. The scan device is named by the parameter device=NAME of the URL, else by the header X-Sapupra-Device, else by Binary Eye’s deviceId, else it is unknown: 1 to 32 letters, digits, - or _. The test request of Binary Eye’s settings (content "test", format "None") is answered with the state of the broker and of the worker, and published nowhere.

GET /

The state of the gateway: the broker connected or not, the worker online or not, the number of inputs waiting for their receipt. The method HEAD, which a health check of a proxy uses, is answered the same way without the body, and records nothing.

REPLIES

To Binary Eye, a line of text, and an HTTP status outside 200 to 299 when the scan device should sound its error:

200

The title found, the title followed by "(again)" for a repeated scan, the location set by a label, or the item shown by the label of an item and where it was put. A location whose place is not made is refused (422).

202

"queued": no verdict within the wait, the worker offline, or a source that did not answer.

422

Not found, not an ISBN, several records, or not a code: set aside for the entry module.

503

"Not recorded, scan again": the broker is out of reach, or did not acknowledge the input in time.

400, 404, 415

An invalid request, another path, or a request that is not JSON.

To AllCodeRelay, a JSON object with the fields code (the kind of answer) and codevalue (the text), with the status 200 in every case but 503, so that AllCodeRelay keeps only the scans that were not recorded.

DIAGNOSTICS

A connection to the broker that fails is reported with its reason and what to check: for a refused connection, where the broker listens (sockstat -4 -l, ss -ltn) against [broker] host, which must be the address of the broker’s listener; for a refused account ("not authorised"), [gateway] user and password against the broker’s password file.

SIGNALS

SIGTERM, SIGINT

Stop: the connection to the broker is closed, and the program exits.

SIGHUP

Ignored: restart the service to read the configuration again.

FILES

/usr/local/etc/sapupra.ini

The configuration, owned by root, mode 0644: every account reads it.

/usr/local/etc/sapupra.secret.ini

The secrets (the broker’s password of the gateway), owned by root, group sapupra, mode 0640: the services read it, and its values win over the configuration’s. Its name is that of the configuration file with .secret before the .ini.

/usr/local/etc/sapupra.secret.ini.sample

An example of it.

/usr/local/etc/sapupra.ini.sample

An example of it.

EXIT STATUS

0

Stopped by a signal.

1

The configuration cannot be read or holds an invalid value, or the port cannot be listened on; the message says which and what to do.

2

A usage error.

EXAMPLES

Run it by hand, with the messages of each publication:

sppgate --debug --config ./sapupra.ini

Check it from the machine, then from the phone’s browser, at the address of the machine:

curl http://localhost:8080/

The forwarding URL to give to Binary Eye, for a scan device named pixel3a:

http://192.168.1.10:8080/scan?device=pixel3a

SEE ALSO

mosquitto(8), daemon(8), systemd.service(5), Design.org, section "The gateway"; Manual.org, section "The gateway".

AUTHOR

Péter Felecan, assisted by Claude Opus 5.5 (Anthropic).

COPYRIGHT

Copyright (C) 2026 Péter Felecan. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.