Arduino 基于 ESP8266 配置WIFI模块

使用ESP8266作为服务器,使用浏览器访问该服务器,从而控制LED灯

  • 选择 【文件】->【示例】->【ESP8266WIFI】->【WiFiWebServer】
  • 用Arduino新建一个文件,将刚打开的的WIFIWebServer的内容复制过去
  • 修改 ssid 和 password 为自家路由器的名称以及密码
  • 将程序上传到 ESP8266 开发板中
  • 最后就可以通过网站 [ip]/gpio/1 或 [ip]/gpio/0 控制灯开关
# http://192.168.0.57/gpio/1
# ip 地址在序列库中可以看到
  • 附上代码
/*
* This sketch demonstrates how to set up a simple HTTP-like server.
* The server will set a GPIO pin depending on the request
* http://server_ip/gpio/0 will set the GPIO2 low,
* http://server_ip/gpio/1 will set the GPIO2 high
* server_ip is the IP address of the ESP8266 module, will be
* printed to Serial when the module is connected.
*/ #include <ESP8266WiFi.h> const char* ssid = "YUCHANJIUYE";
const char* password = "19283746"; // Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80); void setup() {
Serial.begin(115200);
delay(10); // prepare GPIO2
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, 0); // Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected"); // Start the server
server.begin();
Serial.println("Server started"); // Print the IP address
Serial.println(WiFi.localIP());
} void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
} // Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
} // Read the first line of the request
String req = client.readStringUntil('\r');
Serial.println(req);
client.flush(); // Match the request
int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
} // Set GPIO2 according to the request
digitalWrite(LED_BUILTIN, val); client.flush(); // Prepare the response
String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>\r\nGPIO is now ";
s += (val)?"high":"low";
s += "</html>\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
}

Arduino 基于 ESP8266 配置WIFI模块的更多相关文章

  1. Obloq模块:基于ESP8266的物联网模块

    OBLOQ 物联网模块 OBLOQ模块是DFRobot公司开发的一款基于ESP8266芯片的物联网通信模块.模块使用串口(TTL UART)和Arduino(或者其他单片机)通信,支持MQTT,HTT ...

  2. 玩转X-CTR100 l STM32F4 l ESP8266串口WIFI模块

    我造轮子,你造车,创客一起造起来!更多塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ]- ESP8266是一款非常火的WIFI模块,性价 ...

  3. [原创]基于Zybo SDIO WiFi模块调试

    采用的是RTL8189 SDIO 模块,介绍如下 The Realtek RTL8189ES-VB-CG is a highly integrated single-chip 802.11n Wire ...

  4. ESP8266串口WiFi扩展板详解

    产品简介 ESP8266串口WiFi扩展板是深圳四博智联科技有限公司开发的一款基于乐鑫ESP8266的超低功耗的UART-WiFi模块,兼容Arduino UNO.Mega等标准主板,可以方便地进行二 ...

  5. STM32F10xx(高容量)WiFi模块的初始化和使用

    本次实验是使用每次传输不超过200B的ESP8266芯片的WiFi模块,WiFi模块内部自有驱动,我们初始化它,只需要发送指定的指令给他就可以了,指定的指令其实是使用USART3的复用的PB10和PB ...

  6. ARDUINO MEGA2560 经过ESP8266 WIFI模块上传温湿度数据到 OneNet 服务器

    简述 原来写了一个C++的wifi库但是发现用c++ arduino这小身板有点扛不住,代码比较大,使用String类型数据处理速度慢,而且很容易无缘无故跑飞.而且封装成库后使用还需要修改arduin ...

  7. ESA2GJK1DH1K升级篇: STM32远程乒乓升级,基于Wi-Fi模块(ESP8266)AT指令TCP透传方式,MQTT通信控制升级(加入数据校验)

    前言 这节演示下,上两节写的利用MQTT来控制STM32控制的程序 测试准备工作(默认访问我的服务器,改为自己的服务器,请看后面说明) 一,下载BootLoader程序(请自行下载) 首先BootLo ...

  8. WIFI模块ESP8266的使用指南【转】

    本文转载自:http://www.itdadao.com/articles/c15a814052p0.html 本文主要对讲述ESP8266模块硬件连接工作,以及作为服务器和客户端情况下的配置实现的详 ...

  9. 「雕爷学编程」Arduino动手做(33)——ESP-01S无线WIFI模块

    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器和模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里 ...

随机推荐

  1. PHP 奇葩的debug_zval_dump的输出

    有段代码: $a1 = 'Hello world!'; $a2 = &$a1; echo "test1 :"; debug_zval_dump($a1); $b1 = 'H ...

  2. ElasticSearch Bulk API

    做一个简单的记录,以便自己后续查找 一.环境要求 ElasticSearch 7.3.0 Kibana 7.3.0 二.详情 ElasticSearch 的 Bulk API 可以批量进行索引或者删除 ...

  3. pytest3-命令行选项

    1.pytest -h 查看pytest常用命令 E:\myproj\pytest_demo>pytest -h usage: pytest [options] [file_or_dir] [f ...

  4. The All-in-One Note

    基础 操作系统 I/O 模型 阻塞式 I/O 模型(blocking I/O) 描述:在阻塞式 I/O 模型中,应用程序在从调用 recvfrom 开始到它返回有数据报准备好这段时间是阻塞的,recv ...

  5. SpringMvc启动源码解析

    1. 前言 上篇文章介绍了Spring容器的初始化https://www.cnblogs.com/xiaobingblog/p/11738747.html,接下来介绍SpringMvc容器的初始化 2 ...

  6. Spring Cloud - Eureka /actuator/info 如何显示信息

    在pom.xml中添加 <!-- actuator监控信息完善 --> <dependency> <groupId>org.springframework.boot ...

  7. Java基础(三十三)JDBC(3)操作数据库

    一.添加数据 在SQL语句中,一条INSERT语句只能添加一条记录,因此分为几种情况进行添加数据操作. 1.添加一条记录 (1)如果只需要添加一条记录,通常情况下通过Statament实例完成. tr ...

  8. Dubbo 优雅停机演进之路

    一.前言 在 『ShutdownHook- Java 优雅停机解决方案』 一文中我们聊到了 Java 实现优雅停机原理.接下来我们就跟根据上面知识点,深入 Dubbo 内部,去了解一下 Dubbo 如 ...

  9. incompatible implicit declaration of built-in function 'fabs'

    形如: float a = -3.0; float b = fabs(a); 形参数据类型和实参数据类型完全一致,却还报警告: incompatible implicit declaration of ...

  10. 面向云原生的混沌工程工具-ChaosBlade

    作者 | 肖长军(穹谷)阿里云智能事业群技术专家   导读:随着云原生系统的演进,如何保障系统的稳定性受到很大的挑战,混沌工程通过反脆弱思想,对系统注入故障,提前发现系统问题,提升系统的容错能力.Ch ...