請選擇 進入手機版 | 繼續訪問電腦版

施勢帆老師的教學網站

 找回密碼
 註冊
搜索
熱搜: 活动 交友 discuz
查看: 25|回復: 0

ESP13 wifi Shield

[複製鏈接]
shie 發表於 6 天前 | 顯示全部樓層 |閱讀模式
http://www.mantech.co.za/datashe ... IELD-ESP13_KEYS.pdf

https://mouse.oit.edu.tw/Data/Program/ai/IFTTT.zip


Test.ino

#define DEBUG true

String sendData(String command, const int timeout, boolean debug){
    String response = "";
    Serial1.print(command); // send the read character to the esp8266
    long int time = millis();
    while( (time+timeout) > millis()){
      while(Serial1.available()){
        // The esp has data so display its output to the serial window
        char c = Serial1.read(); // read the next character.
        response+=c;
      }  
    }
    if(DEBUG)    {
        Serial.print(response);
    }
    return response;
}

void setup()
{
  Serial.begin(115200);
  while(!Serial);
  Serial1.begin(115200);
  sendData("AT+RST\r\n",2000,DEBUG);
  sendData("AT+CWMODE=3\r\n",2000,DEBUG);
  String commend = "AT+CWJAP=\"";
  commend += "AP-SSID";
  commend += "\",\"";
  commend += "Password";
  commend += "\"\r\n";
  if (sendData(commend,5000,DEBUG)){  
    Serial.print("Join AP success\r\n");
    Serial.print("IP:");
    sendData("AT+CIFSR\r\n",5000,DEBUG);
    sendData("AT+CIPSERVER=0\r\n",200,DEBUG);
    sendData("AT+CIPMUX=0\r\n",200,DEBUG);
  }
}

void loop()
{
  if(Serial1.available()){
    Serial.write(Serial1.read());
  }
  if(Serial.available()){
    Serial1.write(Serial.read());
  }
}      


-----------------------------------------------------------------------------------------------------------------------------------------
String commends = "AT+CIPSTART=\"TCP\",\"";
  commends += host;
  commends += "\",";
  commends += httpsPort; //443
  commends += "\r\n";
  sendData(commends,1000,DEBUG);

  String GET = "GET /update?api_key=T6HJZN26NA26L5FU";
  GET += "&field1=";
  GET += DHT.temperature;
  GET += "&field2=";
  GET += DHT.humidity;
  GET += " HTTP/1.1\r\nHost:";
  GET += host;
  GET += "\r\n\r\n";
  Serial.println(GET);
  String cipSend = "AT+CIPSEND=";

  cipSend += GET.length();
  cipSend += "\r\n";
  sendData(cipSend,500,DEBUG);
  sendData(GET,500,DEBUG);
  delay(200);
  sendData("AT+CIPCLOSE\r\n",500,DEBUG);
  delay(1000);   
  sendData("AT+CIFSR\r\n",5000,DEBUG);



本帖子中包含更多資源

您需要 登錄 才可以下載或查看,沒有帳號?註冊

x
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

小黑屋|手机版|Archiver|施勢帆老師的教學網站  

GMT+8, 2019-10-14 15:12 , Processed in 0.082702 second(s), 18 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表