esp_wifi_repeater-master (1)

所属分类:其他
开发工具:C/C++
文件大小:975KB
下载次数:0
上传日期:2021-03-12 16:00:12
上 传 者mail87523
说明:  esp wifi repeater code development

文件列表:
AutoMesh.JPG (46421, 2019-09-21)
FlashRepeaterWindows.jpg (121831, 2019-09-21)
Makefile (5384, 2019-09-21)
WebConfig.jpg (36338, 2019-09-21)
driver (0, 2019-09-21)
driver\new_uart.c (16109, 2019-09-21)
driver\spi.c (13872, 2019-09-21)
easygpio (0, 2019-09-21)
easygpio\easygpio.c (10887, 2019-09-21)
easygpio\easygpio.h (4536, 2019-09-21)
firmware (0, 2019-09-21)
firmware\0x00000.bin (1968, 2019-09-21)
firmware\0x02000.bin (386752, 2019-09-21)
firmware\0x82000.bin (386752, 2019-09-21)
firmware\sha1sums (189, 2019-09-21)
include (0, 2019-09-21)
include\driver (0, 2019-09-21)
include\driver\spi.h (3776, 2019-09-21)
include\driver\spi_register.h (11789, 2019-09-21)
include\driver\uart.h (6583, 2019-09-21)
include\driver\uart_register.h (7038, 2019-09-21)
include\lwip (0, 2019-09-21)
include\lwip\app (0, 2019-09-21)
include\lwip\app\dhcpserver.h (577, 2019-09-21)
include\lwip\app\dhcpserver_common.h (2148, 2019-09-21)
include\lwip\app\encdhcpserver.h (626, 2019-09-21)
include\lwip\ip_route.h (902, 2019-09-21)
include\lwip\lwip_napt.h (2876, 2019-09-21)
include\lwip\netif.h (12563, 2019-09-21)
include\lwip\netif (0, 2019-09-21)
include\lwip\netif\espenc.h (8771, 2019-09-21)
include\lwip\opt.h (55684, 2019-09-21)
include\lwipopts.h (56528, 2019-09-21)
include\string.h (16, 2019-09-21)
liblwip_open_napt.a (372768, 2019-09-21)
mqtt (0, 2019-09-21)
mqtt\Makefile (1444, 2019-09-21)
mqtt\include (0, 2019-09-21)
... ...

# esp_wifi_repeater A full functional WiFi repeater (correctly: a WiFi NAT router) This is an implementation of a WiFi NAT router on the esp8266 and esp8285. It also includes support for a packet filtering firewall with ACLs, port mapping, traffic shaping, hooks for remote monitoring (or packet sniffing), an MQTT management interface, simple GPIO interaction, and power management. For a setup with multiple routers in a mesh to cover a larger area a new mode "Automesh" has been included https://github.com/martin-ger/esp_wifi_repeater#automesh-mode . *If you are looking for a way to integrate the NAT feature into your Arduino project* - see https://github.com/martin-ger/lwip_nat_arduino . A similar *NAT feature for the ESP32* can be found at: https://github.com/jonask1337/esp-lwip . Typical usage scenarios include: - Simple range extender for an existing WiFi network - Battery powered outdoor (mesh) networks - Setting up an additional WiFi network with different SSID/password for guests - Setting up a secure and restricted network for IoT devices - Translating WPA2 Enterprise networks to WPA-PSK - Monitor probe for WiFi traffic analysis - Network experiments with routes, ACLs and traffic shaping - Meshed IoT device with basic I/O capabilities and MQTT control By default, the ESP acts as STA and as soft-AP and transparently forwards any IP traffic through it. As it uses NAT no routing entries are required neither on the network side nor on the connected stations. Stations are configured via DHCP by default in the 192.168.4.0/24 net and receive their DNS responder address from the existing WiFi network. Measurements show, that it can achieve about 5 Mbps in both directions, so even streaming is possible. Some details are explained in this video: https://www.youtube.com/watch?v=OM2FqnMFCLw # First Boot The esp_wifi_repeater starts with the following default configuration: - ap_ssid: MyAP, ap_password: none, ap_on: 1, ap_open: 1 - network: 192.168.4.0/24 After first boot (or factory reset) it will offer a WiFi network with an open AP and the ssid "MyAP". It does not yet try to automatically re-connect to an uplink AP (as it does not know a valid ssid or password). Connect to this WiFi network and do the basic configuration either via a simple web interface or the full config with all options via the console. # Basic Web Config Interface The web interface allows for the configuration of all parameters required for the basic forwarding functionality. Thanks to rubfi for the major work on that: https://github.com/rubfi/esp_wifi_repeater/ . Point your browser to "http://192.168.4.1". This page should appear: First enter the appropriate values for the uplink WiFi network, the "STA Settings". Use password "none" for open networks. Check the "Automesh" box if and only if you really want to use the automesh mode. Click "Connect". The ESP reboots and will connect to your WiFi router. The status LED should be blinking after some seconds. If you have selected automesh, you are done with config. Configuring the "Soft AP Settings" is not required as in automesh mode these settings are identical to the "STA Settings". The same ssid will be offered by all connected ESP repeaters. If you are not using automesh, you can now reload the page and change the "Soft AP Settings". Click "Set" and again the ESP reboots. Now it is ready for forwarding traffic over the newly configured Soft AP. Be aware that these changes also affect the config interface, i.e. to do further configuration, connect to the ESP through one of the newly configured WiFi networks. For access through the Soft AP remember the address of the Soft APs network if you have changed that (the ESP has always the address x.x.x.1 in this network). If you like, you can mark the "lock" checkbox and click "Lock". Now the config cannot be changed anymore without first unlocking it with the uplink WiFi network's password (define one even if the network is open). If you want to enter non-ASCII or special characters in the web interface you have to use HTTP-style hex encoding like "My%20AccessPoint". This will result in a string "My AccessPoint". With this hex encoding you can enter any byte value you like, except for 0 (for C-internal reasons). If you made a mistake and have lost all contact with the ESP you can still use the serial console to recover it ("reset factory", see below). # Command Line Interface Advanced configuration has to be done via the command line on the console interface. This console is available either via the serial port at 115200 baud or via tcp port 7777 (e.g. "telnet 192.168.4.1 7777" from a connected STA). Use the following commands for an initial setup: - set ssid your_home_router's_SSID - set password your_home_router's_password - set ap_ssid ESP's_ssid - set ap_password ESP's_password - show (to check the parameters) - save - reset Again, if you want to enter non-ASCII or special characters you can use HTTP-style hex encoding (e.g. "My%20AccessPoint") or, only on the CLI, as shortcut C-style quotes with backslash (e.g. "My\ AccessPoint"). Both methods will result in a string "My AccessPoint". The command line understands a lot more commands: ## Basic Commands Enough to get it working in nearly all environments. - help: prints a short help message - set [ssid|password] _value_: changes the settings for the uplink AP (WiFi config of your home-router), use password "none" for open networks. - set [ap_ssid|ap_password] _value_: changes the settings for the soft-AP of the ESP (for your stations) - show [config|stats]: prints the current config or some status information and statistics - save [dhcp]: saves the current config parameters, ACLs, and routing entires [+ the current DHCP leases] to flash - lock [_password_]: saves and locks the current config, changes are not allowed. Password can be left open if already set before (Default is the password of the uplink WiFi) - unlock _password_: unlocks the config, requires password from the lock command - reset [factory]: resets the esp, 'factory' optionally resets WiFi params to default values (works on a locked device only from serial console) - quit: terminates a remote session ## Advanced Commands Most of the set-commands are effective only after save and reset. ### Automesh Config - set automesh [0|1]: selects, whether the automesh mode is on or off (default), see details here https://github.com/martin-ger/esp_wifi_repeater#automesh-mode - set am_threshold _dB_: sets the threshold for a "bad" connection (in negative dB, default 85, i.e. -85 dB) - set am_scan_time _secs_: sets the time interval in seconds the ESP tries in automesh mode to find an uplink AP before going to sleep (0 disabled, default) - set am_sleep_time _secs_: sets the time interval in seconds the ESP sleeps in automesh mode if no uplink AP is found (0 disabled, default) ### WiFi Config - set ap_on [0|1]: selects, whether the soft-AP is disabled (ap_on=0) or enabled (ap_on=1, default) - set ap_open [0|1]: selects, whether the soft-AP uses WPA2-PSK security (ap_open=0, automatic, if an ap_password is set) or open (ap_open=1) - set auto_connect [0|1]: selects, whether the STA should keep retrying to reconnect to the AP. auto_connect is off (0) after first flashing or after "reset factory". When you enter a new SSID it will be automatically set on (1). - set ssid_hidden [0|1]: selects, whether the SSID of the soft-AP is hidden (ssid_hidden=1) or visible (ssid_hidden=0, default) - set phy_mode [1|2|3]: sets the PHY_MODE of the WiFi (1=b, 2=g, 3=n(default)) - set bssid _xx:xx:xx:xx:xx:xx_: sets the specific BSSID of the uplink AP to connect to (default 00:00:00:00:00:00 which means any) - set [ap_mac|sta_mac] _xx:xx:xx:xx:xx:xx_: sets the MAC address of the STA and SOFTAP to a user defined value (bit 0 of the first byte of the MAC address can not be 1) - set sta_mac random: set a new random STA MAC after each reboot - set sta_hostname _name_: sets the name of the STA (visible to the uplink AP) - set max_clients [1-8]: sets the number of STAs that can connct to the SoftAP (limit of the ESP's SoftAP implementation is 8, default) - scan: does a scan for APs - connect: tries to connect to an AP with the currently configured _ssid_ and _password_ - disconnect: disconnects from any uplink AP ### WPA2 Enterprise Config - set use_peap[0|1]: selects, whether the STA should connect via simple WPA-PSK (use_peap=0, default) or usinf WPA2 Enterprise (PEAP) - set peap_identity _value_: sets the PEAP 'outer' identity (the string that is first presented to the RADIUS server, maybe anonymous@yourorg.org) - peap_username _value_: sets the PEAP username - peap_password _value_: sets the PEAP password ### TCP/IP Config - set network _ip-addr_: sets the IP address of the internal network, network is always /24, router is always x.x.x.1 - set dns _dns-addr_: sets a static DNS address that is distributed to clients via DHCP - set dns dhcp: configures use of the dynamic DNS address from DHCP, default - set ip _ip-addr_: sets a static IP address for the STA interface - set ip dhcp: configures dynamic IP address for the STA interface, default - set netmask _netmask_: sets a static netmask for the STA interface - set gw _gw-addr_: sets a static gateway address for the STA interface - set max_nat _no_of_entries_: sets the size of the NAPT table (default 512) - set max_portmap _no_of_entries_: sets the size of the portmap table (default 32) - set tcp_timeout _secs_: sets the NAPT timeout for TCP connections (0=default (1800 secs)) - set udp_timeout _secs_: sets the NAPT timeout for UDP connections (0=default (2 secs)) - show dhcp: prints the current status of the dhcp lease table ### Routing - show route: displays the current routing table - route clear: clears all static routes - route add _network_ _gw_: adds a static route to a network (network given CIDR notation ('x.x.x.x/n')) via gateway gw - route delete _network_: removes a static route to a network - interface _inX_ [up|down]: sets the interface state up or down (no IP routing/traffic through down interfaces, default: up) - set nat [0|1]: selects, whether the soft-AP interface is NATed (nat=1, default) or not (nat=0). Without NAT transparent forwarding of traffic from the internal STAs doesn't work! Useful mainly in combination with static routing. - portmap add [TCP|UDP] _external_port_ _internal_ip_ _internal_port_: adds a port forwarding - portmap remove [TCP|UDP] _external_port_: deletes a port forwarding - nslookup _name_: starts a DNS lookup for the given name and displays the result - ping _host_: checks IP connectivity with ICMP echo request/reply (host as IP address or DNS name) ### Firewall/Monitor Config - acl [from_sta|to_sta|from_ap|to_ap] [TCP|UDP|IP] _src-ip_ [_src_port_] _desr-ip_ [_dest_port_] [allow|deny|allow_monitor|deny_monitor]: adds a new rule to the ACL - acl [from_sta|to_sta|from_ap|to_ap] clear: clears the whole ACL - show acl: shows the defined ACLs and some stats - set acl_debug [0|1]: switches ACL debug output on/off - all denied packets will be logged to the terminal - set [upstream_kbps|downstream_kbps] _bitrate_: sets a maximum upstream/downstream bitrate (0 = no limit, default) - set daily_limit _limit_in_KB_: defined a max. amount of kilobytes that can be transferred by STAs per day (0 = no limit, default) - set timezone _hours_offset_: defines the local timezone (required to know, when a day is over at 00:00) - monitor [on|off|acl] _port_: starts and stops monitor server on a given port ### User Interface Config - set config_port _portno_: sets the port number of the console login (default is 7777, 0 disables remote console config) - set web_port _portno_: sets the port number of the web config server (default is 80, 0 disables web config) - set config_access _mode_: controls the networks that allow config access for console and web (0: no access, 1: only internal, 2: only external, 3: both (default)) ### GPIO Config - show gpio: displays the gpio configuration - gpio [0-16] mode [_in_|_in_pullup_|_out_]: configures a GPIO port of the ESP (saved to flash) - gpio [0-16] set [_high_|_low_]: writes to an output port - gpio [0-16] set [_high_|_low_] for _seconds_: writes to an output port and reverts after a certain duration - gpio [0-16] get: reads from an input port - gpio [0-16] trigger [0-16] [_monostable_NO_|_monostable_NC_|_bistable_NO_|_bistable_NC_]: links an input port to an output port, either as a monostable normally open (pushbutton triggering when state changes to low), a monostable normally closed (pushbutton triggering when state changes to high), a bistable normally open (switch replicating the input), or a bistable normally closed (switch which state is the opposite of the input) - gpio [0-16] trigger none: clears the link ### Chip Config - set speed [80|160]: sets the CPU clock frequency (default 80 Mhz) - sleep _seconds_: Put ESP into deep sleep for the specified amount of seconds. Valid values between 1 and 4294 (aprox. 71 minutes) - set status_led _GPIOno_: selects a GPIO pin for the status LED (default 2, >16 disabled) - set hw_reset _GPIOno_: selects a GPIO pin for a hardware factory reset (>16 disabled, default) - set ap_watchdog _secs_: sets the AP watchdog timeout - if there are no packets received for _secs_ from the uplink AP the repeater resets ("none" = no timeout, default) - set client_watchdog _secs_: sets the client watchdog timeout - if there are no packets received for _secs_ from any connected client the repeater resets ("none" = no timeout, default) - 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 _secs_: sets the time interval in seconds the ESP sleeps on low voltage # Status LED In default config GPIO2 is configured to drive a status LED (connected to GND) with the following indications: - permanently on: started, but not successfully connected to the AP (no valid external IP) - flashing (1 per second): working, connected to the AP - unperiodically flashing: working, traffic in the internal network With "set status_led GPIOno" the GPIO pin can be changed (any value > 16, e.g. "set status_led 255" will disable the status LED completely). When configured to GPIO1, it works with the built-in blue LED on the ESP-01 boards. However, as GPIO1 is also the UART-TX-pin this means, that the serial console is not working. Configuration is then limited to network access. # HW Factory Reset If you pull low a selected GPIO for more than 3 seconds, the repeater will do a factory reset and restart with default config. With "set hw_reset GPIOno" the GPIO pin can be changed (any value > 16, e.g. "set hw_reset 255" will disable the hw factory reset feature). For many modules, incl. ESP-01s and NodeMCUs, it is probably a good idea to use GPIO 0 for that, as it is used anyway. However, it is not the default pin, as it might interfere with pulling it down during flashing. Thus, if you want to use an existing push button on GPIO 0 for HW factory reset, configure it with "set hw_reset 0" and "save" after flashing. A factory reset triggered by the HW pin will NOT reset the configured hw_reset GPIO number ("reset factory" from console will do). # Port Mapping In order to allow clients from the external network to connect to server port on the internal network, ports have to be mapped. An external port is mapped to an internal port of a specific internal IP address. Use the "portmap add" command for that. Port mappings can be listed with the "show" command and are saved with the current config. However, to make sure that the expected device is listening at a certain IP address, it has to be ensured the this devices has the same IP address once it or the ESP is rebooted. To achieve this, either fixed IP addresses can be configured in the devices or the ESP has to remember its DHCP leases. This can be achieved with the "save dhcp" command. It saves the current state and all DHCP leases, so that they will be restored after reboot. DHCP leases can be listed with the "show stats" command. # WPA2 Enterprise (PEAP) WPA2 Enterprise (PEAP) support has now been included into the project. It allows for a "converter" that translates a WPA2 enterprise network with PEAP authentication into a WPA2-PSK network. This solves a common problem especially in university environments: the local WiFi network is a WPA2 Enterprise network with PEAP-MSCHAPv2 authentication. A very prominent example is the "eduroam"-network that is available at many universities around the world. The problem is, that many IoT devices cannot handle WPA2 Enterprise authentication. So development and demos are difficult. What is very helpful is a "converter" that logs into the WPA2 Enterprise network and offers a simpler WPA-PSK network to its clients. To use it set the following config parameters: ssid, use_peap, peap_identity, peap_username, and peap_password (you don't need the usual password parameter). This configuration has to be done (and saved) via the CLI and is not available in the web interface. The code currently does not check the certificate of the RADIUS-Server. It is vulnerable to MITM-attacks, when somebody sets up a rogue AP and RADIUS server. While the password is not send in plaintext, the used MSCHAPv2 is known to be broken. Also, be aware of the fact that the ESP8266 now contains your enterprise network password. All traffic that is forwarded by it can now be related by the network admin to your account. Do not missuse it and offer it to untrusted others, eg. by configuring an open network. And even when the device is locked, your enterprise network password can be extracted via serial port from the ESP's flash in plain text. # Automesh Mode Sometimes you might want to use several esp_wifi_repeaters in a row or a mesh to cover a larger distance or area. Generally, this can be done without any problems with NAT routers, actually you will have several layers of NAT. However, this means connectivity is limited: all nodes can talk to the internet, but generally there's no direct IP connectivity between the nodes. And, of course, the available bandwidth goes down the more hops you need. But users have reported that even 5 esp_wifi_repeaters in a row work quite well. In such a setup configuration is quite a time consuming and error-prone activity. To simplify that, the esp_wifi_repeater now has a new mode: "Automesh". Just configure the SSID and the password and switch "automesh" on. (either on the CLI with "set automesh 1" or on the Web interface with just select the checkbox). This will do the following: Each esp_wifi_repeater configured in that way will automatically offer a WiFi network on the AP with the same SSID/password as it is connected to. Clients can use the same WiFi settings for the original network or the repeated ones. Each esp_wifi_repeater configured with "automesh" will first search for the best other AP to connect to. This is the one which is closest to the original WiFi network and has the best signal strength (RSSI). The signal strength is easy to measure with a scan, but which is the one closest to the original WiFi network when you see several APs with the same SSID? Therefore the protocol use a somewhat dirty trick: the esp_wifi_repeaters in "automesh" mode manipulate their BSSID (actually, according to the IEEE 802.11 standard this is the "ESSID" as it is an AP, but the SDK calls it "BSSID"), i.e. the MAC address of their AP interface, which is send out with every beacon frame 10 about time times per second. It uses the format: 24:24:mm:rr:rr ... ...

近期下载者

相关文件


收藏者