Comments (3)
I created a minimal (working) example for the Arduino IDE:
#include <Arduino_ConnectionHandler.h>
#include <WiFi.h>
#include <SSLClient.h>
#include <MQTT.h>
#include "certificates.h"
WiFiClient tcpClient;
SSLClient sslClient = SSLClient(tcpClient, TAs, (size_t)TAs_NUM, A0, SSLClient::SSL_WARN);
MQTTClient* mqttClient = new MQTTClient(192);
WiFiConnectionHandler wifiConnectionHandler(ssid, password);
int lastPublish = 0;
void setup() {
wifiConnectionHandler.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect);
wifiConnectionHandler.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect);
wifiConnectionHandler.addCallback(NetworkConnectionEvent::ERROR, onNetworkError);
mqttClient->begin(HiveMQ_URL, 8883, sslClient);
}
void loop() {
wifiConnectionHandler.check();
if (mqttClient->connected()) {
mqttClient->loop();
int currentMillis = millis();
if (currentMillis - lastPublish > 10000) {
mqttClient->publish("topic", "log");
lastPublish = currentMillis;
}
}
}
void onNetworkConnect() {
Serial.println(">>>> CONNECTED to network");
mqttClient->connect(clientId, username, password);
}
void onNetworkDisconnect() {
Serial.println(">>>> DISCONNECTED from network");
}
void onNetworkError() {
Serial.println(">>>> ERROR");
}
To make the example work, a certificates.h needs to be generated from the SSLClient library.
If you are having problems with this and using HiveMQ to test, I can provide you with my generated file.
Hope someone can help me figure this out :)
from arduino-mqtt.
Same problem here, I'm using TinyGSM
with qos = 0
everithing works fine, even in reconnections... when I change to qos = 1
and a disconnection occurs, it becomes very unstable.
obs.: I'm using AWS IoT Core broker.
from arduino-mqtt.
Hi @magmilo , updates here!
I solved this problem here for qos1
at least, because AWS IoT Core has no support for qos2
, the solution was holding the next publications depending on PUBACK
. I think it's something related to how to handle the PUBACK from broker, but doing that worked fine here. Including prepareDuplicated
function with this adapted solution (#293) , everything works great!
@256dpi First, congratulations for this excellent job, if you can add this to the Readme I think it will help a lot!
Another thing that you could add is that your library can be installed with arduino-cli named as MQTT
Hi @256dpi I think I have a "kind of bug" in the way the duplicate is handled.
If you use the new function
prepareDuplicate(duplicateID)
it will publish as duplicate OK. But internally, it will not reset the class variablenextDupPacketID
after publishing, thus every packet published afterwars will be marked as duplicate with the same ID unless you callprepareDuplicate(0)
. Maybe it should be a good idea to resetnextDupPacketID
after publish (successful or not)?
from arduino-mqtt.
Related Issues (20)
- Issue with latest lwmqtt and the separation of the header and the payload HOT 4
- MQTT reconnection when not disconnected. ESP8266 HOT 6
- MQTT HOT 1
- Websockets support HOT 3
- MQTT SSL connection issue with QoS1 and QoS2 messages HOT 1
- DCU: cannot connect to local MQTT broker HOT 1
- This library uses some posix functions that are not provided for Uno R4 HOT 3
- Subscribe query HOT 1
- Release version `v2.5.1` different of master version HOT 1
- 0
- Error connect MQTT SSL/TLS with module CBU use platform libretiny
- RP2040 seems to work fine HOT 2
- payload length / reconnect HOT 1
- Random error in MQTTClient::loop() function HOT 2
- Cosmetics only in MQTTClient.h / MQTTClient(...)
- Wrong version in README.md?
- ESP32 PSRAM for MQTT buffer?
- if available bytes on the network is available, close connection. HOT 1
- MQTT5 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arduino-mqtt.