按照教程生成了代码,烧录了固件,可最后就是配置不了
网上买的8266模块带彩灯的,一上电是蓝绿色,按key2模块没有任何反应,根据代码使用模拟串口A2,A3所以RX接A2,TX接A3,VCC接的板载3.3V,按下按键的时候UNO板上的TX指示灯是微微闪了几下的,可模块就是没有任何反应,APP也搜索不到设备,请各位大神们指点一下 以下是自动生成的代码,已经按照教程把两个程序的代码合并,已成功上传到UNO#include <Gizwits.h>
#include <Wire.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(A2, A3); // A2 -> RX, A3 -> TX
Gizwits myGizwits;
#define KEY1 6
#define KEY2 7
#define KEY1_SHORT_PRESS1
#define KEY1_LONG_PRESS 2
#define KEY2_SHORT_PRESS4
#define KEY2_LONG_PRESS 8
#define NO_KEY 0
#define KEY_LONG_TIMER 3
unsigned long Last_KeyTime = 0;
unsigned long gokit_time_s(void)
{
return millis() / 1000;
}
char gokit_key1down(void)
{
unsigned long keep_time = 0;
if (digitalRead(KEY1) == LOW)
{
delay(100);
if (digitalRead(KEY1) == LOW)
{
keep_time = gokit_time_s();
while (digitalRead(KEY1) == LOW)
{
if ((gokit_time_s() - keep_time) > KEY_LONG_TIMER)
{
Last_KeyTime = gokit_time_s();
return KEY1_LONG_PRESS;
}
} //until open the key
if ((gokit_time_s() - Last_KeyTime) > KEY_LONG_TIMER)
{
return KEY1_SHORT_PRESS;
}
return 0;
}
return 0;
}
return 0;
}
char gokit_key2down(void)
{
int unsigned long keep_time = 0;
if (digitalRead(KEY2) == LOW)
{
delay(100);
if (digitalRead(KEY2) == LOW)
{
keep_time = gokit_time_s();
while (digitalRead(KEY2) == LOW) //until open the key
{
if ((gokit_time_s() - keep_time) > KEY_LONG_TIMER)
{
Last_KeyTime = gokit_time_s();
return KEY2_LONG_PRESS;
}
}
if ((gokit_time_s() - Last_KeyTime) > KEY_LONG_TIMER)
{
return KEY2_SHORT_PRESS;
}
return 0;
}
return 0;
}
return 0;
}
char gokit_keydown(void)
{
char ret = 0;
ret |= gokit_key2down();
ret |= gokit_key1down();
return ret;
}
/**
* KEY_Handle
* @param none
* @return none
*/
void KEY_Handle(void)
{
/*Press for over than 3 second is Long Press*/
switch (gokit_keydown())
{
case KEY1_SHORT_PRESS:
mySerial.println(F("KEY1_SHORT_PRESS , Production Test Mode "));
myGizwits.setBindMode(WIFI_PRODUCTION_TEST);
break;
case KEY1_LONG_PRESS:
mySerial.println(F("KEY1_LONG_PRESS ,Wifi Reset"));
myGizwits.setBindMode(WIFI_RESET_MODE);
break;
case KEY2_SHORT_PRESS:
mySerial.println(F("KEY2_SHORT_PRESS Soft AP mode"));
myGizwits.setBindMode(WIFI_SOFTAP_MODE);
//Soft AP mode
break;
case KEY2_LONG_PRESS:
mySerial.println(F("KEY2_LONG_PRESS ,AirLink mode"));
myGizwits.setBindMode(WIFI_AIRLINK_MODE);
//AirLink mode
break;
default:
break;
}
}
void setup() {
pinMode(KEY1, INPUT_PULLUP);
pinMode(KEY2, INPUT_PULLUP);
mySerial.begin(115200);
myGizwits.begin();
mySerial.println("GoKit initOK \n");
}
void wifiStatusHandle()
{
if(myGizwits.wifiHasBeenSet(WIFI_SOFTAP))
{
mySerial.println(F("WIFI_SOFTAP!"));
}
if(myGizwits.wifiHasBeenSet(WIFI_AIRLINK))
{
mySerial.println(F("WIFI_AIRLINK!"));
}
if(myGizwits.wifiHasBeenSet(WIFI_STATION))
{
mySerial.println(F("WIFI_STATION!"));
}
if(myGizwits.wifiHasBeenSet(WIFI_CON_ROUTER))
{
mySerial.println(F("WIFI_CON_ROUTER!"));
}
if(myGizwits.wifiHasBeenSet(WIFI_DISCON_ROUTER))
{
mySerial.println(F("WIFI_DISCON_ROUTER!"));
}
if(myGizwits.wifiHasBeenSet(WIFI_CON_M2M))
{
mySerial.println(F("WIFI_CON_M2M!"));
}
if(myGizwits.wifiHasBeenSet(WIFI_DISCON_M2M))
{
mySerial.println(F("WIFI_DISCON_M2M!"));
}
}
void loop() {
//Configure network
//if(XXX) //Trigger Condition
//myGizwits.setBindMode(0x02);//0x01:Enter AP Mode;0x02:Enter Airlink Mode
/*
float varW_temp = 0;//Add Sensor Data Collection
myGizwits.write(VALUE_temp, varW_temp);
//binary datapoint handle
*/
KEY_Handle();//key handle , network configure
wifiStatusHandle();//WIFI Status Handle
myGizwits.process();
}
为什么加Q群管理员还不同意呢 烧录地址填错了,看文档,附链接http://docs.gizwits.com/zh-cn/deviceDev/ESP8266%E4%B8%B2%E5%8F%A3%E7%83%A7%E5%86%99%E8%AF%B4%E6%98%8E.html
页:
[1]