Add optional notls support

main
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
#define CHECK_BIT(var,pos) ((var) & (1<<(pos)))
#ifndef MQTT_NO_TLS
WiFiClientSecure transport;
#else
WiFiClient transport;
#endif
PubSubClient mqtt;
Adafruit_BME280 bme; // I2C
@ -55,9 +59,11 @@ extern "C" {
#endif
void connect_wifi() {
#ifndef WIFI_ENTERPRISE_ENABLED
#ifndef WIFI_ENTERPRISE_ENABLED
Serial.print("personal");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
#else
#else
Serial.print("enterprise");
// Ref https://gist.github.com/Matheus-Garbelini/2cd780aed2eddbe17eb4adb5eca42bd6
// Setting ESP into STATION mode only (no AP mode or dual mode)
wifi_set_opmode(STATION_MODE);
@ -87,7 +93,7 @@ void connect_wifi() {
wifi_station_connect();
#endif
#endif
}
@ -164,11 +170,22 @@ void setup() {
}
Serial.print("MQTT: ");
#ifdef MQTT_NO_TLS
Serial.print("notls");
#else
Serial.print("tls");
transport.setInsecure(); Serial.print(".");
#endif
// mqtt.setBufferSize(1000);
mqtt.setClient(transport); 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(
("autoplant" + String(random(0, 999999))).c_str(),
("autoplant_" + String(random(0, 999999))).c_str(),
MQTT_USERNAME, MQTT_PASSWORD)
) {
/* Ref https://pubsubclient.knolleary.net/api#state

View File

@ -18,6 +18,9 @@
#define MQTT_USERNAME "autoplant"
// The password to authenticate with when connecting to the MQTT server.
#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
#define INTERVAL 5*60*1000