Skip to content

Commit 045f2e7

Browse files
authored
Merge pull request #583 from blinker-iot/dev_3.0
update codes, update BLINKER PRO WLAN CONFIG CHANGE codes.
2 parents 5721b57 + ebbc82a commit 045f2e7

File tree

14 files changed

+783
-174
lines changed

14 files changed

+783
-174
lines changed

examples/Blinker_Cloud/Blinker_CLOUDDATA/CLOUDDATA_WiFi/CLOUDDATA_WiFi.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ void setup()
8585
void loop()
8686
{
8787
Blinker.run();
88-
}
88+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* *****************************************************************
2+
*
3+
* Download latest Blinker library here:
4+
* https://github.com/blinker-iot/blinker-library/archive/master.zip
5+
*
6+
*
7+
* Blinker is a cross-hardware, cross-platform solution for the IoT.
8+
* It provides APP, device and server support,
9+
* and uses public cloud services for data transmission and storage.
10+
* It can be used in smart home, data monitoring and other fields
11+
* to help users build Internet of Things projects better and faster.
12+
*
13+
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
14+
* if use ESP8266 with Blinker.
15+
* https://github.com/esp8266/Arduino/releases
16+
*
17+
* Make sure installed 1.0.5 or later ESP32/Arduino package,
18+
* if use ESP32 with Blinker.
19+
* https://github.com/espressif/arduino-esp32/releases
20+
*
21+
* Docs: https://diandeng.tech/doc
22+
*
23+
*
24+
* *****************************************************************
25+
*
26+
* Blinker 库下载地址:
27+
* https://github.com/blinker-iot/blinker-library/archive/master.zip
28+
*
29+
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
30+
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
31+
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
32+
*
33+
* 如果使用 ESP8266 接入 Blinker,
34+
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
35+
* https://github.com/esp8266/Arduino/releases
36+
*
37+
* 如果使用 ESP32 接入 Blinker,
38+
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
39+
* https://github.com/espressif/arduino-esp32/releases
40+
*
41+
* 文档: https://diandeng.tech/doc
42+
*
43+
*
44+
* *****************************************************************/
45+
46+
#define BLINKER_WIFI
47+
48+
#include <Blinker.h>
49+
50+
char auth[] = "Your Device Secret Key";
51+
char ssid[] = "Your WiFi network SSID or name";
52+
char pswd[] = "Your WiFi network WPA password or WEP key";
53+
54+
void dataRead(const String & data)
55+
{
56+
BLINKER_LOG("Blinker readString: ", data);
57+
58+
uint32_t BlinkerTime = millis();
59+
60+
Blinker.vibrate();
61+
Blinker.print("millis", BlinkerTime);
62+
63+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
64+
}
65+
66+
void rtData()
67+
{
68+
Blinker.sendRtData("data1", (int32_t)random(0,120));
69+
Blinker.sendRtData("data2", random(0,120)/(float)1.5);
70+
Blinker.printRtData();
71+
}
72+
73+
void setup()
74+
{
75+
Serial.begin(115200);
76+
BLINKER_DEBUG.stream(Serial);
77+
78+
pinMode(LED_BUILTIN, OUTPUT);
79+
digitalWrite(LED_BUILTIN, LOW);
80+
81+
Blinker.begin(auth, ssid, pswd);
82+
Blinker.attachData(dataRead);
83+
Blinker.attachRTData(rtData);
84+
}
85+
86+
void loop()
87+
{
88+
Blinker.run();
89+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/* *****************************************************************
2+
*
3+
* Download latest Blinker library here:
4+
* https://github.com/blinker-iot/blinker-library/archive/master.zip
5+
*
6+
*
7+
* Blinker is a cross-hardware, cross-platform solution for the IoT.
8+
* It provides APP, device and server support,
9+
* and uses public cloud services for data transmission and storage.
10+
* It can be used in smart home, data monitoring and other fields
11+
* to help users build Internet of Things projects better and faster.
12+
*
13+
* Make sure installed 2.7.4 or later ESP8266/Arduino package,
14+
* if use ESP8266 with Blinker.
15+
* https://github.com/esp8266/Arduino/releases
16+
*
17+
* Make sure installed 1.0.5 or later ESP32/Arduino package,
18+
* if use ESP32 with Blinker.
19+
* https://github.com/espressif/arduino-esp32/releases
20+
*
21+
* Docs: https://diandeng.tech/doc
22+
*
23+
*
24+
* *****************************************************************
25+
*
26+
* Blinker 库下载地址:
27+
* https://github.com/blinker-iot/blinker-library/archive/master.zip
28+
*
29+
* Blinker 是一套跨硬件、跨平台的物联网解决方案,提供APP端、设备端、
30+
* 服务器端支持,使用公有云服务进行数据传输存储。可用于智能家居、
31+
* 数据监测等领域,可以帮助用户更好更快地搭建物联网项目。
32+
*
33+
* 如果使用 ESP8266 接入 Blinker,
34+
* 请确保安装了 2.7.4 或更新的 ESP8266/Arduino 支持包。
35+
* https://github.com/esp8266/Arduino/releases
36+
*
37+
* 如果使用 ESP32 接入 Blinker,
38+
* 请确保安装了 1.0.5 或更新的 ESP32/Arduino 支持包。
39+
* https://github.com/espressif/arduino-esp32/releases
40+
*
41+
* 文档: https://diandeng.tech/doc
42+
*
43+
*
44+
* *****************************************************************/
45+
46+
#define BLINKER_WIFI
47+
#define BLINKER_APCONFIG_V2
48+
49+
#include <Blinker.h>
50+
51+
// Download OneButton library here:
52+
// https://github.com/mathertel/OneButton
53+
#include "OneButton.h"
54+
55+
#if defined(ESP32)
56+
#define BLINKER_BUTTON_PIN 4
57+
#else
58+
#define BLINKER_BUTTON_PIN D7
59+
#endif
60+
// button trigged when pin input level is LOW
61+
OneButton button(BLINKER_BUTTON_PIN, true);
62+
63+
void deviceReset()
64+
{
65+
// Reset device ,erase WiFi config.
66+
Blinker.reset();
67+
}
68+
69+
void dataRead(const String & data)
70+
{
71+
BLINKER_LOG("Blinker readString: ", data);
72+
73+
Blinker.vibrate();
74+
75+
uint32_t BlinkerTime = millis();
76+
77+
Blinker.print("millis", BlinkerTime);
78+
}
79+
80+
void setup()
81+
{
82+
Serial.begin(115200);
83+
BLINKER_DEBUG.stream(Serial);
84+
BLINKER_DEBUG.debugAll();
85+
86+
pinMode(LED_BUILTIN, OUTPUT);
87+
digitalWrite(LED_BUILTIN, LOW);
88+
89+
Blinker.begin();
90+
Blinker.attachData(dataRead);
91+
button.attachLongPressStop(deviceReset);
92+
}
93+
94+
void loop()
95+
{
96+
Blinker.run();
97+
button.tick();
98+
}

keywords.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ BLINKER_PRINT KEYWORD2
144144
BLINKER_DEBUG_ALL KEYWORD2
145145
BLINKER_ESP_SMARTCONFIG KEYWORD2
146146
BLINKER_APCONFIG KEYWORD2
147+
BLINKER_APCONFIG_V2 KEYWORD2
147148
BLINKER_WIFI_MULTI KEYWORD2
148149
BLINKER_BLE KEYWORD2
149150
BLINKER_WIFI KEYWORD2

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"type": "git",
1414
"url": "https://github.com/blinker-iot/blinker-library.git"
1515
},
16-
"version": "0.3.80210803",
16+
"version": "0.3.80210927",
1717
"homepage": "https://diandeng.tech/home",
1818
"export": {
1919
"exclude": [

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Blinker
2-
version=0.3.80210803
2+
version=0.3.80210927
33
author=i3water
44
maintainer=i3wawter
55
sentence=Build a easy way for your IoT project.

src/Adapters/BlinkerMQTT.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class BlinkerMQTT : public BlinkerStream
163163
void apconfigBegin();
164164
bool autoInit();
165165
void smartconfig();
166-
#if defined(BLINKER_APCONFIG)
166+
#if defined(BLINKER_APCONFIG) || defined(BLINKER_APCONFIG_V2)
167167
void softAPinit();
168168
void checkAPCFG();
169169
bool parseUrl(String data);
@@ -205,11 +205,11 @@ class BlinkerMQTT : public BlinkerStream
205205
uint32_t _connectTime = 0;
206206
uint8_t _connectTimes = 0;
207207
// const char* _authKey;
208-
char* _authKey;
208+
// char* _authKey;
209209
char* _aliType;
210210
char* _duerType;
211211
char* _miType;
212-
// char _authKey[BLINKER_AUTHKEY_SIZE];
212+
char _authKey[BLINKER_AUTHKEY_SIZE];
213213
bool* isHandle;// = &isConnect;
214214
bool isAlive = false;
215215
// bool isBavail = false;
@@ -1718,8 +1718,10 @@ void BlinkerMQTT::miType(const String & type)
17181718
void BlinkerMQTT::begin(const char* auth) {
17191719
// if (!checkInit()) return;
17201720
// _authKey = auth;
1721-
_authKey = (char*)malloc((strlen(auth)+1)*sizeof(char));
1722-
strcpy(_authKey, auth);
1721+
// if (_authKey == NULL) {
1722+
// _authKey = (char*)malloc((strlen(auth)+1)*sizeof(char));
1723+
// }
1724+
strncpy(_authKey, auth, BLINKER_AUTHKEY_SIZE);
17231725

17241726
BLINKER_LOG_ALL(BLINKER_F("_authKey: "), auth);
17251727
}
@@ -2808,7 +2810,7 @@ bool BlinkerMQTT::checkInit()
28082810
return false;
28092811
}
28102812
case BLINKER_AP_CONFIG :
2811-
#if defined(BLINKER_APCONFIG)
2813+
#if defined(BLINKER_APCONFIG) || defined(BLINKER_APCONFIG_V2)
28122814
switch (_configStatus)
28132815
{
28142816
case AUTO_INIT :
@@ -2963,7 +2965,7 @@ void BlinkerMQTT::multiBegin(const char* _ssid, const char* _pswd)
29632965

29642966
void BlinkerMQTT::apconfigBegin()
29652967
{
2966-
#if defined(BLINKER_APCONFIG)
2968+
#if defined(BLINKER_APCONFIG) || defined(BLINKER_APCONFIG_V2)
29672969
_configType = BLINKER_AP_CONFIG;
29682970

29692971
if (!autoInit()) softAPinit();
@@ -3034,6 +3036,18 @@ bool BlinkerMQTT::autoInit()
30343036
// BLINKER_F("APCONFIG while WiFi not connect!"));
30353037

30363038
BLINKER_LOG(BLINKER_F("Connecting to WiFi: "), WiFi.SSID());
3039+
3040+
#if defined(BLINKER_APCONFIG_V2)
3041+
char _auth[BLINKER_AUTHKEY_SIZE];
3042+
3043+
EEPROM.begin(BLINKER_EEP_SIZE);
3044+
EEPROM.get(2448, _auth);
3045+
EEPROM.commit();
3046+
EEPROM.end();
3047+
3048+
BLINKER_LOG(BLINKER_F("_auth: "), _auth);
3049+
begin(_auth);
3050+
#endif
30373051

30383052
// uint8_t _times = 0;
30393053
// while (WiFi.status() != WL_CONNECTED) {
@@ -3093,7 +3107,7 @@ void BlinkerMQTT::smartconfig()
30933107
// BLINKER_LOG(BLINKER_F("IP Address: "));
30943108
// BLINKER_LOG(WiFi.localIP());
30953109
}
3096-
#if defined(BLINKER_APCONFIG)
3110+
#if defined(BLINKER_APCONFIG) || defined(BLINKER_APCONFIG_V2)
30973111
void BlinkerMQTT::softAPinit()
30983112
{
30993113
// WiFiServer _apServer(80);
@@ -3335,7 +3349,18 @@ bool BlinkerMQTT::parseUrl(String data)
33353349

33363350
BLINKER_LOG(BLINKER_F("ssid: "), _ssid);
33373351
BLINKER_LOG(BLINKER_F("pswd: "), _pswd);
3352+
#if defined(BLINKER_APCONFIG_V2)
3353+
if (wifi_data.containsKey("auth")) {
3354+
String _auth = wifi_data["auth"];
3355+
BLINKER_LOG(BLINKER_F("_auth: "), _auth);
3356+
begin(_auth.c_str());
33383357

3358+
EEPROM.begin(BLINKER_EEP_SIZE);
3359+
EEPROM.put(2448, _authKey);
3360+
EEPROM.commit();
3361+
EEPROM.end();
3362+
}
3363+
#endif
33393364
// free(_apServer);
33403365
// MDNS.end();
33413366
webSocket_MQTT.close();

0 commit comments

Comments
 (0)