Add optional notls support

This commit is contained in:
Starbeamrainbowlabs 2021-12-14 18:45:45 +00:00
parent 3d42f3270b
commit f6d158236e
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
2 changed files with 24 additions and 4 deletions

View file

@ -40,7 +40,11 @@
// Ref https://stackoverflow.com/a/523737/1460422 // Ref https://stackoverflow.com/a/523737/1460422
#define CHECK_BIT(var,pos) ((var) & (1<<(pos))) #define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#ifndef MQTT_NO_TLS
WiFiClientSecure transport; WiFiClientSecure transport;
#else
WiFiClient transport;
#endif
PubSubClient mqtt; PubSubClient mqtt;
Adafruit_BME280 bme; // I2C Adafruit_BME280 bme; // I2C
@ -56,8 +60,10 @@ extern "C" {
void connect_wifi() { void connect_wifi() {
#ifndef WIFI_ENTERPRISE_ENABLED #ifndef WIFI_ENTERPRISE_ENABLED
Serial.print("personal");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD); WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#else #else
Serial.print("enterprise");
// Ref https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6 // Ref https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
// Setting ESP into STATION mode only (no AP mode or dual mode) // Setting ESP into STATION mode only (no AP mode or dual mode)
wifi_set_opmode(STATION_MODE); wifi_set_opmode(STATION_MODE);
@ -164,11 +170,22 @@ void setup() {
} }
Serial.print("MQTT: "); Serial.print("MQTT: ");
#ifdef MQTT_NO_TLS
Serial.print("notls");
#else
Serial.print("tls");
transport.setInsecure(); Serial.print("."); transport.setInsecure(); Serial.print(".");
#endif
// mqtt.setBufferSize(1000);
mqtt.setClient(transport); Serial.print("."); mqtt.setClient(transport); Serial.print(".");
mqtt.setServer(MQTT_SERVER, MQTT_PORT); Serial.print("."); mqtt.setServer(MQTT_SERVER, MQTT_PORT); Serial.print(".");
// Serial.print(MQTT_SERVER);
// Serial.print(":");
// Serial.print(MQTT_PORT);
// Serial.print(".");
if(!mqtt.connect( if(!mqtt.connect(
("autoplant" + String(random(0, 999999))).c_str(), ("autoplant_" + String(random(0, 999999))).c_str(),
MQTT_USERNAME, MQTT_PASSWORD) MQTT_USERNAME, MQTT_PASSWORD)
) { ) {
/* Ref https://pubsubclient.knolleary.net/api#state /* Ref https://pubsubclient.knolleary.net/api#state

View file

@ -18,6 +18,9 @@
#define MQTT_USERNAME "autoplant" #define MQTT_USERNAME "autoplant"
// The password to authenticate with when connecting to the MQTT server. // The password to authenticate with when connecting to the MQTT server.
#define MQTT_PASSWORD "CHANGE_ME" #define MQTT_PASSWORD "CHANGE_ME"
// Uncomment to disable TLS. NOT RECOMMENED. USE TLS WHEREVER POSSIBLE.
// PASSWORDS ARE SENT IN PLAIN TEXT WHEN YOUDO NOT USE TLS!!!!!!
//#define MQTT_NO_TLS
// The interval at which messages should be sent to the MQTT server, in seconds // The interval at which messages should be sent to the MQTT server, in seconds
#define INTERVAL 5*60*1000 #define INTERVAL 5*60*1000