传感器数据采集本地储存
本帖最后由 王大富 于 2021-2-23 13:14 编辑1.下载文件https://pan.baidu.com/s/1cv_82iyG8Pkb59iMlZT8nw
2.解压后打开APMserv
2.安装软件
3 点击执行
4查看数据与导出及数据储存位置
5烧录程序
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h> //自动链接最强wifi库
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include "DHTesp.h" //温度DHT11模块函数库
DHTesp dht;
ESP8266WiFiMulti wifiMulti; //自动链接wifi
const char *keys[] = {"Content-Length", "Content-Type", "Connection", "Date"}; //需要收集的响应头的信息
HTTPClient http;
void setup() {
Serial.begin(115200);
// Serial.setDebugOutput(true);
dht.setup(D4, DHTesp::DHT11); //温湿度模块DHT11初始化,D4脚位
Serial.println();
Serial.println();
Serial.println();
for (uint8_t t = 4; t > 0; t--) {
Serial.printf(" WAIT %d...\n", t);
Serial.flush();
delay(1000);
}
WiFi.mode(WIFI_STA);
wifiMulti.addAP("CMCC-PbWq","1419bf07201"); //添加多个wifi网络
wifiMulti.addAP("FAST_602","1d76dff@9410");
//设置获取响应头的信息
http.collectHeaders(keys, 4);
}
WiFiClient client;
bool http_start_flag = false;
unsigned char http_status = 0;
String custom_url = "";
unsigned long http_timer = 0;
#define HTTP_TIMEOUT 1
#define HTTP_SUCCESS 2
#define HTTP_FAIL 3
unsigned char http_return_status = 0;
String http_return_string = "";
int httpCode =0;
void httpService()
{
switch (http_status)
{
case 0:
if (http_start_flag == true)
{
http_start_flag = false;
http_status = 1;
http_timer = millis();
http_return_status = 0;
Serial.println("1、start sending");
}
break;
case 1: //发起连接
if ((wifiMulti.run() == WL_CONNECTED)) {
http_status = 2;
http.begin(client, custom_url);
httpCode = http.GET();
Serial.println("2、http.begin");
} else if (millis() - http_timer > 5000) //超时未获取wifi
{
http_return_status = HTTP_TIMEOUT;
http_status = 0;
Serial.println("timeout");
}
break;
case 2:
if (httpCode > 0)
{
if (httpCode == HTTP_CODE_OK)
{
http_return_string = http.getString();
http_return_status = HTTP_SUCCESS;
Serial.println("3、SUCCESS");
}
else//访问网络其他错误
{
http_return_status = HTTP_FAIL;
}
http_status = 0;
http.end();
}
break;
default:
break;
}
}
unsigned char DHTtemp=0;
unsigned char DHTrh=0;
const String server_page="http://192.168.1.32/esptemprec/cpost.php";//这是esp8266提交页面,需要修改对应IP或网址
const String espid="0001"; //esp8266的id号,每个节点使用不用的id
String nowdate="2021.1.30";//这是上传日期,需要根据你的时钟对这个值赋值
String nowtime="12:13:45"; //这是上传时间,需要根据你的时钟对这个值赋值
/*以下是定制的上传函数,你只要调用一次,就会上传*/
void userCustomHttpSendmessage(String temp,String rh,String othera,String otherb)
{
custom_url=server_page+"?espid="+espid+"&recdate="+nowdate+"&rectime="+"nowtime"+"&temp="+temp+"&rh="+rh+"&othera="+othera+"&otherb="+otherb;
http_start_flag=true;
}
unsigned long sendtimer=0;//用于发送时间控制
#define SEND_INTERVAL 1000
void loop() {
DHTtemp=dht.getTemperature(); //此处放置你获取到的温度值
DHTrh= dht.getHumidity(); //此处放置你获取到的湿度值
if(millis()-sendtimer>SEND_INTERVAL)
{
userCustomHttpSendmessage(String(DHTtemp),String(DHTrh),"11","22");//此处的1122是备用的,你可以自由放置需要上传的变量
sendtimer=millis();
Serial.println("0、ready to send");
Serial.print("DHTtemp=");Serial.println(DHTtemp);
Serial.print("DHTrh=");Serial.println(DHTrh);
}
if(http_return_status == HTTP_SUCCESS)
{
Serial.print("Send success...");
http_return_status =0;
}
httpService();
}6.修改程序中的wifi和电脑IP即可
没有密码呢?无法下载,谢谢 anqiw 发表于 2021-2-20 11:04
没有密码呢?无法下载,谢谢
已发送给您 密码是wdf1
页:
[1]