Skip to content

Commit

Permalink
Merge pull request #47 from blinker-iot/dev
Browse files Browse the repository at this point in the history
update codes, fix bug.
  • Loading branch information
i3water authored Jun 12, 2018
2 parents 59e210c + d1732ae commit f7b7535
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 48 deletions.
28 changes: 14 additions & 14 deletions src/BlinkerSimpleESP32_MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ class BlinkerSimpleESP32_MQTT
{}

#if defined(BLINKER_ESP_SMARTCONFIG)
void begin(const char* auth) {
void begin(const char* _auth) {
Base::begin();
smartconfig();
this->conn.begin(auth);
this->conn.begin(_auth);
BLINKER_LOG1("ESP32_MQTT Initialled...");
}
#endif

void begin( const char* auth,
const char* ssid,
const char* pswd)
void begin( const char* _auth,
const char* _ssid,
const char* _pswd)
{
Base::begin();
connectWiFi(ssid, pswd);
this->conn.begin(auth);
connectWiFi(_ssid, _pswd);
this->conn.begin(_auth);
BLINKER_LOG1("ESP32_MQTT Initialled...");
}

Expand All @@ -40,14 +40,14 @@ class BlinkerSimpleESP32_MQTT

BLINKER_LOG1("Waiting for SmartConfig.");
while (!WiFi.smartConfigDone()) {
delay(500);
::delay(500);
}

BLINKER_LOG1("SmartConfig received.");

BLINKER_LOG1("Waiting for WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
::delay(500);
}

BLINKER_LOG1("WiFi Connected.");
Expand All @@ -59,17 +59,17 @@ class BlinkerSimpleESP32_MQTT
}
#endif

void connectWiFi(const char* ssid, const char* pswd)
void connectWiFi(const char* _ssid, const char* _pswd)
{
uint32_t connectTime = millis();

BLINKER_LOG2(("Connecting to "), ssid);
BLINKER_LOG2(("Connecting to "), _ssid);
WiFi.mode(WIFI_STA);
if (pswd && strlen(pswd)) {
WiFi.begin(ssid, pswd);
if (_pswd && strlen(_pswd)) {
WiFi.begin(_ssid, _pswd);
}
else {
WiFi.begin(ssid);
WiFi.begin(_ssid);
}

while (WiFi.status() != WL_CONNECTED) {
Expand Down
16 changes: 8 additions & 8 deletions src/BlinkerSimpleESP32_WS.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class BlinkerSimpleESP32_WS
}
#endif

void begin(const char* ssid,
const char* pswd)
void begin(const char* _ssid,
const char* _pswd)
{
Base::begin();
connectWiFi(ssid, pswd);
connectWiFi(_ssid, _pswd);
BLINKER_LOG1("ESP32_WiFi Initialled...");
}

Expand Down Expand Up @@ -74,17 +74,17 @@ class BlinkerSimpleESP32_WS
this->conn.begin(macDeviceName());
}

void connectWiFi(const char* ssid, const char* pswd)
void connectWiFi(const char* _ssid, const char* _pswd)
{
uint32_t connectTime = millis();

BLINKER_LOG2(BLINKER_F("Connecting to "), ssid);
BLINKER_LOG2(BLINKER_F("Connecting to "), _ssid);
WiFi.mode(WIFI_STA);
if (pswd && strlen(pswd)) {
WiFi.begin(ssid, pswd);
if (_pswd && strlen(_pswd)) {
WiFi.begin(_ssid, _pswd);
}
else {
WiFi.begin(ssid);
WiFi.begin(_ssid);
}

while (WiFi.status() != WL_CONNECTED) {
Expand Down
33 changes: 17 additions & 16 deletions src/BlinkerSimpleESP8266_MQTT.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
#define BlinkerSimplerESP8266_MQTT_H

#include "Adapters/BlinkerMQTT.h"
// #include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFi.h>

class BlinkerSimpleESP8266_MQTT
: public BlinkerProtocol<BlinkerMQTT>
Expand All @@ -15,40 +16,40 @@ class BlinkerSimpleESP8266_MQTT
{}

#if defined(BLINKER_ESP_SMARTCONFIG)
void begin(const char* auth) {
void begin(const char* _auth) {
Base::begin();
smartconfig();
this->conn.begin(auth);
this->conn.begin(_auth);
BLINKER_LOG1("ESP8266_MQTT Initialled...");
}
#endif

void begin( const char* auth,
const char* ssid,
const char* pswd)
void begin( const char* _auth,
const char* _ssid,
const char* _pswd)
{
Base::begin();
connectWiFi(ssid, pswd);
this->conn.begin(auth);
connectWiFi(_ssid, _pswd);
this->conn.begin(_auth);
BLINKER_LOG1("ESP8266_MQTT Initialled...");
}

private :
#if defined(BLINKER_ESP_SMARTCONFIG)
#if defined(BLINKER_ESP_SMARTCONFIG)
void smartconfig() {
WiFi.mode(WIFI_STA);
WiFi.beginSmartConfig();

BLINKER_LOG1("Waiting for SmartConfig.");
while (!WiFi.smartConfigDone()) {
delay(500);
::delay(500);
}

BLINKER_LOG1("SmartConfig received.");

BLINKER_LOG1("Waiting for WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
::delay(500);
}

BLINKER_LOG1("WiFi Connected.");
Expand All @@ -74,17 +75,17 @@ class BlinkerSimpleESP8266_MQTT
// this->conn.begin(macDeviceName());
// }

void connectWiFi(const char* ssid, const char* pswd)
void connectWiFi(const char* _ssid, const char* _pswd)
{
uint32_t connectTime = millis();

BLINKER_LOG2(("Connecting to "), ssid);
BLINKER_LOG2(("Connecting to "), _ssid);
WiFi.mode(WIFI_STA);
if (pswd && strlen(pswd)) {
WiFi.begin(ssid, pswd);
if (_pswd && strlen(_pswd)) {
WiFi.begin(_ssid, _pswd);
}
else {
WiFi.begin(ssid);
WiFi.begin(_ssid);
}

while (WiFi.status() != WL_CONNECTED) {
Expand Down
20 changes: 10 additions & 10 deletions src/BlinkerSimpleESP8266_WS.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class BlinkerSimpleESP8266_WS
}
#endif

void begin(const char* ssid,
const char* pswd)
void begin(const char* _ssid,
const char* _pswd)
{
Base::begin();
connectWiFi(ssid, pswd);
connectWiFi(_ssid, _pswd);
BLINKER_LOG1("ESP8266_WiFi Initialled...");
}

Expand All @@ -39,14 +39,14 @@ class BlinkerSimpleESP8266_WS

BLINKER_LOG1("Waiting for SmartConfig.");
while (!WiFi.smartConfigDone()) {
delay(500);
::delay(500);
}

BLINKER_LOG1("SmartConfig received.");

BLINKER_LOG1("Waiting for WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
::delay(500);
}

BLINKER_LOG1("WiFi Connected.");
Expand Down Expand Up @@ -74,17 +74,17 @@ class BlinkerSimpleESP8266_WS
this->conn.begin(macDeviceName());
}

void connectWiFi(const char* ssid, const char* pswd)
void connectWiFi(const char* _ssid, const char* _pswd)
{
uint32_t connectTime = millis();

BLINKER_LOG2(BLINKER_F("Connecting to "), ssid);
BLINKER_LOG2(BLINKER_F("Connecting to "), _ssid);
WiFi.mode(WIFI_STA);
if (pswd && strlen(pswd)) {
WiFi.begin(ssid, pswd);
if (_pswd && strlen(_pswd)) {
WiFi.begin(_ssid, _pswd);
}
else {
WiFi.begin(ssid);
WiFi.begin(_ssid);
}

while (WiFi.status() != WL_CONNECTED) {
Expand Down

0 comments on commit f7b7535

Please sign in to comment.