File README.md

Last commit: Wed Dec 25 18:37:20 2024 +0100	Jan Dankert	Initial release, the original code is taken from OpenRat CMS.
1 # MQTT Client 2 3 This is a MQTT client for PHP applications 4 5 ## Installing a broker 6 7 Install a MQTT broker like Mosquitto 8 9 sudo apt install mosquitto 10 11 ### Sending some example messages with mosquitto 12 13 Send a message to a test topic 14 15 mosquitto_pub 0 -r -m "ON" -t "test/switch" 16 17 And read it from the topic 18 19 mosquitto_sub -C 1 -t "test/switch" 20 21 gives you the value "ON". 22 23 ## Usage 24 25 ### Open a connection to the MQTT broker 26 27 A very simple example would be 28 29 $client = (new Mqtt()) 30 ->open() 31 ->connect(); 32 33 which connects to a local MQTT broker (on localhost) without authentication. 34 35 But you may specify the host, clientId, user, password and logging: 36 37 $client = (new Mqtt()) 38 ->setLog( function ($log) { echo "<pre>$log</pre>"; } ) 39 ->setClientId("test") 40 ->open('mqtt://localhost') 41 ->connect('<user>','<password>'); 42 43 ### Sending a value to a MQTT topic 44 45 $client->publish( $topic, $value ); 46 47 ### Getting a value from the MQTT broker for a topic 48 49 $value = $client->subscribe( $topic ); 50 51 ## Beware 52 53 - The client is only able to get retained messages. It cannot listen to upcoming mqtt event because of the request-based function of a PHP script. 54 - The client is always sending in QOS level 1 55 - Support for MQTT 3.1
Download README.md
History Wed, 25 Dec 2024 18:37:20 +0100 Jan Dankert Initial release, the original code is taken from OpenRat CMS.