Enable MQTTS using port 8883

This commit is contained in:
Mathieu Maret 2016-09-15 22:43:00 +02:00
parent d0707599c2
commit 12c5b9e1b7
2 changed files with 7 additions and 4 deletions

View File

@ -1,8 +1,6 @@
#include <stdarg.h>
#include "MQTT.h"
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
Adafruit_MQTT_Client *mqtt;
Adafruit_MQTT_Publish *mqtt_temp;
Adafruit_MQTT_Publish *mqtt_pressure;
@ -37,16 +35,21 @@ char GPIO_SET_FEED[MAXSUBSCRIPTIONS][FEED_MAX_SIZE] = {};
Adafruit_MQTT_Publish * mqttGpio[MAXSUBSCRIPTIONS] = {};
bool isMqttConfigured = false;
bool useMqtts = false;
int MqttSetup(char *server, char *user, char *passwd, int port, char * hostname) {
mqttId = hostname;
useMqtts = (port == 8883);
isMqttConfigured = server[0] != '\0';
if(!isMqttConfigured)
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_humidity = MqttCreatePublisher(HUMIDITY_DHT_FEED_FORMAT, user, mqttId);
mqtt_temp = MqttCreatePublisher(TEMPERATURE_FEED_FORMAT, user, mqttId);

View File

@ -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=\"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=\"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>"
"<div class=\"button\"> <button type=\"submit\">Save</button></div>"
"</form>");