Comments (3)
Hi,
I'm just trying to find an arduino library managing mqtt over websockets as my broker is set like that.
I already tried the hideakitai lib and yours but I can't connect to the broker on port 443. I'm stuck in the loop attempting connection client.connect()
and an my debug reveals that this error is thrown :
LWMQTT_MISSING_OR_WRONG_PACKET
I'm using M5stack core2.
Could you provide a working example with one of the library you mentioned ?
from arduino-mqtt.
Is it definitely websockets, and not just MQTT over SSL?. This is for an ESP32
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <WebSocketsClient.h>
#include <MQTT.h>
WebSocketsClient client;
MQTTClient mqtt;
WiFiMulti wiFiMulti;
void connect()
{
if (wiFiMulti.run() != WL_CONNECTED)
{
while (wiFiMulti.run() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
// connect to host with MQTT over WebSocket securely
Serial.print("Connecting to mqtt server as ");
String devId = "Arduino-" + String(ESP.getEfuseMac() >> 32, HEX);
Serial.println(devId);
client.beginSSL("server.com", 443, "/", "", "mqtt");
while (!client.isConnected())
{
client.loop();
delay(10);
}
// initialize mqtt client
mqtt.connect(devId.c_str(), "username", "password");
if (mqtt.connected())
{
Serial.println("Connected.");
}
else
{
Serial.println("Fail - retrying in 1 seconds]");
delay(1000);
}
}
void setup()
{
Serial.begin(115200);
wiFiMulti.addAP("wifiuser", "wifipass");
mqtt.begin(client);
connect();
}
void loop()
{
static unsigned long lastMeasure = 0;
static unsigned long measureTime = 1000 * 60;
if ((millis() - lastMeasure) > measureTime)
{
lastMeasure = millis();
// Check WiFi connection status
if (WiFi.status() != WL_CONNECTED || !mqtt.connected())
{
Serial.println("Reconnecting...");
connect();
}
// Send data on last sample
mqtt.publish("hello/world", "data goes here");
}
mqtt.loop();
delay(10);
}
Which gives the output
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13192
load:0x40080400,len:3028
entry 0x400805e4
Connecting to mqtt server as Arduino-3cab
Fail - retrying in 1 seconds]
Reconnecting...
Connecting to mqtt server as Arduino-3cab
Connected.
I've noticed that both libraries don't always connect on the first go, occasionally it takes a few retries. I'm not sure why.
from arduino-mqtt.
Thank you very much, I finally managed to connect to my broker but using hideakitai library.
With yours, along with the example you provided, I wasn't able to compile because when invoking mqtt.begin(client)
the code behind is waiting for a Client
instance and not a WebSocketsClient
's one.
though i'm not sure about my headers management.
Anyway you helped me a lot with your example ! And yes me too, the connection is failing at least once before establishing.
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
- Unreliable behaviour with reconnections HOT 3
- MQTT HOT 1
- 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.