d1sc0
d1sc0
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
ive disabled all firewall , and added an inbound rule in windows defender firewall with advanced security to allow only specific remote ports and entered the ports i tried like 1883, 8883, 8884, 8091 etc (i tried using all these ports with/without encryption and with/without websockets)
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
i tried websockeets on a different ports - 8091 and 888
protocol websockets
protocol websockets
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
ive changed mosquitto.conf like this
listener 8884
allow_anonymous true
max_connections -1
certfile C:\Users\91903\Desktop\encryption\ca-cert.pem
keyfile C:\Users\91903\Desktop\encryption\encryption2\ca-key.pem
listener 8884
allow_anonymous true
max_connections -1
certfile C:\Users\91903\Desktop\encryption\ca-cert.pem
keyfile C:\Users\91903\Desktop\encryption\encryption2\ca-key.pem
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
server is a broker service called mosquitto running on my localhost ... so its my localhost ipv4 address
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
also i used wificlientsecure to use tls with mqtt , not https
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
I didnt quite get what you meant isnt this how we can publish?
client.publish("myTopic", msg);
client.publish("myTopic", msg);
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
i generated certificates referring this
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
No description
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
(generated the certificates using openssl)
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
Ive configured my mosquitto config file also , adding the required listeners and path to certificates
29 replies
Receiving "rc= -2" error with ESP32 MQTT TLS certificates
c++
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>

const char* ssid = "my ssid";
const char* password = "redacted";
const char* mqtt_server = "mylocalhost";

const char* rootca = \
"-----BEGIN CERTIFICATE-----\n"
"-----END CERTIFICATE-----\n";

unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int countValue = 0;

WiFiClientSecure espClient;
PubSubClient client(espClient);

void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
String clientId = "ESP32Client-";
clientId += String(random(0xffff), HEX);

if (client.connect(clientId.c_str())) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}

void setup() {
Serial.begin(115200);
setup_wifi();
espClient.setCACert(rootca);
client.setServer(mqtt_server, 8883);
}

void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();

unsigned long now = millis();
if (now - lastMsg > 5000) {
lastMsg = now;
++countValue;
snprintf(msg, MSG_BUFFER_SIZE, "Count: %d", countValue);
Serial.print("Publish message: ");
Serial.println(msg);
client.publish("myTopic", msg);
}
}
c++
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>

const char* ssid = "my ssid";
const char* password = "redacted";
const char* mqtt_server = "mylocalhost";

const char* rootca = \
"-----BEGIN CERTIFICATE-----\n"
"-----END CERTIFICATE-----\n";

unsigned long lastMsg = 0;
#define MSG_BUFFER_SIZE (50)
char msg[MSG_BUFFER_SIZE];
int countValue = 0;

WiFiClientSecure espClient;
PubSubClient client(espClient);

void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
String clientId = "ESP32Client-";
clientId += String(random(0xffff), HEX);

if (client.connect(clientId.c_str())) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}

void setup() {
Serial.begin(115200);
setup_wifi();
espClient.setCACert(rootca);
client.setServer(mqtt_server, 8883);
}

void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();

unsigned long now = millis();
if (now - lastMsg > 5000) {
lastMsg = now;
++countValue;
snprintf(msg, MSG_BUFFER_SIZE, "Count: %d", countValue);
Serial.print("Publish message: ");
Serial.println(msg);
client.publish("myTopic", msg);
}
}
29 replies