资源简介
乐为物联环境监测代码,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格式的
- 下一篇:软件项目开发总结报告模板
相关资源
- ADNS-3080光流传感器测试程序Arduino
- EESkill NRF24L01 无线模块用户手册
- Arduino nano 工程文件
- Arduino教程 Lesson 之--自制风扇
- 基于Arduino的智能环境监控系统设计
- 基于Arduino和Machtalk的温棚环境监测系
- esp8266 win10驱动 cp2102
- CSDN文件---ESP8266.rar
- arduino pca9685多舵机同时控制案例
- stm32103c8t6ESP8266串口转WIFI模块TCP服务器
- ESP8266ESP8266安卓控制端源代码
- arduino技术内幕
- Arduino电子设计实战指南.零基础篇_超
- 物联网智能家居平台DIY:ARDUINO 物联网
- 实验1.zip arduino跑马灯led灯实验,串口
- opencat所有资料.zip
- arduino主机,stm8从机。I2C测试 。每次
- nudemcu相关工具和固件测试稳定
- DS18B20_Serial_println.ino
- ps2手柄arduino库文件
- 基于手机蓝牙的arduino遥控小车
- 单片机通过ESP8266上传温湿度数据
- STM32F407ZG_ESP8266例程
- arduino中的can库函数
- 密码+指纹锁资料包.rar
- ESP8266最新稳定版固件
- ESP8266AP模式控制51单片机亮灯.docx
- ESP8266使用MQTT协议连接阿里云
- 贝壳物联arduino esp8266 demo版本
- ESP8266程序加上MQTT调试工具
评论
共有 条评论