ESP8266 HTTP 项目(1)在刻度盘上进行ESP8266 NodeMCU模拟读取的步骤
https://circuits4you.com/2018/02/03/esp8266-nodemcu-adc-analog-value-on-dial-gauge/
ESP8266(NodeMCU)ADC表盘上的模拟值
这是它使用JavaScripts,ESP8266,CSS和HTML知识的高级教程。在此示例中,我们正在读取ADC的模拟值并将其显示在HTML网页上,该网页由ESP8266或NodeMCU Web服务器提供。要获得有关ESP8266中基本HTML页面创建的更多详细信息,请阅读此内容。
ESP8266只有一个adc频道。让我们开始阅读模拟并做一些很酷的事情
在刻度盘上进行ESP8266 NodeMCU模拟读取的步骤
步骤1:编写ESP NodeMCU代码,如下所示
此代码在ESP上创建Web服务器并连接到给定的wifi网络配置。根据您的wifi网络更改WiFi配置
代码分为多个部分让我们来了解什么是什么?
1.连接到WiFi网络
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
//Connect to wifi Network
WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
|
2.在onRoot,onNotFound上创建Web服务器,最后读取ADC
Server Initializer有关此内容的更多信息,请参见此处
1
2
3
4
5
|
//Initialize Webserver
server.on("/",handleRoot);
server.on("/getADC",handleADC); //Reads ADC function is called from out index.html
server.onNotFound(handleWebRequests); //Set setver all paths are not found so we can handle as per URI
server.begin();
|
Web服务器主页位于root上。notFound Handler执行诸如向客户端发送javascripts,jQuery和Css文件之类的任务。 ESP重定向在这里解释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
void handleWebRequests(){
if(loadFromSpiffs(server.uri())) return;
String message = "File Not Detected\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " NAME:"+server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
Serial.println(message);
}
|
上面的代码实际上首先解码未找到的URL,然后将这些参数传递给spiffs loader。ESP8266 SPIFFS在这里解释
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
bool loadFromSpiffs(String path){
String dataType = "text/plain";
if(path.endsWith("/")) path += "index.htm";
if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
else if(path.endsWith(".html")) dataType = "text/html";
else if(path.endsWith(".htm")) dataType = "text/html";
else if(path.endsWith(".css")) dataType = "text/css";
else if(path.endsWith(".js")) dataType = "application/javascript";
else if(path.endsWith(".png")) dataType = "image/png";
else if(path.endsWith(".gif")) dataType = "image/gif";
else if(path.endsWith(".jpg")) dataType = "image/jpeg";
else if(path.endsWith(".ico")) dataType = "image/x-icon";
else if(path.endsWith(".xml")) dataType = "text/xml";
else if(path.endsWith(".pdf")) dataType = "application/pdf";
else if(path.endsWith(".zip")) dataType = "application/zip";
File dataFile = SPIFFS.open(path.c_str(), "r");
if (server.hasArg("download")) dataType = "application/octet-stream";
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
}
dataFile.close();
return true;
}
|
一旦你知道了所有编程技术,我们就可以转向实际的编程。
最终完整代码
将此代码复制并粘贴到arduino中。然后上传它
ESP8266(NodeMCU)ADC表盘上的模拟值
2018年2月3日ESP8266 esp,html,Javascript,NodeMCU,web服务器
这是它使用JavaScripts,ESP8266,CSS和HTML知识的高级教程。在此示例中,我们正在读取ADC的模拟值并将其显示在HTML网页上,该网页由ESP8266或NodeMCU Web服务器提供。要获得有关ESP8266中基本HTML页面创建的更多详细信息,请阅读此内容。 ESP8266只有一个adc频道。让我们开始阅读模拟并做一些很酷的事情 ESP8266-模拟读数表盘 在刻度盘上进行ESP8266 NodeMCU模拟读取的步骤
步骤1:编写ESP NodeMCU代码,如下所示
此代码在ESP上创建Web服务器并连接到给定的wifi网络配置。根据您的wifi网络更改WiFi配置 代码分为多个部分让我们来了解什么是什么? 1.连接到WiFi网络 //Connect to wifi Network
WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println(""); // Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
} //If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//Connect to wifi Network
WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println(""); // Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
} //If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
2.在onRoot,onNotFound上创建Web服务器,最后读取ADC Server Initializer有关此内容的更多信息,请参见此处 //Initialize Webserver
server.on("/",handleRoot);
server.on("/getADC",handleADC); //Reads ADC function is called from out index.html
server.onNotFound(handleWebRequests); //Set setver all paths are not found so we can handle as per URI
server.begin();
1
2
3
4
5
//Initialize Webserver
server.on("/",handleRoot);
server.on("/getADC",handleADC); //Reads ADC function is called from out index.html
server.onNotFound(handleWebRequests); //Set setver all paths are not found so we can handle as per URI
server.begin();
Web服务器主页位于root上。notFound Handler执行诸如向客户端发送javascripts,jQuery和Css文件之类的任务。 ESP重定向在这里解释 void handleWebRequests(){
if(loadFromSpiffs(server.uri())) return;
String message = "File Not Detected\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " NAME:"+server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
Serial.println(message);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void handleWebRequests(){
if(loadFromSpiffs(server.uri())) return;
String message = "File Not Detected\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " NAME:"+server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
Serial.println(message);
}
上面的代码实际上首先解码未找到的URL,然后将这些参数传递给spiffs loader。ESP8266 SPIFFS在这里解释 bool loadFromSpiffs(String path){
String dataType = "text/plain";
if(path.endsWith("/")) path += "index.htm"; if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
else if(path.endsWith(".html")) dataType = "text/html";
else if(path.endsWith(".htm")) dataType = "text/html";
else if(path.endsWith(".css")) dataType = "text/css";
else if(path.endsWith(".js")) dataType = "application/javascript";
else if(path.endsWith(".png")) dataType = "image/png";
else if(path.endsWith(".gif")) dataType = "image/gif";
else if(path.endsWith(".jpg")) dataType = "image/jpeg";
else if(path.endsWith(".ico")) dataType = "image/x-icon";
else if(path.endsWith(".xml")) dataType = "text/xml";
else if(path.endsWith(".pdf")) dataType = "application/pdf";
else if(path.endsWith(".zip")) dataType = "application/zip";
File dataFile = SPIFFS.open(path.c_str(), "r");
if (server.hasArg("download")) dataType = "application/octet-stream";
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
} dataFile.close();
return true;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
bool loadFromSpiffs(String path){
String dataType = "text/plain";
if(path.endsWith("/")) path += "index.htm"; if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
else if(path.endsWith(".html")) dataType = "text/html";
else if(path.endsWith(".htm")) dataType = "text/html";
else if(path.endsWith(".css")) dataType = "text/css";
else if(path.endsWith(".js")) dataType = "application/javascript";
else if(path.endsWith(".png")) dataType = "image/png";
else if(path.endsWith(".gif")) dataType = "image/gif";
else if(path.endsWith(".jpg")) dataType = "image/jpeg";
else if(path.endsWith(".ico")) dataType = "image/x-icon";
else if(path.endsWith(".xml")) dataType = "text/xml";
else if(path.endsWith(".pdf")) dataType = "application/pdf";
else if(path.endsWith(".zip")) dataType = "application/zip";
File dataFile = SPIFFS.open(path.c_str(), "r");
if (server.hasArg("download")) dataType = "application/octet-stream";
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
} dataFile.close();
return true;
}
一旦你知道了所有编程技术,我们就可以转向实际的编程。 最终完整代码
将此代码复制并粘贴到arduino中。然后上传它
上传程序后等待你需要做更多的事情
第2步:将网页和jQuery,Javascripts和CSS上传到ESP8266 NodeMCU闪存
为此,请在草图文件夹中创建名为“ data”的文件夹,即保存上述.ino文件的位置。然后下载并解压缩这些文件ESP8266-analog-gauge-data。
文件夹结构是带有数据文件夹的.ino文件。在数据文件夹中,您有这些文件index.html,style.css,jQuery.min.js,d3-gauge.js。
不将这些文件上传到ESP8266 NodeMCU Flash文件系统。这个怎么做 ?阅读此处加载文件需要一些时间。
第3步:测试
假设您已上传程序和SPIFFS文件。打开串行监视器并重置ESP。您将获得IP地址,在Web浏览器中打开它。确保您的ESP和笔记本电脑在同一网络中
你会得到漂亮的界面。正如我们在开始时所展示的那样。
ESP8266 HTTP 项目(1)在刻度盘上进行ESP8266 NodeMCU模拟读取的步骤的更多相关文章
- Android项目,从web上取下汉字,中文部分乱码
Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...
- 如何部署Java_web项目到云服务器上
步骤 1:购买 Linux 实例(略) 步骤2:安装JDK 本节介绍如何安装java jdk. 软件包中包含的软件及版本如下: Tomcat:1.8.0_121 说明:这是写文档时参考的软件版本.您下 ...
- javaWeb开发中关于eclipse等ide重新部署或重启项目等原因造成上传文件丢失问题解决方案
在开发项目时,有时候需要用到上传功能,比如头像上传等,其文件会保存到服务器中.但是我发现在用eclipse做项目的过程中,每次重新部署项目,原来上传的文件就会丢失. 其原因是因为每次项目修改后,ecl ...
- Springboot项目如何把项目运行在服务器上
作为一个开发者,不可避免的要把本地项目变成可以接入外网的上线项目,今天来记录下springboot框架下如果把项目打包放在服务器上运行 第一步,首先要买个服务器,这个一般甲方会提供 第二步,导入jar ...
- 用eclipse怎样将本地的项目打成jar包上传到maven仓库
使用maven的项目中,有时需要把本地的项目打成jar包上传到mevan仓库. 操作如下: 前提:pom文件中配置好远程库的地址,否则会报错 1.将maven 中的settings文件配置好用户名和密 ...
- git操作+一个本地项目推到github上+注意
git init 创建新文件夹,打开,然后执行以创建新的 git 仓库. git config --global user.name "xxx" git config --glob ...
- 将项目添加到服务上时报web modules的错误
将项目添加到服务上时报web modules的错误如下图: 这是tomcat的版本和web modules的版本不支持造成的,如果在如下地方修改不了: 这时候就要在项目的根目录修改如下图: 用工具打开 ...
- 把项目挂载到composer上
1.打开composer的安装包列表网站,点击submit 2.把刚才初始化了composer的项目push到github上(至于怎么push,最简单就是用git了) 3.然后把github的网址复制 ...
- 微服务开发有道之把项目迁移到Kubernetes上的5个小技巧
我们将在本文中提供5个诀窍帮你将项目迁移到Kubernetes上,这些诀窍来源于过去12个月中OpenFaas社区的经验.下文的内容与Kubernetes 1.8兼容,并且已经应用于OpenFaaS ...
随机推荐
- for循环与forEach性能思考
今日看到一句话: 基于循环的迭代比基于函数的迭代法快8倍,因此有了该篇验证博客. 验证代码如图: 验证结果:在数量比较少的时候,无明显差别,当数量级达到10的4次方时候,for循环的效率优势明显:如图 ...
- angular 拼接html 事件无效
主要是要引用$compile方法
- Angular的12个经典问题,看看你能答对几个?(文末附带Angular测试)
Angular作为目前最为流行的前端框架,受到了前端开发者的普遍欢迎.不论是初学Angular的新手,还是有一定Angular开发经验的开发者,了解本文中的12个经典面试问题,都将会是一个深入了解和学 ...
- Spring学习之旅(四)Spring工作原理再探
上篇博文对Spring的工作原理做了个大概的介绍,想看的同学请出门左转.今天详细说几点. (一)Spring IoC容器及其实例化与使用 Spring IoC容器负责Bean的实例化.配置和组装工作有 ...
- NDK时间测量
在NDK中测量时间,有四种方法. LINUX系统方法 gettimeofday 以秒和微秒的形式返回自从Epoch(1970-01-01 00:00:00 +0000 (UTC))时间以来,系统已经经 ...
- C# 实现中国象棋【棋盘,棋子】
本文是利用C# 实现中国象棋的棋盘绘制,以及初始化布局,并不实现中国象棋的对弈逻辑.仅供学习参考使用. 思路: 绘制中国象棋棋盘,竖线九条,横线十条.再中间绘制‘楚河’,‘汉界’ . 绘制棋子,然后将 ...
- 入手FUJIFILM X100S
有个朋友买了,用了说很好,于是在秋叶原的yodobashi体验了好几个星期天之后,终于下定决心出手了,购入了黑色限量版,还能用优惠券减免了200美元,最后全套1200美元.黑色限量版还包括了转接环,那 ...
- Flutter 动画详解(一)
本文主要介绍了动画的原理相关概念,对其他平台的动画做了一个简要的梳理,并简要的介绍了Flutter动画的一些知识. 1. 动画介绍 动画对于App来说,非常的重要.很多App,正是因为有了动画,所以才 ...
- Android--手势及触摸事件的注意点(一)
实现onInterceptTouchEvent方法可以用来拦截父ViewGroup传递下来的所有触屏事件,可以将所有触屏事件交由此ViewGroup自身的onTouchEvent来处理,也可以继续传递 ...
- MFC Bresesnham算法
Bresesnham算法绘制直线段 Bresenham算法的意义:高效的将图形光栅化.其计算过程中均采用加法运算,故大大减少了程序的开销. 绘制直线段(MFC中) //传入参数:起点.终点,颜色 vo ...