enc28j60 yeelink 物联开关
#include <EtherCard.h>static byte mymac[] = {0x74,0x69,0x69,0x2D,0x30,0x21};
const char server[] PROGMEM = "api.yeelink.net";
byte Ethernet::buffer;
byte sensorData;
static uint32_t lastConnectionTime = 0;
const unsigned long postingInterval = 100;
const char SensorID[] PROGMEM = "171286";
const char APIKey[] PROGMEM = "2c4265c045794880588ffeea97d70216";// replace your yeelink api key here
const char DeviceID[] PROGMEM = "153110"; // replace your device ID
Stash stash;
void setup () {
InitIP();
}
void loop() {
ether.packetLoop(ether.packetReceive());
if(millis() - lastConnectionTime > postingInterval){
GetData();
}
}
void GetData()
{
float demo = random(0,500);
word one = random(0,500);
String msje;
if (demo < 250){
msje = "low";
}
else{
msje = "high";
}
byte sd = stash.create();
stash.print("demo,");
stash.println(demo);
stash.print("one,");
stash.println(one);
stash.print("mensaje,");
stash.println(msje);
stash.save();
Stash::prepare(PSTR("GET /v1.0/device/$F/sensor/$F/datapoints HTTP/1.1" "\r\n"
"Host:api.yeelink.net" "\r\n"
"U-ApiKey: $F" "\r\n"
"Content-Length:$D" "\r\n"
"\r\n""$H"),DeviceID,SensorID,APIKey,stash.size(),sd);
sensorData = ether.tcpSend();
const char* reply = ether.tcpReply(sensorData);
const char* re;
char t;
if(reply != 0) {
Serial.println(reply);
Serial.println(strstr(reply,"{"));
if(strstr(reply,"1}") != NULL)
{ Serial.println("Led state: ON");return;}
if(strstr(reply,"0}") != NULL)
{ Serial.println("Led state: OFF");return;}
}else
{
// Serial.println("2");
}
lastConnectionTime = millis();
}
void InitIP()
{
Serial.begin(57600);
Serial.println("Client Demo");
Serial.println();
if (!ether.begin(sizeof Ethernet::buffer, mymac, 10))
Serial.println( "Failed to access Ethernet controller");
else
Serial.println("Ethernet controller initialized");
Serial.println();
if (!ether.dhcpSetup())
Serial.println("Failed to get configuration from DHCP");
else
Serial.println("DHCP configuration done");
ether.printIp("IP Address:\t", ether.myip);
ether.printIp("Netmask:\t", ether.netmask);
ether.printIp("Gateway:\t", ether.gwip);
Serial.println();
if (!ether.dnsLookup(server))
Serial.println("DNS failed");
else
Serial.println("DNS resolution done");
ether.printIp("SRV IP:\t", ether.hisip);
Serial.println();
}
有时候可以 有时候不行
返回数据是空的 等很久才能有数据返回
有大神能帮我看看吗? 谢谢 const char SensorID[] PROGMEM = "171286";
const char APIKey[] PROGMEM = "2c4265c045794880588ffeea97d70216";//
你的APIKEY暴露了 yeelink的话好像是10s suoma 发表于 2015-8-12 21:14 static/image/common/back.gif
const char SensorID[] PROGMEM = "171286";
const char APIKey[] PROGMEM = "2c4265c045794880588ffeea97 ...
暴露会怎么样? suoma 发表于 2015-8-12 21:14 static/image/common/back.gif
yeelink的话好像是10s
把提交时间延长? Atoney 发表于 2015-8-12 23:18 static/image/common/back.gif
暴露会怎么样?
我可以登录看到你的数据,甚至位置 没看到延时,它有个应答过程,类似网络协议的“三次握手” suoma 发表于 2015-8-13 20:06 static/image/common/back.gif
我可以登录看到你的数据,甚至位置
试试私密我位置 suoma 发表于 2015-8-13 20:08 static/image/common/back.gif
没看到延时,它有个应答过程,类似网络协议的“三次握手”
就是有时候返回不了。。提交了 没有返回 要隔很长时间才有反应。有时候 没有了。
有其他方案介绍? yeelink最近老出故障
页:
[1]