|
各位大佬好,之前使用以下代码可以用BLINKER进行配网,前一阵家里换了wifi6的路由,然后不记得esptouch配网更换ssid和密码了,重新更换点灯Key之后刷写了程序,就一直无法通过esptouch配网,显示搜索不到设备,板子重新flash清除过固件。
求帮忙解决~
//WS2812RGB+ESP8266-01s或NodeMCU
//完善亮度控制
#define BLINKER_PRINT Serial
#define BLINKER_MIOT_LIGHT
#define BLINKER_WIFI
#include <Blinker.h> //点灯库
#include <Adafruit_NeoPixel.h>
char auth[] = "736576de038c"; //填写自己的点灯key
//****秘钥****/
#define PIN D7 // 设置引脚D7接WS2812的输入(IN)引脚
#define NUMPIXELS 60 // 设置ws2812的LED灯珠数量
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
//Adafruit_NeoPixel提供以下几种方式组合,自由搭配
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
// 新建组件对象
BlinkerRGB RGB1("RGB");
BlinkerButton Button1("key");
BlinkerNumber Number1("num-abc");
BlinkerText Text_ip("tex-ip");
BlinkerText Text_str("tex-str");
int counter = 0;
int LED_R = 0, LED_G = 0, LED_B = 0, LED_Bright = 180; // RGB和亮度
bool LED_Flag = false;
bool WIFI_Status = true;
void smartConfig()//配网函数
{
WiFi.mode(WIFI_STA);
Serial.println("\r\nWait for Smartconfig...");
WiFi.beginSmartConfig();//等待手机端发出的用户名与密码
while (1)
{
Serial.print(".");
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
if (WiFi.smartConfigDone())//退出等待
{
Serial.println("SmartConfig Success");
Serial.printf("SSID:%s\r\n", WiFi.SSID().c_str());
Serial.printf("PSW:%s\r\n", WiFi.psk().c_str());
break;
}
}
}
void WIFI_Set()//
{
//Serial.println("\r\n正在连接");
int count = 0;
while (WiFi.status() != WL_CONNECTED)
{
if (WIFI_Status)
{
Serial.print(".");
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
count++;
if (count >= 5) //5s
{
WIFI_Status = false;
Serial.println("WiFi连接失败,请用手机进行配网");
}
}
else
{
smartConfig(); //微信智能配网
}
}
/* Serial.println("连接成功");
Serial.print("IP:");
Serial.println(WiFi.localIP());*/
}
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
Blinker.print(state);
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
LED_Flag = !LED_Flag;
if (LED_Flag) SET_RGB(255, 255, 255, LED_Bright);
else SET_RGB(0, 0, 0, 0);
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
counter = counter;
Number1.print(counter);
}
void SET_RGB(int R, int G, int B, int bright)
{
for (uint16_t i = 0; i < NUMPIXELS; i++) //把灯条变色
{
pixels.setPixelColor(i, R, G, B);
}
pixels.setBrightness(bright);//亮度
pixels.show(); //送出显示
}
//APP RGB颜色设置回调
void rgb1_callback(uint8_t r_value, uint8_t g_value,
uint8_t b_value, uint8_t bright_value)
{
//digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
BLINKER_LOG("R value: ", r_value);
BLINKER_LOG("G value: ", g_value);
BLINKER_LOG("B value: ", b_value);
BLINKER_LOG("Rrightness value: ", bright_value);
LED_Bright = bright_value;
SET_RGB(r_value, g_value, b_value, LED_Bright);
}
//小爱电源类回调
void miotPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
//digitalWrite(LED_BUILTIN, LOW);
SET_RGB(255, 255, 255, 255);
BlinkerMIOT.powerState("on");
BlinkerMIOT.print();
}
else if (state == BLINKER_CMD_OFF) {
//digitalWrite(LED_BUILTIN, HIGH);
SET_RGB(255, 255, 255, 0);
BlinkerMIOT.powerState("off");
BlinkerMIOT.print();
}
}
//小爱设置颜色回调
void miotColor(int32_t color)
{
BLINKER_LOG("need set color: ", color);
int colorR, colorG, colorB;
colorR = color >> 16 & 0xFF;
colorG = color >> 8 & 0xFF;
colorB = color & 0xFF;
BLINKER_LOG("colorR: ", colorR, ", colorG: ", colorG, ", colorB: ", colorB);
SET_RGB(colorR, colorG, colorB, LED_Bright);
//pixelShow();
BlinkerMIOT.color(color);//反馈小爱控制状态
BlinkerMIOT.print();
}
//小爱调亮度回调
void miotBright(const String & bright)
{
BLINKER_LOG("need set brightness: ", bright);
int colorW = bright.toInt();
BLINKER_LOG("now set brightness: ", colorW);
LED_Bright = colorW;
if (LED_Bright >= 80 && LED_Bright <= 100) {
SET_RGB(255, 255, 255, 255);
} else if (LED_Bright >= 40 && LED_Bright <= 79) {
SET_RGB(125, 125, 125, 125);
} else if (LED_Bright >= 1 && LED_Bright <= 39) {
SET_RGB(50, 50, 50, 50);
}
Serial.printf("亮度调节中...%d", colorW);
BlinkerMIOT.brightness(colorW);//反馈小爱控制状态
BlinkerMIOT.print();
}
void setup() {
// 初始化串口
Serial.begin(115200);
pixels.begin();//WS2812初始化
pixels.show();
pinMode(LED_BUILTIN, OUTPUT);
#if defined(BLINKER_PRINT)
BLINKER_DEBUG.stream(BLINKER_PRINT);
#endif
WIFI_Set();
// 初始化blinker
Blinker.reset();
Blinker.begin(auth, WiFi.SSID().c_str(), WiFi.psk().c_str());
Blinker.attachData(dataRead);//如果没有被绑定的组件被触发就执行这个回调
Button1.attach(button1_callback);//Button1这个组件被触发就执行这个回调
RGB1.attach(rgb1_callback);//注册调节颜色的回调函数
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachColor(miotColor);//小爱调节颜色
BlinkerMIOT.attachBrightness(miotBright);//小爱调节RGB亮度
Blinker.attachHeartbeat(heartbeat); //将传感器获取的数据传给
}
void loop() {
Blinker.run();
}
/*******************************************
给blinkerapp回传数据
*****************************************/
void heartbeat() {
Text_ip.print(WiFi.localIP().toString().c_str());
//unsigned long timecnt = Blinker.runTime();//获取运行时间单位秒
unsigned long timecnt = millis();
unsigned long fenl = timecnt/ 60000L; //计算分
Text_str.print(fenl);//显示分
}
|
|