Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.

Commit a2db21c

Browse files
authored
v1.0.1 to optimize library, etc.
### Releases v1.0.1 1. Fix Library Manager warnings 2. Suppress all compiler warnings 3. Optimize library code by using `reference-passing` instead of `value-passing`
1 parent 942cce4 commit a2db21c

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

examples/ESP32/FullyFeaturedSSL_ESP32/FullyFeaturedSSL_ESP32.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern "C"
2727
#define ASYNC_TCP_SSL_ENABLED true
2828
//#define ASYNC_TCP_SSL_ENABLED false
2929

30-
#include <AsyncMqttClient_Generic.h>
30+
#include <AsyncMqtt_Generic.h>
3131

3232
//#define MQTT_HOST IPAddress(192, 168, 2, 110)
3333
#define MQTT_HOST "broker.emqx.io" // Broker address
@@ -141,6 +141,8 @@ void onMqttConnect(bool sessionPresent)
141141

142142
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
143143
{
144+
(void) reason;
145+
144146
Serial.println("Disconnected from MQTT.");
145147

146148
if (WiFi.isConnected())
@@ -149,21 +151,24 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
149151
}
150152
}
151153

152-
void onMqttSubscribe(uint16_t packetId, uint8_t qos)
154+
void onMqttSubscribe(const uint16_t& packetId, const uint8_t& qos)
153155
{
154156
Serial.println("Subscribe acknowledged.");
155157
Serial.print(" packetId: "); Serial.println(packetId);
156158
Serial.print(" qos: "); Serial.println(qos);
157159
}
158160

159-
void onMqttUnsubscribe(uint16_t packetId)
161+
void onMqttUnsubscribe(const uint16_t& packetId)
160162
{
161163
Serial.println("Unsubscribe acknowledged.");
162164
Serial.print(" packetId: "); Serial.println(packetId);
163165
}
164166

165-
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
167+
void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
168+
const size_t& len, const size_t& index, const size_t& total)
166169
{
170+
(void) payload;
171+
167172
Serial.println("Publish received.");
168173
Serial.print(" topic: "); Serial.println(topic);
169174
Serial.print(" qos: "); Serial.println(properties.qos);
@@ -174,7 +179,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
174179
Serial.print(" total: "); Serial.println(total);
175180
}
176181

177-
void onMqttPublish(uint16_t packetId)
182+
void onMqttPublish(const uint16_t& packetId)
178183
{
179184
Serial.println("Publish acknowledged");
180185
Serial.print(" packetId: "); Serial.println(packetId);

examples/ESP32/FullyFeatured_ESP32/FullyFeatured_ESP32.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ extern "C"
2222
#include "freertos/FreeRTOS.h"
2323
#include "freertos/timers.h"
2424
}
25-
#include <AsyncMqttClient_Generic.h>
25+
#include <AsyncMqtt_Generic.h>
2626

2727
//#define MQTT_HOST IPAddress(192, 168, 2, 110)
2828
#define MQTT_HOST "broker.emqx.io" // Broker address
@@ -120,6 +120,8 @@ void onMqttConnect(bool sessionPresent)
120120

121121
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
122122
{
123+
(void) reason;
124+
123125
Serial.println("Disconnected from MQTT.");
124126

125127
if (WiFi.isConnected())
@@ -128,21 +130,24 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
128130
}
129131
}
130132

131-
void onMqttSubscribe(uint16_t packetId, uint8_t qos)
133+
void onMqttSubscribe(const uint16_t& packetId, const uint8_t& qos)
132134
{
133135
Serial.println("Subscribe acknowledged.");
134136
Serial.print(" packetId: "); Serial.println(packetId);
135137
Serial.print(" qos: "); Serial.println(qos);
136138
}
137139

138-
void onMqttUnsubscribe(uint16_t packetId)
140+
void onMqttUnsubscribe(const uint16_t& packetId)
139141
{
140142
Serial.println("Unsubscribe acknowledged.");
141143
Serial.print(" packetId: "); Serial.println(packetId);
142144
}
143145

144-
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
146+
void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
147+
const size_t& len, const size_t& index, const size_t& total)
145148
{
149+
(void) payload;
150+
146151
Serial.println("Publish received.");
147152
Serial.print(" topic: "); Serial.println(topic);
148153
Serial.print(" qos: "); Serial.println(properties.qos);
@@ -153,7 +158,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
153158
Serial.print(" total: "); Serial.println(total);
154159
}
155160

156-
void onMqttPublish(uint16_t packetId)
161+
void onMqttPublish(const uint16_t& packetId)
157162
{
158163
Serial.println("Publish acknowledged.");
159164
Serial.print(" packetId: "); Serial.println(packetId);

examples/ESP8266/FullyFeatured_ESP8266/FullyFeatured_ESP8266.ino

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
#include <ESP8266WiFi.h>
1616
#include <Ticker.h>
17-
#include <AsyncMqttClient_Generic.h>
17+
#include <AsyncMqtt_Generic.h>
1818

1919
//#define MQTT_HOST IPAddress(192, 168, 2, 110)
2020
#define MQTT_HOST "broker.emqx.io" // Broker address
@@ -44,12 +44,16 @@ void connectToMqtt()
4444

4545
void onWifiConnect(const WiFiEventStationModeGotIP& event)
4646
{
47+
(void) event;
48+
4749
Serial.print("Connected to Wi-Fi. IP address: "); Serial.println(WiFi.localIP());
4850
connectToMqtt();
4951
}
5052

5153
void onWifiDisconnect(const WiFiEventStationModeDisconnected& event)
5254
{
55+
(void) event;
56+
5357
Serial.println("Disconnected from Wi-Fi.");
5458
mqttReconnectTimer.detach(); // ensure we don't reconnect to MQTT while reconnecting to Wi-Fi
5559
wifiReconnectTimer.once(2, connectToWifi);
@@ -86,6 +90,8 @@ void onMqttConnect(bool sessionPresent)
8690

8791
void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
8892
{
93+
(void) reason;
94+
8995
Serial.println("Disconnected from MQTT.");
9096

9197
if (WiFi.isConnected())
@@ -94,21 +100,24 @@ void onMqttDisconnect(AsyncMqttClientDisconnectReason reason)
94100
}
95101
}
96102

97-
void onMqttSubscribe(uint16_t packetId, uint8_t qos)
103+
void onMqttSubscribe(const uint16_t& packetId, const uint8_t& qos)
98104
{
99105
Serial.println("Subscribe acknowledged.");
100106
Serial.print(" packetId: "); Serial.println(packetId);
101107
Serial.print(" qos: "); Serial.println(qos);
102108
}
103109

104-
void onMqttUnsubscribe(uint16_t packetId)
110+
void onMqttUnsubscribe(const uint16_t& packetId)
105111
{
106112
Serial.println("Unsubscribe acknowledged.");
107113
Serial.print(" packetId: "); Serial.println(packetId);
108114
}
109115

110-
void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
116+
void onMqttMessage(char* topic, char* payload, const AsyncMqttClientMessageProperties& properties,
117+
const size_t& len, const size_t& index, const size_t& total)
111118
{
119+
(void) payload;
120+
112121
Serial.println("Publish received.");
113122
Serial.print(" topic: "); Serial.println(topic);
114123
Serial.print(" qos: "); Serial.println(properties.qos);
@@ -119,7 +128,7 @@ void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProperties
119128
Serial.print(" total: "); Serial.println(total);
120129
}
121130

122-
void onMqttPublish(uint16_t packetId)
131+
void onMqttPublish(const uint16_t& packetId)
123132
{
124133
Serial.println("Publish acknowledged.");
125134
Serial.print(" packetId: "); Serial.println(packetId);

0 commit comments

Comments
 (0)