用ESP8266扩展家中局域网
via https://github.com/rubfi/esp_wifi_repeater
ESP无线中继器
这是一个在esp8266作为WiFi NAT路由器的概念和实现。它可以作为现有WiFi网络的无线AP扩展。esp以STA和soft-AP模式透明转发任何IP的流量。因为它使用NAT转发,所以在网络端和连接的站点上都不需要路由条目。站点在192.168.4.0/24网络中默认通过DHCP配置,并从现有的WiFi网络接收其DNS地址。 经过测试,ESP无线中继器可以在两个方向上实现约 5 Mbps,因此即使流媒体也是可能的。ESP无线中继器还允许远程监控(或数据包嗅探),例如使用 Wireshark。
烧录
在 Windows 上,可以使用”ESP8266 下载工具”在 https://espressif.com/en/support/download/other-tools 从固件目录下载两个文件 0x000000.bin 和 0x10000.bin。(对于 ESP-01,将闪存大小更改为”8Mbit”)
使用 V2.0.0 SDK 编译的固件无法在某些 ESP-01 模块上启动。如果遇到这些问题,请使用目录firmware_sdk_1.5.4(地址 0x00000 和 0x40000)。 我用的D1 mini也只能用firmware_sdk_1.5.4编译的固件启动
使用
固件烧录完成后可以使用putty连接ESP的com口,波特率115200以修改固件默认配置 固件从以下默认配置开始:
- ssid: ssid, pasword: password
- ap_ssid: MyAP, ap_password: none, ap_on: 1, ap_open: 1
- network: 192.168.4.0/24
这意味着它通过AP sid,密码连接到互联网,并提供一个开放的AP与ap_ssid:MyAP。此默认值可以在文件user_config. h 中更改。可以使用控制台接口覆盖默认值并持续保存为闪存。此控制台可通过 115200 波特的串行端口或 tcp 端口 7777(例如,从连接的 STA 获得”telnet 192.168.4.1 7777”)。 控制台使用以下命令:
- help: prints a short help message
- show [configstats]: prints the current config or some statistics eg:show config
- set [ssidpasswordap_ssidap_password] value: changes the named config parameter set ssid TP-LINK_B9C0 set password !@#¥%……&*((
- set ap_open [01]: selects, wheter the soft-AP uses WPA2 security (ap_open=0) or no password (ap_open=1)
- set ap_on [01]: selects, wheter the soft-AP is disabled (ap_on=0) or enabled (ap_on=1)
- set network ip-addr: sets the IP address of the internal network, network is always /24, router is always x.x.x.1
- set speed [80160]: sets the CPU clock frequency
- set vmin voltage: sets the minimum battery voltage in mV. If Vdd drops below, the ESP goes into deep sleep. If 0, nothing happens
- set vmin_sleep time: sets the time interval in seconds the ESP sleeps on low voltage
- set config_port portno: sets the port number of the console login (default is 7777, 0 disables remote console config)
- portmap add [TCPUDP] external_port internal_ip internal_port: adds a port forwarding
- portmap remove [TCPUDP] external_port: deletes a port forwarding
- save [dhcp]: saves the current config parameters [+ the current DHCP leases] to flash
- quit: terminates a remote session
- reset [factory]: resets the esp, optionally resets WiFi params to default values
- lock: locks the current config, changes are not allowed
- unlock password: unlocks the config, requires password of the network AP
- scan: does a scan for APs
- monitor [onoff] port: starts and stops monitor server on a given port
状态指示灯
在默认配置 GPIO2 配置驱动器状态 LED(连接到 GND)与以下指示:
- 常亮:已启动,但未成功连接到 AP
- 闪烁(1 秒):工作,连接到 AP
- 非正常闪烁:工作,内部网络中的流量
在user_config.h 中,可以配置备用 GPIO 端口。当配置为 GPIO1 时,它可与 ESP-01 板上的蓝色 LED 一起使用。但是,由于 GPIO1 ist 也是 UART-TX 引脚,这意味着串行控制台不工作。
MQTT 支持
自版本 1.3 以来,路由器具有一个构建中的 MQTT 客户端(感谢 Tuan PM的库https://github.com/tuanpmt/esp_mqtt。这可以帮助将路由器/中继器集成到 IoT 中。家庭自动化系统可以例如,根据有关当前关联站的信息做出决策,它可以打开和中继器(例如,根据时间安排),或者简单地用于监视负载。路由器可以连接到本地 MQTT 代理或云中的公开代理。但是,当前它不支持 TLS 加密。 默认情况下,MQTT 客户端处于禁用状态。可以通过将配置参数”mqtt_host”设置为不同于”无”的主机名来启用它。要配置 MQTT,可以设置以下参数:
- set mqtt_host IP_or_hostname: IP or hostname of the MQTT broker (“none” disables the MQTT client)
- set mqtt_user username: Username for authentication (“none” if no authentication is required at the broker)
- set mqtt_user password: Password for authentication
- set mqtt_id clientId: Id of the client at the broker (default: “ESPRouter_xxxxxx” derived from the MAC address)
- set mqtt_prefix prefix_path: Prefix for all published topics (default: “/WiFi/ESPRouter_xxxxxx/system”, again derived from the MAC address)
- set mqtt_command_topic command_topic: Topic subscribed to receive commands, same as from the console. (default: “/WiFi/ESPRouter_xxxxxx/command”, “none” disables commands via MQTT)
- set mqtt_interval secs: Set the interval in which the router publishs status topics (default: 15s, 0 disables status publication)
- set mqtt_mask mask_in_hex: Selects which topics are published (default: “ffff” means all)
MQTT 参数可以使用”显示 mqtt”命令显示。
- prefix_path/Uptime: System uptime since last reset in s (mask: 0x0020)
- prefix_path/Vdd: Voltage of the power supply in mV (mask: 0x0040)
- prefix_path/Bpsin: Bytes/s from stations into the AP (mask: 0x0800)
- prefix_path/Bpsout: Bytes/s from the AP to stations (mask: 0x1000)
- prefix_path/Ppsin: Packets/s from stations into the AP (mask: 0x0200)
- prefix_path/Ppsout: Packets/s from the AP to stations (mask: 0x0400)
- prefix_path/Bin: Total bytes from stations into the AP (mask: 0x0080)
- prefix_path/Bout: Total bytes from the AP to stations (mask: 0x0100)
- prefix_path/NoStations: Number of stations currently connected to the AP (mask: 0x2000)
- prefix_path/join: MAC address of a station joining the AP (mask: 0x0008)
- prefix_path/leave: MAC address of a station leaving the AP (mask: 0x0010)
- prefix_path/IP: IP address of the router when received via DHCP (mask: 0x0002)
- prefix_path/ScanResult: Separate topic for the results of a “scan” command (one message per found AP) (mask: 0x0004)
- prefix_path/response: The router publishes on this topic the command line output (mask: 0x0001)
电源管理
中继器监控其电流电源电压(显示在”show stats”命令中)。如果_vmin(_在 mV 中,默认 0)设置为值 > 0,并且电源电压低于此值,则它将进入_深度睡眠模式 vmin_sleep_秒。如果您已将 GPIO16 连接到 RST(很难在 ESP-01 上焊接),它将在此间隔后重新启动,尝试重新连接,并将继续测量。
运行截图
用ESP8266扩展家中局域网