久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 6049|回復(fù): 5
收起左側(cè)

arduino物聯(lián)網(wǎng)程序

[復(fù)制鏈接]
ID:76244 發(fā)表于 2015-4-7 01:32 | 顯示全部樓層 |閱讀模式
#include <SPI.h>

#include <Ethernet.h>
#include <Wire.h>
#include <math.h>

byte buff[2];

// for yeelink api
#define APIKEY         "20314f31cb6934a5187f43b676be2886" // 此處替換為你自己的API KEY
#define DEVICEID       19119 // 此處替換為你的設(shè)備編號(hào)
#define SENSORID1       33314 // 此處替換為你的傳感器編號(hào)


// assign a MAC address for the ethernet controller.
byte mac[] = { 0x00, 0x1D, 0x72, 0x82, 0x35, 0x9D};
// initialize the library instance:
EthernetClient client ;
char server[] = "api.yeelink.net";   // name address for yeelink API

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 3*1000; // delay between 2 datapoints, 30s
String returnValue = "";  
boolean ResponseBegin = false;

void setup() {
   pinMode(5, OUTPUT);
   Wire.begin();
   // start serial port:
  Serial.begin(57600);

   // start the Ethernet connection with DHCP:
   if (Ethernet.begin(mac) == 0) {
     Serial.println("Failed to configure  Ethernet using DHCP");
     for(;;)
       ;
   }
   else {
     Serial.println("Ethernet configuration OK");
   }
}

void loop() {
   // if there's incoming data from the net connection.
   // send it out the serial port.  This is for debugging
   // purposes only:

   if (client.available()) {
     char c = client.read();
    // Serial.print(c);
       if (c == '{')
         ResponseBegin = true;
       else if (c == '}')
         ResponseBegin = false;

       if (ResponseBegin)
         returnValue += c;   
   }
   if (returnValue.length() !=0 && (ResponseBegin == false))
   {
     Serial.println(returnValue);

     if (returnValue.charAt(returnValue.length() - 1) == '1') {
       Serial.println("turn on the LED");  
       digitalWrite(5, HIGH);
     }  
       else if(returnValue.charAt(returnValue.length() - 1) == '0') {
       Serial.println("turn off the LED");  
       digitalWrite(5, LOW);
}
      returnValue = "";
   }
   // if there's no net connection, but there was one last time
   // through the loop, then stop the client:
   if (!client.connected() && lastConnected) {
    Serial.println();
     Serial.println("disconnecting.");     client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    // read sensor data, replace with your code
    //int sensorReading = readLightSensor();
    Serial.print("yeelink:");
    //get data from server   
    getData();    }
  // store the state of the connection for next time through
   // the loop:
  lastConnected = client.connected();
}



// this method makes a HTTP connection to the server and get data back
void getData(void) {
   // if there's a successful connection:
   if (client.connect(server, 80)) {
     Serial.println("connecting...");
     // send the HTTP GET request:

     client.print("GET /v1.0/device/");
     client.print(DEVICEID);
     client.print("/sensor/");
     client.print(SENSORID1);
     client.print("/datapoints");
     client.println(" HTTP/1.1");
     client.println("Host: api.yeelink.net");
     client.print("Accept: *");
     client.print("/");
     client.println("*");
     client.print("U-ApiKey: ");
     client.println(APIKEY);
     client.println("Content-Length: 0");
     client.println("Connection: close");
     client.println();
     Serial.println("print get done.");

   }  
   else {
     // if you couldn't make a connection:
     Serial.println("connection failed");
    Serial.println();
    Serial.println("disconnecting.");
     client.stop();
   }
    // note the time that the connection was made or attempted:
   lastConnectionTime = millis();
}



相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

ID:55838 發(fā)表于 2015-4-12 22:11 | 顯示全部樓層
感謝樓主的分享。
回復(fù)

使用道具 舉報(bào)

ID:76574 發(fā)表于 2015-5-5 19:58 | 顯示全部樓層
這個(gè)是人家YEELINK的代碼吧??
回復(fù)

使用道具 舉報(bào)

ID:48018 發(fā)表于 2015-10-20 23:27 | 顯示全部樓層
謝謝樓主分享!
回復(fù)

使用道具 舉報(bào)

ID:117823 發(fā)表于 2016-5-1 17:26 | 顯示全部樓層
這個(gè)是arduino nano 與enc28j60 開(kāi)關(guān)控制代碼。
回復(fù)

使用道具 舉報(bào)

ID:117823 發(fā)表于 2016-6-4 01:34 來(lái)自觸屏版 | 顯示全部樓層
yeelink現(xiàn)在網(wǎng)頁(yè)有些卡,不好用了。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 成人久久视频 | 欧美精品久久久 | 国产精品视频久久久 | 中文成人在线 | 亚洲欧美久久 | 久久综合伊人 | av日韩一区 | 成人欧美一区二区三区在线播放 | 日本一二三区高清 | 天天操精品视频 | 亚洲国产精品成人 | 国产欧美日韩视频 | 看一级毛片视频 | 精品欧美一区二区三区久久久 | 日本三级做a全过程在线观看 | 精品综合网 | 亚洲视频在线一区 | 亚洲欧美一区二区三区国产精品 | 国产视频精品视频 | 日韩中文一区 | 99这里只有精品视频 | 奇米四色在线观看 | 黄视频免费在线 | 中文字幕亚洲在线 | 羞羞午夜 | 欧美一区二区三区一在线观看 | 国产91在线 | 亚洲 | 国产视频中文字幕在线观看 | 日韩精品一区二区三区免费观看 | 久久久91 | 91最新入口 | 国产精品美女久久久久aⅴ国产馆 | 久久久久久久久久久丰满 | 欧美精品a∨在线观看不卡 欧美日韩中文字幕在线播放 | 在线免费av观看 | 欧美一级二级三级视频 | 狠狠狠干| 久久一区二区三区电影 | 欧美三级免费观看 | 久久精品国产99国产精品 | 天天色天天射天天干 |