完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛扫一扫,分享给好友
|
大家好。
我能够将 ESP8266-01 连接到 Arduino IDE 并上传草图。 它们似乎可以正常工作,因为我看到 ESP8266 访问点在此示例网络服务器中编程(https://learn.sparkfun.com/tutorials/es ... -guide/all) 代码:全选#include ////////////////////// // WiFi Definitions // ////////////////////// const char WiFiAPPSK[] = "sparkfun"; ///////////////////// // Pin Definitions // ///////////////////// const int LED_PIN = 5; // Thing's onboard, green LED const int ANALOG_PIN = A0; // The only analog pin on the Thing const int DIGITAL_PIN = 12; // Digital pin to be read WiFiServer server(80); void setup() { initHardware(); setupWiFi(); server.begin(); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Read the first line of the request String req = client.readStringUntil('r'); Serial.println(req); client.flush(); // Match the request int val = -1; // We'll use 'val' to keep track of both the // request type (read/set) and value if set. if (req.indexOf("/led/0") != -1) val = 0; // Will write LED low else if (req.indexOf("/led/1") != -1) val = 1; // Will write LED high else if (req.indexOf("/read") != -1) val = -2; // Will print pin reads // Otherwise request will be invalid. We'll say as much in HTML // Set GPIO5 according to the request if (val >= 0) digitalWrite(LED_PIN, val); client.flush(); // Prepare the response. Start with the common header: String s = "HTTP/1.1 200 OKrn"; s += "Content-Type: text/htmlrnrn"; s += "rnrn"; // If we're setting the LED, print out a message saying we did if (val >= 0) { s += "LED is now "; s += (val)?"on":"off"; } else if (val == -2) { // If we're reading pins, print out those values: s += "Analog Pin = "; s += String(analogRead(ANALOG_PIN)); s += " "; // Go to the next line. s += "Digital Pin 12 = "; s += String(digitalRead(DIGITAL_PIN)); } else { s += "Invalid Request. Try /led/1, /led/0, or /read."; } s += "n"; // Send the response to the client client.print(s); delay(1); Serial.println("Client disonnected"); // The client will actually be disconnected // when the function returns and 'client' object is detroyed } void setupWiFi() { WiFi.mode(WIFI_AP); // Do a little work to get a unique-ish name. Append the // last two bytes of the MAC (HEX'd) to "Thing-": uint8_t mac[WL_MAC_ADDR_LENGTH]; WiFi.softAPmacAddress(mac); String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); macID.toUpperCase(); String AP_NameString = "ESP8266 Thing " + macID; char AP_NameChar[AP_NameString.length() + 1]; memset(AP_NameChar, 0, AP_NameString.length() + 1); for (int i=0; i WiFi.softAP(AP_NameChar, WiFiAPPSK); } void initHardware() { Serial.begin(115200); pinMode(DIGITAL_PIN, INPUT_PULLUP); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); // Don't need to set ANALOG_PIN as input, // that's all it can be. } 我遇到的问题是我从来没有在串行监视器中得到输出。没有一行……它被设置为与编程时相同的 COM 端口,我尝试了不同的波特率。 关于如何解决它的任何想法?ESP 通过 USB 串行适配器连接。编程有效,但没有串行输出。 |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
462 浏览 0 评论
982 浏览 0 评论
1703 浏览 0 评论
请问一下我想用ESP8685直接替换ESP8266而不用写程序,可以让ESP8685直接通过之前ESP8266的外挂的flash运行程序吗
1359 浏览 1 评论
1249 浏览 1 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
1279浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
942浏览 3评论
2373浏览 3评论
ESP-IDF的VScode插件的build按钮点击会报错的原因?
2564浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
1069浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-11 10:58 , Processed in 0.585838 second(s), Total 69, Slave 52 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1305
