0

I have a local (household 192.168.0.X) network provided by my router/modem which assigns local IP addresses by the usual Dynamic DNS. I have added an ESP8266 runnning in the WiFi Nat (natp) mode to act as an extender. So it connected to the router as a station and then provides an access point that other devices can connect to. Currently, its subnet is 172...X).

This works in the sense that devices on the extended subnet can see the "world" like google.com etc...

The problem is devices on the 192. network can't see any devices on the extended network.

The source of the problem is pretty obvious: the 192 network devices are all connected by the router which has no clue about any devices connnected to the extender access point.

Is this possible and is there a good ESP 82666 example for this?

If not example, I'm unsure what I'm not understanding-- I'm unsure of what to call this configuration so googling it isn't working.

I feel like there ought to be a way to make the extender just a transparent replicator/relay so the Router is seeing every device and is doing the DHCPS job itself rather than the ESP8266 access point. But I'm stuck.

What sort of configuration approach I can use to expose the devices on the extended network to the computers on the 192 network?

There's a myriad of possible settings but I can't seem to find a permutation that works. (e.g. the Gateway setting or turning off DHCP on the extender access point.) I've tried making the extender network be the same 192.168.0.X rather than 172. But that didn't help.

Detail: What I have here is a sensor network out in my barn that lives on the access point. I want to be able to access the sensors from inside the house. I've goofed around with workarounds of having the barn devices send their data to a server out in the world. But I want direct access so I can query the devices or do over the air programming directly to the devices from my home computer. I can only do this right now by connecting the home computer to the (slower) extended network access point rather than the high speed home router.

Here's an example of the code I'm modifying (basically one of the ESPWIFI example sketches.)


// NAPT example released to public domain

#if LWIP_FEATURES && !LWIP_IPV6

#define HAVE_NETDUMP 0

#ifndef STASSID
#define STASSID "HouseModem"
#define STAPSK  "HouseModemPassword"
#endif

#include <ESP8266WiFi.h>
#include <lwip/napt.h>
#include <lwip/dns.h>
#include <dhcpserver.h>

#define NAPT 1000
#define NAPT_PORT 10

#if HAVE_NETDUMP

#include <NetDump.h>

void dump(int netif_idx, const char* data, size_t len, int out, int success) {
  (void)success; // What does this do?
  Serial.print(out ? F("out ") : F(" in "));
  Serial.printf("%d ", netif_idx);

  // optional filter example: if (netDump_is_ARP(data))
  {
    netDump(Serial, data, len);
    //netDumpHex(Serial, data, len);
  }
}
#endif

void setup() {
  Serial.begin(115200);
  Serial.printf("\n\nNAPT Range extender\n");
  Serial.printf("Heap on start: %d\n", ESP.getFreeHeap());

#if HAVE_NETDUMP
  phy_capture = dump;
#endif

  // first, connect to STA so we can get a proper local DNS server
  WiFi.mode(WIFI_STA);
  WiFi.begin(STASSID, STAPSK);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print('.');
    delay(500);
  }
  Serial.printf("\nSTA: %s (dns: %s / %s)\n",
                WiFi.localIP().toString().c_str(),
                WiFi.dnsIP(0).toString().c_str(),
                WiFi.dnsIP(1).toString().c_str());

  // give DNS servers to AP side
  dhcps_set_dns(0, WiFi.dnsIP(0));
  dhcps_set_dns(1, WiFi.dnsIP(1));

  WiFi.softAPConfig(  // enable AP, with android-compatible google domain
 //   IPAddress(172, 217, 28, 254),
 //   IPAddress(172, 217, 28, 254),
 //   IPAddress(255, 255, 255, 0));
   WiFi.localIP(),IPAddress(192,168,0,1),IPAddress(255, 255, 255, 0));
  WiFi.softAP(STASSID "extender", STAPSK);  // odd way to concat strings
  Serial.printf("AP: %s\n", WiFi.softAPIP().toString().c_str());

  Serial.printf("Heap before: %d\n", ESP.getFreeHeap());
  err_t ret = ip_napt_init(NAPT, NAPT_PORT);
  Serial.printf("ip_napt_init(%d,%d): ret=%d (OK=%d)\n", NAPT, NAPT_PORT, (int)ret, (int)ERR_OK);
  if (ret == ERR_OK) {
    ret = ip_napt_enable_no(SOFTAP_IF, 1);
    Serial.printf("ip_napt_enable_no(SOFTAP_IF): ret=%d (OK=%d)\n", (int)ret, (int)ERR_OK);
    if (ret == ERR_OK) {
      Serial.printf("WiFi Network '%s' with same password is now NATed behind '%s'\n", STASSID "extender", STASSID);
    }
  }
  Serial.printf("Heap after napt init: %d\n", ESP.getFreeHeap());
  if (ret != ERR_OK) {
    Serial.printf("NAPT initialization failed\n");
  }
}

#else

void setup() {
  Serial.begin(115200);
  Serial.printf("\n\nNAPT not supported in this configuration\n");
}

#endif

void loop() {
}
  • 1
    Bridging works only on the same network. To route packets between networks, you use a router. Routers learn routes in three ways: directly connected networks, statically configured routes, or through a routing protocol. You really do not want to run NAT internal to your own network when simple routing will work. NAT is _not_ a substitute for routing, and you only use it when you must: public<->private connections or overlapping network addressing. – Ron Maupin May 26 '20 at 01:42
  • I’m voting to close this question because it's about network configuration and not about programming. – gre_gor May 26 '20 at 02:02
  • @gre_gor No it's about how one does this on an ESP8266 – Alexander Hamilton May 26 '20 at 02:06
  • @Ron_maupin I'm not clear on how one sets up the ESP8266 to route. – Alexander Hamilton May 26 '20 at 02:11

1 Answers1

0

You can subnetting the routers network from nat devices onwords. So tree like network structure may form.

Let say your router is assigning 192.168.0.x/24 ip to your first hop devices then those devices could modify their access points network with 192.168.1.x/24 and so on upto the possible last hop.

To make it form dynamically on their own you may need to assign common ssid and password to all devices in that structure.

If you could able to achieve this then their may be chances of accessing individual devices from router.

Also you may get the idea of to what hop level individual device seats in network tree by their subnet ip.

Suraj Inamdar
  • 181
  • 1
  • 1