打开Arduino IDE,通过 文件>示例>(第三方库)Blinker>Blinker_Hello/Hello_WiFi 打开例程在程序中找到如下变量,填入你申请到的Secret Key(auth)和要连接的WiFi热点名(ssid)、密码(pswd),具体代码如下:
- #define BLINKER_PRINT Serial
- #define BLINKER_WIFI
- #include <Blinker.h>
- char auth[] = "6751e5928705";
- char ssid[] = "123456";
- char pswd[] = "linux666666";
- // 新建组件对象
- BlinkerButton Button1("btn-abc");
- BlinkerNumber Number1("num-abc");
- int counter = 0;
- // 按下按键即会执行该函数
- void button1_callback(const String & state)
- {
- BLINKER_LOG("get button state: ", state);
- Serial.print("#01\r\n");
- digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
- }
- // 如果未绑定的组件被触发,则会执行其中内容
- void dataRead(const String & data)
- {
- BLINKER_LOG("Blinker readString: ", data);
- counter++;
- Number1.print(counter);
- }
- void setup() {
- // 初始化串口
- Serial.begin(9600);
- #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();
- }
|