本帖最后由 一新星 于 2019-6-9 00:36 编辑
- 硬件: [esparduino v3]
- 接入方式: [WIFI]
- 开发环境: [Arduino|]
- 操作系统: [Windows]
- IDE设置
- Module: [Nodemcu 0.9(esp-12Module)]
- Flash Size: [4MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Speed: [115200]
问题主要是esparduino连不上WiFi,用例程可以连接上,怀疑我的代码有误,编译显示是成功的,让我抓不着头脑,代码没问题,wifi的ssid,pswd都是对的原来我只设置了开和关都可以进行连接,
[pre]#define BLINKER_WIFI
#define BLINKER_ALIGENIE_LIGHT
#include <Blinker.h>
#define ledR 6//ledR端口
#define ledG 7//ledG 端口
#define ledB 8//ledB 端口
#define ledbright 5//控制亮度的端口
char auth[]="2a3864d31a93";
char ssid[]="114";
char pswd[]="114meiyoumima";
uint8_t colorR,colorG,colorB,colorW;
bool oState=false;
void LightShow(){//颜色输出,出去的方法
analogWrite(ledR,colorR);
analogWrite(ledG,colorG);
analogWrite(ledB,colorB);
analogWrite(ledbright,colorW);
}
void aligeniePowerState(const String & state){
BLINKER_LOG("need set power state:",state);
if(state==BLINKER_CMD_ON){
colorW=255;
BlinkerAliGenie.powerState("on");
BlinkerAliGenie.print();
oState=true;
}else if(state==BLINKER_CMD_OFF){
colorW=0;
BlinkerAliGenie.powerState("off");
BlinkerAliGenie.print();
}
LightShow();
}
void aligenieQuery(int32_t queryCode){
BLINKER_LOG("aligenie query codes:",queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER:
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.powerState(oState?"on":"off");
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER:
BLINKER_LOG("AliGenie Query PowerState");
BlinkerAliGenie.powerState(oState?"on":"off");
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_COLOR_NUMBER:
BLINKER_LOG("set color");
BlinkerAliGenie.color(getcolor());
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_BRIGHTNESS_NUMBER:
BLINKER_LOG("set bright");
BlinkerAliGenie.brightness(colorW);
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.powerState(oState?"on":"off");
BlinkerAliGenie.print();
break;
}
}
void aligenieColor(const String & color)
{
BLINKER_LOG("need set color: ", color);
if (color == "Red") {
colorR = 255; colorG = 0; colorB = 0;
}
else if (color == "Yellow") {
colorR = 255; colorG = 255; colorB = 0;
}
else if (color == "Blue") {
colorR = 0; colorG = 0; colorB = 255;
}
else if (color == "Green") {
colorR = 0; colorG = 255; colorB = 0;
}
else if (color == "White") {
colorR = 255; colorG = 255; colorB = 255;
}
else if (color == "Black") {
colorR = 0; colorG = 0; colorB = 0;
}
else if (color == "Cyan") {
colorR = 0; colorG = 255; colorB = 255;
}
else if (color == "Purple") {
colorR = 128; colorG = 0; colorB = 128;
}
else if (color == "Orange") {
colorR = 255; colorG = 165; colorB = 0;
}
LightShow();
BlinkerAliGenie.color(color);
BlinkerAliGenie.print();
}
void aligenieBright(const String & bright)
{
BLINKER_LOG("need set brightness: ", bright);
if (bright == BLINKER_CMD_MAX) {
colorW = 255;
}
else if (bright == BLINKER_CMD_MIN) {
colorW = 0;
}
else {
colorW = bright.toInt();
}
BLINKER_LOG("now set brightness: ", colorW);
BlinkerAliGenie.brightness(colorW);
BlinkerAliGenie.print();
LightShow();
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
String getcolor(){
uint32_t color = colorR << 16 | colorG << 8 | colorB;
switch (color)
{
case 0xFF0000 :
return "Red";
case 0xFFFF00 :
return "Yellow";
case 0x0000FF :
return "Blue";
case 0x00FF00 :
return "Green";
case 0xFFFFFF :
return "White";
case 0x000000 :
return "Black";
case 0x00FFFF :
return "Cyan";
case 0x800080 :
return "Purple";
case 0xFFA500 :
return "Orange";
default :
return "White";
}
}
void setup()
{
Serial.begin(115200);
pinMode(ledR,OUTPUT);
pinMode(ledG,OUTPUT);
pinMode(ledB,OUTPUT);
pinMode(ledbright,OUTPUT);
colorR=255;
colorG=255;
colorB=255;
colorW=100;
LightShow();
Blinker.begin(auth,ssid,pswd);
BlinkerAliGenie.attachBrightness(aligenieBright);
BlinkerAliGenie.attachColor(aligenieColor);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
BlinkerAliGenie.attachQuery(aligenieQuery);
Blinker.attachData(dataRead);
}
void loop(){
Blinker.run();
LightShow();
}[/pre]
|