Skip to content

Commit 5721b57

Browse files
authored
Merge pull request #582 from blinker-iot/dev_3.0
Dev 3.0
2 parents f7f2db8 + d69d627 commit 5721b57

File tree

10 files changed

+138
-9
lines changed

10 files changed

+138
-9
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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+
// 新建组件对象
55+
BlinkerButton Button1("btn-abc");
56+
BlinkerNumber Number1("num-abc");
57+
58+
int counter = 0;
59+
60+
// 按下按键即会执行该函数
61+
void button1_callback(const String & state)
62+
{
63+
BLINKER_LOG("get button state: ", state);
64+
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
65+
}
66+
67+
// 如果未绑定的组件被触发,则会执行其中内容
68+
void dataRead(const String & data)
69+
{
70+
BLINKER_LOG("Blinker readString: ", data);
71+
counter++;
72+
Number1.print(counter);
73+
74+
if (BLINKER_PROTOCOL_MQTT != NULL) {
75+
String pub_topic = "/device/" + Blinker.deviceName() + "/s";
76+
String pub_data = "{\"toDevice\":\"the device name you need pub to\",\"data\":{\"hello\":\"blinker\"}}";
77+
BLINKER_PROTOCOL_MQTT->publish(pub_topic.c_str(), pub_data.c_str());
78+
}
79+
}
80+
81+
void setup()
82+
{
83+
// 初始化串口
84+
Serial.begin(115200);
85+
BLINKER_DEBUG.stream(Serial);
86+
BLINKER_DEBUG.debugAll();
87+
88+
// 初始化有LED的IO
89+
pinMode(LED_BUILTIN, OUTPUT);
90+
digitalWrite(LED_BUILTIN, HIGH);
91+
// 初始化blinker
92+
Blinker.begin(auth, ssid, pswd);
93+
Blinker.attachData(dataRead);
94+
95+
Button1.attach(button1_callback);
96+
}
97+
98+
void loop() {
99+
Blinker.run();
100+
}

examples/Blinker_PRO/Blinker_PRO_Wlan_Config/Blinker_PRO_Wlan_Config.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void duringLongPress()
168168

169169
if (pressed_time >= 5000 && Blinker.configType() != BLINKER_AP_CONFIG)
170170
{
171-
Blinker.apConfigInit();
171+
Blinker.esptouchInit();
172172
}
173173
}
174174
#endif

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ BlinkerDuerOS KEYWORD1
2121
BlinkerMIOT KEYWORD1
2222
BlinkerUpdater KEYWORD1
2323
BlinkerEvent KEYWORD1
24+
BLINKER_PROTOCOL_MQTT KEYWORD1
2425

2526
#######################################
2627
# Methods and Functions (KEYWORD2)
2728
#######################################
2829
BLINKER_TAST_INIT KEYWORD2
30+
deviceName KEYWORD2
2931

3032
auth KEYWORD2
3133
ssid 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.80210704",
16+
"version": "0.3.80210803",
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.80210704
2+
version=0.3.80210803
33
author=i3water
44
maintainer=i3wawter
55
sentence=Build a easy way for your IoT project.

src/Adapters/BlinkerMQTT.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ class BlinkerMQTT : public BlinkerStream
268268
WiFiClientSecure client_s;
269269
#endif
270270

271+
#define BLINKER_PROTOCOL_MQTT mqtt_MQTT
272+
271273
WiFiClient client;
272-
Adafruit_MQTT_Client* mqtt_MQTT;
274+
Adafruit_MQTT_Client* mqtt_MQTT = NULL;
273275
// Adafruit_MQTT_Publish *iotPub;
274276
Adafruit_MQTT_Subscribe* iotSub_MQTT;
275277
// Adafruit_MQTT_Subscribe* iotSub_RRPC_MQTT;
@@ -2837,6 +2839,7 @@ bool BlinkerMQTT::checkInit()
28372839
if (millis() - _connectTime > 15000)
28382840
{
28392841
BLINKER_LOG(BLINKER_F("APConfig timeout."));
2842+
WiFi.disconnect();
28402843
_configStatus = APCFG_TIMEOUT;
28412844
}
28422845
return false;

src/Adapters/BlinkerPROESP.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ enum b_broker_t {
6464
blinker_b
6565
};
6666

67-
b_config_t _configType = BLINKER_SMART_CONFIG;
67+
b_config_t _configType = BLINKER_AP_CONFIG;
6868

6969
class BlinkerPROESP : public BlinkerStream
7070
{
@@ -226,8 +226,10 @@ class BlinkerPROESP : public BlinkerStream
226226
WiFiClientSecure client_s;
227227
#endif
228228

229+
#define BLINKER_PROTOCOL_MQTT mqtt_PRO
230+
229231
WiFiClient client;
230-
Adafruit_MQTT_Client* mqtt_PRO;
232+
Adafruit_MQTT_Client* mqtt_PRO = NULL;
231233
// Adafruit_MQTT_Publish *iotPub;
232234
Adafruit_MQTT_Subscribe* iotSub_PRO;
233235

@@ -3237,6 +3239,7 @@ bool BlinkerWlan::connected() {
32373239
BLINKER_LOG(BLINKER_F("APConfig time out"));
32383240

32393241
// WiFi.stopSmartConfig();
3242+
WiFi.disconnect();
32403243
_status = BWL_APCONFIG_TIMEOUT;
32413244
}
32423245
return false;

src/Blinker.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
#elif defined(BLINKER_WIFI) || defined(BLINKER_MQTT)
2727

28+
#if defined(BLINKER_APCONFIG_V2)
29+
#define BLINKER_APCONFIG
30+
#define BLINKER_WITHOUT_WS_REG
31+
#endif
32+
2833
#if defined(BLINKER_WIFI)
2934
#undef BLINKER_WIFI
3035
#define BLINKER_MQTT
@@ -37,7 +42,8 @@
3742
#if (defined(ESP8266) || defined(ESP32)) && !defined(BLINKER_MQTT_AT)
3843
#include "BlinkerESPMQTT.h"
3944

40-
BlinkerESPMQTT Blinker;
45+
BlinkerESPMQTT Blinker;
46+
4147
#else
4248
#define BLINKER_ESP_AT
4349

@@ -92,7 +98,14 @@
9298

9399
#elif defined(BLINKER_PRO_ESP) || defined(BLINKER_WIFI_AUTO)
94100

95-
#include "BlinkerAssistant.h"
101+
#include "BlinkerAssistant.h"
102+
103+
#if defined(BLINKER_APCONFIG_V2)
104+
#define BLINKER_APCONFIG
105+
#define BLINKER_WITHOUT_WS_REG
106+
#endif
107+
108+
#define BLINKER_WITHOUT_WS_REG
96109

97110
#if defined(BLINKER_WIFI_AUTO)
98111
#define BLINKER_PRO_ESP

src/Blinker/BlinkerApi.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,10 @@ void BlinkerApi::run()
32423242
}
32433243
else
32443244
{
3245+
#if defined(BLINKER_WITHOUT_WS_REG)
3246+
_getRegister = true;
3247+
_isNew = true;
3248+
#endif
32453249
_proStatus = PRO_DEV_AUTHCHECK_FAIL;
32463250

32473251
BLINKER_LOG_ALL(BLINKER_F("not auth, conn deviceRegister"));
@@ -3476,6 +3480,10 @@ void BlinkerApi::run()
34763480
}
34773481
else
34783482
{
3483+
#if defined(BLINKER_WITHOUT_WS_REG)
3484+
_getRegister = true;
3485+
_isNew = true;
3486+
#endif
34793487
_mqttAutoStatue = AUTO_DEV_AUTHCHECK_FAIL;
34803488

34813489
BLINKER_LOG_ALL(BLINKER_F("not auth, conn deviceRegister"));

src/Blinker/BlinkerConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// #include "Blinker/BlinkerUtility.h"
66
#include "../Server/BlinkerServer.h"
77

8-
#define BLINKER_VERSION "0.3.80210704"
8+
#define BLINKER_VERSION "0.3.80210803"
99

1010
#define BLINKER_CONNECT_TIMEOUT_MS 10000UL
1111

0 commit comments

Comments
 (0)