ayatec logo
Home Store Blog Contact
unispa user guide by ayatec
Home Store Blog Contact

Topics

  1. Getting started
    1. What is unispa
    2. Hardware specification
    3. Connectivity
    4. System controls
    5. Integration options
    6. Network API - HTTP
    7. Network API - MQTT
    8. Network security
    9. Download
  2. Web Interface
    1. Process
      1. Cabin
      2. Pool
      3. Kneipp
    2. Peripheral
      1. Calibration
      2. Mapping (edit)
    3. Device
    4. Network
    5. System

In this article

  • Introduction
advert
unispa > Getting Started > API - MQTT

API - MQTT

Every unispa device is equipped with an MQTT protocol serving for a daily communication with the device. Unlike HTTP , MQTT API is not capable of granting full control over the system or program settings. Its designation is limited to:

  • Obtaining sensor readings and output states
  • Accessing basic program settings, especially times and thresholds
  • Sending basic commands

The necessary prerequisite for using the MQTT API is active and stable connection to an MQTT broker. In choosing one, the user can choose from the following two main options:

  1. Hosting own broker - this itself contains a wide variety of options ranging from having a microcomputer like Raspberry PI connected to your local area network, to reserving capacity on a professional online server.
  2. Using external service - there is a plenty of ready-to-use online MQTT brokers ranging from free to industrial grade services.

A unispa device may connect to all the options contained above. Whatever the final broker choice, all necessary connection details can be provided on the Wireless set-up page. You may also want to check our MQTT connection tutorial for a practical quide and examples.

The SSL-protected connection is only available with additional support. For more info on the safety topic you may check the Security page.

MQTT Message

The main unit of the MQTT exchange is a message consisting of the Payload carrying the data and the Topic carrying the context. While the Payload of the unispa MQTT messages only contain a simple numeric, logical or time value, Topic of those messages is crucial for addressing the right subject of the right device.

For the sake of simplicity the payload of MQTT messages exhanged with unispa is never in the JSON form.

Addressing the device

The first task is to identify the device to communicate with. This purpose is served by setting up the first three levels of the MQTT message topic accessible in the Wireless set-up page. The user may define each of the first three topic levels there. Each may be up to 25 characters long and the first one must not be empty.

Standard rules for MQTT topics also apply. For the individual topic levels you should only use UTF-8-compatible characters other than + , # (wildcards) or / (separator).
  • Topic Level 1 is compulsory and serves mainly to identify the user. It is a good practice to set it equal to the broker account user name, or any unique string assigned to this account.
  • Topic Level 2 is optional and is intended to identify the place of duty or designation. It is a good practice to briefly describe the device's location here.
  • Topic Level 3 is optional and is intended to unambiguously identify the device in case of a larger concentration of devices is used in a single location. It is a good practice to set it equal to the device Name.
Keep the topic levels concise and well understandable by anyone who may need to use them.
Topic set-up

By adding another level flagging the message direction - pub for outbound and sub for inbound message from the device perspective - we arrive at the pub/sub Topic roots representing the main basis for the two-way communication with the device. All messages sent by the device then have their topics starting with:
[Topic L1] / [Topic L2]* / [Topic L3]* /pub/

* if non-empty

, just as all messages accepted by the device must have topics starting with:
[Topic L1] / [Topic L2]* / [Topic L3]* /sub/

* if non-empty
If the second and/or third topic level is left empty, their subsequent separators are also left out from the final topic as empty topic levels are not allowed by the protocol.

Finally, as long as the Subscription is enabled, the device is automatically subscribed to receive all messages satisfying following topic rule:
[Topic L1] / [Topic L2]* / [Topic L3]* /sub/#

* if non-empty

Similarly, the user may receive all messages published by the device by subscribing to:
[Topic L1] / [Topic L2]* / [Topic L3]* /pub/#

* if non-empty
The character # is a wildcard meaning any valid continuation of the topic. Please check the MQTT protocol for more details.
Good MQTT apps like IoT MQTT Panel will let you define a dashboard prefix which is automatically added to each individual panel. Setting it equal to the Topic root (with or without pub/ or sub/) may save a significant effort when setting up your personalised dashboard.

Addressing the subject

Once the required Device is identified, the remaining topic levels will address the desired subject of the MQTT message. These can be divided into 3 main groups as detailed out in the following sections:

  • Telemetry - sensor readings and output states
  • Parameters - basic program settings, especially times and thresholds
  • Commands - basic executable instructions

Telemetry

To receive the required telemetry data as a payload, the user needs to subscribe to messages with the following topic:
[Topic L1] / [Topic L2]* / [Topic L3]* /pub/ [TELEMETRY]

* if non-empty

All telemetry messages are sent with Retain = true and QoS = 0. For detailed reference on the message Payload and topic's [TELEMETRY] please consult the table below:

[TELEMETRY] Payload Note Relevance
tempmainnumeric readingPrimary temperature reading on I2 (T1NTC).Cabin
tempauxSecondary temperature reading on I4 (T2NTC).
tempdhtTemperature / Rel. Humidity reading from DHT22 on D4.
humdht
temp1Temperature reading of the cold pool 1 on I3 (T1NTC).Kneipp
temp2Temperature reading of the cold pool 2 on I4 (T2NTC).
temp3Temperature reading of the hot pool 1 on I5 (T3NTC).
temp4Temperature reading of the hot pool 2 on I6 (T4NTC).
RE1/output"0" - Off, or
"1" - On
Respective relay state as per the valid configuration. All, according to the valid configuration
RE2/output
RE3/output
RE4/output
RE5/output
RE6/output
RE7/output
RE8/output
RE9/output
RE10/output
RE11/output
RE12/output

Technical messages

Several technical messages are automatically published 30 seconds after a successful connection to an MQTT broker and then repeatedly every 5 minutes for the entire duration of the session:

If the Minimal option is selected for the MQTT connection, the technical messages are only sent once upon establishing connection with the broker and are not repeated afterwards.
  1. Connection status - with the Payload equal to 1 and the following topic:

    [Topic L1] / [Topic L2]* / [Topic L3]* /pub/conn

    * if non-empty

    At the same time, a Testament message is saved within the broker using the same topic and Payload equal to 0.

    The Testament (i.e., Will, or Last Will) message is automatically delivered to all subscribed clients up to 30 seconds after the device's connection with the broker is lost.
  2. IP address - with the latest local network IPv4 address as Payload and the topic as follows:

    [Topic L1] / [Topic L2]* / [Topic L3]* /pub/ip

    * if non-empty
  3. Wi-Fi RSSI - with the Wi-Fi signal strength (RSSI) as Payload and the topic as follows:

    [Topic L1] / [Topic L2]* / [Topic L3]* /pub/rssi

    * if non-empty
Subscribe to all technical messages described above to always keep track of the device's status. They can reliably inform you of whether your device is connected and its network location.
Example of MQTT technical messages displayed in a Node-RED dashboard.

Parameters

To set or change the selected program parameter, publish the message with the new value as a payload and the following topic:
[Topic L1] / [Topic L2]* / [Topic L3]* /sub/ [PARAMETER]

* if non-empty

Sending the message with Retain = true will allow to keep the respective parameter updates in real time throughout all devices connected to the given topic. For detailed reference on the message Payload and topic's [PARAMETER] please consult the table below:

[PARAMETER] Variable Payload Note Relevance
masterstateMain state0 for OFF, or
1 for On, or
2 for Auto, or
3 for Sleep, or
4 for Test
Determines the main operating state of the program.

note: Changes made to the physical switch override the saved value and vice versa.
All
timefrom1OperationHH:MM
in 24h format

(HH:MM:SS also accepted, although seconds are ignored)
Module's operation start time for the respective days of the week.
timefrom2
timefrom3
timefrom4
timefrom5
timefrom6
timefrom7
timeto1Module's operation end time for the respective days of the week.
timeto2
timeto3
timeto4
timeto5
timeto6
timeto7
endtimefromDrainStart and end time of the automated water drain.Kneipp
endtimeto
ledmodMode (LED)Follow here for value reference Main program Mode of the RGB driver to be played.All
ledspdSpeed (LED)integer between
0 and 100
Determines the maximum Speed of the RGB driver program.
ledbrtBrightness (LED) Determines the maximum Brightness of the LED's.
ledhexColor (LED)standard 6-digit (non-abbreviated) RGB hex code #RRGGBB**
(web color)
Determines the base color for the RGB program. Only effective for relevant programs.Kneipp
Pool
pirmodPIR circuit 0 for NC, or
1 for NO
Circuit of the PIR sensor in the resting state (no movement detected) Kneipp
fillmodFill mode0 for Timer, or
1 for Thermostat
Pools' operating Mode:
Timer - filling is regulated by the set times.
Thermostat - filling is regulated by the preset temperatures.
fillupFilling-up0 for Disabled, or
1 for Enabled
If Enabled, the modules operation is initiated by Filling-up the pools with warm and cold water, respectively. It should be Disabled if the pools are usually filled prior to the program start.

note: Changes made to the physical switch override the saved value and vice versa.
airpumpAir pumpdecimal number between
0 and 9999.9
Time for which an Air pump is running following a movement detected by the PIR sensor (in minutes with up to 1 decimal place).
timhotonRefillingDuration of the ON/OFF-phase of the Refill timer cycle for warm / cold pools (in minutes with up to 1 decimal place). Only relevant if the Timer Fill mode is selected.
timcoldon
timhotoffPause (Refilling)
timcoldoff
filluphotFill-up (pools) Fill-up time for the warm/cold pools (in minutes with up to 1 decimal place) at the beginning of the operation if allowed.
fillupcold
tempcoldminMin. Temp.integer between
0 and 40
The lower / upper bound of the warm / cold pools' Temperature range to be maintained. Only relevant if the Thermostat Fill mode is selected.
temphotmin
tempcoldmaxMax. Temp.
temphotmax
saunaoptConfiguration 0 for None,
or
12: Steam
cabin,
or
13: Biosauna,
or
14: Hot sauna,
or
15: Herbal
inhalation
Defines the main hardware Configuration of the cabin module.Cabin
heatpowerPower integer between
0 and 100
Power of the steam or heat generator in % when re-heating. Only active when the temperature reading is in the predefined range.
dsmpowerDSM PowerAs long as the incoming DSM signal is HIGH, the power output cannot exceed this value, overriding the standard operation.
humidlowMin./Max.
Humidity
The lower / upper bound of the ambient air's Relative Humidity range to be maintained.
humidhigh
templowMin./Max.
Temperature
integer between
0 and 105
The lower / upper bound of the ambient air's Temperature range to be maintained.
temphigh
aromaoptAroma 0 for Auto,
or
1 for Aroma A, or
2 for Aroma B, or
3 for Aroma C
Selects the Aroma for dosing.
aromaonAroma
on / wait
integer between
0 and 255
Duration of the ON (dosing) / OFF (waiting) phase of the Aroma dosing timer cycle. (ON phase expressed in seconds, OFF phase is in minutes with up to 1 decimal place). Only active when the temperature reading is in operating range.
aromaoffdecimal number between
0 and 9999.9
sprinkleonSprinkler
on / wait
integer between
0 and 255
Duration of the ON (sprinkling) / OFF (waiting) phase of the sauna stones Sprinkler timer cycle. (ON phase expressed in seconds, OFF phase is in minutes with up to 1 decimal place)
sprinkleoffdecimal number between
0 and 9999.9
ventonVent
on / wait
Duration of the ON (valve closed) / OFF (valve open) phase of the Ventilation timer cycle. (in minutes with up to 1 decimal place). Only active when the temperature reading is in operating range.
ventoff
recirconRecirculation
on / wait
Duration of the ON (recirculating) / OFF (waiting) phase of the Recirculation timer cycle. (in minutes with up to 1 decimal place). Only active when the temperature reading is in operating range.
recircoff
heatonHeating / Wait
time
Duration of the ON (heating) / OFF (waiting) phase of the Heating timer cycle. (in minutes with up to 1 decimal place). Only active when the temperature reading is in operating range.
heatoff

Commands

To execute the selected command, publish the message with the following topic:
[Topic L1] / [Topic L2]* / [Topic L3]* /pub/ [COMMAND]

* if non-empty
Always send commands with Retain = false as otherwise the command will be executed after every subscription to the MQTT. Please note that the retained messages can only be overwritten with a new payload, but not withdrawn or deleted. This makes retain useful for sensor readings, but undesirable for one-off commands.

For detailed reference on the message Payload and topic's [COMMAND] please consult the table below:

[COMMAND] Note
rebootReboots the device.
© 2024 ayatec.eu • Found a mistake?  Let us know!