【问题标题】:Communicating between subnets with ESP8266 wifi extender使用 ESP8266 wifi 扩展器在子网之间进行通信
【发布时间】:2020-05-26 01:30:22
【问题描述】:

我的路由器/调制解调器提供了一个本地(家庭 192.168.0.X)网络,它通过通常的动态 DNS 分配本地 IP 地址。我添加了一个在 WiFi Nat (natp) 模式下运行的 ESP8266 作为扩展器。因此它作为一个站点连接到路由器,然后提供其他设备可以连接的接入点。目前,其子网为 172...X)。

这意味着扩展子网上的设备可以看到“世界”,如 google.com 等......

问题是192上的设备。网络看不到扩展网络上的任何设备。

问题的根源很明显:192个网络设备都是由路由器连接的,路由器不知道连接到扩展接入点的任何设备。

这可能吗?是否有一个很好的 ESP 82666 示例?

如果不是示例,我不确定我不理解什么 - 我不确定如何调用此配置,因此使用谷歌搜索它不起作用。

我觉得应该有一种方法让扩展器只是一个透明的复制器/中继器,这样路由器就可以看到每个设备,并且自己做 DHCPS 工作,而不是 ESP8266 接入点。但我被困住了。

我可以使用什么样的配置方法将扩展网络上的设备暴露给 192 网络上的计算机?

有无数种可能的设置,但我似乎找不到可行的排列。 (例如,网关设置或关闭扩展器接入点上的 DHCP。)我尝试让扩展器网络使用相同的 192.168.0.X 而不是 172。但这没有帮助。

详情: 我这里有一个传感器网络,位于我的谷仓中,位于接入点上。我希望能够从屋内访问传感器。我已经搞砸了让谷仓设备将他们的数据发送到世界各地的服务器的解决方法。但我想要直接访问,这样我就可以查询设备或从我的家用计算机直接对设备进行无线编程。我现在只能通过将家用计算机连接到(速度较慢的)扩展网络接入点而不是高速家用路由器来做到这一点。

这是我正在修改的代码示例(基本上是 ESPWIFI 示例草图之一。)


// 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() {
}

【问题讨论】:

  • 桥接只能在同一个网络上工作。要在网络之间路由数据包,请使用路由器。路由器通过三种方式学习路由:直接连接的网络、静态配置的路由或通过路由协议。当简单的路由可以工作时,你真的不想在你自己的网络内部运行 NAT。 NAT不是路由的替代品,只有在必须时才使用它:公共私有连接或重叠网络寻址。
  • 我投票结束这个问题,因为它是关于网络配置而不是关于编程。
  • @gre_gor 不,这是关于如何在 ESP8266 上做到这一点
  • @Ron_maupin 我不清楚如何设置 ESP8266 进行路由。

标签: esp8266 nat access-point esp8266wifi


【解决方案1】:

您可以从 nat devices onwords 对路由器网络进行子网划分。所以可能会形成树状的网络结构。

假设您的路由器正在为您的第一跳设备分配 192.168.0.x/24 ip,然后这些设备可以使用 192.168.1.x/24 修改其接入点网络,依此类推,直到可能的最后一跳。

要使其自行动态形成,您可能需要为该结构中的所有设备分配通用 ssid 和密码。

如果你能做到这一点,那么他们可能有机会从路由器访问单个设备。

您还可以通过子网 ip 了解单个设备在网络树中所处的跃点级别。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-13
    • 2013-02-19
    • 2011-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-09
    相关资源
    最近更新 更多