You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 10 PC与Arduino UNO双IPWiFi通信配置及网卡需求问询

实现PC与Arduino UNO的双IP WiFi通信方案

不需要额外配备第二块USB WiFi网卡,通过以下两种方案即可实现需求:

方案一:让Arduino WiFi模块工作在STA+AP双模式(推荐)

大部分主流WiFi模块(如ESP8266、ESP32)都支持同时开启STA模式(连接家庭路由器)和AP模式(自身热点),具体步骤如下:

1. 配置Arduino的WiFi双模式与网络参数

编写Arduino代码,完成以下配置:

  • STA模式配置:连接家庭路由器,设置静态IP为192.168.1.40,子网掩码255.255.255.0,网关192.168.1.254,DNS可设置为网关或公共DNS(如8.8.8.8)。
  • AP模式配置:开启自身热点,设置SSID、密码,保持AP的静态IP为192.168.4.1,子网掩码255.255.255.0。
  • 开启IP转发:在代码中启用WiFi模块的IP转发功能,确保PC发往192.168.4.x网段的流量能通过STA接口转发到AP接口(不同模块代码略有差异)。

示例代码片段(以ESP8266为例):

#include <ESP8266WiFi.h>

// STA模式参数
const char* ssid_sta = "你的家庭WiFi名称";
const char* password_sta = "家庭WiFi密码";
IPAddress ip_sta(192, 168, 1, 40);
IPAddress gateway_sta(192, 168, 1, 254);
IPAddress subnet_sta(255, 255, 255, 0);

// AP模式参数
const char* ssid_ap = "Arduino_AP";
const char* password_ap = "12345678";
IPAddress ip_ap(192, 168, 4, 1);
IPAddress subnet_ap(255, 255, 255, 0);

void setup() {
  Serial.begin(115200);
  
  // 配置STA模式并连接路由器
  WiFi.config(ip_sta, gateway_sta, subnet_sta);
  WiFi.begin(ssid_sta, password_sta);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("STA模式连接成功");

  // 配置AP模式
  WiFi.softAPConfig(ip_ap, ip_ap, subnet_ap);
  WiFi.softAP(ssid_ap, password_ap);
  Serial.println("AP模式开启成功");

  // 启用IP转发(ESP8266专属配置)
  wifi_set_opmode(STATIONAP_MODE);
  wifi_softap_dhcps_start();
}

void loop() {
  // 此处可添加Web服务器或TCP通信逻辑
}

2. 在Windows 10上添加静态路由

以管理员身份打开命令提示符,执行以下命令,让PC识别192.168.4.x网段的路由路径:

# 临时生效,重启后失效
route add 192.168.4.0 mask 255.255.255.0 192.168.1.40 metric 1

# 永久生效,重启后保留
route -p add 192.168.4.0 mask 255.255.255.0 192.168.1.40 metric 1

完成配置后:

  • PC可直接通过192.168.1.40与Arduino进行TCP/IP通信;
  • PC浏览器输入192.168.4.1即可访问Arduino的内置Web服务器。

方案二:单网卡切换连接(应急方案)

如果Arduino的WiFi模块不支持STA+AP双模式,可通过单网卡切换连接:

  • 需要与192.168.1.40通信时,让PC连接家庭路由器;
  • 需要访问192.168.4.1的Web服务器时,断开家庭WiFi,连接Arduino的AP热点。

这种方法无需额外硬件,但无法同时实现两种通信场景,仅适合临时需求。


内容的提问来源于stack exchange,提问作者user20420531

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 03:35:48