Skip to content

Commit d69d627

Browse files
committed
update codes, upgrade BLINKER WIFI CONFIG & MQTT codes.
1 parent aa21b13 commit d69d627

File tree

6 files changed

+111
-4
lines changed

6 files changed

+111
-4
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

src/Adapters/BlinkerMQTT.h

Lines changed: 3 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;

src/Adapters/BlinkerPROESP.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/Blinker.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
#if (defined(ESP8266) || defined(ESP32)) && !defined(BLINKER_MQTT_AT)
4343
#include "BlinkerESPMQTT.h"
4444

45-
BlinkerESPMQTT Blinker;
45+
BlinkerESPMQTT Blinker;
46+
4647
#else
4748
#define BLINKER_ESP_AT
4849

0 commit comments

Comments
 (0)