Skip to content

Commit

Permalink
Merge pull request #36 from HomeControlAS/issue_30_mqtt_encryption
Browse files Browse the repository at this point in the history
added support for encryption
  • Loading branch information
sekyHC authored Oct 5, 2018
2 parents 3238307 + 734126d commit 9181c0b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
5 changes: 4 additions & 1 deletion examples/basic_Color/basic_Color.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "HomeControlMagic.h"
#include "Endpoints/EndpointColor.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -15,6 +16,8 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "COLOR_DEVICE"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

bool active_pin_state = true; // reverse pin state

Expand All @@ -24,7 +27,7 @@ uint16_t last_color_R = 0;
uint16_t last_color_G = 0;
uint16_t last_color_B = 0;

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);
EndpointColor endpointColor(&hcm);

uint16_t adjLevel(uint16_t color_X, uint16_t level)
Expand Down
7 changes: 5 additions & 2 deletions examples/basic_Level/basic_Level.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "HomeControlMagic.h"
#include "Endpoints/EndpointLevel.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -13,13 +14,15 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "LEVEL_DEVICE"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

bool active_pin_state = false; // reverse pin state

bool last_state = false;
uint16_t last_level = 0;

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);
EndpointLevel endpointLevel(&hcm);

void controlPin()
Expand Down Expand Up @@ -67,4 +70,4 @@ void loop()
{
controlPin();
hcm.doMagic();
}
}
7 changes: 5 additions & 2 deletions examples/basic_Motion/basic_Motion.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "HomeControlMagic.h"
#include "Endpoints/EndpointMotion.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -14,11 +15,13 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "MOTION_SENSOR"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

bool active_pin_state = false; // reverse pin state
bool last_motion = false;

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);
EndpointMotion endpointMotion(&hcm);

void controlPin()
Expand Down Expand Up @@ -61,4 +64,4 @@ void loop()
{
controlPin();
hcm.doMagic();
}
}
7 changes: 5 additions & 2 deletions examples/basic_OnOff/basic_OnOff.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "HomeControlMagic.h"
#include "Endpoints/EndpointOnOff.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -13,11 +14,13 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "ON_OFF_DEVICE"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

bool active_pin_state = false; // reverse pin state
bool last_state = false;

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);
EndpointOnOff endpointOnOff(&hcm);

void controlPin()
Expand Down Expand Up @@ -55,4 +58,4 @@ void loop()
{
controlPin();
hcm.doMagic();
}
}
7 changes: 5 additions & 2 deletions examples/basic_Temperature/basic_Temperature.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Endpoints/EndpointTemperature.h"
#include "DHT.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -16,8 +17,10 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "TEMPERATURE_SENSOR"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);
EndpointTemperature endpointTemperature(&hcm);

DHT dht(DHT_PIN, DHTTYPE);
Expand Down Expand Up @@ -66,4 +69,4 @@ void loop()
}

hcm.doMagic();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Endpoints/EndpointOnOff.h"
#include "DHT.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -18,11 +19,13 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "TERMOSTAT"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

bool active_pin_state = false; // reverse pin state
bool last_state = false;

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);

EndpointTemperatureTarget endpointTemperatureTarget(&hcm);
EndpointOnOff endpointOnOff(&hcm);
Expand Down Expand Up @@ -104,4 +107,4 @@ void loop()

controlPin();
hcm.doMagic();
}
}
7 changes: 5 additions & 2 deletions examples/basic_multipleEndpoints/basic_multipleEndpoints.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Endpoints/EndpointTemperature.h"
#include "DHT.h"
#define ESP_LOOP
#define SECURE
#define WIFI_SSID "" // Wifi network name
#define WIFI_PASS "" // Wifi password
#include "NetworkLoops.hpp"
Expand All @@ -19,8 +20,10 @@

static char* const GW_IP = "GW_IP"; // gateway IP address
static char* const deviceName = "TEMPERATURE_SENSORS"; // name of device
static char* const username = "hc"; // copy username from app
static char* const password = ""; // copy password from app

HomeControlMagic hcm(GW_IP, deviceName, network);
HomeControlMagic hcm(GW_IP, deviceName, network, username, password);

EndpointTemperature endpointTemperature_1(&hcm);
EndpointTemperature endpointTemperature_2(&hcm);
Expand Down Expand Up @@ -83,4 +86,4 @@ void loop()
}

hcm.doMagic();
}
}
11 changes: 9 additions & 2 deletions src/HomeControlMagic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ HomeControlMagic::HomeControlMagic(char* server_ip, char* deviceName, NetworkObj
epZ->setId("0");
m_endpoints_pointers[m_number_of_endpoints++] = epZ;

m_mqtt_client.setServer(server_ip, 1883);
uint16_t port = 1883;
if(m_network_object.isSecure())
{
port = 8883;
}

m_mqtt_client.setServer(server_ip, port);
m_mqtt_client.setCallback(callback);

m_id = m_network_object.getUniqueId();
Expand Down Expand Up @@ -294,7 +300,8 @@ bool HomeControlMagic::reconnectMqtt()

void HomeControlMagic::announce()
{
sendMessage("announce", m_name, "0");
strcat(m_message_buffer, m_name);
sendStringMessage("announce", "0");

sendFeedback();
}
Expand Down

0 comments on commit 9181c0b

Please sign in to comment.