Sensorclouds
Device Profiles

MQTT Settings

QoS, keep-alive, and clean session: what they do and which values to pick

ADMIN ENGINEER

A profile's MQTT Configuration tab records how devices of this type connect. Sensorclouds uses these values in two places: it sends commands at the profile's QoS, and it uses the Keep Alive to decide when a device is offline. Your device's own MQTT client must be set to match, because the profile doesn't change settings on the device.

To change the settings, open the profile, go to MQTT Configuration, click Edit, change the values, and click Save Changes.

The MQTT Configuration tab

SettingAllowed valuesDefault
Quality of Service (QoS)0, 1, or 20
Keep Alive (seconds)30–360060
Clean SessionOn or offOn
Timestamp SourcePlatform Timestamp or Device TimestampPlatform Timestamp

QoS level

Quality of Service controls the delivery guarantee for each message.

QoSNameBehaviorBest for
0At most onceSent once, with no confirmationFrequent readings where an occasional gap is fine
1At least onceConfirmed, and may arrive twiceMost devices (recommended)
2Exactly onceConfirmed exactly once, with more overheadRarely needed for telemetry

The default is 0. Change it to 1 for most devices, and use QoS 1 in your device code when it publishes telemetry, status, and command acknowledgments. Commands from the platform are sent at the profile's QoS, so QoS 1 also makes command delivery more reliable.

Keep-alive

The keep-alive is how often, in seconds, the device's MQTT client pings the broker when it has nothing else to send.

It also controls offline detection: a device that sends nothing for 1.5 × keep-alive is marked OFFLINE. With the default of 60 seconds, that's 90 seconds. See Device Status.

ValueUse for
30 s (minimum)Fastest offline detection, with more network traffic
60 s (default)Devices that report every few seconds, up to about once a minute
120–3600 sDevices that report rarely. Set it above the reporting interval, or they'll flicker offline between readings

Set the same keep-alive in your device's MQTT client, so the broker and the platform agree on when a device has gone quiet.

Clean session

SettingBehaviorUse when
On (default)The broker forgets the device's subscriptions and queued messages when it disconnectsMost devices
OffThe broker remembers subscriptions and queues QoS 1/2 messages while the device is offlineThe device must receive commands sent while it was offline

The device chooses clean session when it connects. Set the same value in your device code for the behavior above to apply.

Timestamp source

Platform Timestamp stamps each reading with the time it arrived. Device Timestamp uses the timestamp in the payload. See Creating Device Profiles.

Troubleshooting

Message or symptomCauseFix
mqttKeepAlive must be at least 30 secondsThe value is below 30Use 30 or more
Devices flicker between ONLINE and OFFLINEThey report less often than 1.5 × keep-aliveRaise the keep-alive above the reporting interval, or publish more often
A device that lost power still shows ONLINE for a whileOffline detection waits 1.5 × keep-aliveLower the keep-alive, and set a Last Will (see Connecting Your Device)
Commands sent while the device was offline never arriveClean session is on, or QoS is 0Turn clean session off in the device code, and use QoS 1
MQTT configuration is only applicable for MQTT transport typeThe profile's transport type isn't MQTTEdit the profile and choose MQTT

Next Steps

On this page