Merge branch 'mqtts' into 'master'
Enable MQTTS using port 8883 See merge request !2
This commit is contained in:
commit
2e94b98ef2
@ -1,8 +1,6 @@
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "MQTT.h"
|
#include "MQTT.h"
|
||||||
|
|
||||||
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
|
|
||||||
WiFiClient client;
|
|
||||||
Adafruit_MQTT_Client *mqtt;
|
Adafruit_MQTT_Client *mqtt;
|
||||||
Adafruit_MQTT_Publish *mqtt_temp;
|
Adafruit_MQTT_Publish *mqtt_temp;
|
||||||
Adafruit_MQTT_Publish *mqtt_pressure;
|
Adafruit_MQTT_Publish *mqtt_pressure;
|
||||||
@ -37,16 +35,21 @@ char GPIO_SET_FEED[MAXSUBSCRIPTIONS][FEED_MAX_SIZE] = {};
|
|||||||
Adafruit_MQTT_Publish * mqttGpio[MAXSUBSCRIPTIONS] = {};
|
Adafruit_MQTT_Publish * mqttGpio[MAXSUBSCRIPTIONS] = {};
|
||||||
|
|
||||||
bool isMqttConfigured = false;
|
bool isMqttConfigured = false;
|
||||||
|
bool useMqtts = false;
|
||||||
|
|
||||||
|
|
||||||
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname) {
|
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname) {
|
||||||
mqttId = hostname;
|
mqttId = hostname;
|
||||||
|
useMqtts = (port == 8883);
|
||||||
isMqttConfigured = server[0] != '\0';
|
isMqttConfigured = server[0] != '\0';
|
||||||
|
|
||||||
if(!isMqttConfigured)
|
if(!isMqttConfigured)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mqtt = new Adafruit_MQTT_Client(&client, server, port, user, passwd);
|
if(useMqtts)
|
||||||
|
mqtt = new Adafruit_MQTT_Client(new WiFiClientSecure(), server, port, user, passwd);
|
||||||
|
else
|
||||||
|
mqtt = new Adafruit_MQTT_Client(new WiFiClient(), server, port, user, passwd);
|
||||||
mqtt_dht_temp = MqttCreatePublisher(TEMPERATURE_DHT_FEED_FORMAT, user, mqttId);
|
mqtt_dht_temp = MqttCreatePublisher(TEMPERATURE_DHT_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_dht_humidity = MqttCreatePublisher(HUMIDITY_DHT_FEED_FORMAT, user, mqttId);
|
mqtt_dht_humidity = MqttCreatePublisher(HUMIDITY_DHT_FEED_FORMAT, user, mqttId);
|
||||||
mqtt_temp = MqttCreatePublisher(TEMPERATURE_FEED_FORMAT, user, mqttId);
|
mqtt_temp = MqttCreatePublisher(TEMPERATURE_FEED_FORMAT, user, mqttId);
|
||||||
|
@ -109,7 +109,7 @@ void WebHandleSetup() {
|
|||||||
"<div><label for=\"mqttServer\">Server :</label><br/><input type=\"text\" name=\"mqttServer\" value=\"" + String(mqttServer) + "\" /> </div>"
|
"<div><label for=\"mqttServer\">Server :</label><br/><input type=\"text\" name=\"mqttServer\" value=\"" + String(mqttServer) + "\" /> </div>"
|
||||||
"<div><label for=\"mqttUser\">Username :</label><br/><input type=\"text\" name=\"mqttUser\" value=\"" + String(mqttUser) + "\" /> </div>"
|
"<div><label for=\"mqttUser\">Username :</label><br/><input type=\"text\" name=\"mqttUser\" value=\"" + String(mqttUser) + "\" /> </div>"
|
||||||
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" /> </div>"
|
"<div><label for=\"mqttPasswd\">Password :</label><br/><input type=\"password\" name=\"mqttPasswd\" style=\"border-color:red\" /> </div>"
|
||||||
"<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(mqttPort) + "\" /> </div>"
|
"<div><label for=\"mqttPort\">Port :</label><br/><input type=\"text\" name=\"mqttPort\" value=\"" + String(mqttPort) + "\" /> (8883 for secure Mqtts) </div>"
|
||||||
"</fieldset>"
|
"</fieldset>"
|
||||||
"<div class=\"button\"> <button type=\"submit\">Save</button></div>"
|
"<div class=\"button\"> <button type=\"submit\">Save</button></div>"
|
||||||
"</form>");
|
"</form>");
|
||||||
|
Loading…
Reference in New Issue
Block a user