震惊20元的物联网方案(NodeMCU接入Blinker物联网平
2019-08-16 本文已影响127人
呆呆的院长
Blinker是一个专业且轻松的物联网接入平台,旨在让开发者更好的开发物联网设备,以下教程讲解如何使用某宝20元的NodeMCU接入Blinker平台)
第一步:下载Blinker app
第二步:创建设备,获取设备Secret Key
进入app,点击屏幕右上方加号添加设备,如图-1所示:

选择Diy设备中Arduino设备,如下图-2:

选择通过wifi接入,获取设备Secret Key如下图-3、图-4(Secret Key后续编写程序时需要使用)


第三步:手机端导入示例程序,如图-5:

第四步:编写实例代码:
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "Your Device Secret Key";//
char ssid[] = "Your WiFi network SSID or name";//这你替换为您的无线网名称
char pswd[] = "Your WiFi network WPA password or WEP key";//这你替换为您的无线网密码
// 新建组件对象
BlinkerButton Button1("btn-abc");
BlinkerNumber Number1("num-abc");
int counter = 0;
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
// 如果未绑定的组件被触发,则会执行其中内容
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter++;
Number1.print(counter);
}
void setup() {
// 初始化串口
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
// 初始化有LED的IO
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
}
void loop() {
Blinker.run();
}
第四步:使用Arduino IDE将程序烧入NodeMCU
第五步:测试
如果上述各个步骤顺利完成,点击手机端实例程序中的开关灯按钮,即可观察到NodeMCU开发板上蓝色led闪烁。
