Mosquitto_sub - Timestamp Format

Hi - I’m using OSS Mosquitto on Linux.

I have mosquitto_pub on a Raspberry Pi publishing sensor data to a broker, and then mosquitto_sub on a Rocky Linux box to receive the data for further processing.

For various reasons, it’s easiest for me to consume the data in a JSON format, so I’m running _sub with the -F %j command line argument. The JSON payload includes a timestamp that looks like this: “2024-11-01T12:59:12.393613-0400”. I need this timestamp in a Unix timestamp format (i.e. 1730482113, either in ms or ns), but I can’t figure out how to get there. I don’t see any settings in the broker or pub/sub that can change this.

I’ve tried using jq and strptime(), but it can’t handle fractional seconds. I’ve seen examples on the internet where it looks like _sub is putting out Unix timestamps, but I don’t see how that’s happening.

So, how can I get the timestamp from mosquitto_sub to be in a Unix timestamp format?

Thanks.

Hi,

I’m afraid it’s not currently possible to have a unix timestamp in the json output.

Cheers,

Roger