Git Product home page Git Product logo

Comments (3)

magmilo avatar magmilo commented on July 16, 2024

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.

Decezaris avatar Decezaris commented on July 16, 2024

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.

Decezaris avatar Decezaris commented on July 16, 2024

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 variable nextDupPacketID after publishing, thus every packet published afterwars will be marked as duplicate with the same ID unless you call prepareDuplicate(0) . Maybe it should be a good idea to reset nextDupPacketID after publish (successful or not)?

from arduino-mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.