TA的每日心情 | 奋斗 2019-10-1 12:54 |
---|
签到天数: 313 天 连续签到: 1 天 [LV.8]以坛为家I
|
本帖最后由 可乐丸子 于 2016-4-26 22:44 编辑
下面介绍使用小e开发板打造一个简易Hello World网页服务器,首先按下面的帖子搭载开发环境
https://www.cirmall.com/bbs/thread-47295-1-1.html
然后新建源代码输入如下
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266mDNS.h>
- const char* ssid = "无线信号名称";
- const char* password = "无线密码";
- MDNSResponder mdns;
- ESP8266WebServer server(80);
- void handleRoot() {
- server.send(200, "text/plain", "Hello World!");
- }
- void handleNotFound(){
- String message = "File Not Foundnn";
- 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 += " " + server.argName(i) + ": " + server.arg(i) + "n";
- }
- server.send(404, "text/plain", message);
- }
- void setup(void){
- Serial.begin(115200);
- WiFi.begin(ssid, password)
- Serial.println("");
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- if (mdns.begin("esp8266", WiFi.localIP())) {
- Serial.println("MDNS responder started");
- }
- server.on("/", handleRoot);
- server.on("/inline", [](){
- server.send(200, "text/plain", "this works as well");
- });
- server.onNotFound(handleNotFound);
- server.begin();
- Serial.println("HTTP server started");
- }
- void loop(void){
- server.handleClient();
- }
复制代码 然后在菜单栏选Build
然后设置串口
然后把程序上传到小e开发板中,把小e所有的拨码开关拨到自己想用的功能上,按住开发板 AirKiss 键不放给开发板上电,然后点击upload按键,等待程序烧写完毕运行,接着在路由器里面找到小e开发板的局域网IP,在浏览器里面输入小e开发板的局域网IP即可显示如下
|
|