|
本帖最后由 マイナス37度 于 2014-6-6 22:04 编辑
yeelink+wifi控制双路快关失败,求原因求大神!!
不会发代码直接粘了啊
boolean ResponseBegin = false;
String returnValue = "";
unsigned long previousMillis = 0;
unsigned long interval = 900;
char flag =0; //定义开关循环控制变量
String SENSORno[]={"11941","14701"}; // 把sensor ID 依次替在这里,程序定义为数组,几个开关就写几个
byte ledPin[]={12,13}; //定义输出的针脚
char c ;
void setup()
{
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(115200);
}
void loop()
{
if(Serial.available())
c = Serial.read();
if(c == '{')
ResponseBegin = true;
if(c == '}')
ResponseBegin = false;
if (ResponseBegin)
returnValue += c;
if (returnValue.length() !=0 && (ResponseBegin == false))
{
if(returnValue.charAt(returnValue.length() - 1) == '1') //2hao
{
digitalWrite( ledPin[flag], HIGH);
Serial.println("ON");}
if(returnValue.charAt(returnValue.length() - 1) == '0')
{
digitalWrite( ledPin[flag], LOW);
Serial.println("OFF");}
returnValue = "";
flag ++; if(flag>=2) flag =0;
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
Serial.println("GET /v1.0/device/7577/sensor/SENSORno[flag])/datapoints HTTP/1.1");
Serial.println("Host: api.yeelink.net");//2hao
Serial.print("Accept: *");
Serial.print("/");
Serial.println("*");
Serial.print("U-ApiKey: ");
Serial.println("175063fac1143fd891b2e1eb66f90ce6"); // 此处用你的APIKEY替代
Serial.println("Content-Length: 0");
Serial.println("Connection: close");
Serial.println();
}
}
|
|