完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好!
终于有时间来攻击这个项目了。 它包括从 Pot 收集数据(在 NodeMcu 上模拟读取),将数据传递到网页,然后在仪表上显示数据。 有用!!! 以下是 Sketch 的主要部分: Ino 代码:全选* Wifi-AP MODE * 07/11/2019 */ #include #include #include const char* htmlfile = "/index.html"; //WiFi Connection configuration const char *ssid = "My Wifi"; const char *password = "123456789"; ESP8266WebServer server(80); void handleADC(){ int a = analogRead(A0); a = map(a,0,1023,0,100); String adc = String(a); Serial.println(adc); server.send(200, "text/plane",adc); //sends data to server } void handleRoot(){ server.sendHeader("Location", "/index.html",true); //Redirect to our html web page server.send(302, "text/plane",""); } void handleWebRequests(){ if(loadFromSpiffs(server.uri())) return; String message = "File Not Detectednn"; 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.send(404, "text/plain", message); Serial.println(message); } void setup() { delay(1000); Serial.begin(115200); Serial.println(); //Initialize File System SPIFFS.begin(); Serial.println("File System Initialized"); Serial.print("Setting AP (Access Point)…"); Serial.println(); //Connect to wifi Network WiFi.mode(WIFI_AP); //Only Access point WiFi.softAP(ssid, password); //Start HOTspot //If connection successful show IP address in serial monitor Serial.print("Connected to: "); Serial.println(ssid); IPAddress IP = WiFi.softAPIP(); Serial.print("Server IP address: "); Serial.println(IP); //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(); Serial.println("HTTP server started"); } void loop() { server.handleClient(); } 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; } 这是 Index.html: 代码:全选 Testing Gauge |
|
相关推荐 |
|
只有小组成员才能发言,加入小组>>
944 浏览 0 评论
1671 浏览 0 评论
请问一下我想用ESP8685直接替换ESP8266而不用写程序,可以让ESP8685直接通过之前ESP8266的外挂的flash运行程序吗
1330 浏览 1 评论
1233 浏览 1 评论
5015 浏览 2 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
1252浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
927浏览 3评论
2333浏览 3评论
ESP-IDF的VScode插件的build按钮点击会报错的原因?
2526浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
1051浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-1 23:51 , Processed in 0.578070 second(s), Total 69, Slave 52 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
525
