Thursday 2 July 2015

Second (successful) attempt to route IP packets with ESP8266

Now that one was a piece of cake:
As suspected /app/include/lwipopts.h overruled the file I modified previously.

So with a 
#define IP_FORWARD 1
in there, the the module started forwarding packets

Ping connectivity table
PING 192.168.1.50 192.168.1.75 192.168.4.1 192.168.4.3
192.168.1.50 n/a n/a n/a YES
192.168.1.75 YES n/a n/a n/a
192.168.4.1 YES n/a n/a YES
192.168.4.3 YES n/a YES n/a



So I now could ping the Laptop (ouch: forgot to disable the firewall first) from the mobile device and vice versa.
Here is the caveat:
  • I need a static route from the Laptop to the "StationMode" interface of the ESP8266. The cooler way to do that is on the default router.
Up to now this is an easy one for the ESP module. Both subnets are directly connected, so the routing decision is not really that hard. With very little tweaking, this could already be used  as an extremely simple range extender working at layer 3.
To daisy-chain / mesh more of these, I need to supply routing information to LWIP. It is not too obvious where to do that in the code or what it takes to add commands to manipulate routes through LUA.

17 comments:

  1. I have the same problem. But I can not compile nodemcu from source. Could you write some advise?

    ReplyDelete
    Replies
    1. Which way have you tried? I use the VirtualBox image supplied by Espressif, their SDK and the NodeMCU sources cloned from GitHub.

      Delete
    2. I use Espressif's VirtualBox image and their SDK
      but I can't compile toolchain. Could you advise how to compile toolchain for compiling IP FORWARDING Lua image?

      Delete
    3. I use more or less the same setup. I use pfalcon's tools to install the SDK: https://github.com/pfalcon/esp-open-sdk
      All I need to to then is to set the environment variable for the path to the SDK and I can compile NodeMCU from the source.
      Where exactly does it fail for you?

      Delete
    4. At last, I can compile by Eclipse on Windows10.

      Changing points is :
      1. file "lwipopts.h"

      #define IP_FORWARD 1

      2. file "opts.h"

      #define IP_FORWARD 1

      Are these points enough for IP_FORWARD ?
      After compiling how to use it?

      Thank you.

      Delete
    5. Which version of the NodeMCU source are you using? They switched to a newer LWIP version a little while ago. In older versions, you had to define USE_DNS, which is already the case in the newer version.
      You can check out the old video for the details on using the RangeExtender here: https://youtu.be/NH1rjk3Q_MU

      Just last week, I have made a new, extremely well working build that simplifies things a lot. I'll release that along with docs and a video tutorial shortly.

      Delete
    6. Thank you very much.
      I have tried to compile as following steps.

      http://tridenttd-iot.blogspot.com/2016/02/lwip-ip-forward-espressif-devkit-eclipse.html

      I don't know how to use them for using IP FORWARD on esp8266.

      Delete
  2. Hello Andreas. is http requests working on client side? for ex. can i receive abc.com/abc.php result from esp's client ?

    ReplyDelete
  3. Hi Mehmet, I am still working on that. I had disconnects from the downstram AP when I put traffic through the ESP. It might be a power issue, but I haven't fully investigated the issue. In theory it should work, but it doesn't.

    ReplyDelete
  4. Is your source code available for this project? If so, where could I download it from?

    ReplyDelete
    Replies
    1. Yes.
      Read here:
      http://www.areresearch.net/2015/10/using-esp8266-as-wifi-range-extender.html
      Or watch this:
      https://youtu.be/NH1rjk3Q_MU

      Delete
  5. Hello Andreas, I tried following the code changes you mention here, applied to the latest nodemcu dev branch. I changed the lwip code in the nodemcu repo itself (as opposed to the lwip contained in the SDK), then rebuilt the firmware.
    However, I can't seem to ping through the ESP. I can ping both ESP interfaces from either side, but not through it.
    Are the code changes here still applicable to the latest dev branch? I understand that the firmware migrated to open lwip as of firmware 1.4.0.

    ReplyDelete
    Replies
    1. I also got it working with 1.4.0
      If you can't ping accross the module, the most likely reason is that the
      #define IP_FORWARD 1
      is not set or in the wrong place.
      Please try the firmware here:
      Read here:
      http://www.areresearch.net/2015/10/using-esp8266-as-wifi-range-extender.html
      And watch this:
      https://youtu.be/NH1rjk3Q_MU

      Delete
  6. I finally managed to ping through the ESP, the issue was the router, for some reason the static route didn't work. I switched to an older router I had and it worked.
    Then, with the DNS forwarder code I was able to browse and even stream netflix through the ESP. That's not bad at all :)
    Like I mentioned in your other article, I did not experience any disconnection issues during my tests (although I didn't really test too long either ;p)

    ReplyDelete
    Replies
    1. Hi Daniel, great to hear that! I have a version available that does not require the DNS forwarder any more. Unfortunately it is affected by NodeMCU bug #1164, so I don't particularly like it, although it works. (Not much need for SPIFFS in this case.)

      Delete
    2. Do you mean this:
      http://www.areresearch.net/2015/10/using-esp8266-as-wifi-range-extender.html?showComment=1448065651378#c3704870924627971911
      ?
      Or something else?
      What I think would be interesting is to set the dns server sent out by the AP dhcp option to be the same as the dns server received by the STA.

      Delete
    3. Yes, exactly. That works great as suggested by Alx Aly. Your idea should also work. That would usually be the DSL-Router and is a bit more universal than a fixed IP.

      Delete