Standard MQTT state topics
WARNING
Supported state topics must be listed in schema_example.json under output_base_topic.
The Unit must send formatted data to the specified topics. Pepeunit processes these messages according to the unified pattern described in this section.
There are two state topics in Pepeunit:
state/pepeunit–output_base_topiclog/pepeunit–output_base_topic
state/pepeunit - output_base_topic
When does a Unit send data to this topic?
- Every
PU_STATE_SEND_INTERVALseconds as specified in env.json.
The data sent by the Unit is converted by Pepeunit into a state view in the Unit menu. This state can also be retrieved via REST and GQL.
Message format for the state/pepeunit topic
{
"ifconfig": ["192.168.0.3", "255.255.255.0", "192.168.0.1", "192.168.0.1"],
"millis": 595925249.0,
"mem_free": 12368.0,
"mem_alloc": 25648.0,
"freq": 80000000.0,
"statvfs": [4096, 4096, 763, 716, 716, 0, 0, 0, 0, 255],
"pu_commit_version": "7f1b6564c4885432a17e5892e3c98f3a2ad33658"
}Field breakdown:
ifconfig– network connection data,[ip, subnet, gateway, dns].millis– milliseconds since program start or Unix time in milliseconds.mem_free– freeRAMin bytes.mem_alloc– allocatedRAMin bytes.freq– CPU clock frequency in Hz.statvfs–flashfile system state; lets you compute used/availableflash:python[ f_bsize, # file system block size f_frsize, # fragment size f_blocks, # size of fs in f_frsize units f_bfree, # number of free blocks f_bavail, # number of free blocks for unprivileged users f_files, # number of inodes f_ffree, # number of free inodes f_favail, # number of free inodes for unprivileged users f_flag, # mount flags f_namemax, # maximum filename length ]pu_commit_version– thePU_COMMIT_VERSIONvalue from the Unit env.json. This key is used by the Pepeunit update system to track the current Unit version.
DANGER
To correctly display update statuses for a Unit, you must send pu_commit_version.
WARNING
The size of a state message sent by a Unit is limited by PU_MQTT_MAX_PAYLOAD_SIZE in the Backend ENV.
INFO
Pepeunit does not require you to send all keys shown in the example. You can, for instance, send only millis and pu_commit_version.
Sending algorithm
- Every
PU_STATE_SEND_INTERVALseconds, gather system state data. - Format the data as
json. - Send the data to the
state/pepeunittopic fromoutput_base_topicas defined in schema.json.
log/pepeunit - output_base_topic
When does a Unit send data to this topic?
The logs sent by the Unit are converted into the Unit log view in Pepeunit. These logs are also accessible via REST and GQL.
Message format for the log/pepeunit topic
Several formats are supported:
Sending a single log entry:
json{ "level": "Info", "text": "Subscribed: 83 (0, 0, 0, 0, 0)", "create_datetime": "2025-04-08T11:27:52.044394" }Sending a single log entry without timestamp:
json{ "level": "Info", "text": "Subscribed: 83 (0, 0, 0, 0, 0)" }Sending multiple logs:
json[ { "level": "Info", "text": "Subscribed: 5 (0, 0, 0, 0, 0)", "create_datetime": "2025-04-08T11:37:55.087036" }, { "level": "Debug", "text": "Unit 7d99d194-fe09-4737-b991-0a67cff966d7 get msg from topic log_sync", "create_datetime": "2025-04-08T11:38:22.828806" }, { "level": "Debug", "text": "Unit 7d99d194-fe09-4737-b991-0a67cff966d7 get msg from topic env_update", "create_datetime": "2025-04-08T11:41:15.974031" } ]Sending multiple logs without timestamps:
json[ { "level": "Info", "text": "Subscribed: 5 (0, 0, 0, 0, 0)" }, { "level": "Debug", "text": "Unit 7d99d194-fe09-4737-b991-0a67cff966d7 get msg from topic log_sync" }, { "level": "Debug", "text": "Unit 7d99d194-fe09-4737-b991-0a67cff966d7 get msg from topic env_update" } ]
Field breakdown and behavior in Pepeunit:
level– log level; one of:Debug,Info,Warning,Error,Critical.text– log message text; should ideally not exceed256characters for correct display in the Frontend.create_datetime– optional timestamp. If omitted, Pepeunit uses:
WARNING
The size of a log message sent by a Unit through EMQX is limited by the PU_MQTT_MAX_PAYLOAD_SIZE variable in the Backend ENV.
By default, logs live for 86400 seconds (~1 day). This is controlled by the PU_UNIT_LOG_EXPIRATION variable in the Backend ENV.
Sending algorithm
- Format log data as
json. - Send data to the
log/pepeunittopic fromoutput_base_topicas specified in schema.json.