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

專注電子技術學習與研究
當前位置:單片機教程網 >> Arduino >> 瀏覽文章

物聯網之遠程控制家電開關

作者:小東   來源:轉自小東   點擊數:  更新時間:2014年05月30日   【字體:

   基于Dccduino uno 結合Dcc ethernet W5100擴張在yeelink物聯網平臺控制家電開關的例子,本教程實現的功能通過PC端網頁服務器和手機APP的控制一個LED.   

 

硬件準備:


     軟件準備:
1.安裝Arduino開發環境,如果您的電腦上沒有安裝Arduino開發環境,點擊這里學習如何安裝Arduino
2.成為Yeelink開發者,如果您還沒有注冊,點擊這里注冊。
3.下載Yeelink移動客戶端APP,點擊這里下載


在yeelink平臺添加設備和傳感器
1.進入用戶中心

2.增加新設備





3.增加傳感器




下一步往DCCduino上傳代碼:

#include
#include
#include
#include

byte buff[2];

// for yeelink api
#define APIKEY         "xxxxxxxxxxxxxxxxxxxx" // 此處替換為你自己的API KEY
#define DEVICEID       7003 // 此處替換為你的設備編號
#define SENSORID1       10926 // 此處替換為你的傳感器編號


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



如上圖接線,前提是保證你的網線是鏈接到路由器上面能上網的,LED的端口鏈接到數字端口5腳,按照設想我們是在PC端或者手機APP遠程控制這個LED,好了,切換
我們的設備管理器,控制我們的開關:

可以看到LED是受控了,也就說PC端能控制了。

再轉化到我們的手機APP,打開yeelink應用,找到你的設備進行操作



大伙覺得就控制一個led不好玩是吧,看到桌面的小電風扇,直接拿開刀,話不多說,看視頻。

關閉窗口

相關文章

主站蜘蛛池模板: aⅴ色国产 欧美 | 在线成人免费视频 | 在线观看国产视频 | 九九亚洲精品 | 国产美女视频一区 | 三级视频在线观看电影 | 伊人精品国产 | 熟女毛片| 中文字幕久久久 | 91精品国产欧美一区二区 | 91免费版在线观看 | 国产特一级黄色片 | 91原创视频 | 天天躁日日躁狠狠躁2018小说 | 成人在线中文字幕 | 成人亚洲一区 | 亚洲精品日韩在线观看 | 午夜视频在线观看网址 | 成年男女免费视频网站 | 国产精品人人做人人爽 | 日韩欧美国产一区二区三区 | 亚洲交性 | 日韩欧美久久 | 久久精品国产一区二区三区不卡 | a级性视频 | 日韩三区| 精品中文在线 | 国产一区91精品张津瑜 | 欧美久久久久久 | 成人国产精品久久 | 久久精品在线播放 | 国产欧美日韩在线 | 日韩在线国产 | 精品国产一区二区国模嫣然 | 色综合欧美 | 欧美日韩国产精品一区二区 | 红桃视频一区二区三区免费 | 久久精品国产免费 | 丝袜 亚洲 欧美 日韩 综合 | 欧美一区二区三区大片 | 欧美白人做受xxxx视频 |