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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 5937|回復: 5
收起左側

arduino物聯網程序

[復制鏈接]
ID:76244 發表于 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 // 此處替換為你的設備編號
#define SENSORID1       33314 // 此處替換為你的傳感器編號


// 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();
}



回復

使用道具 舉報

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

使用道具 舉報

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

使用道具 舉報

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

使用道具 舉報

ID:117823 發表于 2016-5-1 17:26 | 顯示全部樓層
這個是arduino nano 與enc28j60 開關控制代碼。
回復

使用道具 舉報

ID:117823 發表于 2016-6-4 01:34 來自手機 | 顯示全部樓層
yeelink現在網頁有些卡,不好用了。
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 久久久久国产精品www | 色久电影 | 日本免费一区二区三区 | 国产激情综合五月久久 | 亚洲v日韩v综合v精品v | 亚洲欧美中文字幕在线观看 | 特级黄一级播放 | 日韩欧美在线视频播放 | 中文字幕精品一区 | 亚洲成av | 成人在线中文字幕 | 国产四虎| 午夜影院在线观看免费 | 亚洲精品欧美 | 久久久观看 | 极情综合网 | 午夜不卡一区二区 | 日韩一区二区三区视频在线观看 | 国产精品美女久久久免费 | 欧美成人免费在线视频 | 久久久久久久久久影视 | 久久久国产网站 | 亚洲综合一区二区三区 | 少妇一区在线观看 | 孰女乱色一区二区三区 | 中文字幕精品视频 | 成人网在线观看 | 99精品在线 | 国产玖玖 | 九九99靖品 | 日韩欧美中文字幕在线观看 | 国产高清精品一区二区三区 | 久久精品国产清自在天天线 | 亚洲精品毛片av | 日韩精品一区二区在线观看 | 波多野结衣一区二区三区 | 中文字幕不卡在线观看 | av喷水| k8久久久一区二区三区 | 午夜视频一区 | 国产精品美女久久久久久久网站 |