
ESP 8266 Wi-Fi Repeater with Mesh Networking - rcarmo
https://github.com/martin-ger/esp_wifi_repeater
======
acidburnNSA
Very cool. Most of you probably already know this, but the ESP8266 is a
glorious microcontroller that costs about $7 in a nice package. It has Wifi
and a bunch of GPIO ports, and the newer model ESP32 has bluetooth too. They
can be programmed like an Arduino (using Arduino IDE among other tools) and
are a really interesting way to get a bunch of very cheap, highly connected
things going on.

For instance, I have one rigged up across a zone valve on my mom's "dumb"
furnace and it's now smart furnace that heats the house up before she wakes up
and controls the temperature to whatever tolerance she wants. I have another
one running the stepper motor that turns the screw of my $30 DIY star-tracking
camera mount. Another is hooked up to a thermocouple that transmits readings
from wherever through a MQTT server to processing equipment to characterize
oven temperatures, water heaters, or anything else you want to measure. I have
other ones hooked to reed sensors that tell my security system when things get
opened or closed.

The possibilities with this kind of cheap SoC are nearly endless. I love how
many fun ideas become really practical (as in, "Ooh, I could set this up right
now using my drawer of ESPs! Here I go...") with this kind of thing.

~~~
matt_the_bass
I think these are great for people with experience using embedded electronics
and comfortabke with soldering and low level programming (I.e probably a
significant portion of HN readers).

However for those that don't have a background other than simple programming
experience, I strongly recommend paying g more for a platform with good
infrastructure. For example , I'm really impressed with particle.io.

Board costs are <$20 but come with cloud infrastructure and lots of examples
and documentation. For those that value time over money I recommend them.

~~~
keldaris
Are these particle.io kits completely soldering-free? I've been looking to
experiment a bit with some embedded projects purely for fun and I don't mind
low level programming at all (if it has a C compiler or at least a decent
assembly manual, I'm good), but soldering (presumably, the smell of the flux,
but I've never cared to investigate and would rather just avoid it) is a
strong migraine trigger for me.

~~~
fader
There are some other devices out there that are made to allow alligator clips
onto leads or to use conductive thread, so no soldering is required. Adafruit
makes several great little boards, but if you're getting started I'd recommend
the "Circuit Playground" board:
[https://www.adafruit.com/product/3333](https://www.adafruit.com/product/3333)
It has a number of sensors and LEDs built in already as well and supports
CircuitPython, Microsoft MakeCode, and the Arduino framework.

------
escapologybb
Here's a quick question I hope somebody can shed some light on. I live in a
small-ish town in Yorkshire, probably a couple of miles square and was
wondering about the feasibility of using these little devices to create a mesh
network to extend my home network.

The reason being is that I have lots of Internet connected devices which watch
over me whilst I'm in the house, being Quadriplegic it's much more comforting
to have a computer watch over my health and do things for me than it is to
have a potentially tired, angry and/or bored person doing it. However, that
bubble ends as soon as I pass out of Wi-Fi range.

So obviously I would like to extend coverage to cover my smalltown, but
everything I've seen so far has been prohibitively expensive. It wouldn't need
to have a massive amount of bandwidth available as it would be just me using
it, but it would need to be fairly cheap and as near to 100% reliable as
possible.

Any insights, questions, comments? TIA

Edited To Add: I've just measured it using Google Earth and I need to cover a
circle with an area of about one square kilometre.

~~~
sputr
Maby contact these guys: [https://wlan-si.net/en/](https://wlan-si.net/en/)

They are(were) deploying wifi mesh networks on the cheap in Slovenia. They've
covered entire towns that did not have internet access in the past (mesh
network in the town + string of directed antenna to get an uplink from a
bigger town). Routers they used cost in the range of 15€ each, but the last
time I talked to them they had trouble supplying new routers.

~~~
escapologybb
Thanks for the link, I will definitely get in touch with them. Paying for the
equipment isn't the issue I don't think, it's the expertise and looking for.

------
kees99
Two limitations here are worth keeping in mind:

\- Throughput is not stellar (less than 1 mbit/s in a realistic setup);

\- This is not a real IEEE 802.11s mesh, but rather some clever mechanism on
how a node can select an "uplink".

~~~
mtgx
It's a shame the Wi-Fi Alliance is showing no interest in long-range mesh
capabilities for its Wi-Fi standards.

The mesh-like standards it does have currently are mainly focused on home
automation, and they only cared about developing those because Bluetooth was
becoming the de-factor standard for IoT, and now 6LoWPAN seems to be taking
over.

802.11ax promised 5x the range of 802.11n _in theory_ , but implementers will
go up to 2x, at most, likely preferring to focus on increased
performance/bandwidth instead.

I think it would be really cool if we could have a Wi-Fi standard that would
go through buildings over 1 mile even at 1Mbps speeds. And I think we now have
the technology and know-how for how to deal with interference from similar Wi-
Fi emitters.

It would be nice if something like this was made by the Wi-Fi Alliance because
then we could all have that capability in our phones within 5 years after
release. Think how much that would help in cases of disaster: earthquakes,
tsunamis, hurricanes, wars, and so on.

~~~
ac29
>long-range mesh capabilities for its Wi-Fi standards

>go through buildings over 1 mile even at 1Mbps speeds

That sounds like a nightmare. WiFi is already nearly unusuable in high density
situations. A recent trip to help a friend living in a medium density part of
a large city showed ~100 access points, using the lousy WiFi antenna on my
smartphone. Even every single 5GHz channel (which really doesnt travel well
through objects) was taken, usually twice or more, including all the DFS
channels. Mind you, this was inside.

I cant begin to imagine how unusable WiFi (and its related unlicenced
spectrum) would become if had 5x the range. Even in low-density suburban
areas, 2.4GHz is crowded to the point of degraded performance (although 5GHz
is pretty clear for now).

------
conk
Has anyone actually tried to mesh a large number of ESP8266 chips in practice?
I tried it, hooked a 7-seg display to each 8266 and started adding nodes 1 at
a time. Each node would display the number of additional nodes available in
the mesh (on the 7-seg). I found the mesh became unstable around 12+ nodes and
would auto arrange into 2+ separate meshed networks. This was a while ago and
maybe it's more stable today. I'm interested in anyone actually getting 20+
nodes working reliably.

~~~
tuskan
This solution was limited to 8. \- Due to the limitations of the ESP's SoftAP
implementation, there is a maximum of 8 simultaniously connected stations.
(from the README)

~~~
conk
Interesting, I remember reading some documentation from Espressif's website
early on that claimed 50+, but can't seem to find it now.

------
pingec
This sounds like a really fun thing to play with and could be useful for
extending covered range where bandwidth requirements are low.

Where I usually struggle is making it all small and robust enough. Does anyone
know of any products which integrate power supply (mains or battery) and the
esp8266 into a small, cheap enclosed product. The best candidate I have found
so far would be the Sonoff products.

~~~
kees99
Battery would probably be a no-go here.

You can't put repeater into sleep mode[#], and in active AP+STA mode ESP8266
takes 70mA @3.3v, which is 3-4 times lower than best purpose-made wifi
repeaters, but will still drain 3000mA*h battery in couple of days.

[#] ...unless whole sensor network has scheduled "data upload" internals,
something like 1-minute window twice a day. But even that is going to be very
tricky due to notoriously poor precision of ESP's real-time clock - see for
example
[https://github.com/micropython/micropython/issues/2724](https://github.com/micropython/micropython/issues/2724)

~~~
morsch
Schedule it more often than once per day and when it triggers, resync the
clock with your neighbours? If you wake up and nobody else seems to be awake,
go into degraded mode where you continually listen for the next scheduled
interval.

~~~
kees99
> when it triggers, resync the clock with your neighbours?

Indeed. Periodic clock resync is a must here. Better from external NTP though,
as neighbours have their clock badly drifting as well.

> If you wake up and nobody else seems to be awake, go into degraded mode
> where you continually listen for the next scheduled interval.

That'll defeat the purpose completely. Here's why:

\- "Listen" consumes full 70mA;

\- "wake up and no neighbours awake" will happen very, very often. Let's take
simplest example of two nodes with drifting clock. When they both wake up
(each by local clock), inevitably one will wake up first. That node will
discover there's no neighbours awake. I a mesh, statistically this will happen
to 1/N nodes each wake-up, where N is average number of neighbours. If we
tighten requirement from "anybody awake" to "enough nodes awake to reach
uplink" (so to make use of external NTP) probability of "not enough neighbours
awake" even will come close to 100% on each wakeup.

Slightly better approach would be - when each node wakes up, it stays awake
for long enough to cover worst-case all neighbour's clock drift. Average clock
drift seem to be +/-2%. Let's say +/-5% would be worst case. That means, all
nodes have to be awake 10% of the time just to re-sync clock so that next
wake-up will be not worse off than current one.

And staying awake 10% of the time means average power draw of 70mA * 10% =
7mA, which is pretty darn high (3 weeks on a 3000mA*h Lithium cell. Even less
if there is payload data transmitted on this mesh.)

~~~
c3833174
External high accuracy RTCs with builtin alarms like the ds3231 can be had for
cheap

------
Corrado
I'm trying to view the recent FCC Net Neutrality reversal in a positive light;
will it finally force us to abandon traditional ISPs? Building a mesh seems
like the proper solution to ISPs that won't treat our packets with respect.
Given the correct cost/performance ratio I think we could see a mass of tiny
devices scattered around the neighborhood/town/city/state/country with
backhauls in as many places as possible.

If they are cheap enough and self configuring then we could just plug them in
to any available electrical outlet and go. Put a couple in your house and put
a couple in your parent's/sister's/cousin's house. Talk to your neighbors and
have them plug a couple in. Head to the local taco place and have them plug a
couple in. It shouldn't be hard to get everyone on board: "Plug this in and
get free {libre|beer} Internet access!"

~~~
SunboX
Did you hear about Freifunk?
[https://en.m.wikipedia.org/wiki/Freifunk](https://en.m.wikipedia.org/wiki/Freifunk)
It's more or less what you described.

------
Corrado
For those of you, like me, who don't know exactly what an ESP8266 is or how it
might be used, check out this video by EEVBlog[0]. It gives a brief background
on the chip and its alternatives and shows some simple programming examples.

[0]
[https://www.youtube.com/watch?v=Q6NBnPfPhWE](https://www.youtube.com/watch?v=Q6NBnPfPhWE)

------
triangleman
Do Wi-Fi repeaters work in general? It would seem that if you had two AP's
broadcasting with the same SSID, one of which is relaying back to the other,
the computer or the AP's or both would get confused. I only saw it tried once
and it didn't really work but what is the state of the art? Is this a solved
problem?

------
geokon
It's been quite a few years since my college networking class, but am I wrong
to expect this to just kinda work out of the box? The ESPs can already act as
routers and the MAC/IP protocols should already insure packets get routed
around correctly. How is it different from, for instance, hooking up several
WiFi routers at home?

I'm curious about the challenges b/c I've been wanting to try to get a more
long-distance mesh going with Lora. Some of the newer chips are incredibly
affordable:

[https://www.cnx-software.com/2017/10/13/this-ttgo-board-
comb...](https://www.cnx-software.com/2017/10/13/this-ttgo-board-combines-
esp32-lora-radio-and-oled-display-for-just-10/)

~~~
jessaustin
That's nice, but it would seem more useful at 915 mhz...

~~~
geokon
why?

~~~
jessaustin
433 mhz isn't open for unlicensed use in North America.

------
fulafel
Why v4 NAT instead of IPv6?

~~~
kees99
Dynamic routing is the hardest part of mesh network. By using NAT _martin-ger_
has side-stepped need to have routing altogether (it's just default gateway
for each node like that). But that of course comes at cost - reaching your
device from "outside" becomes much harder.

Also, ESP8266's official SDK doesn't support IPv6.

~~~
abraae
Could you elucidate on that? I don't get how a message is somehow routed
through a thicket of say 1000 of these things to get from one node to another,
because NAT?

~~~
kees99
"Mesh" (in thick air-quotes) here is just a way for self-organizing for
shortest uplink hop count.

Strict uplink-downlink hierarchy still stays regardless of whether "manual
uplink" or "mesh" mode is in use. Each repeater doing Source NAT still stays.
Lack of "sideways" connectivity still stays (unless you configure manual DNAT
which is incompatible with "mesh" mode to begin with).

I.e., if you have 3 of those ESP8266 repeaters with two clients connected to
different repeaters, there is no (easy) way to have those two clients talk to
each other. Let's say this is our network diagram:

    
    
            {The Internet}----[Cloud Server]
                  |
              [Wired AP]----[Local Server]
                  |
             [ESP8266-R1]
               |      |
      [ESP8266-R2]  [ESP8266-R3]
            |            |
       [Clinet 1]    [Client 2]
    

...then, we have two options how to make Client 1 and Client 2 talk to each
other:

\- each client talks to the same server (local or cloud) and server takes care
of passing the message;

or

\- we configure _static_ destination NAT (option _portmap add_ ) on both
ESP8266-R2 and ESP8266-R3, and disable "mesh" mode (i.e. manually configure
uplinks for all 3 repeaters);

...and arranging 1000 of those in a single string and routing a single packet
through that is better avoided. "Mesh" mode helps a lot with this, by
selecting shorter path to the internet and bringing topology closer to a tree,
where possible.

~~~
abraae
Thanks! Will peruse over coffee

------
vog
Is this interesting (or at least relevant) for the freifunk project?

------
feelin_googley
Whats up with NodeUSB? It was in Kickstarter some years ago. Anyone here have
one?

It is ESP8266 and can be programmed without grahical IDE, using only GCC
toolchain and Lua?

------
ferongr
The amount of possible chained NATs gave me an aneurysm.

------
jaytaylor
Why can it only do about 5mbps?

~~~
kees99
5mbps is about the best case (all 3 nodes on the same table). In more
realistic deployment, it'll be much less.

So, why so slow?

TL;DR: Too little RAM on ESP8266.

WiFi is half-duplex, i.e. in basic scenario (no MIMO; all stations close
enough that each can hear at least some other), only one node can transmit at
a time. [CSMA/CA] protocol is used to enforce this limitation. This protocol
is susceptible to [Hidden node problem], which absolutely will be present for
wifi repeater. Meaning that data in a single burst is transmitted fast, but
any switch-over of who's transmitting is going to be really slow, with
collisions, pauses, etc. In turn, that means that to achieve any decent
throughput, WiFi repeater should buffer as much data as possible to minimize
number of transmitter switch-overs. And that requites RAM - say to buffer
half-second data burst at 54Mbps you'll need 3.5MB of RAM. Alas, ESP8266 only
has 96KB of data RAM, out of which just 32KB is used as packet buffer with
standard SDK.

[CSMA/CA]
[https://en.wikipedia.org/wiki/CSMA/CA](https://en.wikipedia.org/wiki/CSMA/CA)

[Hidden node problem]
[https://en.wikipedia.org/wiki/Hidden_node_problem](https://en.wikipedia.org/wiki/Hidden_node_problem)

------
avesfan
Could you integrate a bitcoin address that I can pay to for bandwidth? Have
the operator set the kB/satoshi and the rate at which withdrawls occur over
the lightning network? When the address is empty the connection is terminated?

~~~
lucaspiller
IUNGO is a blockchain based project to do exactly this:

[https://medium.com/@iungo/iungo-global-wifi-networks-is-
abou...](https://medium.com/@iungo/iungo-global-wifi-networks-is-about-to-
disrupt-the-old-standards-d856880e04a4)

