It shows how an ESP8266 module (like this one) can be used as a (rather unreliable) WiFi range extender.
Overview of the setup |
Beside an ESP8266 module, you need to:
- download the modified firmeware here and flash it to your module
- copy the DNS forwarder script from here to your module
- add a route to the 192.168.4.0 subnet to your default gateway (i.e. usually your WiFi dsl/cable router)
- attach the module to your WiFi network and run it in StationAP mode:
wifi.setmode(wifi.STATIONAP)
wifi.sta.config("YOURSSID","YOURWIFIPASSWD")
tmr.alarm(0, 500, 1, function()
if wifi.sta.getip()==nil then
print("Connecting to AP...")
else
tmr.stop(1)
tmr.stop(0)
print("Connected as: " .. wifi.sta.getip())
end
end)
cfg={}
cfg.ssid="intarwebs"
wifi.ap.config(cfg)
- connect another device to the "intarwebs" SSID. If you want to really use that, you should encrypt that side as well. Here is how.
I have captured the traffic with wireshark, but could not make sense of it yet. My best guess at the moment is that with a big TCP windows size, the module runs into a buffer size problem or that it is busy for too long on the "left" side. The module only has one radio to serve both connections, so unlike your typical router, it can't forward a continuous stream of packets.
Great work! But what is "modified firmware" actually? Yeah, we can just install it to the nodemcu but I want to know more. Can you share changes or source code?
ReplyDeleteThe modifications are scattered around my blog, sorry about that. The relevant changes to make this work are:
DeleteIn /app/include/lwipopts.h add a #define IP_FORWARD 1
and
In /app/include/lwip/app/dhcpserver.h add #define USE_DNS somewhere (around line 54)
These two should be sufficient to make it work.
Could you the content of this post without modifying the firmware?
DeleteMichael, I've thought about that for a while: If we need to stick to the original firmware, we'd need a http-proxy implementation on the ESP8266. While this is certainly possible, I haven't seen an implementation yet.
DeleteWe can only run one TCP server on the module, so support for automatic proxy detection is an additional (if optional) challenge.
So at the moment the firmware approach seems like the easiest solution.
Post a source code here. Pls. To use it with ArduinoIDE. Or just u grab&post here ?
DeletePlease, fix URL for "DNS forwarder script"
ReplyDeleteYou've missed "h".
Thanks! Fixed.
DeleteThanks for this post. One question have you tried to implement this with the Arduino IDE for the ESP8266?
ReplyDeleteNo, only with NodeMCU. If you try it with the Arduino IDE, I'd be most interested in the results. There have been hints in the NodeMCU issues that the disconnect-problem might be fixed in the lastest -dev version. I'll try that some time.
ReplyDeleteHi, can you share compiled liblwip.a with IP_FORWARD enabled?
ReplyDeleteThank you
You find the compiled NodeMCU formware here: https://www.dropbox.com/s/fyblkervtz02q97/NodeMCU095-ARe-redu-fw-dns.bin?dl=0
DeleteThe changes are just:
In /app/include/lwipopts.h add a #define IP_FORWARD 1
and
In /app/include/lwip/app/dhcpserver.h add #define USE_DNS somewhere (around line 54)
Hi ! I dont know what you wanted to achieve, but i did a similar repeater focused on one task : when the repeater (running your classic dns-liar dns server, using my speed improvements) is asked for a specific kind of urls (starting with folderxyy/ ) then it tries to hit the same url on the AP he is connected to.
ReplyDeleteA first ESP (located too far from my wifi AP to connect directly with it) can signal that the mailman opened my mailbox by hitting a link on the repeater, which hits the same link on the hotspot. The repeater ESP is put into a recycled phone charger and permanently powered. The ESP in my mailbox is only powered when the mailbox is opened.
This is a very minimalist repeater, but probably enough for many uses. I'll post sources later on...
Andreas, here is a working repeater - very limited compared to your version, but good enough if you just want to transmit a simple information (like hittinh a PHP page)
ReplyDeletehttp://iotests.blogspot.fr/2015/11/extend-range-of-esp8266-as-wide-as-you.html
Good job! I've also thought about a similar solution, but could not get it done because of the "only one TCP server" limitation of the firmware. I'll see if I can work my way around that somehow to make a proper HTTP-proxy chain.
DeleteThank you so much for the "IP_FORWARD = 1" idea!
ReplyDeleteBy the way, you don't need a DNS forwarder. Just edit app/lwip/app/dhcpserver.c to modify this:
148 #ifdef USE_DNS
149 *optptr++ = DHCP_OPTION_DNS_SERVER;
150 *optptr++ = 4;
151 *optptr++ = ip4_addr1( &ipadd);
152 *optptr++ = ip4_addr2( &ipadd);
153 *optptr++ = ip4_addr3( &ipadd);
154 *optptr++ = ip4_addr4( &ipadd);
155 #endif
to look like this:
148 #ifdef USE_DNS
149 *optptr++ = DHCP_OPTION_DNS_SERVER;
150 *optptr++ = 4;
151 *optptr++ = 8;
152 *optptr++ = 8;
153 *optptr++ = 8;
154 *optptr++ = 8;
155 #endif
(or instead of 8.8.8.8 put IP address of your fritzbox).
That's it!
Yes, you're quite right. That makes things even simpler. - Thanks!
DeleteHi
ReplyDeleteSuppose I setup a wifi hotspot on my windows pc and I provide the hotspot credentials to the ESP. How do I add the routing step?
"add a route to the 192.168.4.0 subnet to your default gateway (i.e. usually your WiFi dsl/cable router)"
Can you please list the commands?will this be helpful http://www.howtogeek.com/howto/windows/adding-a-tcpip-route-to-the-windows-routing-table/
Thanks
First you need to get the local lan address of the ESP. You'll see that on the ESP's serial console. I'll call that w.x.y.z
DeleteIf your stationary PC is a windows machine, you need to open a commend window (run cmd.exe). In that command window, type:
"route add 192.168.4.0 mask 255.255.255.0 w.x.y.z"
you should then be able to send pings between the device connected to the ESP and the stationary PC.
The more universal option is to set the route on the router. But that depends on the make/model of your particular router.
Perhaps the Video will make that clear: https://youtu.be/NH1rjk3Q_MU
how do you add a route to the 192.168.4.0 subnet to your default gateway (i.e. usually your WiFi dsl/cable router)?
ReplyDeleteThat depends on your router. I'd download the manual as a pdf and search it for "static route". If all else fails, you might have to insert an OpenWRT router. But I think practically all DSL/CABLE routers should have an option for that. (Probably hidden somewhere in the "advanced settings" menue)
DeleteWhich esp8266 module u have used? Is it ESP8266 esp-1??
ReplyDeleteI used this development board:
Deletehttp://www.banggood.com/V3-NodeMcu-Lua-WIFI-Development-Board-p-992733.html?p=NT1005763073201409DA
It has an ESP-12e on it. But that is pretty much irrelevant. An ESP-01 will work ok, too. Flash RAM size is not really an issue here.
any thoughts on paired back to back ESP's as range extender / repeater
ReplyDeleteone configured as an AP the other as gateway / router station
a serial channel connection between them is maxed out at ~900 Kbaud
is it possible to use more than one wired channel connect to match WiFi bandwidth?
this is the exact idea I have while reading the 8266 specs - putting 2 devices back to back each on their own wifi channel. Did you managed to do some real testing yet?
DeleteMartin has greatly improved the code and added some great features, including a capture function.
Deletehttps://github.com/martin-ger/esp_wifi_repeater
I recommend his solution over my approach.
Thanks for another nice project link.
DeleteThis one does not work with 2 devices too. It's just using the same wifi channel for both network, literally disabling the network usage for stations located between the base access point and this range "extender".
Leider hängt sich mein esp nach dem zugriff auf websiten über einen client auf. der esp ist dann auch nicht mehr an ping bar, nach einem reset geht dann wieder genau ein aufruf
ReplyDeletemein esp hängt sich auf nach dem ein client versucht eine website aufzurufen. ein ping auf den esp ist ab dem moment nicht mehr möglich
ReplyDeleteWie im Text beschrieben, kam das bei mit auch immer wieder vor. Andererseits schaffen es andere Leute ganze Videos darüber abzuspielen. Über die Ursachen kann ich nur spekulieren. Es ist aber einen Versuch wert, die Firmware mit einen neueren NodeMCU Version nochmals zu bauen. Die hier verwendete Version hat ja schon bald ein Jahr auf dem Buckel.
DeleteHi,
ReplyDeletethanks for the post. I've just tried it on a Wemos D1 mini with the latest NodeMCU firmware (modified according to your blog and Aex Aey's comment - thanks).
And it just works without noticable drops.
Anyway this was my first try with ESP8266 and it looks cool :)
Great to hear it works for you. People will probably be interested in your firmware, as I haven't updated my build environment for quite a while.
DeleteIm new to this area, and im studying lua and dont have great knowledge on lua. when i run code gives the error: "ap.lua:11: wrong arg type"
ReplyDeleteline 11 is: "wifi.ap.setmac("AC-1B-1C-D1-0B-22")"
it seems like firmware 0.9 doesn't support set mac function.
can u please give changed firmware 1.0 which supports set mac function or give a solution for this
I think you're quite right: My firmware version is too old and some commends have changed or have been added since 0.95. Have a look at the comment above from "klaca", he has made a new firmware build. Perhaps he is willing to share it.
DeleteOk, anyone can try it with the newer firmware:
ReplyDeletehttp://tiny.cc/modemcu_wifi_extender_fw
Cool! Thanks @klaca
Deletecould you reupload the firmware again and maybe the source code.
DeleteHello, i try with newer firmware and all work ok, in my router put ip destination 192.168.4.0 ( esp8266 mode ap ), gateway put ip station esp8266 192.168.1.33, and submask 255.255.255.240, but if want to connect many esp8266 to my router...i have to put the gateway different for each esp8266, anybody know can put only a gateway for many esp8266? more simple, thanks
ReplyDeleteYou have to use differnt subnets behind each of the ESPs and route each network to the respective ESP. In newer firmwares, you can set the SoftAP IP range: https://nodemcu.readthedocs.io/en/master/en/modules/wifi/#wifiapsetip
Deletedo you have some new stable version?
ReplyDeleteTry [klaca]'s firmware build. He posted a link here in the comments back in September.
DeleteHello again, thanks for your reply Andreas Reischle, routing in my router all work good, but now i have other problem. Esp8266 only can connect in AP 4 stations, but i need about 10 stations per AP, i will need to build custom firmware but i dont know if it will work this modify. And only see https://nodemcu-build.com/ and i cant modify any lines, it is automatic, thanks.
ReplyDeletecan you explain how you made setup at router means connection.
ReplyDeletewhat i am doing wrong that I can't ping www.google.com ...
ReplyDeleteDoes "nslookup www.google.com" work?
ReplyDeleteGreat tutorial.
ReplyDeleteI am a university student and live in hostel, having wifi but its range is not reach in my room. I figured out that the wifi had 192.168.16.1 and 192.168.12.1 as default gateways. I am unable to access the router page, so can I still have this repeater working. How can I change the 192.168.4.0 thing? and to what ip?
User Martin-ger on Gitgub ( https://github.com/martin-ger/esp_wifi_repeater ) has done a much better job than me. His solution includes NAT which should make things easy for you.
DeleteThis comment has been removed by the author.
DeleteHis binary doesn't work for me either.
DeleteIn which way does it fail?
DeleteThe version 2.0 failed for my nodemcu 3 device. Now I use firmware 1.5.4 and it works now
ReplyDeleteAndreas: Is there any forums for the "https://github.com/martin-ger/esp_wifi_repeater" method of making a repeater.
ReplyDeleteI have two esp 12's which are virtually identical yet one has slightly different logo on the esp chip. both flashed with martins firmware.
One of the esp's simply doesn't work. specifically - the Ap doesn't show in a wifi scan.
I am ready to hit it with a hammer.
I have done a lot of work on the ESP8266, but I never broke one. Still it might simply be broken.
DeleteIf you think it is a software problem, you can open an issue on GitHub.
thanks for replying
Deleteturns out it may have been software issues. flashed using other program + had to power cycle the mcu.
This comment has been removed by a blog administrator.
ReplyDelete