首先手机下载点灯科技app,并且打开,点击app里面的加号,然后点击独立设备,可以选择蓝牙也可以选择WiFi,本次我们选择网络接入,然后点击电灯科技,就会有一个Secret Key,将其复制然后可以到arduino ide写代码
代码如下:
#define BLINKER_PRINT Serial
#define BLINKER_WIFI
#define jidianqi 5
#include <Blinker.h>
char auth[] = "e3d772afc0ba"; //刚刚复制的Secret Key
char ssid[] = "iQOO Z1"; //你的wifi名称
char pswd[] = "123qweasd"; //你的WiFi密码
BlinkerButton Button_jidianqi("jidianqi"); //你的点灯科技的数据键名
void heartbeat() //esp8266的心跳,即发送数据的跳动
{
Button_jidianqi.print("on");
}
void button_jidianqi_led(const String & state) //连上点灯科技的配置
{
BLINKER_LOG("get button state: ",state);
digitalWrite(jidianqi, !digitalRead(jidianqi));
if(digitalRead(jidianqi))
{
Button_jidianqi.text("已打开");
Button_jidianqi.print("on");
}else
{
Button_jidianqi.text("已关闭");
Button_jidianqi.print("off");
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ",data);
}
void setup() //你的主函数
{
Serial.begin(115200);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
pinMode(jidianqi,OUTPUT);
digitalWrite(jidianqi,LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button_jidianqi.attach(button_jidianqi_led);
}
void loop()
{
Blinker.run();
}
|