Skip to content

Commit 62663c1

Browse files
authored
Merge pull request #1 from Imroy/master
update on 2020/3/22
2 parents 11fd8d0 + beb81e3 commit 62663c1

24 files changed

Lines changed: 1050 additions & 478 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
*~
22
*#
33
/docs
4+
tests/*.o
5+
tests/bin/*
6+
tests/src/lib/*.o

examples/ESP8266-OTA/ESP8266-OTA.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ void receive_ota(const MQTT::Publish& pub) {
4444

4545
Serial.setDebugOutput(true);
4646
if (ESP.updateSketch(*pub.payload_stream(), size, true, false)) {
47-
pub.payload_stream()->stop();
4847
Serial.println("Clearing retained message.");
4948
client.publish(MQTT::Publish(pub.topic(), "")
5049
.set_retain());

examples/mqtt_will/mqtt_will.ino

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
MQTT "will" message example
3+
4+
- connects to an MQTT server with a will message
5+
- publishes a message
6+
- waits a little bit
7+
- disconnects the socket *without* sending a disconnect packet
8+
9+
You should see the will message published when we disconnect
10+
*/
11+
12+
#include <ESP8266WiFi.h>
13+
#include <PubSubClient.h>
14+
15+
const char *ssid = "xxxxxxxx"; // cannot be longer than 32 characters!
16+
const char *pass = "yyyyyyyy"; //
17+
18+
// Update these with values suitable for your network.
19+
IPAddress server(172, 16, 0, 2);
20+
21+
WiFiClient wclient;
22+
PubSubClient client(wclient, server);
23+
24+
void setup() {
25+
// Setup console
26+
Serial.begin(115200);
27+
delay(10);
28+
Serial.println();
29+
Serial.println();
30+
}
31+
32+
void loop() {
33+
delay(1000);
34+
35+
if (WiFi.status() != WL_CONNECTED) {
36+
Serial.print("Connecting to ");
37+
Serial.print(ssid);
38+
Serial.println("...");
39+
WiFi.begin(ssid, pass);
40+
41+
if (WiFi.waitForConnectResult() != WL_CONNECTED)
42+
return;
43+
Serial.println("WiFi connected");
44+
}
45+
46+
if (WiFi.status() == WL_CONNECTED) {
47+
MQTT::Connect con("arduinoClient");
48+
con.set_will("test", "I am down.");
49+
// Or to set a binary message:
50+
// char msg[4] = { 0xde, 0xad, 0xbe, 0xef };
51+
// con.set_will("test", msg, 4);
52+
if (client.connect(con)) {
53+
client.publish("test", "I am up!");
54+
delay(1000);
55+
wclient.stop();
56+
} else
57+
Serial.println("MQTT connection failed.");
58+
59+
delay(10000);
60+
}
61+
}
62+

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name=PubSubClient
1+
name=PubSubClient(imroy)
22
version=1.99.1
33
author=Nick O'Leary, Ian Tester <imroykun@gmail.com>
44
maintainer=Ian Tester <imroykun@gmail.com>

0 commit comments

Comments
 (0)