Skip to content

Commit

Permalink
MQTT Authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
martinusGH committed Dec 8, 2015
1 parent d1d90d5 commit 619f003
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 13 deletions.
11 changes: 9 additions & 2 deletions Controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@ void MQTTConnect()
for (byte x = 1; x < 3; x++)
{
String log = "";
if (MQTTclient.connect(clientid))
{
boolean MQTTresult = false;

if ((SecuritySettings.ControllerUser) && (SecuritySettings.ControllerPassword))
MQTTresult = (MQTTclient.connect(MQTT::Connect(clientid).set_auth(SecuritySettings.ControllerUser, SecuritySettings.ControllerPassword)));
else
MQTTresult = (MQTTclient.connect(clientid));

if (MQTTresult)
{
log = F("MQTT : Connected to broker");
addLog(LOG_LEVEL_INFO, log);
subscribeTo = Settings.MQTTsubscribe;
Expand Down
3 changes: 2 additions & 1 deletion ESPEasy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
#define ESP_PROJECT_PID 2015050101L
#define ESP_EASY
#define VERSION 9
#define BUILD 48
#define BUILD 49
#define REBOOT_ON_MAX_CONNECTION_FAILURES 30
#define FEATURE_SPIFFS false

Expand Down Expand Up @@ -279,6 +279,7 @@ struct ProtocolStruct
boolean usesAccount;
boolean usesPassword;
char Name[20];
int defaultPort;
} Protocol[CPLUGIN_MAX];

int deviceCount = -1;
Expand Down
7 changes: 3 additions & 4 deletions WebServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,6 @@ void handle_config() {

char tmpString[64];



String name = urlDecode(WebServer.arg("name").c_str());
String password = urlDecode(WebServer.arg("password").c_str());
String ssid = urlDecode(WebServer.arg("ssid").c_str());
Expand Down Expand Up @@ -266,6 +264,7 @@ void handle_config() {
{
Settings.Protocol = protocol.toInt();
byte ProtocolIndex = getProtocolIndex(Settings.Protocol);
Settings.ControllerPort = Protocol[ProtocolIndex].defaultPort;
if (Protocol[ProtocolIndex].usesMQTT)
CPlugin_ptr[ProtocolIndex](CPLUGIN_PROTOCOL_TEMPLATE, 0);
}
Expand Down Expand Up @@ -327,13 +326,13 @@ void handle_config() {
reply += F("'><TR><TD>Controller Port:<TD><input type='text' name='controllerport' value='");
reply += Settings.ControllerPort;

if (Settings.Protocol == 9999)
byte ProtocolIndex = getProtocolIndex(Settings.Protocol);
if (Protocol[ProtocolIndex].usesAccount)
{
reply += F("'><TR><TD>Controller User:<TD><input type='text' name='controlleruser' value='");
reply += SecuritySettings.ControllerUser;
}

byte ProtocolIndex = getProtocolIndex(Settings.Protocol);
if (Protocol[ProtocolIndex].usesPassword)
{
reply += F("'><TR><TD>Controller Password:<TD><input type='text' name='controllerpassword' value='");
Expand Down
1 change: 1 addition & 0 deletions _C001.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event)
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = false;
Protocol[protocolCount].defaultPort = 8080;
break;
}

Expand Down
5 changes: 3 additions & 2 deletions _C002.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ boolean CPlugin_002(byte function, struct EventStruct *event)
Protocol[++protocolCount].Number = CPLUGIN_ID_002;
strcpy_P(Protocol[protocolCount].Name, PSTR(CPLUGIN_NAME_002));
Protocol[protocolCount].usesMQTT = true;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = false;
Protocol[protocolCount].usesAccount = true;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 1883;
break;
}

Expand Down
1 change: 1 addition & 0 deletions _C003.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ boolean CPlugin_003(byte function, struct EventStruct *event)
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 23;
break;
}

Expand Down
1 change: 1 addition & 0 deletions _C004.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ boolean CPlugin_004(byte function, struct EventStruct *event)
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 80;
break;
}

Expand Down
5 changes: 3 additions & 2 deletions _C005.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ boolean CPlugin_005(byte function, struct EventStruct *event)
Protocol[++protocolCount].Number = CPLUGIN_ID_005;
strcpy_P(Protocol[protocolCount].Name, PSTR(CPLUGIN_NAME_005));
Protocol[protocolCount].usesMQTT = true;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = false;
Protocol[protocolCount].usesAccount = true;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 1883;
break;
}

Expand Down
1 change: 1 addition & 0 deletions _C006.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event)
Protocol[protocolCount].usesMQTT = true;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = false;
Protocol[protocolCount].defaultPort = 1883;
break;
}

Expand Down
1 change: 1 addition & 0 deletions _C007.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ boolean CPlugin_007(byte function, struct EventStruct *event)
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 80;
break;
}

Expand Down
9 changes: 7 additions & 2 deletions __ReleaseNotes.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// R49 08-12-2015
// Changes to urldecode and WPAKey handling (contributed by ixtrader)
// Added MQTT authentication (contributed by Chrille)
// Changing protocol sets default TCP port

// R48 01-12-2015
// Code cleanup, candidate for Arduino ESP Core 2.0.0.

Expand Down Expand Up @@ -36,10 +41,10 @@
// Added support for IR signal reception (needs a third party library!)

// R38 13-10-2015
// Added support for I2C TSL2561 Luminosity Sensor
// Added support for I2C TSL2561 Luminosity Sensor (contributed by Hallard)

// R37 12-10-2015
// Added support for I2C SI7021 Temperature Humidity sensor
// Added support for I2C SI7021 Temperature Humidity sensor (contributed by Hallard)

// R36 11-10-2015
// Added support to control (max 2) Servo motors using http control commands
Expand Down

0 comments on commit 619f003

Please sign in to comment.