You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-35Lines changed: 52 additions & 35 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The first release of the library only supports QoS0 and the basic features to ge
8
8
9
9
This library is an alternative to the [pubsubclient](https://github.com/knolleary/pubsubclient) library by [knolleary](https://github.com/knolleary) which uses a custom protocol implementation.
10
10
11
-
[Download version 1.7.0 of the library.](https://github.com/256dpi/arduino-mqtt/releases/download/v1.7.0/mqtt.zip)
11
+
[Download version 1.8.0 of the library.](https://github.com/256dpi/arduino-mqtt/releases/download/v1.8.0/mqtt.zip)
12
12
13
13
*Or even better use the newly available Library Manager in the Arduino IDE.*
14
14
@@ -35,13 +35,15 @@ Here is a list of platforms that are supported:
35
35
#include<MQTTClient.h>
36
36
37
37
YunClient net;
38
-
MQTTClient client("broker.shiftr.io", net);
38
+
MQTTClient client;
39
39
40
40
unsignedlong lastMillis = 0;
41
41
42
42
voidsetup() {
43
43
Bridge.begin();
44
44
Serial.begin(9600);
45
+
client.begin("broker.shiftr.io", net);
46
+
45
47
Serial.println("connecting...");
46
48
if (client.connect("arduino", "try", "try")) {
47
49
Serial.println("connected!");
@@ -54,7 +56,7 @@ void setup() {
54
56
55
57
voidloop() {
56
58
client.loop();
57
-
// publish message roughly every second
59
+
// publish a message roughly every second.
58
60
if(millis() - lastMillis > 1000) {
59
61
lastMillis = millis();
60
62
client.publish("/hello", "world");
@@ -72,55 +74,70 @@ void messageReceived(String topic, String payload, char * bytes, unsigned int le
- **`MQTTClient(const char * hostname, int port, Client& client)`**
77
+
Initialize the object using the hostname of the broker, the brokers port (default: `1883`) and the underlying Client class for network transport:
77
78
78
-
Constructor for the `MQTTClient` object using the hostname of the broker, the brokers port (default: `1883`) and the underlying Client class for network transport.
79
-
80
-
- **`YunMQTTClient(const char * hostname)`**
81
-
- **`YunMQTTClient(const char * hostname, int port)`**
void begin(const char * hostname, int port, Client& client);
82
+
```
82
83
83
-
Constructor for the `YunMQTTClient` object using the hostname of the broker and the brokers port (default: `1883`).
84
+
_The special`YunMQTTClient`does not need the `client` parameter._
84
85
85
-
- **`int installBridge(boolean force)`**
86
+
Set the will message that gets registered on a connect:
86
87
87
-
Installs the python bridge on the linux processor. Pass `true` to force an update if the code already exists. This function only works in conjunction with the `YunMQTTClient` object. A return value of 0 means that there was an error while installing, 1 means that the bridge is already installed and 2 means that there was an update.
_This functions returns a value that indicates if the connection has been established successfully._
96
101
97
-
Connects to broker using the supplied client id and an optional username and password. This functions return value indicates if the connection has been established successfully.
102
+
Publishes a message to the broker with an optional payload:
0 commit comments