https://github.com/bulba-man/esp8266-pubsubclient-secure
https://github.com/bulba-man/esp8266-pubsubclient-secure
arduino esp8266 mqtt tls
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/bulba-man/esp8266-pubsubclient-secure
- Owner: bulba-man
- Created: 2019-04-04T14:18:42.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-11T12:53:11.000Z (about 7 years ago)
- Last Synced: 2025-06-01T07:13:10.039Z (about 1 year ago)
- Topics: arduino, esp8266, mqtt, tls
- Language: C++
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ESP8266-PubSubClient-Secure
On the Internet, there are many examples of implementing secure connections for MQTT, but they are all outdated.
I took the liberty of writing a few examples for modern libraries.
- **[ESP8266 Arduino core](https://github.com/esp8266/Arduino "ESP8266 Arduino core")** *ver* 2.5.0
- **[PubSubClient](https://github.com/knolleary/pubsubclient "PubSubClient")** *ver* 2.7
- **[ArduinoJson](https://github.com/bblanchon/ArduinoJson "ArduinoJson")** *ver* 6.10.0
## Generate Certificates
I suggest to generate certificates by myself using the [openssl](https://www.openssl.org/) utility. You can also use other certificates.
First of all, we need to generate a self-signed CA certificate.
##### Generate Key for CA:
```bash
openssl genrsa -out rootCA.key 2048
```
##### Generate self-signed CA Certificate:
```bash
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 1024 -out rootCA.pem
```
Now we generate a certificate for the client, i.e. of our device.
> **Note**: for each device you need to generate a separate key-certificate pair and sign them with a CA certificate
##### Generate private key for the client:
```bash
openssl genrsa -out client.key 2048
```
##### Request for Certificate Signing Request (CSR) to generate client certificate:
```bash
openssl req -new -key client.key -out client.csr
```
##### Generate Client Certificate:
```bash
openssl x509 -req -in client.csr -CA rootCA.pem -CAkey rootCA.key -CAcreateserial -out client.pem -days 500 -sha256
```