rasProject_01 / weSweetHome  R. 146 2026-09-26
process control       /     RasPi software         by   weinert-automation
Loading...
Searching...
No Matches
mqttHome.h File Reference

MQTT related definitions for an experimental smart home (lab) project. More...

#include <mosquitto.h>

Macros

#define SUBTOP_I
 Length of base topic including trailing /.

Functions

void mqttClean ()
 End as MQTT client.
int mqttInit ()
 Initialise as MQTT client.
void mqttPlg01Set (uint8_t const on)
 Switch the plug Plug01.
void mqttPlg02Set (uint8_t const on)
 Switch the plug PLG2.
void mqttPlg03Set (uint8_t const on)
 Switch the plug PLG3.
void mqttPlg04Set (uint8_t const on)
 Switch the plug PLG4.

Variables

char clientId [38]
 MQTT client ID.
char messCmdOffPlg [4]
 Message to turn a S20 plug off.
char messCmdOnPlg [4]
 Message to turn a S20 plug on.
char messSttOffPlg [6]
 State message: a S20 plug is now off.
char messSttOnPlg [6]
 State message: a S20 plug is now on.
struct mosquitto * mosq
 MQTT interface state.
int mosqLoopError
 Return value of mosquitto_loop.
char mqttHost [68]
 MQTT broker address or name.
int mqttPort
 MQTT broker port.
char const subTopBatU [10]
 Relative topic to subscribe Ubat (bat/volt).
char const subTopEco3 [14]
 Relative topic for topic for EcoWorthy BT readings.
char const subTopGrow [14]
 Relative topic for Growatt readings.
char subTopStPlg01 [14]
 State sub topic of S20 plug Number 01 to 09.
char const topicSubs [20]
 The MQTT topic to subscribe to.

Detailed Description

MQTT related definitions for an experimental smart home (lab) project.

MQTT is used to control relay devices like Sonoff S20 switchable plugs with Tasmota and to communicate battery and inverter values got by Bluetooth respectively Modbus by dedicated controllers.

Copyright (c) 2018 2026 Albrecht Weinert
weinert-automation.de a-weinert.de
/ / /\
/ /___ / \ |
\ /____\ /____\ | _|__
\ /\ / \ / \| |
\/ \/ \__/ \__/|_

Revision history

Rev. 218 07.09.2019 : MQTT excerpted from sweetHome2.h
Rev. 219 30.09.2019 : reconstructed after HDD crash
Rev. 144 15.09.2026 : consistent Rev., 1&1 discontinued SVN server; comments

Macro Definition Documentation

◆ SUBTOP_I

#define SUBTOP_I

Length of base topic including trailing /.

The value is 17.

See also
topicSubs

Function Documentation

◆ mqttPlg01Set()

void mqttPlg01Set ( uint8_t const on)

Switch the plug Plug01.

This function publishes the switch command via MQTT to the relay device Plug01, usually a Sonoff S20 with Tasmota.

Parameters
onswitch on when true, else off

◆ mqttPlg02Set()

void mqttPlg02Set ( uint8_t const on)

Switch the plug PLG2.

See mqttPlg01Set

◆ mqttPlg03Set()

void mqttPlg03Set ( uint8_t const on)

Switch the plug PLG3.

See mqttPlg01Set

◆ mqttPlg04Set()

void mqttPlg04Set ( uint8_t const on)

Switch the plug PLG4.

See mqttPlg01Set

◆ mqttInit()

int mqttInit ( )

Initialise as MQTT client.

On success only: subscribe, loop and publish.

Returns
0: success the common mosq is set and usable; else: errno
See also
mqttClean

◆ mqttClean()

void mqttClean ( )

End as MQTT client.

Stop and cleanup.

See also
mqttInit

Variable Documentation

◆ mqttHost

char mqttHost[68]
extern

MQTT broker address or name.

It is either the hostname or the IP address as text. like e.g. 192.168.178.86 or mqttpi.

See also
mqttPort topicSubs

◆ mqttPort

int mqttPort
extern

MQTT broker port.

It is usually the standard port 1883.

See also
mqttHost topicSubs

◆ topicSubs

char const topicSubs[20]
extern

The MQTT topic to subscribe to.

The array's lenght is 20, fitting SUBTOP_I.

See also
mqttHost mqttPort SUBTOP_I

◆ subTopBatU

char const subTopBatU[10]
extern

Relative topic to subscribe Ubat (bat/volt).

Hardware setup: (old) ESP with ADU. The EcoWorthy Bluetooth (BT) value subTopEco3 gets precedence when available.

See also
subTopEco3 subTopGrow

◆ subTopGrow

char const subTopGrow[14]
extern

Relative topic for Growatt readings.

See also
subTopEco3 subTopBatU

◆ subTopEco3

char const subTopEco3[14]
extern

Relative topic for topic for EcoWorthy BT readings.

Hardware setup 2026: M5Stamp S3; software platformIO

See also
subTopGrow subTopBatU

◆ messCmdOnPlg

char messCmdOnPlg[4]
extern

Message to turn a S20 plug on.

See also
messCmdOffPlg messSttOnPlg messSttOffPlg subTopStPlg01

◆ messCmdOffPlg

char messCmdOffPlg[4]
extern

Message to turn a S20 plug off.

See also
messCmdOmPlg messSttOnPlg messSttOffPlg subTopStPlg01 message to turn a S20 plug off

◆ subTopStPlg01

char subTopStPlg01[14]
extern

State sub topic of S20 plug Number 01 to 09.

It's preset as plug01/POWER for 01, but the digit at index [5] will be set before each use accordingly.

See also
messSttOnPlg messSttOffPlg

◆ messSttOnPlg

char messSttOnPlg[6]
extern

State message: a S20 plug is now on.

See also
messSttOffPlg subTopStPlg01

◆ messSttOffPlg

char messSttOffPlg[6]
extern

State message: a S20 plug is now off.

See also
messSttOnPlg subTopStPlg01

◆ mosq

struct mosquitto* mosq
extern

MQTT interface state.

Defined in <mosquitto.h> without description. MQTT interface (state)

◆ clientId

char clientId[38]
extern

MQTT client ID.

default value: sweetHomeControl; length: 15; max. length: 36
May be changed before mqttInit().