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

專注電子技術(shù)學(xué)習(xí)與研究
當(dāng)前位置:單片機(jī)教程網(wǎng) >> Arduino >> 瀏覽文章

物聯(lián)網(wǎng)之遠(yuǎn)程控制家電開關(guān)

作者:小東   來源:轉(zhuǎn)自小東   點(diǎn)擊數(shù):  更新時(shí)間:2014年05月30日   【字體:

   基于Dccduino uno 結(jié)合Dcc ethernet W5100擴(kuò)張?jiān)趛eelink物聯(lián)網(wǎng)平臺(tái)控制家電開關(guān)的例子,本教程實(shí)現(xiàn)的功能通過PC端網(wǎng)頁服務(wù)器和手機(jī)APP的控制一個(gè)LED.   

 

硬件準(zhǔn)備:


     軟件準(zhǔn)備:
1.安裝Arduino開發(fā)環(huán)境,如果您的電腦上沒有安裝Arduino開發(fā)環(huán)境,點(diǎn)擊這里學(xué)習(xí)如何安裝Arduino
2.成為Yeelink開發(fā)者,如果您還沒有注冊,點(diǎn)擊這里注冊。
3.下載Yeelink移動(dòng)客戶端APP,點(diǎn)擊這里下載


在yeelink平臺(tái)添加設(shè)備和傳感器
1.進(jìn)入用戶中心

2.增加新設(shè)備





3.增加傳感器




下一步往DCCduino上傳代碼:

#include
#include
#include
#include

byte buff[2];

// for yeelink api
#define APIKEY         "xxxxxxxxxxxxxxxxxxxx" // 此處替換為你自己的API KEY
#define DEVICEID       7003 // 此處替換為你的設(shè)備編號
#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();
}



如上圖接線,前提是保證你的網(wǎng)線是鏈接到路由器上面能上網(wǎng)的,LED的端口鏈接到數(shù)字端口5腳,按照設(shè)想我們是在PC端或者手機(jī)APP遠(yuǎn)程控制這個(gè)LED,好了,切換
我們的設(shè)備管理器,控制我們的開關(guān):

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

再轉(zhuǎn)化到我們的手機(jī)APP,打開yeelink應(yīng)用,找到你的設(shè)備進(jìn)行操作



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

關(guān)閉窗口

相關(guān)文章

主站蜘蛛池模板: 国产精品免费看 | 羞羞色在线观看 | 国产精品久久99 | 黄网站涩免费蜜桃网站 | 亚洲三区在线 | 欧美一a | 欧美日韩中文字幕在线 | 中日字幕大片在线播放 | 欧美精品一二区 | 欧美成ee人免费视频 | 久久久久国产精品一区二区 | 四虎永久免费影院 | 国产激情视频网址 | 中文字幕一区二区三区不卡 | 欧美一级淫片免费视频黄 | 欧美精品在线视频 | 亚洲欧美自拍偷拍视频 | 日韩福利在线观看 | 一级黄色av电影 | 自拍 亚洲 欧美 老师 丝袜 | 黄在线免费观看 | 成人免费视频网站在线看 | 亚洲九色 | 日本高清不卡视频 | 久久久久国产一区二区三区 | 日本一区二区高清不卡 | 欧美在线观看一区 | 中国毛片免费 | 天天操天天射天天 | 国外成人在线视频 | 青青草综合 | 91中文字幕在线 | 人操人人 | 欧洲一区二区三区 | 国产精品18久久久久久白浆动漫 | 久热精品在线观看视频 | 91麻豆精品一区二区三区 | 国产丝袜一区二区三区免费视频 | 99九九久久 | 伊人免费在线观看高清 | 亚洲精品一区中文字幕乱码 |