timmbogner / Farm-Data-Relay-System

A system that uses ESP-NOW, LoRa, and other protocols to transport sensor data in remote areas without relying on WiFi.
MIT License
485 stars 108 forks source link

MQTT over TLS/SSL #162

Closed PerRieland closed 1 year ago

PerRieland commented 1 year ago

Some cloud MQTT services will only work over TLS/SSL. It would be nice if FDRS had the option to connect encrypted. I made some small changes to fdrs_gateway_mqtt.h so it could connect via SSL. Maybee not the right way to do it, but it can be used as a starter. It works with EMQX cloud. Here is what i did in fdrs_gateway_mqtt.h: 1: Add #include 2: Add a certificate 3: Changed WiFiClient espClient; to WiFiClientSecure espClient; 4: In void begin_mqtt(), set the certificate using espClient.setCACert(ca_cert);

fdrs_gateway_mqtt.zip

timmbogner commented 1 year ago

Very cool, thanks for posting this! There's another user aiming for something like this to use AWS.

Can WiFiClientSecure fully replace regular WiFiClient? If so, I can find a way to make it into an optional element and put it into the official code at some point without much extra fuss.

PerRieland commented 1 year ago

Not sure if WiFiClientSecure can replace WiFiClient. It compile and upload without any problems. But when trying to use a NON SSL MQTT services, i failed.