資源簡介
樂為物聯環境監測代碼,arduinio+dht11+MQ9+火焰,AT控制ESP8266。

代碼片段和文件信息
//?
//?
//?
#include?“ESP8266SoftwareSerialHTTPPOST.h“
SoftwareSerial?wifi_SoftSerial(rxPin?txPin);
ESP8266SoftwareSerialHTTPPOST::ESP8266SoftwareSerialHTTPPOST()
{
wifi_SoftSerial.begin(9600);
}
int?ESP8266SoftwareSerialHTTPPOST::initESP8266()
{
int?errcnt?=?0;
if?(!doATCommand(F(“AT+CIPMODE=1“)?deftStr?deffStr?10))?{?errcnt++;?}
if?(!doATCommand(F(“AT+RST“)?deftStr?deffStr?100))?{?errcnt++;?}
if?(!doATCommand(F(“AT+CIPMUX=0“)?deftStr?deffStr?10))?{?errcnt++;?}
if?(!doATCommand(F(“AT+CWMODE=1“)?deftStr?deffStr?10))?{?errcnt++;?}
return?errcnt;
}
bool?ESP8266SoftwareSerialHTTPPOST::initWifi()
{
//測試Wifi連接
if?(!doATCommand(F(“AT+CWJAP?“)wifi_ssid?F(“No?AP“)100))?{
//連接到WIFI
if?(!doATCommand(“AT+CWJAP=\““?+?wifi_ssid?+?“\“\““?+?wifi_password?+?“\““?deftStrdeffStr10000))?{
Serial.println(F(“AT+CWJAP:ERROR:“));
Serial.println(resultLine);
return?false;
}
}
return?true;
}
bool?ESP8266SoftwareSerialHTTPPOST::httpPost()
{
bool?result?=?true;
//連接服務器
result?=?doATCommand(“AT+CIPSTART=\“TCP\“\““?+?HostAddress?+?“\““?+?HostPort?deftStr?deffStr?1000);
if?(!result)?{
Serial.println(F(“AT+CIPSTART:ERROR:“));
Serial.println(resultLine);
return?false;
}
/*
POST?/api/V1/gateway/Updatesensors/01?HTTP/1.1
userkey:e7b5ff49b74245ef905bf2150907d5cb
Host:www.lewei50.com
Content-Length:30
[{“Name“:“H1““Value“:“22“}]
*/
String?curData?=?mathData();
//Post數據
result?=?postString(“POST?“?+?HostApiPath?+?“?HTTP/1.1“?);
if?(result)?{
result?=?postString(“userkey:“?+?UserKey?);
}
if?(result)?{
result?=?postString(“Host:?“?+?HostAddress?);
}
if?(result)?{
result?=?postString(“Content-Length:“?+?(String)curData.length());
}
if?(result)?{
result?=?postString(““);
}
if?(result?)?{
result?=?postString(curData);
}
curData?=?““;
//退出透傳
doATCommand(F(“+++“)?deftStr?deffStr?20);
//關閉TCP/UDP連接
doATCommand(F(“AT+CIPCLOSE“)?deftStr?deffStr?20);
return?result;
}
bool?ESP8266SoftwareSerialHTTPPOST::doATCommand(String?cmd?String?tStr?String?fStr?unsigned?long?outTime)
{
unsigned?long?LastTime?=?0UL; //過去的時間
unsigned?long?StartTime; //開始時間
int?result?=?-1;
//發送命令
wifi_SoftSerial.println(cmd);
//等待數據返回
while?(result==-1)
{
StartTime?=?micros();
if?(wifi_SoftSerial.available()>0)?{
while?(wifi_SoftSerial.available()>0)
{
resultLine?=?wifi_SoftSerial.readStringUntil(‘\n‘)?+?‘\n‘;
//Serial.print(resultLine);
if?(resultLine.lastIndexOf(tStr)>-1)?{
result?=?0;
}
if?(resultLine.lastIndexOf(fStr)>-1)?{
result?=?1;
}
}
}
LastTime?+=?micros()-StartTime; //增加經過的時間
if?(LastTime?>?outTime*1000)?{
break;
}
}
delay(100);
return?result?==?0;
}
String?ESP8266SoftwareSerialHTTPPOST::mathData()
{
String?curData?=?“[“;
int?count?=?sizeof(infos)?/?sizeof(infos[0]);
for?(int?i?=?0;?i {
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????24119??2018-10-13?13:58??智能家居V1\Debug\board.buildinfo
?????文件???????1358??2018-07-04?11:22??智能家居V1\Debug\DHT11SimpleRead.cpp.d
?????文件???????7188??2018-07-04?11:22??智能家居V1\Debug\DHT11SimpleRead.cpp.o
?????文件???????1315??2018-10-13?13:58??智能家居V1\Debug\DHT_sensor_library\DHT.cpp.d
?????文件??????21820??2018-10-13?13:58??智能家居V1\Debug\DHT_sensor_library\DHT.cpp.o
?????文件???????1573??2018-10-13?13:58??智能家居V1\Debug\DHT_sensor_library\DHT_U.cpp.d
?????文件??????27692??2018-10-13?13:58??智能家居V1\Debug\DHT_sensor_library\DHT_U.cpp.o
?????文件???????1585??2018-10-13?13:58??智能家居V1\Debug\ESP8266SoftwareSerialHTTPPOST.cpp.d
?????文件??????38864??2018-10-13?13:58??智能家居V1\Debug\ESP8266SoftwareSerialHTTPPOST.cpp.o
?????文件???????1331??2018-07-03?20:58??智能家居V1\Debug\GP2Y10.cpp.d
?????文件???????7440??2018-07-03?20:58??智能家居V1\Debug\GP2Y10.cpp.o
?????文件???????1451??2018-10-13?13:58??智能家居V1\Debug\SoftwareSerial\SoftwareSerial.cpp.d
?????文件??????34540??2018-10-13?13:58??智能家居V1\Debug\SoftwareSerial\SoftwareSerial.cpp.o
?????文件???????1348??2018-10-13?13:58??智能家居V1\Debug\VM_DBG\VM_DBG.cpp.d
?????文件??????49592??2018-10-13?13:58??智能家居V1\Debug\VM_DBG\VM_DBG.cpp.o
?????文件????????228??2018-10-13?13:58??智能家居V1\Debug\VM_DBG\VM_mem_check_sam.cpp.d
?????文件???????1660??2018-10-13?13:58??智能家居V1\Debug\VM_DBG\VM_mem_check_sam.cpp.o
?????文件???????1810??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.cpp.d
?????文件??????29388??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.cpp.o
?????文件??????97064??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.elf
?????文件??????39777??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.hex
?????文件??????97064??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.ino.elf
?????文件??????39777??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.ino.hex
?????文件??????44287??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.ino.with_bootloader.hex
?????文件??????44287??2018-10-13?13:58??智能家居V1\Debug\智能家居V1.with_bootloader.hex
?????文件???????3667??2018-07-03?21:29??智能家居V1\ESP8266SoftwareSerialHTTPPOST.cpp
?????文件???????1342??2018-10-13?13:46??智能家居V1\ESP8266SoftwareSerialHTTPPOST.h
?????文件???????2523??2018-07-05?07:37??智能家居V1\__vm\.智能家居V1.vsarduino.h
?????文件??????25128??2018-10-13?13:58??智能家居V1\__vm\Compile.vmps.xm
?????文件??????20553??2018-10-13?13:58??智能家居V1\__vm\Configuration.Debug.vmps.xm
............此處省略15個文件信息
- 上一篇:武漢電子地圖mapinfo格式的
- 下一篇:軟件項目開發總結報告模板
評論
共有 條評論