mosquitto_pub.1.xml 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887
  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <?xml-stylesheet type="text/xsl" href="manpage.xsl"?>
  3. <refentry xml:id="mosquitto_pub" xmlns:xlink="http://www.w3.org/1999/xlink">
  4. <refmeta>
  5. <refentrytitle>mosquitto_pub</refentrytitle>
  6. <manvolnum>1</manvolnum>
  7. <refmiscinfo class="source">Mosquitto Project</refmiscinfo>
  8. <refmiscinfo class="manual">Commands</refmiscinfo>
  9. </refmeta>
  10. <refnamediv>
  11. <refname>mosquitto_pub</refname>
  12. <refpurpose>an MQTT version 5/3.1.1/3.1 client for publishing simple messages</refpurpose>
  13. </refnamediv>
  14. <refsynopsisdiv>
  15. <cmdsynopsis>
  16. <command>mosquitto_pub</command>
  17. <group choice='req'>
  18. <arg choice='plain'>
  19. <arg><option>-h</option> <replaceable>hostname</replaceable></arg>
  20. <arg><option>--unix</option> <replaceable>socket path</replaceable></arg>
  21. <arg><option>-p</option> <replaceable>port-number</replaceable></arg>
  22. <arg><option>-u</option> <replaceable>username</replaceable></arg>
  23. <arg><option>-P</option> <replaceable>password</replaceable></arg>
  24. <arg choice='plain' rep='repeat'><option>-t</option> <replaceable>message-topic</replaceable></arg>
  25. </arg>
  26. <arg choice='plain'><option>-L</option> <replaceable>URL</replaceable></arg>
  27. </group>
  28. <arg><option>-A</option> <replaceable>bind-address</replaceable></arg>
  29. <arg><option>-c</option></arg>
  30. <arg><option>-d</option></arg>
  31. <arg><option>-D</option> <replaceable>command</replaceable> <replaceable>identifier</replaceable> <replaceable>value</replaceable></arg>
  32. <arg><option>-i</option> <replaceable>client-id</replaceable></arg>
  33. <arg><option>-I</option> <replaceable>client-id-prefix</replaceable></arg>
  34. <arg><option>-k</option> <replaceable>keepalive-time</replaceable></arg>
  35. <arg><option>--nodelay</option></arg>
  36. <arg><option>-q</option> <replaceable>message-QoS</replaceable></arg>
  37. <arg><option>--quiet</option></arg>
  38. <arg><option>-r</option></arg>
  39. <arg><option>--repeat</option> <replaceable>count</replaceable></arg>
  40. <arg><option>--repeat-delay</option> <replaceable>seconds</replaceable></arg>
  41. <arg><option>-S</option></arg>
  42. <arg><option>-V</option> <replaceable>protocol-version</replaceable></arg>
  43. <arg><option>-x</option> <replaceable>session-expiry-interval</replaceable></arg>
  44. <group choice='req'>
  45. <arg choice='plain'><option>-f</option> <replaceable>file</replaceable></arg>
  46. <arg choice='plain'><option>-l</option></arg>
  47. <arg choice='plain'><option>-m</option> <replaceable>message</replaceable></arg>
  48. <arg choice='plain'><option>-n</option></arg>
  49. <arg choice='plain'><option>-s</option></arg>
  50. </group>
  51. <arg>
  52. <option>--will-topic</option> <replaceable>topic</replaceable>
  53. <arg><option>--will-payload</option> <replaceable>payload</replaceable></arg>
  54. <arg><option>--will-qos</option> <replaceable>qos</replaceable></arg>
  55. <arg><option>--will-retain</option></arg>
  56. </arg>
  57. <group>
  58. <arg>
  59. <group choice='req'>
  60. <arg choice='plain'><option>--cafile</option> <replaceable>file</replaceable></arg>
  61. <arg choice='plain'><option>--capath</option> <replaceable>dir</replaceable></arg>
  62. </group>
  63. <arg><option>--cert</option> <replaceable>file</replaceable></arg>
  64. <arg><option>--key</option> <replaceable>file</replaceable></arg>
  65. <arg><option>--ciphers</option> <replaceable>ciphers</replaceable></arg>
  66. <arg><option>--tls-version</option> <replaceable>version</replaceable></arg>
  67. <arg><option>--tls-alpn</option> <replaceable>protocol</replaceable></arg>
  68. <arg><option>--tls-engine</option> <replaceable>engine</replaceable></arg>
  69. <arg><option>--keyform</option>
  70. <group choice='req'>
  71. <arg choice='plain'><replaceable>pem</replaceable></arg>
  72. <arg choice='plain'><replaceable>engine</replaceable></arg>
  73. </group></arg>
  74. <arg><option>--tls-engine-kpass-sha1</option> <replaceable>kpass-sha1</replaceable></arg>
  75. <arg><option>--tls-use-os-certs</option></arg>
  76. <arg><option>--insecure</option></arg>
  77. </arg>
  78. <arg>
  79. <arg choice='plain'><option>--psk</option> <replaceable>hex-key</replaceable></arg>
  80. <arg choice='plain'><option>--psk-identity</option> <replaceable>identity</replaceable></arg>
  81. <arg><option>--ciphers</option> <replaceable>ciphers</replaceable></arg>
  82. <arg><option>--tls-version</option> <replaceable>version</replaceable></arg>
  83. </arg>
  84. </group>
  85. <arg><option>--proxy</option> <replaceable>socks-url</replaceable></arg>
  86. </cmdsynopsis>
  87. <cmdsynopsis>
  88. <command>mosquitto_pub</command>
  89. <group choice='plain'>
  90. <arg><option>--help</option></arg>
  91. </group>
  92. </cmdsynopsis>
  93. </refsynopsisdiv>
  94. <refsect1>
  95. <title>Description</title>
  96. <para><command>mosquitto_pub</command> is a simple MQTT version 5/3.1.1
  97. client that will publish a single message on a topic and
  98. exit.</para>
  99. </refsect1>
  100. <refsect1>
  101. <title>Encrypted Connections</title>
  102. <para><command>mosquitto_pub</command> supports TLS encrypted
  103. connections. It is strongly recommended that you use an encrypted
  104. connection for anything more than the most basic setup.</para>
  105. <para>To enable TLS connections when using x509 certificates, one of
  106. either <option>--cafile</option> or <option>--capath</option> can
  107. be provided as an option.</para>
  108. <para>Alternatively, if the <option>-p 8883</option> option is used
  109. then the OS provided certificates will be loaded and neither
  110. <option>--cafile</option> or <option>--capath</option> are
  111. needed</para>
  112. <para>To enable TLS connections when using TLS-PSK, you must use the
  113. <option>--psk</option> and the <option>--psk-identity</option>
  114. options.</para>
  115. </refsect1>
  116. <refsect1>
  117. <title>Options</title>
  118. <para>The options below may be given on the command line, but may also
  119. be placed in a config file located at
  120. <option>$XDG_CONFIG_HOME/mosquitto_pub</option> or
  121. <option>$HOME/.config/mosquitto_pub</option> with one pair of
  122. <option>-option <replaceable>value</replaceable></option>
  123. per line. The values in the config file will be used as defaults
  124. and can be overridden by using the command line. The exceptions to
  125. this are the message type options, of which only one can be
  126. specified. Note also that currently some options cannot be negated,
  127. e.g. <option>-S</option>. Config file lines that have a
  128. <option>#</option> as the first character are treated as comments
  129. and not processed any further.</para>
  130. <variablelist>
  131. <varlistentry>
  132. <term><option>-A</option></term>
  133. <listitem>
  134. <para>Bind the outgoing connection to a local ip
  135. address/hostname. Use this argument if you need to
  136. restrict network communication to a particular
  137. interface.</para>
  138. </listitem>
  139. </varlistentry>
  140. <varlistentry>
  141. <term><option>-c</option></term>
  142. <term><option>--disable-clean-session</option></term>
  143. <listitem>
  144. <para>Disable 'clean session' / enable persistent client mode.
  145. When this argument is used, the broker will be instructed
  146. not to clean existing sessions for the same client id when
  147. the client connects, and sessions will never expire when
  148. the client disconnects. MQTT v5 clients can change their
  149. session expiry interval with the <option>-x</option> argument.
  150. </para>
  151. <para>When a session is persisted on the broker, the subscriptions
  152. for the client will be maintained after it disconnects, along
  153. with subsequent QoS 1 and QoS 2 messages that arrive. When the
  154. client reconnects and does not clean the session, it will
  155. receive all of the queued messages.</para>
  156. <para>If using this option, the client id must be set
  157. manually with <option>--id</option></para>
  158. </listitem>
  159. </varlistentry>
  160. <varlistentry>
  161. <term><option>--cafile</option></term>
  162. <listitem>
  163. <para>Define the path to a file containing PEM encoded CA
  164. certificates that are trusted. Used to enable SSL
  165. communication.</para>
  166. <para>See also <option>--capath</option></para>
  167. </listitem>
  168. </varlistentry>
  169. <varlistentry>
  170. <term><option>--capath</option></term>
  171. <listitem>
  172. <para>Define the path to a directory containing PEM encoded CA
  173. certificates that are trusted. Used to enable SSL
  174. communication.</para>
  175. <para>For <option>--capath</option> to work correctly, the
  176. certificate files must have ".crt" as the file ending
  177. and you must run "openssl rehash &lt;path to capath&gt;" each
  178. time you add/remove a certificate.</para>
  179. <para>See also <option>--cafile</option></para>
  180. </listitem>
  181. </varlistentry>
  182. <varlistentry>
  183. <term><option>--cert</option></term>
  184. <listitem>
  185. <para>Define the path to a file containing a PEM encoded
  186. certificate for this client, if required by the
  187. server.</para>
  188. <para>See also <option>--key</option>.</para>
  189. </listitem>
  190. </varlistentry>
  191. <varlistentry>
  192. <term><option>--ciphers</option></term>
  193. <listitem>
  194. <para>An openssl compatible list of TLS ciphers to support
  195. in the client. See
  196. <citerefentry><refentrytitle><link xlink:href="https://linux.die.net/man/1/ciphers">ciphers</link></refentrytitle><manvolnum>1</manvolnum></citerefentry>
  197. for more information.</para>
  198. </listitem>
  199. </varlistentry>
  200. <varlistentry>
  201. <term><option>-d</option></term>
  202. <term><option>--debug</option></term>
  203. <listitem>
  204. <para>Enable debug messages.</para>
  205. </listitem>
  206. </varlistentry>
  207. <varlistentry>
  208. <term><option>-D</option></term>
  209. <term><option>--property</option></term>
  210. <listitem>
  211. <para>Use an MQTT v5 property with this publish. If you use
  212. this option, the client will be set to be an MQTT v5
  213. client. This option has two forms:</para>
  214. <para><option>-D command identifier value</option></para>
  215. <para><option>-D command identifier name value</option></para>
  216. <para><option>command</option> is the MQTT command/packet
  217. identifier and can be one of CONNECT, PUBLISH, PUBREL,
  218. DISCONNECT, AUTH, or WILL. The properties available for
  219. each command are listed in the
  220. <link linkend='properties'>Properties</link>
  221. section.</para>
  222. <para><option>identifier</option> is the name of the
  223. property to add. This is as described in the
  224. specification, but with '-' as a word separator. For
  225. example:
  226. <option>payload-format-indicator</option>. More details
  227. are in the <link linkend='properties'>Properties</link>
  228. section.</para>
  229. <para><option>value</option> is the value of the property
  230. to add, with a data type that is property
  231. specific.</para>
  232. <para><option>name</option> is only used for the
  233. <option>user-property</option> property as the first of
  234. the two strings in the string pair. In that case,
  235. <option>value</option> is the second of the strings in
  236. the pair.</para>
  237. </listitem>
  238. </varlistentry>
  239. <varlistentry>
  240. <term><option>-f</option></term>
  241. <term><option>--file</option></term>
  242. <listitem>
  243. <para>Send the contents of a file as the message.</para>
  244. </listitem>
  245. </varlistentry>
  246. <varlistentry>
  247. <term><option>--help</option></term>
  248. <listitem>
  249. <para>Display usage information.</para>
  250. </listitem>
  251. </varlistentry>
  252. <varlistentry>
  253. <term><option>-h</option></term>
  254. <term><option>--host</option></term>
  255. <listitem>
  256. <para>Specify the host to connect to. Defaults to localhost.</para>
  257. </listitem>
  258. </varlistentry>
  259. <varlistentry>
  260. <term><option>-i</option></term>
  261. <term><option>--id</option></term>
  262. <listitem>
  263. <para>The id to use for this client. If not given, a client id will
  264. be generated depending on the MQTT version being used. For v3.1.1/v3.1,
  265. the client generates a client id in the format
  266. <option>mosq-XXXXXXXXXXXXXXXXXX</option>, where the
  267. <option>X</option> are replaced with random alphanumeric
  268. characters. For v5.0, the client sends a zero length client id, and the
  269. server will generate a client id for the client.</para>
  270. <para>This option cannot be used at the same time as the
  271. <option>--id-prefix</option> argument.</para>
  272. </listitem>
  273. </varlistentry>
  274. <varlistentry>
  275. <term><option>-I</option></term>
  276. <term><option>--id-prefix</option></term>
  277. <listitem>
  278. <para>Provide a prefix that the client id will be built
  279. from by appending the process id of the client. This is
  280. useful where the broker is using the clientid_prefixes
  281. option. Cannot be used at the same time as the
  282. <option>--id</option> argument.</para>
  283. </listitem>
  284. </varlistentry>
  285. <varlistentry>
  286. <term><option>--insecure</option></term>
  287. <listitem>
  288. <para>When using certificate based encryption, this option
  289. disables verification of the server hostname in the
  290. server certificate. This can be useful when testing
  291. initial server configurations but makes it possible for
  292. a malicious third party to impersonate your server
  293. through DNS spoofing, for example. Use this option in
  294. testing <emphasis>only</emphasis>. If you need to
  295. resort to using this option in a production
  296. environment, your setup is at fault and there is no
  297. point using encryption.</para>
  298. </listitem>
  299. </varlistentry>
  300. <varlistentry>
  301. <term><option>-k</option></term>
  302. <term><option>--keepalive</option></term>
  303. <listitem>
  304. <para>The number of seconds between sending PING commands
  305. to the broker for the purposes of informing it we are still
  306. connected and functioning. Defaults to 60 seconds.</para>
  307. </listitem>
  308. </varlistentry>
  309. <varlistentry>
  310. <term><option>--key</option></term>
  311. <listitem>
  312. <para>Define the path to a file containing a PEM encoded
  313. private key for this client, if required by the
  314. server.</para>
  315. <para>See also <option>--cert</option>.</para>
  316. </listitem>
  317. </varlistentry>
  318. <varlistentry>
  319. <term><option>--keyform</option></term>
  320. <listitem>
  321. <para>Specifies the type of private key in use when making
  322. TLS connections.. This can be "pem" or "engine". This
  323. parameter is useful when a TPM module is being used and
  324. the private key has been created with it. Defaults to
  325. "pem", which means normal private key files are
  326. used.</para>
  327. <para>See also <option>--tls-engine</option>.</para>
  328. </listitem>
  329. </varlistentry>
  330. <varlistentry>
  331. <term><option>-L</option></term>
  332. <term><option>--url</option></term>
  333. <listitem>
  334. <para>Specify specify user, password, hostname, port and
  335. topic at once as a URL. The URL must be in the form:
  336. mqtt(s)://[username[:password]@]host[:port]/topic</para>
  337. <para>If the scheme is mqtt:// then the port defaults to
  338. 1883. If the scheme is mqtts:// then the port defaults
  339. to 8883.</para>
  340. </listitem>
  341. </varlistentry>
  342. <varlistentry>
  343. <term><option>-l</option></term>
  344. <term><option>--stdin-line</option></term>
  345. <listitem>
  346. <para>Send messages read from stdin, splitting separate lines into separate messages.</para>
  347. </listitem>
  348. </varlistentry>
  349. <varlistentry>
  350. <term><option>-m</option></term>
  351. <term><option>--message</option></term>
  352. <listitem>
  353. <para>Send a single message from the command line.</para>
  354. </listitem>
  355. </varlistentry>
  356. <varlistentry>
  357. <term><option>-n</option></term>
  358. <term><option>--null-message</option></term>
  359. <listitem>
  360. <para>Send a null (zero length) message.</para>
  361. </listitem>
  362. </varlistentry>
  363. <varlistentry>
  364. <term><option>--nodelay</option></term>
  365. <listitem>
  366. <para>Disable Nagle's algorithm for the socket. This means
  367. that latency of sent messages is reduced, which is
  368. particularly noticeable for small, reasonably infrequent
  369. messages. Using this option may result in more packets
  370. being sent than would normally be necessary.</para>
  371. </listitem>
  372. </varlistentry>
  373. <varlistentry>
  374. <term><option>-p</option></term>
  375. <term><option>--port</option></term>
  376. <listitem>
  377. <para>Connect to the port specified. If not given, the
  378. default of 1883 for plain MQTT or 8883 for MQTT over
  379. TLS will be used.</para>
  380. </listitem>
  381. </varlistentry>
  382. <varlistentry>
  383. <term><option>-P</option></term>
  384. <term><option>--pw</option></term>
  385. <listitem>
  386. <para>Provide a password to be used for authenticating with
  387. the broker. Using this argument without also specifying
  388. a username is invalid when using MQTT v3.1 or v3.1.1.
  389. See also the <option>--username</option> option.</para>
  390. </listitem>
  391. </varlistentry>
  392. <varlistentry>
  393. <term><option>--proxy</option></term>
  394. <listitem>
  395. <para>Specify a SOCKS5 proxy to connect through. "None" and
  396. "username" authentication types are supported. The
  397. <option>socks-url</option> must be of the form
  398. <option>socks5h://[username[:password]@]host[:port]</option>.
  399. The protocol prefix <option>socks5h</option> means that
  400. hostnames are resolved by the proxy. The symbols %25,
  401. %3A and %40 are URL decoded into %, : and @
  402. respectively, if present in the username or
  403. password.</para>
  404. <para>If username is not given, then no authentication is
  405. attempted. If the port is not given, then the default
  406. of 1080 is used.</para>
  407. <para>More SOCKS versions may be available in the future,
  408. depending on demand, and will use different protocol
  409. prefixes as described in <citerefentry>
  410. <refentrytitle><link xlink:href="https://linux.die.net/man/1/curl">curl</link></refentrytitle>
  411. <manvolnum>1</manvolnum> </citerefentry>.</para>
  412. </listitem>
  413. </varlistentry>
  414. <varlistentry>
  415. <term><option>--psk</option></term>
  416. <listitem>
  417. <para>Provide the hexadecimal (no leading 0x)
  418. pre-shared-key matching the one used on the broker to
  419. use TLS-PSK encryption support.
  420. <option>--psk-identity</option> must also be provided
  421. to enable TLS-PSK.</para>
  422. </listitem>
  423. </varlistentry>
  424. <varlistentry>
  425. <term><option>--psk-identity</option></term>
  426. <listitem>
  427. <para>The client identity to use with TLS-PSK support. This
  428. may be used instead of a username if the broker is
  429. configured to do so.</para>
  430. </listitem>
  431. </varlistentry>
  432. <varlistentry>
  433. <term><option>-q</option></term>
  434. <term><option>--qos</option></term>
  435. <listitem>
  436. <para>Specify the quality of service to use for the message, from 0, 1 and 2. Defaults to 0.</para>
  437. </listitem>
  438. </varlistentry>
  439. <varlistentry>
  440. <term><option>--quiet</option></term>
  441. <listitem>
  442. <para>If this argument is given, no runtime errors will be
  443. printed. This excludes any error messages given in case of
  444. invalid user input (e.g. using <option>--port</option> without a
  445. port).</para>
  446. </listitem>
  447. </varlistentry>
  448. <varlistentry>
  449. <term><option>-r</option></term>
  450. <term><option>--retain</option></term>
  451. <listitem>
  452. <para>
  453. If retain is given, the message will be retained as a
  454. "last known good" value on the broker. See
  455. <citerefentry><refentrytitle><link xlink:href="mqtt-7.html">mqtt</link></refentrytitle><manvolnum>7</manvolnum></citerefentry>
  456. for more information. Note that zero length payloads
  457. are never retained. If you send a zero length
  458. payload retained message it will clear any retained
  459. message on the topic.
  460. </para>
  461. </listitem>
  462. </varlistentry>
  463. <varlistentry>
  464. <term><option>--repeat</option></term>
  465. <listitem>
  466. <para>If the publish mode is<option>-m</option>,
  467. <option>-f</option>, or <option>-s</option> (i.e. the modes
  468. where only a single message is sent), then
  469. <option>--repeat</option> can be used to specify that the
  470. message will be published multiple times.</para>
  471. <para>See also <option>--repeat-delay</option>.</para>
  472. </listitem>
  473. </varlistentry>
  474. <varlistentry>
  475. <term><option>--repeat-delay</option></term>
  476. <listitem>
  477. <para>If using <option>--repeat</option>, then the default
  478. behaviour is to publish repeated messages as soon as the
  479. previous message is delivered. Use
  480. <option>--repeat-delay</option> to specify the number of
  481. seconds to wait after the previous message was delivered
  482. before publishing the next. Does not need to be an integer
  483. number of seconds.</para>
  484. <para>Note that there is no guarantee as to the actual interval
  485. between messages, this option simply defines the minimum
  486. time from delivery of one message to the start of the
  487. publish of the next.</para>
  488. </listitem>
  489. </varlistentry>
  490. <varlistentry>
  491. <term><option>-s</option></term>
  492. <term><option>--stdin-file</option></term>
  493. <listitem>
  494. <para>Send a message read from stdin, sending the entire content as a single message.</para>
  495. </listitem>
  496. </varlistentry>
  497. <varlistentry>
  498. <term><option>-S</option></term>
  499. <listitem>
  500. <para>Use SRV lookups to determine which host to connect
  501. to. Performs lookups to
  502. <option>_mqtt._tcp.&lt;host&gt;</option> when used in
  503. conjunction with <option>-h</option>, otherwise uses
  504. <option>_mqtt._tcp.&lt;local dns
  505. domain&gt;</option>.</para>
  506. </listitem>
  507. </varlistentry>
  508. <varlistentry>
  509. <term><option>-t</option></term>
  510. <term><option>--topic</option></term>
  511. <listitem>
  512. <para>The MQTT topic on which to publish the message. See <citerefentry><refentrytitle><link xlink:href="mqtt-7.html">mqtt</link></refentrytitle><manvolnum>7</manvolnum></citerefentry> for more information on MQTT topics.</para>
  513. </listitem>
  514. </varlistentry>
  515. <varlistentry>
  516. <term><option>--tls-alpn</option></term>
  517. <listitem>
  518. <para>Provide a protocol to use when connecting to a broker
  519. that has multiple protocols available on a single port,
  520. e.g. MQTT and WebSockets.</para>
  521. </listitem>
  522. </varlistentry>
  523. <varlistentry>
  524. <term><option>--tls-engine</option></term>
  525. <listitem>
  526. <para>A valid openssl engine id. These can be listed with
  527. openssl engine command.</para>
  528. <para>See also <option>--keyform</option>.</para>
  529. </listitem>
  530. </varlistentry>
  531. <varlistentry>
  532. <term><option>--tls-engine-kpass-sha1</option></term>
  533. <listitem>
  534. <para>SHA1 of the private key password when using an TLS
  535. engine. Some TLS engines such as the TPM engine may
  536. require the use of a password in order to be accessed.
  537. This option allows a hex encoded SHA1 hash of the
  538. password to the engine directly, instead of the user
  539. being prompted for the password.</para>
  540. <para>See also <option>--tls-engine</option>.</para>
  541. </listitem>
  542. </varlistentry>
  543. <varlistentry>
  544. <term><option>--tls-use-os-certs</option></term>
  545. <listitem>
  546. <para>
  547. If used, this will load and trust the OS provided CA
  548. certificates. This can be used in conjunction with
  549. <option>--cafile</option> and <option>--capath</option>
  550. and can be used on its own to enable TLS mode. This
  551. will be set by default if <option>-L mqtts://...</option>
  552. is used, or if port is 8883 and no other certificate
  553. options are used.
  554. </para>
  555. </listitem>
  556. </varlistentry>
  557. <varlistentry>
  558. <term><option>--tls-version</option></term>
  559. <listitem>
  560. <para>Choose which TLS protocol version to use when
  561. communicating with the broker. Valid options are
  562. <option>tlsv1.3</option>, <option>tlsv1.2</option> and
  563. <option>tlsv1.1</option>. The default value is
  564. <option>tlsv1.2</option>. Must match the protocol
  565. version used by the broker.</para>
  566. </listitem>
  567. </varlistentry>
  568. <varlistentry>
  569. <term><option>-u</option></term>
  570. <term><option>--username</option></term>
  571. <listitem>
  572. <para>Provide a username to be used for authenticating with
  573. the broker. See also the <option>--pw</option>
  574. argument.</para>
  575. </listitem>
  576. </varlistentry>
  577. <varlistentry>
  578. <term><option>--unix</option></term>
  579. <listitem>
  580. <para>Connect to a broker through a local unix domain socket
  581. instead of a TCP socket. This is a replacement for
  582. <option>-h</option> and <option>-L</option>. For example:
  583. <option>mosquitto_pub --unix /tmp/mosquitto.sock ...</option>
  584. </para>
  585. <para>See the <option>socket_domain</option> option in
  586. <refentrytitle>
  587. <link xlink:href="mosquitto-conf-5.html">mosquitto.conf</link>
  588. </refentrytitle><manvolnum>5</manvolnum>
  589. to configure Mosquitto to listen on a unix socket.</para>
  590. </listitem>
  591. </varlistentry>
  592. <varlistentry>
  593. <term><option>-V</option></term>
  594. <term><option>--protocol-version</option></term>
  595. <listitem>
  596. <para>Specify which version of the MQTT protocol should be
  597. used when connecting to the rmeote broker. Can be
  598. <option>5</option>, <option>311</option>,
  599. <option>31</option>, or the more verbose
  600. <option>mqttv5</option>, <option>mqttv311</option>, or
  601. <option>mqttv31</option>.
  602. Defaults to <option>311</option>.</para>
  603. </listitem>
  604. </varlistentry>
  605. <varlistentry>
  606. <term><option>--will-payload</option></term>
  607. <listitem>
  608. <para>Specify a message that will be stored by the broker
  609. and sent out if this client disconnects unexpectedly. This
  610. must be used in conjunction with <option>--will-topic</option>.</para>
  611. </listitem>
  612. </varlistentry>
  613. <varlistentry>
  614. <term><option>--will-qos</option></term>
  615. <listitem>
  616. <para>The QoS to use for the Will. Defaults to 0. This must
  617. be used in conjunction with <option>--will-topic</option>.</para>
  618. </listitem>
  619. </varlistentry>
  620. <varlistentry>
  621. <term><option>--will-retain</option></term>
  622. <listitem>
  623. <para>If given, if the client disconnects unexpectedly the
  624. message sent out will be treated as a retained message.
  625. This must be used in conjunction with <option>--will-topic</option>.
  626. Note that zero length payloads are never retained. If you send a zero length
  627. payload retained message it will clear any retained
  628. message on the topic.
  629. </para>
  630. </listitem>
  631. </varlistentry>
  632. <varlistentry>
  633. <term><option>--will-topic</option></term>
  634. <listitem>
  635. <para>The topic on which to send a Will, in the event that
  636. the client disconnects unexpectedly.</para>
  637. </listitem>
  638. </varlistentry>
  639. <varlistentry>
  640. <term><option>-x</option></term>
  641. <listitem>
  642. <para>Set the session-expiry-interval property on the CONNECT packet.
  643. Applies to MQTT v5 clients only. Set to 0-4294967294 to specify
  644. the session will expire in that many seconds after the client
  645. disconnects, or use -1, 4294967295, or ∞ for a session that does
  646. not expire. Defaults to -1 if -c is also given, or 0 if -c not
  647. given.</para>
  648. <para>If the session is set to never expire, either with -x or -c, then
  649. a client id must be provided.</para>
  650. </listitem>
  651. </varlistentry>
  652. </variablelist>
  653. </refsect1>
  654. <refsect1>
  655. <title>Wills</title>
  656. <para>mosquitto_sub can register a message with the broker that will be
  657. sent out if it disconnects unexpectedly. See
  658. <citerefentry><refentrytitle><link xlink:href="mqtt-7.html">mqtt</link></refentrytitle><manvolnum>7</manvolnum></citerefentry>
  659. for more information.</para>
  660. <para>The minimum requirement for this is to use <option>--will-topic</option> to
  661. specify which topic the will should be sent out on. This will result in
  662. a non-retained, zero length message with QoS 0.</para>
  663. <para>Use the <option>--will-retain</option>,
  664. <option>--will-payload</option> and <option>--will-qos</option>
  665. arguments to modify the other will parameters.</para>
  666. </refsect1>
  667. <refsect1 id='properties'>
  668. <title>Properties</title>
  669. <para>The <option>-D</option> / <option>--property</option> option
  670. allows adding properties to different stages of the mosquitto_pub
  671. run. The properties supported for each command are as
  672. follows:</para>
  673. <refsect2>
  674. <title>Connect</title>
  675. <itemizedlist>
  676. <listitem><para><option>authentication-data</option> (binary data - note treated as a string in mosquitto_pub)</para></listitem>
  677. <listitem><para><option>authentication-method</option> (UTF-8 string pair)</para></listitem>
  678. <listitem><para><option>maximum-packet-size</option> (32-bit unsigned integer)</para></listitem>
  679. <listitem><para><option>receive-maximum</option> (16-bit unsigned integer)</para></listitem>
  680. <listitem><para><option>request-problem-information</option> (8-bit unsigned integer)</para></listitem>
  681. <listitem><para><option>request-response-information</option> (8-bit unsigned integer)</para></listitem>
  682. <listitem><para><option>session-expiry-interval</option> (32-bit unsigned integer, note use <option>-x</option> instead)</para></listitem>
  683. <listitem><para><option>topic-alias-maximum</option> (16-bit unsigned integer)</para></listitem>
  684. <listitem><para><option>user-property</option> (UTF-8 string pair)</para></listitem>
  685. </itemizedlist>
  686. </refsect2>
  687. <refsect2>
  688. <title>Publish</title>
  689. <itemizedlist>
  690. <listitem><para><option>content-type</option> (UTF-8 string)</para></listitem>
  691. <listitem><para><option>correlation-data</option> (binary data - note treated as a string in mosquitto_pub)</para></listitem>
  692. <listitem><para><option>message-expiry-interval</option> (32-bit unsigned integer)</para></listitem>
  693. <listitem><para><option>payload-format-indicator</option> (8-bit unsigned integer)</para></listitem>
  694. <listitem><para><option>response-topic</option> (UTF-8 string)</para></listitem>
  695. <listitem><para><option>topic-alias</option> (16-bit unsigned integer)</para></listitem>
  696. <listitem><para><option>user-property</option> (UTF-8 string pair)</para></listitem>
  697. </itemizedlist>
  698. </refsect2>
  699. <refsect2>
  700. <title>Disconnect</title>
  701. <itemizedlist>
  702. <listitem><para><option>session-expiry-interval</option> (32-bit unsigned integer)</para></listitem>
  703. <listitem><para><option>user-property</option> (UTF-8 string pair)</para></listitem>
  704. </itemizedlist>
  705. </refsect2>
  706. <refsect2>
  707. <title>Will properties</title>
  708. <itemizedlist>
  709. <listitem><para><option>content-type</option> (UTF-8 string)</para></listitem>
  710. <listitem><para><option>correlation-data</option> (binary data - note treated as a string in mosquitto_pub)</para></listitem>
  711. <listitem><para><option>message-expiry-interval</option> (32-bit unsigned integer)</para></listitem>
  712. <listitem><para><option>payload-format-indicator</option> (8-bit unsigned integer)</para></listitem>
  713. <listitem><para><option>response-topic</option> (UTF-8 string)</para></listitem>
  714. <listitem><para><option>user-property</option> (UTF-8 string pair)</para></listitem>
  715. <listitem><para><option>will-delay-interval</option> (32-bit unsigned integer)</para></listitem>
  716. </itemizedlist>
  717. </refsect2>
  718. </refsect1>
  719. <refsect1>
  720. <title>Exit Status</title>
  721. <para>
  722. mosquitto_sub returns zero on success, or non-zero on error. If
  723. the connection is refused by the broker at the MQTT level, then
  724. the exit code is the CONNACK reason code. If another error
  725. occurs, the exit code is a libmosquitto return value.
  726. </para>
  727. <para>MQTT v3.1.1 CONNACK codes:</para>
  728. <itemizedlist mark="circle">
  729. <listitem><para><option>0</option> Success</para></listitem>
  730. <listitem><para><option>1</option> Connection refused: Bad protocol version</para></listitem>
  731. <listitem><para><option>2</option> Connection refused: Identifier rejected</para></listitem>
  732. <listitem><para><option>3</option> Connection refused: Server unavailable</para></listitem>
  733. <listitem><para><option>4</option> Connection refused: Bad username/password</para></listitem>
  734. <listitem><para><option>5</option> Connection refused: Not authorized</para></listitem>
  735. </itemizedlist>
  736. <para>MQTT v5 CONNACK codes:</para>
  737. <itemizedlist>
  738. <listitem><para><option>0</option> Success</para></listitem>
  739. <listitem><para><option>128</option> Unspecified error</para></listitem>
  740. <listitem><para><option>129</option> Malformed packet</para></listitem>
  741. <listitem><para><option>130</option> Protocol error</para></listitem>
  742. <listitem><para><option>131</option> Implementation specific error</para></listitem>
  743. <listitem><para><option>132</option> Unsupported protocol version</para></listitem>
  744. <listitem><para><option>133</option> Client ID not valid</para></listitem>
  745. <listitem><para><option>134</option> Bad username or password</para></listitem>
  746. <listitem><para><option>135</option> Not authorized</para></listitem>
  747. <listitem><para><option>136</option> Server unavailable</para></listitem>
  748. <listitem><para><option>137</option> Server busy</para></listitem>
  749. <listitem><para><option>138</option> Banned</para></listitem>
  750. <listitem><para><option>139</option> Server shutting down</para></listitem>
  751. <listitem><para><option>140</option> Bad authentication method</para></listitem>
  752. <listitem><para><option>141</option> Keep alive timeout</para></listitem>
  753. <listitem><para><option>142</option> Session taken over</para></listitem>
  754. <listitem><para><option>143</option> Topic filter invalid</para></listitem>
  755. <listitem><para><option>144</option> Topic name invalid</para></listitem>
  756. <listitem><para><option>147</option> Receive maximum exceeded</para></listitem>
  757. <listitem><para><option>148</option> Topic alias invalid</para></listitem>
  758. <listitem><para><option>149</option> Packet too large</para></listitem>
  759. <listitem><para><option>148</option> Message rate too high</para></listitem>
  760. <listitem><para><option>151</option> Quota exceeded</para></listitem>
  761. <listitem><para><option>152</option> Administrative action</para></listitem>
  762. <listitem><para><option>153</option> Payload format invalid</para></listitem>
  763. <listitem><para><option>154</option> Retain not supported</para></listitem>
  764. <listitem><para><option>155</option> QoS not supported</para></listitem>
  765. <listitem><para><option>156</option> Use another server</para></listitem>
  766. <listitem><para><option>157</option> Server moved</para></listitem>
  767. <listitem><para><option>158</option> Shared subscriptions not supported</para></listitem>
  768. <listitem><para><option>159</option> Connection rate exceeded</para></listitem>
  769. <listitem><para><option>160</option> Maximum connect time</para></listitem>
  770. <listitem><para><option>161</option> Subscription IDs not supported</para></listitem>
  771. <listitem><para><option>162</option> Wildcard subscriptions not supported</para></listitem>
  772. </itemizedlist>
  773. </refsect1>
  774. <refsect1>
  775. <title>Examples</title>
  776. <para>Publish temperature information to localhost with QoS 1:</para>
  777. <itemizedlist mark="circle">
  778. <listitem><para>mosquitto_pub <literal>-t</literal> sensors/temperature <literal>-m</literal> 32 <literal>-q</literal> 1</para></listitem>
  779. </itemizedlist>
  780. <para>Publish timestamp and temperature information to a remote host on a non-standard port and QoS 0:</para>
  781. <itemizedlist mark="circle">
  782. <listitem><para>mosquitto_pub <literal>-h</literal> 192.168.1.1
  783. <literal>-p</literal> 1885 <literal>-t</literal>
  784. sensors/temperature <literal>-m</literal> "1266193804
  785. 32"</para></listitem>
  786. </itemizedlist>
  787. <para>Publish light switch status. Message is set to retained because there may be a long period of time between light switch events:</para>
  788. <itemizedlist mark="circle">
  789. <listitem><para>mosquitto_pub <literal>-r</literal> <literal>-t</literal> switches/kitchen_lights/status <literal>-m</literal> "on"</para></listitem>
  790. </itemizedlist>
  791. <para>Send the contents of a file in two ways:</para>
  792. <itemizedlist mark="circle">
  793. <listitem><para>mosquitto_pub <literal>-t</literal> my/topic <literal>-f</literal> ./data</para></listitem>
  794. <listitem><para>mosquitto_pub <literal>-t</literal> my/topic <literal>-s</literal> &lt; ./data</para></listitem>
  795. </itemizedlist>
  796. <para>Send parsed electricity usage data from a Current Cost meter, reading from stdin with one line/reading as one message:</para>
  797. <itemizedlist mark="circle">
  798. <listitem><para>read_cc128.pl | mosquitto_pub <literal>-t</literal> sensors/cc128 <literal>-l</literal></para></listitem>
  799. </itemizedlist>
  800. </refsect1>
  801. <refsect1>
  802. <title>Files</title>
  803. <variablelist>
  804. <varlistentry>
  805. <term><filename>$XDG_CONFIG_HOME/mosquitto_pub</filename></term>
  806. <term><filename>$HOME/.config/mosquitto_pub</filename></term>
  807. <listitem>
  808. <para>Configuration file for default options.</para>
  809. </listitem>
  810. </varlistentry>
  811. </variablelist>
  812. </refsect1>
  813. <refsect1>
  814. <title>Bugs</title>
  815. <para><command>mosquitto</command> bug information can be found at
  816. <ulink url="https://github.com/eclipse/mosquitto/issues"/></para>
  817. </refsect1>
  818. <refsect1>
  819. <title>See Also</title>
  820. <simplelist type="inline">
  821. <member>
  822. <citerefentry>
  823. <refentrytitle><link xlink:href="mqtt-7.html">mqtt</link></refentrytitle>
  824. <manvolnum>7</manvolnum>
  825. </citerefentry>
  826. </member>
  827. <member>
  828. <citerefentry>
  829. <refentrytitle><link xlink:href="mosquitto_rr-1.html">mosquitto_rr</link></refentrytitle>
  830. <manvolnum>1</manvolnum>
  831. </citerefentry>
  832. </member>
  833. <member>
  834. <citerefentry>
  835. <refentrytitle><link xlink:href="mosquitto_sub-1.html">mosquitto_sub</link></refentrytitle>
  836. <manvolnum>1</manvolnum>
  837. </citerefentry>
  838. </member>
  839. <member>
  840. <citerefentry>
  841. <refentrytitle><link xlink:href="mosquitto-8.html">mosquitto</link></refentrytitle>
  842. <manvolnum>8</manvolnum>
  843. </citerefentry>
  844. </member>
  845. <member>
  846. <citerefentry>
  847. <refentrytitle><link xlink:href="libmosquitto-3.html">libmosquitto</link></refentrytitle>
  848. <manvolnum>3</manvolnum>
  849. </citerefentry>
  850. </member>
  851. <member>
  852. <citerefentry>
  853. <refentrytitle><link xlink:href="mosquitto-tls-7.html">mosquitto-tls</link></refentrytitle>
  854. <manvolnum>7</manvolnum>
  855. </citerefentry>
  856. </member>
  857. </simplelist>
  858. </refsect1>
  859. <refsect1>
  860. <title>Author</title>
  861. <para>Roger Light <email>roger@atchoo.org</email></para>
  862. </refsect1>
  863. </refentry>