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.htmlstyle.css,jQuery.min.js,d3-gauge.js。

不将这些文件上传到ESP8266 NodeMCU Flash文件系统。这个怎么做 ?阅读此处加载文件需要一些时间。

第3步:测试

假设您已上传程序和SPIFFS文件。打开串行监视器并重置ESP。您将获得IP地址,在Web浏览器中打开它。确保您的ESP和笔记本电脑在同一网络中

你会得到漂亮的界面。正如我们在开始时所展示的那样。

ESP8266 HTTP 项目(1)在刻度盘上进行ESP8266 NodeMCU模拟读取的步骤的更多相关文章

  1. Android项目,从web上取下汉字,中文部分乱码

    Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...

  2. 如何部署Java_web项目到云服务器上

    步骤 1:购买 Linux 实例(略) 步骤2:安装JDK 本节介绍如何安装java jdk. 软件包中包含的软件及版本如下: Tomcat:1.8.0_121 说明:这是写文档时参考的软件版本.您下 ...

  3. javaWeb开发中关于eclipse等ide重新部署或重启项目等原因造成上传文件丢失问题解决方案

    在开发项目时,有时候需要用到上传功能,比如头像上传等,其文件会保存到服务器中.但是我发现在用eclipse做项目的过程中,每次重新部署项目,原来上传的文件就会丢失. 其原因是因为每次项目修改后,ecl ...

  4. Springboot项目如何把项目运行在服务器上

    作为一个开发者,不可避免的要把本地项目变成可以接入外网的上线项目,今天来记录下springboot框架下如果把项目打包放在服务器上运行 第一步,首先要买个服务器,这个一般甲方会提供 第二步,导入jar ...

  5. 用eclipse怎样将本地的项目打成jar包上传到maven仓库

    使用maven的项目中,有时需要把本地的项目打成jar包上传到mevan仓库. 操作如下: 前提:pom文件中配置好远程库的地址,否则会报错 1.将maven 中的settings文件配置好用户名和密 ...

  6. git操作+一个本地项目推到github上+注意

    git init 创建新文件夹,打开,然后执行以创建新的 git 仓库. git config --global user.name "xxx" git config --glob ...

  7. 将项目添加到服务上时报web modules的错误

    将项目添加到服务上时报web modules的错误如下图: 这是tomcat的版本和web modules的版本不支持造成的,如果在如下地方修改不了: 这时候就要在项目的根目录修改如下图: 用工具打开 ...

  8. 把项目挂载到composer上

    1.打开composer的安装包列表网站,点击submit 2.把刚才初始化了composer的项目push到github上(至于怎么push,最简单就是用git了) 3.然后把github的网址复制 ...

  9. 微服务开发有道之把项目迁移到Kubernetes上的5个小技巧

    我们将在本文中提供5个诀窍帮你将项目迁移到Kubernetes上,这些诀窍来源于过去12个月中OpenFaas社区的经验.下文的内容与Kubernetes 1.8兼容,并且已经应用于OpenFaaS ...

随机推荐

  1. ES6中字符串扩展

    ES6中字符串扩展 ① for...of 遍历字符串: 例如: for(let codePoint of 'string'){ console.log(codePoint) } 运行结果: ②  in ...

  2. angular 去掉url里面的#

    1.适合客户端的方法,但是页面不能刷新,一刷新就404 (1)在index.html里添加 <base href="/"> (2)在app.js的config里,注入$ ...

  3. jstack 排查 java 进程占用大量 CPU 问题

    1. top 看看哪个进程是罪魁祸首 2.将这个进程的jstack dump 到一个文件里面,以备使用. jstack -l 25886 > /tmp/jstack.log # 如果报错,则加 ...

  4. Mobius反演的套路

    T1 \(\sum_{i=1}^N \sum_{j=1}^M [(i,j)=1]\) \(f(d)=\sum_{i=1}^N \sum_{j=1}^M [(i,j)=d]\) \(g(d)=\sum_ ...

  5. Win7录制电脑屏幕视频

    在日常生活中,有时候我们需要在电脑上录制视频,那就需要找到一款合适的录像工具,选择迅捷屏幕录像工具就是一个不错的选择,操作简单轻松易上手,美轮美奂的无损画质,教学视频.电影.游戏等都可以进行录制哦! ...

  6. HashMap 与 ConcrrentHashMap 使用以及源码原理分析

    前奏一:HashMap面试中常见问题汇总 HashMap的工作原理是近年来常见的Java面试题,几乎每个Java程序员都知道HashMap,都知道哪里要用HashMap,知道HashTable和Has ...

  7. winsock 编程(简单客户&服务端通信实现)

    winsock 编程(简单客户&服务端通信实现) 双向通信:Client send message to Server, and if  Server receive the message, ...

  8. 适用于VS C++环境的注释代码段,可以让你的代码被使用时有高可读性的注释

    编码时,在对高级语言(C#/VB etc)函数的访问时,经常会有很明确的函数功能提示,参数提示,与返回值提示.微软的VisualStudio C++集成开发环境同样有这样的功能,只是常见开源的代码很少 ...

  9. MySQL 约束、表连接、表关联、索引

    一.外键: 1.什么是外键 2.外键语法 3.外键的条件 4.添加外键 5.删除外键 1.什么是外键: 主键:是唯一标识一条记录,不能有重复的,不允许为空,用来保证数据完整性. 外键:是另一表的唯一性 ...

  10. c/c++ 线性表之单向循环链表

    c/c++ 线性表之单向循环链表 线性表之单向循环链表 不是存放在连续的内存空间,链表中的每个节点的next都指向下一个节点,最后一个节点的下一个节点不是NULL,而是头节点.因为头尾相连,所以叫单向 ...