imtoken钱包下载安卓2.0|ethernet manager

作者: imtoken钱包下载安卓2.0
2024-03-14 19:38:56

NetworkManager设置 - 知乎

NetworkManager设置 - 知乎切换模式写文章登录/注册NetworkManager设置周京成​计算机技术与软件专业技术资格证持证人通常的linux发行版对于网络的配置方法一般会同时支持network.service(即配置和使用/etc/sysconfig/network-scripts/下的配置文件来配置网络,对于ubuntu是/etc/network/interfaces等等)和NetworkManager.service(简称NM)。默认情况下,这2个服务都有开启,而且功能上是平行的,可以通过任意一个来配置网络,正常的情况下通过NM来配置网络后它会自动把配置同步到network.service的配置中。NM能管理各种网络物理网卡、虚拟网卡有线网卡、无线网卡动态ip、静态ip以太网、非以太网 使用方法 nmcli:命令行。这是最常用的工具。 nmtui:在shell终端开启文本图形界面。 Freedesktop applet:如GNOME上自带的网络管理工具 nm-connection-editor图形配置工具 cockpit:redhat自带的基于web图形界面的"驾驶舱"工具,具有dashborad和基础管理功能。nmcli使用方法nmcli使用方法非常类似linux ip命令、cisco交换机命令,并且支持tab补全,也可在命令最后通过-h、--help、help查看帮助。在nmcli中有2个命令最为常用:nmcli connection连接,可理解为配置文件,相当于ifcfg-ethX。可以简写为nmcli cnmcli device这里注意一点:ethernet是设备类型,eth0是设备名称。不要混了,设备类型可以是ethernet代表以太网,还可以是loopback代表环回口等等。设备,可理解为实际存在的网卡(包括物理网卡和虚拟网卡)。可以简写为nmcli d在NM里,有2个层级:连接(connection)和设备(device),连接的配置记录在(对于ubuntu为/etc/NetworkManager/system-connections/内),通常NM的管理是以连接为单位的,在连接的配置文件里指明设备名,所以我们在NM的所有配置目录里找不到针对设备的配置文件,只有针对连接的配置文件,就像你的手机wifi可以记住多个无线连接一样,多个连接可以使用同一个设备,但同一时刻,一个设备只能有一个连接活跃。意思就是你的手机wifi在一个时刻只能连接一个wifi。可以通过 nmcli connetion up<连接> 来切换连接。对于一个device有4种常见状态:connected:已被NM托管,并且当前有活跃的connection disconnected:已被NM托管,但是当前没有活跃的connection unmanaged:未被NM托管,就是不让NM动这个设备相关的任何操作unavailable:不可用,NM无法托管,通常出现于网卡link为down的时候(比如ip link set ethX down)对于任意设备上的任一connection通常有2种状态: 活跃(带颜色字体):表示当前该connection是正在使用的。 非活跃(正常字体):表示当前该connection没有连接。nmcli常用命令一览对于连接:# 查看ip(类似于ifconfig、ip addr)

nmcli

# 创建connection,配置静态ip(等同于配置ifcfg,其中BOOTPROTO=none,并ifup启动)

nmcli c add type ethernet con-name CNNCT1 ifname ethX ipv4.addr 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.method manual

# 创建connection,配置动态ip(等同于配置ifcfg,其中BOOTPROTO=dhcp,并ifup启动)

nmcli c add type ethernet con-name CNNCT1 ifname ethX ipv4.method auto

# 修改ip(非交互式)

nmcli c modify CNNCT1 ipv4.addr '192.168.1.200/24'

nmcli c up CNNCT1

# 修改ip(交互式)

nmcli c edit CNNCT1

nmcli> goto ipv4.addresses

nmcli ipv4.addresses> change

Edit 'addresses' value: 192.168.1.200/24

Do you also want to set 'ipv4.method' to 'manual'? [yes]: yes

nmcli ipv4> save

nmcli ipv4> activate

nmcli ipv4> quit

# 启用connection(相当于ifup)

nmcli c up CNNCT1

# 停止connection(相当于ifdown)

nmcli c down

# 删除connection(类似于ifdown并删除ifcfg)

nmcli c delete CNNCT1

# 查看connection列表

nmcli c show

# 查看connection详细信息

nmcli c show CNNCT1

# 重载所有ifcfg或route到connection(不会立即生效)

nmcli c reload

# 重载指定ifcfg或route到connection(即导入原来的系统配置,不会立即生效)

nmcli c load /etc/sysconfig/network-scripts/ifcfg-eth0 //注意eth0是设备名(centos)

nmcli c load /etc/sysconfig/network-scripts/route-eth0 //这个是配置的路由(centos)

# 立即生效connection,有3种方法

nmcli c up CNNCT1

nmcli d reapply CNNCT1

nmcli d connect CNNCT1

对于设备(device)# 查看device列表

nmcli d

# 查看所有device详细信息

nmcli d show

# 查看指定device的详细信息

nmcli d show eth0

# 激活网卡

nmcli d connect eth0

# 关闭无线网络(NM默认启用无线网络)

nmcli r all off

# 查看NM托管状态

nmcli n

# 开启NM托管

nmcli n on

# 关闭NM托管(谨慎执行)

nmcli n off

# 监听事件

nmcli m

# 查看NM本身状态

nmcli

# 检测NM是否在线可用

nm-online本文提及的ifcfg均指代/etc/sysconfig/network-scripts/ifcfg-ethX及/etc/sysconfig/network-scripts/route-ethX(即原来的配置方法)NetworkManager自己的配置文件在/etc/NetworkManager/下[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0 #网卡设备名称

ONBOOT=yes#启动时是否激活 yes | no

BOOTPROTO=static #协议类型 dhcp bootp none

IPADDR=192.168.1.90#网络IP地址

NETMASK=255.255.255.0#网络子网地址

GATEWAY=192.168.1.1#网关地址

BROADCAST=192.168.1.255#广播地址

HWADDR=00:0C:29:FE:1A:09#网卡MAC地址

TYPE=Ethernet #网卡类型为以太网

[root@localhost ~]# cat /etc/sysconfig/network-scripts/route-eth0

0.0.0.0/0 via 192.168.3.1 dev eth0

10.211.6.0/24 via 192.168.3.1 dev eth0

# cat /etc/sysconfig/network-scripts/route-eth1

10.0.0.0/8 via 10.212.52.1 dev eth1nmcli connection重点nmcli c show▪ 第一列是connection名字,简称con-name(注意con-name不是网卡名) ▪ 第二列是connection的UUID ▪ 最后一列才是网卡名(标准说法叫device名),可通过nmcil d查看device对connection做操作时需要指定标识,标识可以是con-name、UUID、如果存在ifcfg文件则也可以用ifcfg的完整路径,即/etc/sysconfig/network-scripts/ifcfg-ethXnmcli c show CNNT1

nmcli c show cae3f1ef-e79a-46c3-8e0c-946b91a65e11

nmcli c show /etc/sysconfig/network-scripts/ifcfg-ethXnmcli c的con-name同时对应ifcfg的文件名以及内容中的NAME=,该参数表示连接(connection)的名字,无需和网卡名相同,可以为一个设备(device)创建多个连接,但同一时刻只能有一个连接生效。当有多个连接时候, nmcli cdelete删除当前连接,就会自动选择同一个设备的其他连接来顶替生效。可以通过 nmcli c up来将指定连接切换生效。注意:通过nmcli c modify修改con-name,只会对应修改ifcfg文件中的NAME,而不会更改ifcfg文件名。nmcli c的ipv4.method对应ifcfg文件内容的BOOTPROTO,ipv4.method默认为auto,对应为BOOTPROTO=dhcp,这种时候如果指定ip,就可能导致网卡同时有dhcp分配的ip和静态ip。设置为manual表示BOOTPROTO=none,即只有静态ip。例子:创建一个连接(connection)nmcli c add type ethernet con-name ethX-test ifname ethX ipv4.addresses '192.168.1.100/24,192.168.1.101/32' ipv4.routes '10.0.0.0/8 192.168.1.10,192.168.0.0/16 192.168.1.11' ipv4.gateway 192.168.1.254 ipv4.dns '8.8.8.8,4.4.4.4' ipv4.method manual▪ type ethernet:创建连接时候必须指定类型,类型有很多,可以通过 nmcli c add type-h看到,这里指定为ethernet。 ▪ con-name ethX ifname ethX:第一个ethX表示连接(connection)的名字,这个名字可以任意定义,无需和网卡名相同;第二个ethX表示网卡名,这个ethX必须是在 nmcli d里能看到的。 ▪ ipv4.addresses '192.168.1.100/24,192.168.1.101/32':配置2个ip地址,分别为192.168.1.100/24和192.168.1.101/32 ▪ ipv4.gateway 192.168.1.254:网关为192.168.1.254 ▪ ipv4.dns '8.8.8.8,4.4.4.4':dns为8.8.8.8和4.4.4.4 ▪ ipv4.method manual:配置静态IP对应的ifcfg和dns就是# /etc/sysconfig/network-scripts/ifcfg-eth0-test

TYPE=Ethernet

PROXY_METHOD=none

BROWSER_ONLY=no

BOOTPROTO=none

IPADDR=192.168.1.100

PREFIX=24

IPADDR1=192.168.1.101

PREFIX1=32

GATEWAY=192.168.1.254

DNS1=8.8.8.8

DNS2=4.4.4.4

DEFROUTE=yes

IPV4_FAILURE_FATAL=no

IPV6INIT=yes

IPV6_AUTOCONF=yes

IPV6_DEFROUTE=yes

IPV6_FAILURE_FATAL=no

IPV6_ADDR_GEN_MODE=stable-privacy

NAME=ethX-test

UUID=9a10ad89-437c-4caa-949c-a394a6d28c8d

DEVICE=ethX

ONBOOT=yes

# /etc/resolv.conf

nameserver 8.8.8.8

nameserver 4.4.4.4此时,通过 nmcli c应该可以看到增加了一条连接注意:如果这是为eth0创建的第一个连接,则自动生效;如果此时已有连接存在,则该连接不会自动生效,可以执行 nmcli c up eth0-test来切换生效nmcli device重点nmcli d connect eth0由NM对指定网卡进行管理,同时刷新该网卡对应的活跃connection(如果之前有修改过connection配置);如果有connection但是都处于非活跃状态,则自动选择一个connection并将其活跃;如果没有connection,则自动生成一个并将其活跃。nmcli d disconnect eth0让NM断开指定网卡的连接,此操作不会变更实际网卡的link状态,只会使对应的connection变成非活跃。若重启系统则又会自动connect。另外,如果手工将该网卡的connection全部删掉,该网卡状态也会自动变为disconnected。nmcli d reapply eth0专门用于刷新connection,前提是网卡的device处于connected状态,否则会报错。nmcli d set eth0 autoconnect yes|no managed yes|no可以设置是否自动连接和是否自动管理,但经测试只能用于当前开机状态, 如果这2个参数都设置为no,然后重启系统,又会自动恢复成connected和managed yes的状态。所以该命令用途不大。注意事项:如果managed设置为no,那么 nmcli c reload会读取配置文件,但是不会立即生效,接着如果执行nmcli c up CNNT1,就会立即生效,同时managed自动变为yes。重启系统自动恢复成connected和managed yes的状态,这种逻辑并不实用也不够合理,笔者已将此问题提交给redhat,据回复,这么设计是因为目前没有一个有效的手段来证明“我是我”,比如当网卡重新拔插到其他插槽时候,网卡名有很大可能性会发生变化,因此无法确定关机前设置的是对应开机后的哪个网卡,目前暂无办法解决,笔者将持续跟进。3种网络配置方法在讲3种配置方法前,需要先明白ifcfg和NM connection的关联:虽然network.service被废弃了,但是redhat为了兼容传统的ifcfg,通过NM进行网络配置时候,会自动将connection同步到ifcfg配置文件中。也可以通过 nmcli c reload或者 nmcli c load/etc/sysconfig/network-scripts/ifcfg-ethX的方式来让NM读取ifcfg配置文件到connection中。因此ifcfg和connection是一对一的关系,另外上面有提到,connection和device是多对一的关系。在rhel8上,有3种方法进行网络配置1. 手工配置ifcfg,通过NM来生效 ,意思就是导入原来的配置到NM

2. 通过NM自带工具配ip,比如nmcli,意思是从头建立自己的配置

3. 手工配置ifcfg,通过传统network.service来生效建议:推荐使用上述第1种网络配置方法(手工配置ifcfg,通过NM生效),因为这样既兼容了传统的ifcfg配置,又能熟悉nmcli。举例:cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <

NAME=eth0

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

TYPE=Ethernet

IPADDR=192.168.1.10

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

EOF

nmcli c reload

# nmcli c up eth0 # 如果之前没有eth0的connection,则上一步reload后就已经自动生效了这么做有2个好处: 按官方建议使用NM而不是network.service 当还不太熟悉nmcli命令时候,这样最稳妥Tips1. nmcli命令支持tab补全,但是需要 yum install bash-completion2. 如果希望NM不要纳管网卡,只有一个办法最彻底最靠谱,就是自己写ifcfg,内容加上 NM_CONTROLLED=no,这样该device的状态就会始终保持unmanaged。nmcli c up、nmcli c reload、nmcil c load都不会对其起任何作用。3. NM只能对link状态为up的网卡进行操作,如果手动 ip linksetethX down,那么NM就无法对该网卡做任何操作(即使nmcli d connect也没有用)。4. 可以通过 yum install network-scripts来安装传统的network.service,不过redhat说了,在下一个rhel的大版本里将彻底废除,因此不建议使用network.service。5. 手工创建新的ifcfg或者在ifcfg里修改ip等配置,NM不会自动读取,需要手工执行 nmcli c reload或者 nmcli c load/etc/sysconfig/network-scripts/ifcfg-ethX。这一点可能和其他系统的NM行为不太一样,但这种做法实则更适合服务器。6. 不手工配置ifcfg,使用默认的dhcp情况下,网卡的增减是不会自动生成ifcfg,此时nmcli c看到的con-name将类似'System ethX'或者'Wired connection 1'。7. NetworkManager支持3种获取dhcp的方式:dhclient、dhcpcd、internal,当/etc/NetworkManager/NetworkManager.conf配置文件中的[main]部分没配置 dhcp=时候,默认使用internal(rhel7/centos7默认是dhclient)。internal是NM内部实现的dhcp客户端。8. 关于手动指定网关ip的方法,经过实测,/etc/sysconfig/network中的GATEWAY仅在3种情况下有效: NM_CONTROLLED=no或 ipv4.method manual或 从ipv4.method manual第一次转到ipv4.methodauto时候。建议:当NM_CONTROLLED=no时,将网关写在/etc/sysconfig/network(GATEWAY);当使用NM时候,使用nmcli c命令配置网关(比如 nmcli c modify ethX ipv4.gateway192.168.1.1)。9. NM默认会从dhcp里获取dns信息,并修改/etc/resolv.conf,如果不想让NM管理/etc/resolv.conf,则只需在/etc/NetworkManager/NetworkManager.conf里的[main]里增加 dns=none即可。10. 如果想让NM不要自动管理新网卡(比如不要给新网卡获取ip地址),则只需在/etc/NetworkManager/NetworkManager.conf里的[main]里增加 no-auto-default=*即可,改完后通过 systemctl restartNetworkManager或者重启系统来生效。除了手工在NetworkManager.conf里加配置,也可以 yum installNetworkManager-config-server,这会生成/usr/lib/NetworkManager/conf.d/00-server.conf,内容为如下截图。建议使用前者方案,因为后者的ingore-carrier是不被推荐的参数。11. 更多NetworkManager参数详见man NetworkManager.conf12. nmtui示意图:13. cockpit示意图:在rhel8.0 beta时候,必须要先将浏览器语言设置为英语,才可以使用,如果为中文,在登陆后是空白页面。笔者已将该bug提交给redhat,据回复会在RHEL8.0正式版修复,笔者将持续跟进。本文转自基于RHEL8/CentOS8的网络IP配置详解,作者:小慢哥 略有修改。发布于 2018-12-19 10:57网络配置​赞同 50​​8 条评论​分享​喜欢​收藏​申请

Linux NetworkManager、nmcli - 知乎

Linux NetworkManager、nmcli - 知乎首发于有趣好玩的 Linux切换模式写文章登录/注册Linux NetworkManager、nmcli李经纬Jingwei LI本文基于以下内容翻译、删改而成:Becoming friends with NetworkManager | Enable Sysadmin (redhat.com)NetworkManager - ArchWiki (archlinux.org)NetworkManager 是一个系统网络服务,其能够管理网络设备以及它们到网络的连接。NetworkManager 能够管理以太网、wifi、移动宽带(WWAN, mobile broadband)和 PPPoE 设备等。简单来说,其为这些功能提供支持:WiFi 连接WAN 连接(和 ModemManager 共同提供)Ethernet 连接创建 WiFi AP共享连接VPN 连接NetworkManager 配置中的两大基本概念是 设备(device) 和 连接(connection) 。NetworkManager 对每个设备都会保存一些与之相关的信息,包括:该设备是否由 NetworkManager 管理该设备的可用连接该设备上已经激活的连接(如果有)"连接"代表应用到设备上的配置,一个连接实际上是多个属性组成的一个列表。一组相同方面的属性被归类为一组设置(比如 ipv4 设置组(setting group)就包含地址、网关、路由等属性)。nmcli 是对 NetworkManager 进行配置、管理以及使用的命令行工具。下面将介绍如何通过 nmcli 使用 NetworkManagernmcli 基础设备列出 NetworkManager 检测到的设备:$ nmcli device

DEVICE TYPE STATE CONNECTION

enp1s0 ethernet connected ether-enp1s0

enp7s0 ethernet disconnected --

enp8s0 ethernet disconnected -- 在这个例子中,NetworkManager 在系统中检测到了三个以太网设备,只有第一个 enp1s0 有一个已经激活的连接(也就是说这个设备已经被配置(configured)了)。如果想让 NetworkManager 暂时停止对某个设备的管理,可以临时 unmanage 这个设备:$ nmcli device set enp8s0 managed no

$ nmcli device

DEVICE TYPE STATE CONNECTION

enp1s0 ethernet connected ether-ens3

enp7s0 ethernet disconnected --

enp8s0 ethernet unmanaged -- 这是个临时方案,重启后就会被重置。如果要再启动,使用 nmcli device set enp8s0 managed yes 即可如果直接使用 nmcli 而不加任何参数,则将打印每个设备的 IP 配置情况$ nmcli

enp1s0: connected to enp1s0

"Red Hat Virtio"

ethernet (virtio_net), 52:54:00:XX:XX:XX, hw, mtu 1500

ip4 default

inet4 192.168.122.225/24

route4 0.0.0.0/0

route4 192.168.122.0/24

inet6 fe80::4923:6a4f:da44:6a1c/64

route6 fe80::/64

route6 ff00::/8

enp7s0: disconnected

"Intel 82574L"

ethernet (e1000e), 52:54:00:XX:XX:XX, hw, mtu 1500

enp8s0: unmanaged

"Red Hat Virtio"

ethernet (virtio_net), 52:54:00:XX:XX:XX, hw, mtu 1500连接列出所有可用连接:$ nmcli connection

NAME UUID TYPE DEVICE

ether-enp1s0 23e0d89e-f56c-3617-adf2-841e39a85ab4 ethernet enp1s0

Wired connection 1 fceb885b-b510-387a-b572-d9172729cf18 ethernet --

Wired connection 2 074fd16d-daa6-3b6a-b092-2baf0a8b91b9 ethernet --例子中的输出说明,当前只有 ether-enp1s0 这一个连接处于激活状态,且被应用于 enp1s0 设备上。另外两个连接则并没有被激活。关闭连接:$ nmcli connection down ether-enp1s0再次启动连接:$ nmcli connection up ether-enp1s0查看某个连接的详细属性信息:$ nmcli connection show ether-enp1s0

connection.id: ether-enp1s0

connection.uuid: 23e0d89e-f56c-3617-adf2-841e39a85ab4

connection.stable-id: --

connection.type: 802-3-ethernet

connection.interface-name: enp1s0

connection.autoconnect: yes

connection.autoconnect-priority: -999

connection.autoconnect-retries: -1 (default)

connection.auth-retries: -1

connection.timestamp: 1559320203

connection.read-only: no

[...]上面这些属性的含义以及别名对照如下属性描述别名connection.id人类可读的连接名称con-nameconnection.uuid用于唯一识别连接的 UUID无connection.type连接类型typeconnection.interface-name绑定该连接的特定设备。该连接只能在这个设备上激活ifnameconnection.autoconnect是否自动激活该连接autoconnectipv4.method连接的 IPv4 方法:auto, disabled, link local, manual, shared无ipv4.address连接的静态 IPv4 地址无当 autoconnect 启用(=yes,默认启用)时,只要 interface-name 设备就绪且其上没有已经激活的连接,该连接就会被 NetworkManager 自动激活。如果 ipv4.method 被设置为 auto ,则会从 DHCP 获取 IPv4 配置。如果想要手动设置静态配置,可以将 ipv4.method 设置为 manual,然后在 ipv4.addresses 属性中指定静态 IP 地址和子网( 用 CIDR 写法 )。相关属性的详细的描述和含义请查阅 man (man nm-settings)如果想要修改一个连接的属性,可以用 nmcli connection modify 命令。下面演示将一个连接改为静态 IPv4 地址 10.10.10.1, 网关 10.10.10.254 , DNS 10.10.10.254$ nmcli connection modify ether-enp1s0 ipv4.method manual \

ipv4.address 10.10.10.1/24 \

ipv4.gateway 10.10.10.254 ipv4.dns 10.10.10.254该命令会永久性修改该连接。新的设置需要在下次使用设备激活连接时才会生效。可以手动重新激活连接以使新设置生效:$ nmcli connection up ether-enp1s0可以像下面这样取消 NetworkManager 自动激活该连接$ nmcli connection modify ether-ens1s0 connection.autoconnect no这之后就需要手动控制连接了使用 nmcli 创建新连接通过 nmcli 的子命令 add 来新增连接(下面的 con 是 connection 的简写)$ nmcli con add type ethernet ifname enp0s1 con-name enp0s1_dhcp autoconnect no

$ nmcli con

NAME UUID TYPE DEVICE

ether-enp1s0 23e0d89e-f56c-3617-adf2-841e39a85ab4 ethernet enp1s0

enp0s1_dhcp 64b499cb-429f-4e75-a54d-b3fd980c39aa ethernet --

Wired connection 1 fceb885b-b510-387a-b572-d9172729cf18 ethernet --

Wired connection 2 074fd16d-daa6-3b6a-b092-2baf0a8b91b9 ethernet --因为并没有指定任何 IPv4 属性,因此 ipv4.method 属性值为默认的 auto ,该连接会自动从 DHCP 服务器获取 IPv4 配置。在创建连接时,根据连接类型 connection.type 的不同(ethernet, wifi, bond, vpn 等),会有不同的必须包含的属性要求,如果没有提供相应的必选属性则 nmcli 会报错并给出相应缺失属性的名称。也可以添加 --ask 选项,使用交互式的方式来创建连接:$ nmcli --ask con add

Connection type: ethernet

Interface name [*]: enp0s1

There are 3 optional settings for Wired Ethernet.

Do you want to provide them? (yes/no) [yes] no

There are 2 optional settings for IPv4 protocol.

Do you want to provide them? (yes/no) [yes] no

There are 2 optional settings for IPv6 protocol.

Do you want to provide them? (yes/no) [yes] no

There are 4 optional settings for Proxy.

Do you want to provide them? (yes/no) [yes] no

Connection 'ethernet-enp0s1' (64b499cb-429f-4e75-a54d-b3fd980c39aa) successfully added.此外,也可以用 nmcli con edit 来使用一个 nmcli 编辑器创建连接nmcli 命令 cheat sheet下面整理了 nmcli connection 的相关命令命令参数描述down连接名关闭指定链接up连接名启动指定链接show[连接名]不加参数时列出所有连接。加名称或 UUID 可指定连接modify连接名 {属性名, 属性值}...修改连接的熟悉add连接名 {属性名, 属性值}...使用给定选项创建新连接一些 nmcli 命令例子列出附近的 Wi-Fi 网络:$ nmcli device wifi list连接到 Wi-Fi 网络:$ nmcli device wifi connect SSID_or_BSSID password password连接到隐藏的 Wi-Fi 网络:$ nmcli device wifi connect SSID_or_BSSID password password hidden yes在 wlan1 网络接口上连接 Wi-Fi 网络:$ nmcli device wifi connect SSID_or_BSSID password password ifname wlan1 profile_name断开特定接口的连接:$ nmcli device disconnect ifname eth0获取连接信息列表,包括连接名称、UUID、类型以及设备:$ nmcli connection show激活连接 (即使用已经有的配置连接网络):$ nmcli connection up name_or_uuid删除一个连接:$ nmcli connection delete name_or_uuid列出当前网络设备以及对应状态:$ nmcli device关闭 Wi-Fi:$ nmcli radio wifi off编辑于 2023-05-18 18:31・IP 属地广东Linux计算机网络​赞同 2​​添加评论​分享​喜欢​收藏​申请转载​文章被以下专栏收录有趣好玩的 LinuxLinux 有趣又好玩,确定不和我一起看

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP_getethernetipconfiguration-CSDN博客

>

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP_getethernetipconfiguration-CSDN博客

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP

最新推荐文章于 2023-12-20 15:24:13 发布

Code-Porter

最新推荐文章于 2023-12-20 15:24:13 发布

阅读量8k

收藏

26

点赞数

3

分类专栏:

Android

文章标签:

EthernetManager

以太网

静态IP

android

版权声明:本文为博主原创文章,遵循 CC 4.0 BY 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/a_zhon/article/details/108148055

版权

Android

专栏收录该内容

53 篇文章

18 订阅

订阅专栏

一、对于一些工控行业的Android主板一般都会扩展个以太网接口,也就是可以插网线进行上网;然后在系统设置页面有个以太网菜单可以进行IP、网关等设置,如下:

二、那怎么通过代码去设置呢?

1、Android系统在Framework层是有提供操作以太网Api的也就是android.net.EthernetManager,但是Google把Api给隐藏了;所以最终你是调用不了的 2、那需要怎么操作才能调用到隐藏的Api呢?相信你肯定会立马想到使用反射去调用;对,没错!这里我就是使用的这个方式;当然如果你公司系统层也是自己搞的话就更简单了

三、先假装如果可以调用到android.net.EthernetManager的Api,那么代码应该怎么写呢?

设置静态IP地址, new LinkAddress()报错是因为源码@hide了 设置动态ip地址

四、接下来就是通反射去调用了,代码量就比上面多的多了

/**

* 文件名: EthernetUtil

* 创建时间: 2020/8/21 on 11:22

* 描述: TODO 设置以太网静态ip 动态ip地址

*

* @author 阿钟

*/

public class EthernetUtil {

/**

* 设置以太网动态获取IP

*/

public static boolean setDynamicIp(Context context) {

try {

Class ethernetManagerCls = Class.forName("android.net.EthernetManager");

//获取EthernetManager实例

Object ethManager = context.getSystemService("ethernet");

//创建IpConfiguration

Class ipConfigurationCls = Class.forName("android.net.IpConfiguration");

Object ipConfiguration = ipConfigurationCls.newInstance();

//获取ipAssignment、proxySettings的枚举值

Map ipConfigurationEnum = getIpConfigurationEnum(ipConfigurationCls);

//设置ipAssignment

Field ipAssignment = ipConfigurationCls.getField("ipAssignment");

ipAssignment.set(ipConfiguration, ipConfigurationEnum.get("IpAssignment.DHCP"));

//设置proxySettings

Field proxySettings = ipConfigurationCls.getField("proxySettings");

proxySettings.set(ipConfiguration, ipConfigurationEnum.get("ProxySettings.NONE"));

//获取EthernetManager的setConfiguration()

Method setConfigurationMethod = ethernetManagerCls.getDeclaredMethod("setConfiguration", ipConfiguration.getClass());

//设置动态IP

setConfigurationMethod.invoke(ethManager, ipConfiguration);

return true;

} catch (Exception e) {

e.printStackTrace();

return false;

}

}

/**

* 设置以太网静态IP地址

*

* @param address ip地址

* @param mask 子网掩码

* @param gate 网关

* @param dns dns

*/

public static boolean setEthernetStaticIp(Context context, String address, String mask, String gate, String dns) {

try {

Class ethernetManagerCls = Class.forName("android.net.EthernetManager");

//获取EthernetManager实例

Object ethManager = context.getSystemService("ethernet");

//创建StaticIpConfiguration

Object staticIpConfiguration = newStaticIpConfiguration(address, gate, mask, dns);

//创建IpConfiguration

Object ipConfiguration = newIpConfiguration(staticIpConfiguration);

//获取EthernetManager的setConfiguration()

Method setConfigurationMethod = ethernetManagerCls.getDeclaredMethod("setConfiguration", ipConfiguration.getClass());

//保存静态ip设置

saveIpSettings(context, address, mask, gate, dns);

//设置静态IP

setConfigurationMethod.invoke(ethManager, ipConfiguration);

return true;

} catch (Exception e) {

e.printStackTrace();

return false;

}

}

/**

* 获取StaticIpConfiguration实例

*/

private static Object newStaticIpConfiguration(String address, String gate, String mask, String dns) throws Exception {

Class staticIpConfigurationCls = Class.forName("android.net.StaticIpConfiguration");

//实例化StaticIpConfiguration

Object staticIpConfiguration = staticIpConfigurationCls.newInstance();

Field ipAddress = staticIpConfigurationCls.getField("ipAddress");

Field gateway = staticIpConfigurationCls.getField("gateway");

Field domains = staticIpConfigurationCls.getField("domains");

Field dnsServers = staticIpConfigurationCls.getField("dnsServers");

//设置ipAddress

ipAddress.set(staticIpConfiguration, newLinkAddress(address, mask));

//设置网关

gateway.set(staticIpConfiguration, InetAddress.getByName(gate));

//设置掩码

domains.set(staticIpConfiguration, mask);

//设置dns

ArrayList dnsList = (ArrayList) dnsServers.get(staticIpConfiguration);

dnsList.add(InetAddress.getByName(dns));

return staticIpConfiguration;

}

/**

* 获取LinkAddress实例

*/

private static Object newLinkAddress(String address, String mask) throws Exception {

Class linkAddressCls = Class.forName("android.net.LinkAddress");

Constructor linkAddressConstructor = linkAddressCls.getDeclaredConstructor(InetAddress.class, int.class);

return linkAddressConstructor.newInstance(InetAddress.getByName(address), getPrefixLength(mask));

}

/**

* 获取IpConfiguration实例

*/

private static Object newIpConfiguration(Object staticIpConfiguration) throws Exception {

Class ipConfigurationCls = Class.forName("android.net.IpConfiguration");

Object ipConfiguration = ipConfigurationCls.newInstance();

//设置StaticIpConfiguration

Field staticIpConfigurationField = ipConfigurationCls.getField("staticIpConfiguration");

staticIpConfigurationField.set(ipConfiguration, staticIpConfiguration);

//获取ipAssignment、proxySettings的枚举值

Map ipConfigurationEnum = getIpConfigurationEnum(ipConfigurationCls);

//设置ipAssignment

Field ipAssignment = ipConfigurationCls.getField("ipAssignment");

ipAssignment.set(ipConfiguration, ipConfigurationEnum.get("IpAssignment.STATIC"));

//设置proxySettings

Field proxySettings = ipConfigurationCls.getField("proxySettings");

proxySettings.set(ipConfiguration, ipConfigurationEnum.get("ProxySettings.STATIC"));

return ipConfiguration;

}

/**

* 获取IpConfiguration的枚举值

*/

private static Map getIpConfigurationEnum(Class ipConfigurationCls) {

Map enumMap = new HashMap<>();

Class[] enumClass = ipConfigurationCls.getDeclaredClasses();

for (Class enumC : enumClass) {

Object[] enumConstants = enumC.getEnumConstants();

if (enumConstants == null) continue;

for (Object enu : enumConstants) {

enumMap.put(enumC.getSimpleName() + "." + enu.toString(), enu);

}

}

return enumMap;

}

/**

* 保存静态ip设置

*/

private static void saveIpSettings(Context context, String address, String mask, String gate, String dns) {

ContentResolver contentResolver = context.getContentResolver();

Settings.Global.putString(contentResolver, "ethernet_static_ip", address);

Settings.Global.putString(contentResolver, "ethernet_static_mask", mask);

Settings.Global.putString(contentResolver, "ethernet_static_gateway", gate);

Settings.Global.putString(contentResolver, "ethernet_static_dns1", dns);

}

/**

* 获取长度

*/

private static int getPrefixLength(String mask) {

String[] strs = mask.split("\\.");

int count = 0;

for (String str : strs) {

if (str.equals("255")) {

++count;

}

}

return count * 8;

}

}

使用只需调用方法即可:

//设置静态ip

EthernetUtil.setEthernetStaticIp(context, "192.168.5.33", "255.255.255.0", "192.168.5.1", "8.8.8.8");

//设置动态获取ip

EthernetUtil.setDynamicIp(context)

最后:这个代码本人在Android7.0的原生系统验证是可以使用的,有需要的可以使用试试EthernetUtil源码下载地址

最后在推荐个好用的系统源码查看网址吧:Android 系统源码在线查看

优惠劵

Code-Porter

关注

关注

3

点赞

26

收藏

觉得还不错?

一键收藏

打赏

知道了

27

评论

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP

一、对于一些工控行业的Android主板一般都会扩展个以太网接口,也就是可以插网线进行上网;然后在系统设置页面有个以太网菜单可以进行IP、网关等设置,如下:二、那怎么通过代码去设置呢?1、Android系统在Framework层是有提供操作以太网Api的也就是android.net.EthernetManager,但是Google把Api给隐藏了;所以最终你是调用不了的2、那需要怎么操作才能调用到隐藏的Api呢?相信你肯定会立马想到使用反射去调用;对,没错!这里我就是使用的这个方式;当然如果你公

复制链接

扫一扫

专栏目录

EthernetUtil.java

08-21

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP

https://azhon.blog.csdn.net/article/details/108148055

Android 7.0 增加Ethernet设置(DHCP与Static ip)

10-31

Android 7.0 增加Ethernet设置(DHCP与Static ip)

静态IP设置选项有:

IP 地址

子网掩码

默认网关

首选DNS服务器

备用DNS服务器

参考文章:http://blog.csdn.net/hclydao/article/details/50972932

感谢 hclydao

27 条评论

您还未登录,请先

登录

后发表或查看评论

EthernetManager Android 以太网静态IP设置

热门推荐

杀气码的博客

08-01

3万+

关于以太网设置由于公司的需求,需要在项目中加入设置以太网静态IP的功能,在网上找了一下,发 现这方面的资料比较少最后只找到了一个demo,但是导入后发现项目报错.之后查了一下资料才发现原来EthernetManager是谷歌隐藏的API,关于隐藏API的调用,可以去看下下面这篇文章:

如何调用Android隐藏API废话不多说先上代码 // 监听以太网状态的广播,包括网线插拔和以太网开关

Android 以太网DHCP和静态切换 设置ip/掩码/网关/DNS

最新发布

Cicy_17的博客

12-20

532

最近公司项目需要实现功能,Android设备用代码设置静态IP,然后重启设备,固定IP还有效,并且能切换静态IP或动态IP。

EthernetManager Android设置以太网静态IP

jgw2008的专栏

09-06

4552

下边是引入jar包直接调用的代码,通过EthernetManager 的setConfiguration方法来设置,但是需要构造IpConfiguration 和StaticIpConfiguration对象,IpConfiguration.IpAssignment.STATIC就代表设置为静态IP,也可以设置DHCP。想要设置以太网为静态IP通过搜索是需用到EthernetManager,但是EthernetManager是谷歌隐藏的API,app是无法调用到的,所以只能通过反射来进行设置。

Android 获取当前网络状态

不若艳阳的代码空间

03-19

393

在Android系统中获取当前网络状态,如果当前无连接则跳转到网络设置中,具体代码如下

ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo.State mobile = connectivityMa

Android11反射限制-网络连接相关预研

qq_46269365的博客

08-14

240

(1)无法连接以太网:涉及反射部分功能不可用:获取有线网配置的所有功能,包括有线网络管理类、获取IP配置、获取IP地址、获取子网掩码、获取网关、获取域名、设置静态IP置等;1、Room层支持,单独封装有线网络相关API调用jar包,依照上述导入framework.jar包依赖,与AndroidSDK共存的方式直接进行对隐藏API的调用。下载地址:https://gitee.com/xiayiye5/framework-jar-demo/tree/master/app/libs。

Android 7.1 以太网反射 EthernetManager 配置 DHCP、静态 IP

WzoneLayer的博客

09-17

2879

Android 7.1 以太网设置 IP

@hide EthernetManager

通过 android.net.EthernetManager#setConfiguration 可以设置以太网 IP 信息,可惜 EthernetManager 无法直接调用。

/**

* A class representing the IP configuration of the Ethernet network.

*

* @hide

*/

public class EthernetManager {

..

android平板以太网设置

陌上花开缓缓归的博客

06-01

3909

修改SDK的android.jar,通过反射获取EthernetManager进行以太网设置。

Android 13 Ethernet变更

androidzmm的博客

08-28

1313

(2)移除源码中限制接口的版本号 目前我采用的是二,但是如果项目需要过gms认证,则只能使用一,因为gms合入mainline,packages\modules\Connectivity生成的jar会被覆盖。以太网相关的功能在Android12 和13 网络部分变化是不大的,Android11 到Android 12 网络部分无论是代码存放目录和代码逻辑都是有较多修改的,主要包括以下几个部分。这个是新增的接口方法 setEthernetEnabled ,之前是要自己实现有线网开关的。

android app 设置以太网静态Ip

gddw1954的专栏

07-21

9942

写文目的

公司是做工控和楼宇智能方面产品,使用的设备有rk和全志平台,运行的是android操作系统,部分场景需要设置有线网络的静态Ip。所以针对这一需求做了如下工作,并以此文作为总结。

遇到的问题

工作前也有百度过相关方案,但大部分使用的是busybox ifconfig来设置,而这种方式有很多弊端,如设置的app必须拥有root权限、不能实时切换static和dhcp、重启后设置的就不生效、不能通过系统的settings参看设置的状态。经过一番折腾后发现为了解决这些问题必须从android的系统应

android 设置IP地址

01-12

android平台 通过settingAPK,监听用户APP广播设置IP地址,具体使用方法请查看我的文章

Android 判断网络是否可用 & 获取IP地址 & 获取以太网口MAC地址

01-03

判断网络是否可用:

注意!是判断网络是否可用,但网络可用不代表一定能上外网的!

public static boolean isNetworkAvailable(Context context) {

ConnectivityManager manager = (ConnectivityManager) context

.getApplicationContext().getSystemService(

Context.CONNECTIVITY_SERVICE);

if (m

EthernetManager需要用到的android源码jar包

05-10

获取android设备有线连接时的网络信息,ip,子网掩码,网关,dns时,需要用到EthernetManager这个被android api隐藏的类,这个jar包就是从源码抽出来的网络模块,导入可直接使用。

android以太网设置Demo(可运行,但仅提供思路哦,包含所需的framework.jar)

06-01

提供framework.jar文件修改本地SDK中的android.jar,配合反射获取EthernetManager进行以太网开关设置,

Android-6.0以太网静态IP补丁

04-09

设置 -> 更多 -> 以太网功能: 1. 支持以太网开启与禁用 2. 支持以太网静态IP和动态获取切换

Android5.1以太网开关控制以及动静态IP设置

03-21

通过调用安卓隐藏api来对以太网开关以及静动态IP进行设置,在某些定制的开发板上以及某些不提供点击界面的地方可以用到!

android-ethernet-staticIP-app,安卓-以太网设置-app

02-11

这个是api 21~25(android 5.0.1-7.1.1)能用的app源码,使用eclipse+adt开发(不习惯用AS),android8.0(api26)因时间原因未能测试是否可用。不过android10.0因为api变化被证明肯定不能用。里面除了源码、还有...

rk3399 android10.0 开机 以太网 设置 静态ip

10-25

要在RK3399 Android 10.0设备中设置静态IP,可以按照以下步骤操作:

1. 首先,在设备上找到并打开“设置”应用程序。

2. 在设置界面中,向下滚动直到找到“网络和互联网”选项,并点击进入。

3. 在网络和互联网菜单中,选择“以太网”选项。如果设备没有物理以太网接口,可能显示为“有线连接”或类似选项。

4. 进入以太网设置后,点击右上角的菜单按钮(通常是三个竖排的点或线),然后选择“高级”或“高级选项”。

5. 在高级设置中,寻找一个类似“IP设置”、“IP地址设置”或“连接类型”等选项,点击进入。

6. 在IP设置菜单中,通常默认为“DHCP”(动态IP分配)。如果要切换为静态IP,请选择“静态”或“手动”选项。

7. 在静态IP设置中,输入您想要使用的IP地址、子网掩码、默认网关和DNS服务器。确保这些信息准确无误,一般可以从网络管理员或路由器配置中获取。

8. 输入完毕后,点击“保存”或“应用”按钮,以应用并保存新的静态IP设置。

9. 返回网络设置主菜单,重新启动RK3399设备,以使新的静态IP设置生效。

在完成以上步骤后,您的RK3399 Android 10.0设备将会使用您所提供的静态IP地址进行以太网连接。请注意,静态IP设置通常用于特定网络环境中,如企业网络或技术调试,一般家庭用户使用动态IP更为常见。

“相关推荐”对你有帮助么?

非常没帮助

没帮助

一般

有帮助

非常有帮助

提交

Code-Porter

CSDN认证博客专家

CSDN认证企业博客

码龄8年

暂无认证

169

原创

6841

周排名

8154

总排名

96万+

访问

等级

9799

积分

1万+

粉丝

889

获赞

642

评论

1491

收藏

私信

关注

热门文章

Android常用对话框大全——Dialog

76674

何谓三十而立 四十不惑 五十知天命 六十知耳顺?

51720

解决Mac连接RIOCH(理光)打印机无法打印问题

40520

基于Openfire Smack开发即时通讯应用、搭建Openfire服务器(一)

26145

Android自定义View——实现联系人列表字母索引

22515

分类专栏

Android自定义View

付费

10篇

Flutter编程

17篇

Java

10篇

部标协议终端开发

5篇

Python

4篇

Android

53篇

杂七杂八

20篇

Java Web

2篇

ReatNative

11篇

Objective-c

1篇

开发中遇到的坑

14篇

Android JNI编程

7篇

Android开发艺术探索

4篇

React Native的学习之旅

11篇

Google Material Design 控件

8篇

Smack+Openfire搭建即时通讯

4篇

最新评论

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP

weixin_39691532:

你好请问解决了嘛

微信小程序蓝牙(BLE)开发与蓝牙设备数据交互开发总结

努力开发小程序ing:

大佬我想请问一下怎么样把不显示选择特征值啊就是点击蓝牙直接连接了之后就可以发送信息

微信小程序蓝牙(BLE)开发与蓝牙设备数据交互开发总结

努力开发小程序ing:

大佬我想请问一下怎么样把不显示选择特征值啊就是点击蓝牙直接连接了之后就可以发送信息

Flutter视频编辑轨道 | 自定义View实现UI交互效果 | 触摸事件处理

我还没有吃饱:

有办法应对多个视频的情况吗?

创建Google play开发者账号,并验证身份通过

出海的小红薯:

新版企业开发者专业做

您愿意向朋友推荐“博客详情页”吗?

强烈不推荐

不推荐

一般般

推荐

强烈推荐

提交

最新文章

Flutter自定义TextInputFormatter实现金额输入框,同时解决iOS数字键盘不能输入小数点的问题

Flutter自定义TextInputFormatter实现金额输入框

Flutter 开发、测试,网络调试工具

2023年7篇

2022年7篇

2021年8篇

2020年11篇

2019年20篇

2018年22篇

2017年41篇

2016年54篇

目录

目录

分类专栏

Android自定义View

付费

10篇

Flutter编程

17篇

Java

10篇

部标协议终端开发

5篇

Python

4篇

Android

53篇

杂七杂八

20篇

Java Web

2篇

ReatNative

11篇

Objective-c

1篇

开发中遇到的坑

14篇

Android JNI编程

7篇

Android开发艺术探索

4篇

React Native的学习之旅

11篇

Google Material Design 控件

8篇

Smack+Openfire搭建即时通讯

4篇

目录

评论 27

被折叠的  条评论

为什么被折叠?

到【灌水乐园】发言

查看更多评论

添加红包

祝福语

请填写红包祝福语或标题

红包数量

红包个数最小为10个

红包总金额

红包金额最低5元

余额支付

当前余额3.43元

前往充值 >

需支付:10.00元

取消

确定

下一步

知道了

成就一亿技术人!

领取后你会自动成为博主和红包主的粉丝

规则

hope_wisdom 发出的红包

打赏作者

Code-Porter

你的鼓励将是我创作的最大动力

¥1

¥2

¥4

¥6

¥10

¥20

扫码支付:¥1

获取中

扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元

使用余额支付

点击重新获取

扫码支付

钱包余额

0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值

Linux下network与NetworkManager的和平共处 - 知乎

Linux下network与NetworkManager的和平共处 - 知乎切换模式写文章登录/注册Linux下network与NetworkManager的和平共处运维贼船简介我们在使用CentoOS系统时偶尔会遇到配置都正确但network启动不了的问题,这问题经常是由NetworkManager引起的,关闭NetworkManager并取消开机启动network就能正常启动。使用的Linux经常使用命令行模式,所以大家都不怎么去了解NetworkManager,造成了糊里糊涂的解决问题。下面我们看一下NetworkManager的基础使用。分析NetworkManage与network功能类似,都是用于管理网络,NetworkManager提供了nmctl和nmtui两个工具:nmctl:命令行工具[root@mx ~]# nmcli --help

Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS

-a, --ask ask for missing parameters

-c, --colors auto|yes|no whether to use colors in output

-e, --escape yes|no escape columns separators in values

-f, --fields |all|common specify fields to output

-g, --get-values |all|common shortcut for -m tabular -t -f

-h, --help print this help

-m, --mode tabular|multiline output mode

-o, --overview overview mode

-p, --pretty pretty output

-s, --show-secrets allow displaying passwords

-t, --terse terse output

-v, --version show program version

-w, --wait set timeout waiting for finishing operations

OBJECT

g[eneral] NetworkManager's general status and operations

n[etworking] overall networking control

r[adio] NetworkManager radio switches

c[onnection] NetworkManager's connections

d[evice] devices managed by NetworkManager

a[gent] NetworkManager secret agent or polkit agent

m[onitor] monitor NetworkManager changes

[root@mx ~]#我们可以直接使用命令行来管理网络,下面是对应参数项目与配置文件内的参数对应关系图。# 比如我这里设置eth0为手动设置静态地址,为192.168.31.5,子网掩码24,自启动

nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.31.5/24 connection.autoconnect yes

nmcli connection up eth0nmtui:伪图形界面两个都是用来管理网络,但是有一个前提:nmctl networking 状态必须是enable否则设备状态为unmanaged,这会导致network启动不了!查看方式如下:[root@master03 ~]# nmcli networking

enabled使用nmtui来查看网络,直接在命令行下敲nmtui,就会出现蓝底的伪图形界面,可以很方便的配置服务器的网络。设置完成后,要记得在第二项目中设置对应网卡启动,这样才能正常使用。解决如果遇到network无法启动的情况,检测配置是是否有问题,如果是服务器(多网口),检测网线是否插在你启动的网网口上 检测你的NetworkManager是否启动,如果启动了可参考一下方法处理 简单粗暴:关闭NetworkManager服务,并取消开机启动(要是你使用的为命令行模式,没有有用图形界面,可以放心使用这种方法,使用图形界面的话还是建议自己排查一下) 排查NetworkManage:检查nmctl networking 状态是否为enabled,如果不是,执行一下命令开启[root@master03 ~]# nmcli networking on

[root@master03 ~]# systemctl restart NetworkManager

[root@master03 ~]# systemctl restart network

[root@master03 ~]# nmcli device

DEVICE TYPE STATE CONNECTION

ens33 ethernet connected ens33

docker0 bridge unmanaged --

lo loopback unmanaged --

[root@master03 ~]#检测device有没有连接到connection,命令:nmcli connection来查看连接状态。 若没有,则使用命令来连接:nmcli device connect ens33检测连接是否启用[root@master03 ~]# nmcli connection

NAME UUID TYPE DEVICE

ens33 4d574cba-a63e-49ae-8cb2-d663a8dd796e ethernet ens33如果没有启用注意了:我的连接名称是ens33,根据你自己的情况自己改进,所有操作完成以后都执行以下命令。[root@master03 ~]# systemctl restart NetworkManager

[root@master03 ~]# systemctl restart network否则可能不生效,当然上面两种网络管理方式network与NetworkManager其它是相辅相成的作用,只需要使用其中一种方式来管理即可,另外一种可以禁用掉(注意:至少保持一种自启动,否则可能会出现开机没有网络的状况)。我比较喜欢使用NetworkManager来管理网络,更大的强大和易用,所以我这里把NetworkManager设置为开机启动,network为禁止开机启动。使用以下命令来查看启动状态。# 查看NetworkManager的是否为自启动

[root@mx ~]# systemctl list-unit-files --type service | grep NetworkManager

# 查看network是否设置为自启动

[root@mx ~]# chkconfig --list | grep network至此!发布于 2021-10-28 21:14networkLinux计算机网络​赞同 14​​2 条评论​分享​喜欢​收藏​申请

Android 7.1 以太网反射 EthernetManager 配置 DHCP、静态 IP_android.net.ethernetmanager-CSDN博客

>

Android 7.1 以太网反射 EthernetManager 配置 DHCP、静态 IP_android.net.ethernetmanager-CSDN博客

Android 7.1 以太网反射 EthernetManager 配置 DHCP、静态 IP

最新推荐文章于 2023-08-03 19:10:06 发布

wzlayer

最新推荐文章于 2023-08-03 19:10:06 发布

阅读量2.8k

收藏

1

点赞数

1

分类专栏:

android

文章标签:

android

7.1

EthernetManager

以太网

反射

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/WzoneLayer/article/details/120352057

版权

android

专栏收录该内容

4 篇文章

0 订阅

订阅专栏

@hide EthernetManager

通过 android.net.EthernetManager#setConfiguration 可以设置以太网 IP 信息,可惜 EthernetManager 无法直接调用。

/**

* A class representing the IP configuration of the Ethernet network.

*

* @hide

*/

public class EthernetManager {

...

/**

* Set Ethernet configuration.

*/

public void setConfiguration(IpConfiguration config) {

try {

mService.setConfiguration(config);

} catch (RemoteException e) {

throw e.rethrowFromSystemServer();

}

}

...

}

反射调用 setConfiguration 方法

DHCP 配置

步骤:

实例化 IpConfiguration() 对象 ipConfiguration设置 ipConfiguration.ipConfiguration = xxx设置 ipConfiguration.ipConfiguration = xxx调用 ethernetManager.setConfiguration(ipConfiguration) 完成设置

/**

* 调用 EthernetManager.setConfiguration(IpConfiguration config) 设置 DHCP

*

* 步骤:

* - 实例化 IpConfiguration() 对象 ipConfiguration

* - 设置 ipConfiguration.ipConfiguration = xxx

* - 设置 ipConfiguration.ipConfiguration = xxx

* - 调用 ethernetManager.setConfiguration(ipConfiguration) 完成设置

*/

@WorkerThread

fun setDynamicIp(ethernetManager: EthernetManager): Boolean {

try {

// 获取 IpConfiguration 对象

val ipConfigurationCls = Class.forName("android.net.IpConfiguration")

val ipConfigurationEnum = getEnumMap(ipConfigurationCls)

val ipConfiguration = ipConfigurationCls.newInstance()

// 设置 ipConfiguration.ipAssignment 为 IpAssignment.DHCP

val ipAssignment = ipConfigurationCls.getField("ipAssignment")

ipAssignment.set(ipConfiguration, ipConfigurationEnum["IpAssignment.DHCP"])

// 设置 ipConfiguration.proxySettings 为 ProxySettings.NONE

val proxySettings = ipConfigurationCls.getField("proxySettings")

proxySettings.set(ipConfiguration, ipConfigurationEnum["ProxySettings.NONE"])

// 调用 ethernetManager.setConfiguration(ipConfiguration) 设置 DHCP

val setConfigurationMethod = ethernetManager.javaClass.getDeclaredMethod(

"setConfiguration", ipConfiguration.javaClass

)

setConfigurationMethod.invoke(ethernetManager, ipConfiguration)

return true

} catch (e: Exception) {

e.printStackTrace()

return false

}

}

/**

* 获取 Class 中枚举类键值对

*

* 注:key = 枚举类名 + 枚举名

* value = 枚举

*/

private fun getEnumMap(ipConfigurationCls: Class<*>): Map {

val enumMap: MutableMap = HashMap()

val enumClasses = ipConfigurationCls.declaredClasses

for (enumClass in enumClasses) {

val enumConstants = enumClass.enumConstants ?: continue

for (enumConstant in enumConstants) {

// 枚举 Class 名 + 枚举名 = key

enumMap[enumClass.simpleName + "." + enumConstant.toString()] = enumConstant

}

}

return enumMap

}

Static IP 配置

步骤:

实例化 StaticIpConfiguration 对象 staticIpConfiguration 1.1. 设置 staticIpConfiguration.ipAddress = xxx 1.2. 设置 staticIpConfiguration.gateway = xxx 1.3. 设置 staticIpConfiguration.domains = xxx 1.4. 设置 staticIpConfiguration.dnsServers = xxx实例化 IpConfiguration() 对象 ipConfiguration 2.1. 设置 ipConfiguration.staticIpConfiguration = staticIpConfiguration 2.2. 设置 ipConfiguration.ipAssignment = xxx 2.3. 设置 ipConfiguration.proxySettings = xxx 2.4. 设置 ipConfiguration.httpProxy = xxx调用 ethernetManager.setConfiguration(ipConfiguration) 完成设置

/**

* 调用 EthernetManager.setConfiguration(IpConfiguration config) 设置静态 IP

*

* 步骤:

* - 实例化 StaticIpConfiguration 对象 staticIpConfiguration

* - 设置 staticIpConfiguration.ipAddress = xxx

* - 设置 staticIpConfiguration.gateway = xxx

* - 设置 staticIpConfiguration.domains = xxx

* - 设置 staticIpConfiguration.dnsServers = xxx

* - 实例化 IpConfiguration() 对象 ipConfiguration

* - 设置 ipConfiguration.staticIpConfiguration = staticIpConfiguration

* - 设置 ipConfiguration.ipAssignment = xxx

* - 设置 ipConfiguration.proxySettings = xxx

* - 设置 ipConfiguration.httpProxy = xxx

* - 调用 ethernetManager.setConfiguration(ipConfiguration) 完成设置

*/

@WorkerThread

fun setStaticIp(

ethernetManager: EthernetManager,

ip: String,

mask: String,

gateway: String,

dns: String

): Boolean {

try {

// 获取 StaticIpConfiguration 对象

val staticIpConfiguration = newStaticIpConfiguration(ip, mask, gateway, dns)

// 获取 IpConfiguration 对象

val ipConfiguration = newIpConfiguration(staticIpConfiguration)

// 通过 setConfiguration 方法设置静态 IP

val setConfigurationMethod = ethernetManager.javaClass.getDeclaredMethod(

"setConfiguration", ipConfiguration.javaClass

)

setConfigurationMethod.invoke(ethernetManager, ipConfiguration)

return true

} catch (e: Exception) {

e.printStackTrace()

return false

}

}

/**

* 获取 IpConfiguration 实例

*/

private fun newIpConfiguration(staticIpConfiguration: Any): Any {

// 获取 IpConfiguration 对象

val ipConfigurationCls = Class.forName("android.net.IpConfiguration")

val ipConfigurationEnum = getEnumMap(ipConfigurationCls)

val ipConfiguration = ipConfigurationCls.newInstance()

// 设置 ipConfiguration.staticIpConfiguration 为 staticIpConfiguration

val staticIpConfigurationField = ipConfigurationCls.getField("staticIpConfiguration")

staticIpConfigurationField[ipConfiguration] = staticIpConfiguration

// 设置 ipConfiguration.ipAssignment 为 IpAssignment.STATIC

val ipAssignment = ipConfigurationCls.getField("ipAssignment")

ipAssignment[ipConfiguration] = ipConfigurationEnum["IpAssignment.STATIC"]

// 设置 ipConfiguration.proxySettings 为 ProxySettings.NONE

val proxySettings = ipConfigurationCls.getField("proxySettings")

proxySettings[ipConfiguration] = ipConfigurationEnum["ProxySettings.NONE"]

// 设置 ipConfiguration.httpProxy 为 httpProxy

val httpProxy = ipConfigurationCls.getField("httpProxy")

httpProxy[ipConfiguration] = ProxyInfo.buildDirectProxy(null, 0)

return ipConfiguration

}

/**

* 获取 StaticIpConfiguration 实例

*/

private fun newStaticIpConfiguration(

ip: String,

mask: String,

gate: String,

dns: String

): Any {

// 获取 StaticIpConfiguration 对象

val staticIpConfigurationCls = Class.forName("android.net.StaticIpConfiguration")

val staticIpConfiguration = staticIpConfigurationCls.newInstance()

// 设置 ipAddress

val ipAddress = staticIpConfigurationCls.getField("ipAddress")

ipAddress[staticIpConfiguration] = newLinkAddress(ip, mask)

// 设置网关

val gateway = staticIpConfigurationCls.getField("gateway")

gateway[staticIpConfiguration] = InetAddress.getByName(gate)

// 设置子网掩码

val domains = staticIpConfigurationCls.getField("domains")

domains[staticIpConfiguration] = mask

// 设置 DNS

val dnsServers = staticIpConfigurationCls.getField("dnsServers")

val dnsList = dnsServers[staticIpConfiguration] as ArrayList

dnsList.add(InetAddress.getByName(dns))

return staticIpConfiguration

}

/**

* 获取 LinkAddress 实例

*/

private fun newLinkAddress(ip: String, mask: String): Any? {

val linkAddressCls = Class.forName("android.net.LinkAddress")

val linkAddressConstructor = linkAddressCls.getDeclaredConstructor(

InetAddress::class.java,

Int::class.javaPrimitiveType

)

return linkAddressConstructor.newInstance(

InetAddress.getByName(ip),

getPrefixLength(mask)

)

}

/**

* 获取长度

*/

private fun getPrefixLength(mask: String): Int {

var count = 0

for (str in mask.split(".")) {

if (str == "255") {

++count

}

}

return count * 8

}

注意事项

以上代码需要是系统应用才能调用,需要在 AndroidManifest 文件中配置 android:sharedUserId=“android.uid.system”。

...

android:sharedUserId="android.uid.system">

...

参考连接

android 7.1反射调用系统接口设置静态IP地址Android 以太网DHCP、STATIC两种IP分配方式的API调用Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP

优惠劵

wzlayer

关注

关注

1

点赞

1

收藏

觉得还不错?

一键收藏

知道了

0

评论

Android 7.1 以太网反射 EthernetManager 配置 DHCP、静态 IP

Android 7.1 以太网设置 IP@hide EthernetManager通过 android.net.EthernetManager#setConfiguration 可以设置以太网 IP 信息,可惜 EthernetManager 无法直接调用。/** * A class representing the IP configuration of the Ethernet network. * * @hide */public class EthernetManager { ..

复制链接

扫一扫

专栏目录

RK3399_android7.1_root(7.1 root补丁).rar

09-16

RK远程提供的RK3399 Android7.1 root patch,有需要root的朋友,请下载,

android4.0.3添加 Ethernet框架支持

wonview的专栏

03-07

1万+

一、移植framework部分(+号的行代表增加的内容,-号的行代表删除的内容)

从4.0.3 master分支移植到4.0.3_r1

1.1.将源路径framework/base/ethernet 复制到目标路径的framework/base/目录下

1.2.修改目标路径的framework/base目录下的Android.mk

    vpn/java/android

参与评论

您还未登录,请先

登录

后发表或查看评论

android5.1以太网共享4g,wifi网络.zip

01-23

rk平台android5.1通过网线共享4g,wifi网络,外加设置UI开关按钮,默认是打开共享的 可以通过系统属性persist.tethering.tether_eth 来设置,个人测试可行,有需要可以私聊交流

android7.1环境配置以及服务器搭建.docx

04-30

android7.1环境配置以及服务器搭建.docx

android平板以太网设置

陌上花开缓缓归的博客

06-01

3909

修改SDK的android.jar,通过反射获取EthernetManager进行以太网设置。

Android通过反射EthernetManager Api设置以太网为静态IP地址或者动态获取IP

上辈子作恶多端,这辈子写前端。

08-21

8038

一、对于一些工控行业的Android主板一般都会扩展个以太网接口,也就是可以插网线进行上网;然后在系统设置页面有个以太网菜单可以进行IP、网关等设置,如下:

二、那怎么通过代码去设置呢?

1、Android系统在Framework层是有提供操作以太网Api的也就是android.net.EthernetManager,但是Google把Api给隐藏了;所以最终你是调用不了的

2、那需要怎么操作才能调用到隐藏的Api呢?相信你肯定会立马想到使用反射去调用;对,没错!这里我就是使用的这个方式;当然如果你公

EthernetManager Android设置以太网静态IP

jgw2008的专栏

09-06

4552

下边是引入jar包直接调用的代码,通过EthernetManager 的setConfiguration方法来设置,但是需要构造IpConfiguration 和StaticIpConfiguration对象,IpConfiguration.IpAssignment.STATIC就代表设置为静态IP,也可以设置DHCP。想要设置以太网为静态IP通过搜索是需用到EthernetManager,但是EthernetManager是谷歌隐藏的API,app是无法调用到的,所以只能通过反射来进行设置。

如何优雅的实现Android Ethernet 以太网的开启与关闭

Thatcher Li

03-05

6260

My Blog: 基你太美

Gitee: 基你实在是太美

背景

最近产品提了一个网络管理的需求,其中要求有以太网的开启/关闭功能。这里总结一下整个开发过程中遇到的坑。

EthernetManager 不可用

在 android.net 包下面其实有一个 EthernetManager 类负责以太网的管理,然而这个 Api 并没有对我们开放使用,官方标记为隐藏。自然这种方法是不适用的,遂弃之。

/**

* A class representing the IP configuration of the Et

Android12 以太网功能实现

最新发布

weixin_52521865的博客

08-03

1726

Android 12 有线网络适配

Android 7.0 增加Ethernet设置(DHCP与Static ip)

10-31

Android 7.0 增加Ethernet设置(DHCP与Static ip) 静态IP设置选项有: IP 地址 子网掩码 默认网关 首选DNS服务器 备用DNS服务器 参考文章:http://blog.csdn.net/hclydao/article/details/50972932 感谢 hclydao

android 7.1以太网分享功能

12-21

android 7.1 分享以太网,增加状态栏分享开关,修复关闭以太网分享后无法使用以太网口的bug

android5.1 增加ethernet设置(DHCP与Static ip)

笨笨的牛的专栏

05-18

2671

转自:http://blog.csdn.net/hclydao/article/details/50972932

自己的记录:

1.我按下面这文章只改到

这里只设置了一个设备名,为保存是eth0所以加上这句,防止意外.

这里,后面的没有改,因为我的系统没有上面的状态栏,所以不需要状态提示。

2.参照修改时要注意的几个事项

a.在添加开关控制的时候,修改文件frameworks/base...

Android7.1.2修改以太网静态设置

weixin_43847093的博客

04-24

3104

如何设置以太网有线网络静态配置

从源码看设置以太网配置调用的是EthernetManager的setConfiguration方法,

所以我们就只需要创建IpConfiguration这个实例,他的构造方法传入值是

最终配置的参数就是StaticIpConfiguration这个类来配置ipAddress,gateway,dnsServers这三个值

涉及的类主要有,但这些都是隐藏的apk无法调用,只能通过反射进行调用,但前提是你的apk是系统apk,不然没有权限。

private static

安卓通过DHCP协议获取IP地址的过程

Zach-Zona的博客

12-24

8739

安卓通过DHCP协议的DORA Discovery发现 Offer提供 Request请求 Ack确认 获取IP地址的过程

android 7.1反射调用系统接口设置静态IP地址

Adversity reveals genius; fortune conceals it.

03-31

6361

直接调用下面的方法,传入的参数见注释

private static InetAddress inetAddress;

private static Object ipConfigurationInstance;

/**

* context 参数,mode参数为静动态模式,分别为STATIC ,DHCP

**/

public static ...

EthernetManager Android 以太网静态IP设置

热门推荐

杀气码的博客

08-01

3万+

关于以太网设置由于公司的需求,需要在项目中加入设置以太网静态IP的功能,在网上找了一下,发 现这方面的资料比较少最后只找到了一个demo,但是导入后发现项目报错.之后查了一下资料才发现原来EthernetManager是谷歌隐藏的API,关于隐藏API的调用,可以去看下下面这篇文章:

如何调用Android隐藏API废话不多说先上代码 // 监听以太网状态的广播,包括网线插拔和以太网开关

Android 12 以太网开发,反射调用隐藏的api

weixin_44917215的博客

04-08

1207

【代码】Android 12 以太网开发,反射调用隐藏的api。

android 反射调用 ethernetmanager

04-27

Android 反射调用 EthernetManager 可以通过如下步骤实现:

1. 首先需要获取一个 EthernetManager 类的实例,可以使用 Context.getSystemService() 来获取:

```

EthernetManager ethernetManager = (EthernetManager) context.getSystemService(Context.ETHERNET_SERVICE);

```

2. 接着需要获取 EthernetManager 类的 class 对象,使用 Class.forName() 来获取:

```

Class ethernetManagerClass = Class.forName("android.net.EthernetManager");

```

3. 然后可以使用 getDeclaredMethod() 方法获取 EthernetManager 类的方法,该方法接收一个字符串作为参数,表示要获取的方法名:

```

Method setEthernetEnabled = ethernetManagerClass.getDeclaredMethod("setEthernetEnabled", boolean.class);

```

4. 最后需要设置调用该方法的对象和传入参数,并调用该方法,可以通过 setAccessible() 方法来设置调用权限:

```

setEthernetEnabled.setAccessible(true);

setEthernetEnabled.invoke(ethernetManager, true);

```

以上就是使用反射调用 EthernetManager 的步骤,需要注意的是,使用反射会增加代码的复杂度,同时也会降低代码的可读性和可维护性,因此在实际开发中需要谨慎使用。

“相关推荐”对你有帮助么?

非常没帮助

没帮助

一般

有帮助

非常有帮助

提交

wzlayer

CSDN认证博客专家

CSDN认证企业博客

码龄8年

暂无认证

26

原创

6万+

周排名

89万+

总排名

12万+

访问

等级

1239

积分

354

粉丝

174

获赞

29

评论

801

收藏

私信

关注

热门文章

《计算机系统概论》-第3章-习题答案

23021

《计算机系统概论》-第2章-习题答案

21746

《计算机系统概论》-第5章-习题答案

18191

《计算机系统概论》-第4章-习题答案

12702

《计算机系统概论》-第1章-习题答案

11243

分类专栏

(组词)[造句]{写作文}

面试

3篇

openwrt

1篇

android

4篇

introduction to computing systems

8篇

并发

1篇

最新评论

《计算机系统概述》-第7章-习题答案

minecraft_box:

请问还有其他章的吗

《计算机系统概论》-第5章-习题答案

SZUbill:

第25题第六行应该是#2

《计算机系统概论》-第5章-习题答案

lightmainCS:

第九题那个ADD不行的原因是会修改nzp的状态

《计算机系统概论》-第1章-习题答案

lightmainCS:

小错误,telescope是望远镜,不是电话

《计算机系统概论》-第5章-习题答案

不会取名怎么办:

第23题是怎么做的

您愿意向朋友推荐“博客详情页”吗?

强烈不推荐

不推荐

一般般

推荐

强烈推荐

提交

最新文章

Win11 设置 Syncthing 开机自启动

Ubuntu 截图工具 Flameshot

Ubuntu+Windows双系统,默认从Windows启动

2022年5篇

2021年5篇

2019年15篇

2017年1篇

目录

目录

分类专栏

(组词)[造句]{写作文}

面试

3篇

openwrt

1篇

android

4篇

introduction to computing systems

8篇

并发

1篇

目录

评论

被折叠的  条评论

为什么被折叠?

到【灌水乐园】发言

查看更多评论

添加红包

祝福语

请填写红包祝福语或标题

红包数量

红包个数最小为10个

红包总金额

红包金额最低5元

余额支付

当前余额3.43元

前往充值 >

需支付:10.00元

取消

确定

下一步

知道了

成就一亿技术人!

领取后你会自动成为博主和红包主的粉丝

规则

hope_wisdom 发出的红包

实付元

使用余额支付

点击重新获取

扫码支付

钱包余额

0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值

EthernetManager Android设置以太网静态IP_android11 放开ethernetmanager接口-CSDN博客

>

EthernetManager Android设置以太网静态IP_android11 放开ethernetmanager接口-CSDN博客

EthernetManager Android设置以太网静态IP

lebulangzhen

于 2020-11-13 17:19:55 发布

阅读量2.1k

收藏

5

点赞数

分类专栏:

Android

文章标签:

android

反射

安卓

java

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

本文链接:https://blog.csdn.net/lebulangzhen/article/details/109679020

版权

Android

专栏收录该内容

32 篇文章

1 订阅

订阅专栏

想要设置以太网为静态IP通过搜索是需用到EthernetManager,但是EthernetManager是谷歌隐藏的API,app是无法调用到的,所以只能通过反射来进行设置

也可以通过下载系统的class.jar包,放到自己的项目中,就可以不用反射,直接调用

下边是引入jar包直接调用的代码,通过EthernetManager 的setConfiguration方法来设置,但是需要构造IpConfiguration 和StaticIpConfiguration对象,IpConfiguration.IpAssignment.STATIC就代表设置为静态IP,也可以设置DHCP

private void setStaticIP() {

EthernetManager mEthManager = (EthernetManager) getSystemService("ethernet");

StaticIpConfiguration mStaticIpConfiguration = new StaticIpConfiguration();

/*

* get ip address, netmask,dns ,gw etc.

*/

Inet4Address inetAddr = getIPv4Address(mEthIpAddress);

int prefixLength = NetUtils.maskStr2InetMask(mEthNetmask);

InetAddress gatewayAddr = getIPv4Address(mEthGateway);

InetAddress dnsAddr = getIPv4Address(mEthdns1);

if (inetAddr.getAddress().toString().isEmpty() || prefixLength ==0 || gatewayAddr.toString().isEmpty()

|| dnsAddr.toString().isEmpty()) {

return;

}

Class clazz = null;

try {

clazz = Class.forName("android.net.LinkAddress");

} catch (Exception e) {

// TODO: handle exception

}

Class[] cl = new Class[]{InetAddress.class, int.class};

Constructor cons = null;

//取得所有构造函数

try {

cons = clazz.getConstructor(cl);

} catch (NoSuchMethodException e) {

e.printStackTrace();

}

//给传入参数赋初值

Object[] x = {inetAddr, prefixLength};

String dnsStr2 = mEthdns2;

//mStaticIpConfiguration.ipAddress = new LinkAddress(inetAddr, prefixLength);

try {

mStaticIpConfiguration.ipAddress = (LinkAddress) cons.newInstance(x);

} catch (InstantiationException e) {

e.printStackTrace();

} catch (IllegalAccessException e) {

e.printStackTrace();

} catch (InvocationTargetException e) {

e.printStackTrace();

}

mStaticIpConfiguration.gateway=gatewayAddr;

mStaticIpConfiguration.dnsServers.add(dnsAddr);

if (!dnsStr2.isEmpty()) {

mStaticIpConfiguration.dnsServers.add(getIPv4Address(dnsStr2));

}

Log.d("2312321", "chanson mStaticIpConfiguration ====" + mStaticIpConfiguration);

IpConfiguration mIpConfiguration = new IpConfiguration(IpConfiguration.IpAssignment.STATIC, IpConfiguration.ProxySettings.NONE, mStaticIpConfiguration, null);

mEthManager.setConfiguration(mIpConfiguration);

}

参考项目链接

不想引用jar包的话就需要使用反射来实现,下边代码是我模仿这个逻辑通过反射来实现的代码

try {

Class ethernetManagerCls = Class.forName("android.net.EthernetManager");

//获取EthernetManager实例

Object ethManager = VfiServiceApp.getContext().getSystemService("ethernet");

// get ip address, netmask,dns ,gw etc.

Inet4Address inetAddr = getIPv4Address(STATIC_IP);

int prefixLength = NetUtils.maskStr2InetMask(STATIC_NETMASK);

InetAddress gatewayAddr = getIPv4Address(STATIC_GATEWAY);

InetAddress dnsAddr = getIPv4Address(STATIC_DNS1);

Class clazz = Class.forName("android.net.LinkAddress");

if (ethManager == null || inetAddr == null || inetAddr.getAddress() == null || gatewayAddr == null

|| dnsAddr == null || Arrays.toString(inetAddr.getAddress()).isEmpty() || prefixLength == 0

|| gatewayAddr.toString().isEmpty() || dnsAddr.toString().isEmpty() || clazz == null) {

return;

}

Class[] cl = new Class[]{InetAddress.class, int.class};

Constructor cons = null;

//取得所有构造函数

try {

cons = clazz.getConstructor(cl);

} catch (NoSuchMethodException e) {

e.printStackTrace();

}

if (cons == null) {

return;

}

//给传入参数赋初值

Object[] x = {inetAddr, prefixLength};

Class staticIpConfigurationCls = Class.forName("android.net.StaticIpConfiguration");

//实例化StaticIpConfiguration

Object staticIpConfiguration = null;

staticIpConfiguration = staticIpConfigurationCls.newInstance();

Field ipAddress = staticIpConfigurationCls.getField("ipAddress");

Field gateway = staticIpConfigurationCls.getField("gateway");

Field dnsServers = staticIpConfigurationCls.getField("dnsServers");

//设置ipAddress

ipAddress.set(staticIpConfiguration, (LinkAddress) cons.newInstance(x));

//设置网关

gateway.set(staticIpConfiguration, gatewayAddr);

//设置dns

ArrayList dnsList = (ArrayList) dnsServers.get(staticIpConfiguration);

dnsList.add(dnsAddr);

if (!STATIC_DNS2.isEmpty()) {

dnsList.add(getIPv4Address(STATIC_DNS2));

}

Log.d(TAG, "chanson mStaticIpConfiguration ====" + staticIpConfigurationCls);

Class ipConfigurationCls = Class.forName("android.net.IpConfiguration");

Object ipConfiguration = ipConfigurationCls.newInstance();

//设置StaticIpConfiguration

Field staticIpConfigurationField = ipConfigurationCls.getField("staticIpConfiguration");

staticIpConfigurationField.set(ipConfiguration, staticIpConfiguration);

//获取ipAssignment、proxySettings的枚举值

Map ipConfigurationEnum = getIpConfigurationEnum(ipConfigurationCls);

//设置ipAssignment

Field ipAssignment = ipConfigurationCls.getField("ipAssignment");

ipAssignment.set(ipConfiguration, ipConfigurationEnum.get("IpAssignment.STATIC"));

//设置proxySettings

Field proxySettings = ipConfigurationCls.getField("proxySettings");

proxySettings.set(ipConfiguration, ipConfigurationEnum.get("ProxySettings.NONE"));

@SuppressLint("PrivateApi")

Method setConfigurationMethod = ethernetManagerCls.getDeclaredMethod("setConfiguration", ipConfiguration.getClass());

//设置静态IP

setConfigurationMethod.invoke(ethManager, ipConfiguration);

} catch (NoSuchFieldException | IllegalAccessException | InstantiationException | InvocationTargetException | ClassNotFoundException | NoSuchMethodException e) {

e.printStackTrace();

}

最好放到主线程中执行,因为我之前测试在子线程有报错,所以需要切换到主线程,参考文章https://blog.csdn.net/lebulangzhen/article/details/108519311

两种方式都可以设置成功,根据个人需要使用即可,class.jar可以通过到参考项目libs中进行下载

当然还需要应用有系统权限才可以设置,所以需要改为系统应用并进行系统签名才可真正设置成功

优惠劵

lebulangzhen

关注

关注

0

点赞

5

收藏

觉得还不错?

一键收藏

知道了

2

评论

EthernetManager Android设置以太网静态IP

想要设置以太网为静态IP通过搜索是需用到EthernetManager,但是EthernetManager是谷歌隐藏的API,app是无法调用到的,所以只能通过反射来进行设置也可以通过下载系统的class.jar包,放到自己的项目中,就可以不用反射,直接调用下边是引入jar包直接调用的代码,通过EthernetManager 的setConfiguration方法来设置,但是需要构造IpConfiguration 和StaticIpConfiguration对象,IpConfiguration.IpAs

复制链接

扫一扫

专栏目录

2 条评论

您还未登录,请先

登录

后发表或查看评论

lebulangzhen

CSDN认证博客专家

CSDN认证企业博客

码龄7年

企业员工

33

原创

11万+

周排名

90万+

总排名

8万+

访问

等级

687

积分

11

粉丝

33

获赞

96

评论

141

收藏

私信

关注

热门文章

ADB命令安装APK常见错误总结

7715

Android获取移动网络信号强度

5758

百度地图Android API实现点聚合功能以及设置最小聚合数和最大显示数

4998

Android中切换到主线程执行的方法

4548

Android代码中实现关机

4483

分类专栏

Android

32篇

RxJava

1篇

学习

2篇

算法

1篇

Java

1篇

线程

1篇

ADB

1篇

百度地图

1篇

最新评论

Android设置WIFI静态IP

lebulangzhen:

有系统签名比较好,root应该也可以

Android设置WIFI静态IP

qq_29204935:

您好,需要root手机才能实现吗

Android设置WIFI静态IP

lebulangzhen:

Class staticIpConfigurationCls = Class.forName("android.net.StaticIpConfiguration");

反射也没有吗

Android设置WIFI静态IP

Xikw_QQ1757994871:

大佬,找不到这个android.net.StaticIpConfiguration类啊

Android离线文件预览服务

lebulangzhen:

不联网这个用不了的,就会走到失败方法,使用手机内其他应用打开

最新文章

Android 实现禁止复制

Android SandHook 使用

Android Drawable对应关系和各个子类使用详解

2022年4篇

2021年8篇

2020年16篇

2019年3篇

2018年2篇

目录

目录

分类专栏

Android

32篇

RxJava

1篇

学习

2篇

算法

1篇

Java

1篇

线程

1篇

ADB

1篇

百度地图

1篇

目录

评论 2

被折叠的  条评论

为什么被折叠?

到【灌水乐园】发言

查看更多评论

添加红包

祝福语

请填写红包祝福语或标题

红包数量

红包个数最小为10个

红包总金额

红包金额最低5元

余额支付

当前余额3.43元

前往充值 >

需支付:10.00元

取消

确定

下一步

知道了

成就一亿技术人!

领取后你会自动成为博主和红包主的粉丝

规则

hope_wisdom 发出的红包

实付元

使用余额支付

点击重新获取

扫码支付

钱包余额

0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。 2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值

在 Ubuntu/Debian 上安装和使用 NetworkManager (NMCLI)

在 Ubuntu/Debian 上安装和使用 NetworkManager (NMCLI)

Linux-Console.net

自我发展

所有文章

Linux发行版

Ubuntu

Linux Mint

Debian

OpenSUSE

Kali Linux

Arch Linux

CentOS

Fedora

RHEL

网站部分

Network

Server

PHP

VirtualBox

SSH

Bash

Apache

MySQL

phpMyAdmin

Office / LibreOffice

grep

awk

sed

iptables

Docker

Python

fail2ban

Windows

Windows

Word

Office

Google

Excel

PowerPoint

ChatGPT

Stable Diffusion

网站搜索

在 Ubuntu/Debian 上安装和使用 NetworkManager (NMCLI)

对于系统管理员来说,他们的日常工作围绕着配置(配置)、维护、故障排除、监控、保护和管理数据中心的服务器。本指南回答了如何使用一些默认工具管理 Ubuntu/Debian 网络接口的问题。网络管理器是一个设计用于管理计算机上的网络的工具。它有许多工具可用于管理几乎所有 Linux 发行版上的网络配置。该工具是 Ubuntu 系统上默认的网络管理工具。它提供以下网络管理工具:Nmtui——该工具在 Linux 终端窗口上运行。它是一种基于文本的网络管理器工具,可以通过输入数据和菜单选择来对网络进行更改。它用于执行基本的网络管理任务,它具有许多 NMCLI 中缺少的功能。Gnome 设置 - 在 Gnome 桌面上,可以使用 Gnome 网络应用程序来管理网络。它提供基本的网络管理并且易于执行配置。nm-connection-editor——这是一种基于图形的网络管理器工具,允许访问 NetworkManager 配置选项NMCLI - 通常称为网络命令行界面是一种网络工具,用于管理 NetworkManager 并显示网络连接的状态。当无法访问图形环境或运行服务器版本并进行网络配置更改时,它非常有用网络管理器由于具有以下功能而成为首选:灵活的网络可视化全面的网络管理内置根本原因分析功能完全可定制的内容内置设备和接口轮询功能单击网络故障排除广泛的报告功能多种集成选项越来越大的网络发现读完本指南后,您应该能够在 Ubuntu/Debian 系统上安装和使用 NetworkManager NMCLI。先决条件对于本指南,请确保您的 Ubuntu|Debian 系统已按如下方式更新和升级。sudo apt-get update && sudo apt-get upgrade步骤 1 – 在 Ubuntu|Debian 系统上安装 NetworkManager默认情况下,NetworkManager 存在于 Ubuntu|Debian 系统上,但如果您需要安装它,我将演示两种在您的 Ubuntu|Debian 系统上安装 NetworkManager 的方法。使用APT使用捕捉1a) 使用 APT 在 Ubuntu|Debian 系统上安装 NetworkManager

NetworkManager 在默认的 ubuntu|Debian 系统的 APT 存储库中可用,可以按如下方式安装。sudo apt-get install network-manager如下启动并启用网络管理器。sudo systemctl start NetworkManager.service

sudo systemctl enable NetworkManager.service1b) 使用 Snap 在 Ubuntu|Debian 系统上安装 NetworkManager。NetworkManager 也可以在 Snap 商店中找到,并且可以安装在已安装并启用 snap 的 Ubuntu|Debian 系统上,如下所示。sudo apt install snapd

sudo systemctl enable --now snapd.socket

sudo ln -s /var/lib/snapd/snap /snap然后使用以下命令安装 NetworkManager:snap install network-manager安装完成后,所有必需的插头和插槽将自动连接,请按如下所示验证这一点。snap connections network-manager示例输出:Interface Plug Slot Notes

dbus network-manager:wpa - -

firewall-control network-manager:firewall-control :firewall-control -

hardware-observe network-manager:hardware-observe :hardware-observe -

login-session-observe network-manager:login-session-observe :login-session-observe -

modem-manager network-manager:modem-manager :modem-manager -

network network-manager:network :network -

network-manager - network-manager:service -

network-manager network-manager:nmcli - -

network-observe network-manager:network-observe :network-observe -

network-setup-control network-manager:network-setup-control :network-setup-control -

network-setup-observe network-manager:network-setup-observe :network-setup-observe -

ppp network-manager:ppp :ppp -

安装完成后,Network Manager 将自动启动并在后台运行,使用以下命令检查其状态:$ sudo systemctl status NetworkManager.service

● NetworkManager.service - Network Manager

Loaded: loaded (/lib/systemd/system/NetworkManager.service; enabled; vendor preset: enabled)

Active: active (running) since Tue 2021-09-28 14:50:00 EAT; 1min ago

Docs: man:NetworkManager(8)

Main PID: 423 (NetworkManager)

Tasks: 3 (limit: 2404)

Memory: 13.6M

CPU: 303ms

CGroup: /system.slice/NetworkManager.service

└─423 /usr/sbin/NetworkManager --no-daemon

Sep 28 14:50:16 debian NetworkManager[423]: [1632829816.7357] manager: NetworkManager state is now CONNECTED_LOCAL

Sep 28 14:50:16 debian NetworkManager[423]: [1632829816.7434] manager: NetworkManager state is now CONNECTED_SITE

Sep 28 14:50:16 debian NetworkManager[423]: [1632829816.7468] policy: set 'Wired connection 1' (enp0s3) as default for IPv4 routing and DNS步骤 2 – 在 Ubuntu|Debian 系统上使用 NetworkManager NMCLI。NMCLI 是一个网络实用工具,可让我们管理网络配置。有几个命令可以用来管理网络。修改网络连接使用 NMCLI 修改网络连接需要我们从列出网络连接开始,使用命令:nmcli connection show示例输出:AME UUID TYPE DEVICE

Wired connection 1 ac98eab7-1ad3-4cf0-93a0-210bfe3bb7e2 ethernet enp0s3 显示活动连接

上面的命令显示了所有连接,但是如果您想查看活动或已启动的连接,您将在上面的命令中添加 --active 标志;nmcli connection show --active示例输出:NAME UUID TYPE DEVICE

Wired connection 1 ac98eab7-1ad3-4cf0-93a0-210bfe3bb7e2 ethernet enp0s3通过连接配置文件名称,您可以查看如下附加信息。nmcli connection show "Wired connection 1"示例输出:使用 NMCLI 添加和修改网络连接使用 NMCLI 添加网络连接使用 NMCLI,可以使用以下语法向 Ubuntu|Debian 系统添加新连接。sudo nmcli connection add type ifname 使用 NMCLI 修改现有网络连接借助 NMCLI,人们可以对现有网络连接进行调整和配置,例如使用以下语法在静态配置和 DHCP 配置之间进行切换。sudo nmcli connection modify 现在让我们看看可以使用 NMCLI 添加和修改连接的配置。我们将首先为我们的连接添加 NetworkManager 连接配置文件。对我来说,它是以太网连接,我将添加一个名为 My-New-Connection 的连接配置文件nmcli connection add con-name My-New-Connection ifname enp0s3 type ethernet

示例输出:Connection 'My-New-Connection' (a6b26540-4c06-4a80-a0fa-a2868e4006e5) successfully added.添加连接配置文件后,我们将进行以下调整。请记住使用与我给出的语法类似的语法来设置您自己的 IP 地址、网关、DNS 服务器等。要设置网络连接的自动启动,请使用:nmcli connection modify My-New-Connection connection.autoconnect yes1.设置带有 /24 子网掩码的静态 IPv4 地址例如,我们将修改现有连接到静态IP_地址,并更改子网/24,如果没有此规范,它将分配一个具有默认掩码的IP,这可能会在以后引起问题。sudo nmcli connection modify My-New-Connection ipv4.address 192.168.100.157/242。 设置带有 /64 子网掩码的静态 IPv6 地址nmcli connection modify My-New-Connection ipv6.addresses 2001:db8:1::1/643.设置 IPv4/IPv6 默认网关##For IPv4

nmcli connection modify My-New-Connection ipv4.gateway 192.168.100.1

##For IPv6

nmcli connection modify My-New-Connection ipv6.gateway 2001:db8:1::fffe4。 设置 IPv4/IPv6 DNS 服务器##For IPv4

nmcli connection modify My-New-Connection ipv4.dns "192.168.100.200"

##For IPv6

nmcli connection modify My-New-Connection ipv6.dns "2001:db8:1::ffbb"5.将 IPv4 和 IPv6 连接方法设置为自动##For IPv4

nmcli connection modify My-New-Connection ipv4.method auto

##For IPv6

nmcli connection modify My-New-Connection ipv6.method auto为了使所做的更改生效,您需要激活配置文件。$ nmcli connection up My-New-Connection

connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)现在检查活动连接。nmcli connection show --active验证设置的 IP_Address。hostname -I

192.168.100.120 192.168.100.157 从输出来看,我有两个 IP 地址,一个主 IP 和一个由新连接配置文件 My-New-Connection 添加的 辅助 IP。您可以使用ip a命令检查附加信息,如下所示。使用 NMCLI 管理设备NMCLI 实用工具还可用于管理设备,例如:显示设备状态sudo nmcli -p dev status示例输出:修改设备配置在修改设备配置之前,您首先需要获取设备信息。sudo nmcli device show示例输出:通过设备信息,您可以使用以下语法修改设备设置。$ sudo nmcli device modify

###OR

$ sudo nmcli dev mod 请记住,上述更改是暂时的,可以使用以下命令重置为默认设置:sudo nmcli dev reapply interface-name如果您在使用 NMCLI 设备管理器时遇到困难,请使用以下命令查找帮助:sudo nmcli device help结论。这就对了!我们已经介绍了如何在 Ubuntu/Debian 系统上安装和使用 NetworkManager NMCLI。我希望本指南对您有意义。我假设您现在可以使用 NetworkManager NMCLI 管理网络连接和网络设备。查看更多:如何在Xen中创建内部网络| XCP-ng将辅助 IP 地址添加到 CentOS/RHEL 网络接口在 Debian 上配置 BIND 从属 DNS 服务器

版权所有。 © Linux-Console.net • 2019-2024

使用 NetworkManager 配置 Debian 路由器 :: 星野玲的博客

etworkManager 配置 Debian 路由器 ::

星野玲的博客星野玲的博客

RSS关于友链RSS关于友链使用 NetworkManager 配置 Debian 路由器2023-10-01

(最后修改于:

2023-11-24)

— 作者: 星野玲#Debian 

#路由器 

#软路由 大约一年半前,小玲写了《使用 Debian 作为路由器》这篇文章。由于 Armbian 自带了 NetworkManager 而 Debian 没有自带 NetworkManager,所以当时小玲一开始就把 NetworkManager 卸载了,不过现在小玲打算用上 NetworkManager。这次小玲使用的系统是通过虚拟机安装的 Debian 12,默认没有安装 NetworkManager。安装 NetworkManager

#首先安装 NetworkManager,如果需要 PPPoE 拨号,还需要安装 ppp。sudo apt install -y network-manager ppp

nmcli 命令的使用

#查看网络情况

#通过 nmcli 命令查看当前网络情况。可以看到有两个连接外部的网络设备——ens33 和 ens34。ens34 设备已经通过 DHCP 获取了 IP 地址。ens33 还没有被设置。小玲将 ens34 设备当作 WAN 口,ens33 设备当作 LAN 口。ens34: connected to Wired connection 1

"Intel 82545EM"

ethernet (e1000), 00:0C:29:BD:87:34, hw, mtu 1500

ip4 default, ip6 default

inet4 192.168.█.9/26

route4 192.168.█.0/26 metric 100

route4 default via 192.168.█.1 metric 100

inet6 240█:████:████:████:████:████:████:████/64

inet6 fe80::90ec:3e41:215c:ac29/64

route6 fe80::/64 metric 1024

route6 240█:████:████:████::/64 metric 100

route6 default via fe80::████:████:████:████ metric 100

lo: connected (externally) to lo

"lo"

loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

inet4 127.0.0.1/8

inet6 ::1/128

ens33: unmanaged

"Intel 82545EM"

ethernet (e1000), 00:0C:29:BD:87:2A, hw, mtu 1500

DNS configuration:

servers: 192.168.█.1

interface: ens34

servers: fe80::████:████:████:████

interface: ens34

Use "nmcli device show" to get complete information about known devices and

"nmcli connection show" to get an overview on active connection profiles.

Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.

查看网络设备

#使用 nmcli d 命令查看网络设备。现在 ens33 设备并没有被 NetworkManager 管理,待会会通过 NetworkManager 创建一个连接,使其被 NetworkManager 管理。DEVICE TYPE STATE CONNECTION

ens34 ethernet connected Wired connection 1

lo loopback connected (externally) lo

ens33 ethernet unmanaged --

查看网络连接

#使用 nmcli c 命令查看网络连接。只有 Wired connection 1 这个 NetworkManager 自动创建的连接。NAME UUID TYPE DEVICE

Wired connection 1 7d5979e9-c222-3fa0-a86e-9c1ea3f330b5 ethernet ens34

lo 609bc8f3-b78b-40c6-9836-9f67f0dab964 loopback lo

创建以太网连接

#在 ens33 设备上创建一个名为 lan 的以太网连接,这个连接的 IPv4 地址为 192.168.3.1/24。注意创建时需要 sudo 给权限。命令里带了双引号的是参数的值,小玲这里是为了让大家看得更明白。sudo nmcli c add type "ethernet" con-name "lan" ifname "ens33" ipv4.method "manual" ipv4.addresses "192.168.3.1/24"

如果需要设置静态 IPv6 地址,可以这么添加。sudo nmcli c add type "ethernet" con-name "lan" ifname "ens33" ipv4.method "manual" ipv4.addresses "192.168.3.1/24" ipv6.method "manual" ipv6.addresses "fddd:afcf::/64"

查看连接详情

#可以通过 nmcli c show 查看连接的详情。比如要查看刚刚添加的 lan 连接,可以通过下面的命令。nmcli c show "lan"

忽略自动下发的 DNS 服务器地址

#因为 NetworkManager 会控制 /etc/resolv.conf 文件。里面通常是通过 DHCP 获取的 DNS 服务器地址。如果不想被 NetworkManager 控制 /etc/resolv.conf 文件,可以通过下面的命令忽略自动下发的 DNS 服务器地址sudo nmcli c modify ipv4.ignore-auto-dns "yes" ipv6.ignore-auto-dns "yes"

删除一个连接

#删除一个连接可以用 nmcli c delete 命令。如果要把刚刚创建的 lan 连接删除,就可以使用下面的命令。sudo nmcli c delete "lan"

添加 PPPoE 连接

#如果要通过 ens34 设备使用 PPPoE 拨号,可以创建这么一个连接。username 和 password 的值,请填写自己的宽带账号和密码。sudo nmcli c add type "pppoe" con-name "pppoe" ifname "ens34" username "" password ""

添加成功后,通过下面的命令启动刚刚添加的 pppoe 连接。sudo nmcli c up pppoe

值得注意的是,通过 nmcli c add 添加的所有连接,都是默认开机自启动的。所以 PPPoE 的连接也是开机自启动的。注意在 Debian 上使用 PPPoE 拨号的前提是安装 ppp。如果还没有安装 ppp,请趁着能联网时安装 ppp。sudo apt install -y ppp

获取 IPv6 PD 前缀

#如果要获取 PD 前缀,并把它添加到 lan 连接上,可以使用下面的命令。sudo nmcli c modify "lan" ipv6.method "shared"

通过 NetworkManager 获取 PD 前缀时,几乎没有可以自定义的选项,例如前缀长度,路由器在 lan 连接上的主机地址。不过小玲只能获取一个 /64 前缀,所以不能配置也没有多大负面影响。如果当前没有 PD 前缀,重新启用 pppoe 连接以获取 PD 前缀。sudo nmcli c down pppoe && sudo nmcli c up pppoe

自动重新获取 PD 前缀

#有时候,PPPoE 连接会自己断开重连,这时候如果 PD 前缀没有更新,会导致局域网内的设备无法使用 IPv6。小玲为了解决这个问题,用了个野路子,思路就是写一个脚本,当 PPPoE 连接断开时,自动禁用并启用 PPPoE 连接以达到重新获取 PD 前缀的目的。sudo vim /etc/ppp/ipv6-down.d/restart_pppoe

#!/usr/bin/bash

# CONNECTION_NAME 变量的值为 NetworkManager 里用于 PPPoE 拨号的连接名称

CONNECTION_NAME=pppoe

nmcli c down $CONNECTION_NAME && nmcli c up $CONNECTION_NAME

添加一个带 VLAN ID 的连接

#通过下面的命令来添加一个带 VLAN ID 的连接。ifname 的值可以自由设置,这里小玲就设置为 ens33.10。vlan.parent 的值是这个 VLAN 连接依附的网络设备的名称。vlan.id 的值可以自由设置,这里小玲就设置为 10。sudo nmcli c add type "vlan" ifname "ens33.10" vlan.parent "ens33" vlan.id "10" ipv4.method "manual" ipv4.addresses "192.168.3.1/24"

添加一个网桥并开启 WiFi 热点

#如果路由器有多个网络设备,可以通过创建一个网桥将它们桥接起来。比如现在有一个 USB 无线网卡,要把它和 LAN 口桥接起来,LAN 提供有线连接,USB 无线网卡开启热点后提供无线连接。那么可以这么设置。注意,如果 LAN 口上已经有连接了,需要先把 LAN 口的连接删除。先用 nmcli d 查看 USB 无线网卡的设备名称。DEVICE TYPE STATE CONNECTION

ens34 ethernet connected Wired connection 1

lo loopback connected (externally) lo

ens33 ethernet unmanaged --

wlx908d78eb1c7b wifi disconnected --

p2p-dev-wlx908d78eb1c7b wifi-p2p disconnected --

USB 无线网卡的设备名称为 wlx908d78eb1c7b。通过下面的命令创建一个名为 bridge 的网桥,ifname 的值可以自由设置,这里小玲就设置为 br0。sudo nmcli c add type "bridge" con-name "bridge" ifname "br0" ipv4.method "manual" ipv4.addresses "192.168.3.1/24"

将 ens33 设备加入刚刚创建的网桥。sudo nmcli c add type "bridge-slave" ifname "ens33" master "br0"

通过下面的命令创建一个无线的连接。wifi.band 是 WiFi 的频段,值为 a 或 bg。无论哪个都是特别慢的,nmcli 并不支持 WiFi 5 甚至 WiFi 6。wifi.ssid 的值请填写自己想设置的 SSID。802-11-wireless-security.key-mgmt "wpa-psk" 和 802-11-wireless-security.proto "rsn" 这两个参数将 WiFi 加密方式设置为 WPA2。802-11-wireless-security.psk 的值请填写自己想设置的密码。sudo nmcli c add type "wifi" ifname "wlx908d78eb1c7b" master "br0" wifi.band "a" wifi.mode "ap" wifi.ssid "" 802-11-wireless-security.key-mgmt "wpa-psk" 802-11-wireless-security.proto "rsn" 802-11-wireless-security.psk ""

小玲并不建议大家通过 NetworkManager 开启 WiFi 热点,因为速度实在是太慢了,如果有这方面的需求,小玲的建议是买一个无线路由器通过网线连接 LAN 口后当作 AP。如果要使用 Tproxy 透明代理,小玲也不建议设置网桥。因为 nftables 对网桥的数据的处理有些问题。小玲在这里只是介绍这个方法而已,并不是建议大家使用网桥。连接 WiFi

#通过 nmcli d wifi list ifname "" 命令查看无线网卡,ifname 的值请填写自己的无线网卡设备名。如果只有一张无线网卡,那么这个命令可以省略为 nmcli d wifi。通过 nmcli d wifi connect "" password "" ifname "" 命令连接 WiFi,connect 的值请填写要连接的 WiFi 的 SSID,password 的值请填写 WiFi 的密码,ifname 的值请填写自己的无线网卡设备名。如果只有一张无线网卡,那么 ifname 及其后面的内容可以省略。结尾

#这篇文章更多的是一篇补充性而不是教程性的文章,所以没看过小玲之前的文章的话有可能看不懂。如果看不懂请看《使用 Debian 作为路由器》和《Debian 软路由 + 华硕AX86U 实现多个 WiFi VLAN 隔离》。阅读其它文章←

使用 fnm 管理 Node.js 版本

关于 router.push() 会报错这件事

→星野玲的博客

© 2023 Powered by Hugo

Theme made by panr

NetworkManager - ArchWiki

NetworkManager - ArchWiki

Home Packages Forums Wiki GitLab Security AUR Download

Jump to content

Main menu

Main menu

move to sidebar

hide

Navigation

Main pageTable of contentsGetting involvedWiki newsRandom page

Interaction

HelpContributingRecent changesRecent talksNew pagesStatisticsRequests

ArchWiki

Search

Search

Create accountLog in

Personal tools

Create account Log in Dark mode

Contents

move to sidebar

hide

Beginning

1Installation

Toggle Installation subsection

1.1Enable NetworkManager

1.2Additional interfaces

1.3Mobile broadband support

1.4PPPoE / DSL support

1.5VPN support

2Usage

Toggle Usage subsection

2.1nmcli examples

2.2Edit a connection

3Front-ends

Toggle Front-ends subsection

3.1GNOME

3.2KDE Plasma

3.3nm-applet

3.3.1Appindicator

3.4networkmanager-dmenu

4Configuration

Toggle Configuration subsection

4.1NetworkManager-wait-online

4.2Set up PolicyKit permissions

4.3Proxy settings

4.4Checking connectivity

4.5Captive portals

4.6DHCP client

4.7DNS management

4.7.1DNS caching and conditional forwarding

4.7.1.1dnsmasq

4.7.1.1.1Custom dnsmasq configuration

4.7.1.1.2IPv6

4.7.1.1.3DNSSEC

4.7.1.2systemd-resolved

4.7.1.3DNS resolver with an openresolv subscriber

4.7.2Custom DNS servers

4.7.2.1Setting custom global DNS servers

4.7.2.2Setting custom DNS servers in a connection

4.7.2.2.1Setting custom DNS servers in a connection (GUI)

4.7.2.2.2Setting custom DNS servers in a connection (nmcli / connection file)

4.7.3/etc/resolv.conf

4.7.3.1Unmanaged /etc/resolv.conf

4.7.3.2Use openresolv

4.8Firewall

5Network services with NetworkManager dispatcher

Toggle Network services with NetworkManager dispatcher subsection

5.1Avoiding the dispatcher timeout

5.2Dispatcher examples

5.2.1Mount remote directory with sshfs

5.2.2Mounting of SMB shares

5.2.3Mounting of NFS shares

5.2.4Use dispatcher to automatically toggle wireless depending on LAN cable being plugged in

5.2.5Use dispatcher to connect to a VPN after a network connection is established

5.2.6Use dispatcher to disable IPv6 on VPN provider connections

5.2.7OpenNTPD

5.2.8Dynamically set NTP servers received via DHCP with systemd-timesyncd

6Testing

7Tips and tricks

Toggle Tips and tricks subsection

7.1Encrypted Wi-Fi passwords

7.1.1Using GNOME Keyring

7.1.2Using KDE Wallet

7.2Sharing internet connection over Wi-Fi

7.3Sharing internet connection over Ethernet

7.4Checking if networking is up inside a cron job or script

7.5Connect to network with secret on boot

7.6OpenConnect with password in KWallet

7.7Ignore specific devices

7.8Configuring MAC address randomization

7.9Enable IPv6 Privacy Extensions

7.10Configure a unique DUID per connection

7.11Working with wired connections

7.12Using iwd as the Wi-Fi backend

7.13Running in a network namespace

7.14Automatically connect to VPN

8Troubleshooting

Toggle Troubleshooting subsection

8.1No prompt for password of secured Wi-Fi networks

8.2Network management disabled

8.3Problems with internal DHCP client

8.4DHCP problems with dhclient

8.53G modem not detected

8.6Switching off WLAN on laptops

8.7Static IP address settings revert to DHCP

8.8Cannot edit connections as normal user

8.9Forget hidden wireless network

8.10VPN not working in GNOME

8.11Unable to connect to visible European wireless networks

8.12Automatic connect to VPN on boot is not working

8.13Systemd Bottleneck

8.14Regular network disconnects, latency and lost packets (WiFi)

8.15Unable to turn on Wi-Fi with Lenovo laptop (IdeaPad, Legion, etc.)

8.16Turn off hostname sending

8.17nm-applet disappears in i3wm

8.18Unit dbus-org.freedesktop.resolve1.service not found

8.19Secrets were required, but not provided

8.20WPA Enterprise connection with iwd

8.21Failed to request VPN secrets

8.22OpenVPN connections fail with OpenSSL "ca md too weak" error

8.23WPA Enterprise connections fail to authenticate with OpenSSL "unsupported protocol" error

9See also

Toggle the table of contents

Toggle the table of contents

NetworkManager

5 languages

DeutschFrançais日本語Português中文(简体)

PageDiscussion

English

ReadView sourceView history

Tools

Tools

move to sidebar

hide

Actions

ReadView sourceView history

General

What links hereRelated changesSpecial pagesPrintable versionPermanent linkPage information

From ArchWiki

Related articles

Network configuration

Wireless network configuration

NetworkManager is a program for providing detection and configuration for systems to automatically connect to networks. NetworkManager's functionality can be useful for both wireless and wired networks. For wireless networks, NetworkManager prefers known wireless networks and has the ability to switch to the most reliable network. NetworkManager-aware applications can switch from online and offline mode. NetworkManager also prefers wired connections over wireless ones, has support for modem connections and certain types of VPN. NetworkManager was originally developed by Red Hat and now is hosted by the GNOME project.

Warning: By default, secrets (e.g. WiFi passwords) are accessible to the root user in the filesystem and to users with access to settings via the GUI (e.g. nm-applet). see #Encrypted Wi-Fi passwords.

Installation

NetworkManager can be installed with the package networkmanager, which contains a daemon, a command line interface (nmcli) and a curses‐based interface (nmtui).

Enable NetworkManager

After installation, you should start/enable NetworkManager.service. Once the NetworkManager daemon is started, it will automatically connect to any available "system connections" that have already been configured. Any "user connections" or unconfigured connections will need nmcli or an applet to configure and connect.

Note:

This article or section is a candidate for merging with Network configuration.

Notes: Conflicting networking services is a generic issue not specific to NetworkManager. (Discuss in Talk:NetworkManager)

You must ensure that no other service that wants to configure the network is running; in fact, multiple networking services will conflict. You can find a list of the currently running services with systemctl --type=service and then stop them. See #Configuration to enable the NetworkManager service.

If systemd-resolved is not started, an error message will start flooding your logs. See #Unit dbus-org.freedesktop.resolve1.service not found for more info.

Additional interfaces

nm-connection-editor for a graphical user interface,

network-manager-applet for a system tray applet (nm-applet).

Mobile broadband support

NetworkManager uses ModemManager for mobile broadband connection support.

Install modemmanager and usb_modeswitch. Afterwards enable and start ModemManager.service.

It may be necessary to restart NetworkManager.service for it to detect ModemManager. After you restart it, re-plug the modem again and it should be recognized.

Add connections from a front-end (e.g. nm-connection-editor) and select mobile broadband as the connection type. After selecting your ISP and billing plan, APN and other settings should be filled in automatically using information from mobile-broadband-provider-info.

PPPoE / DSL support

Install rp-pppoe package for PPPoE / DSL connection support. To actually add PPPoE connection, use nm-connection-editor and add new DSL/PPPoE connection.

VPN support

NetworkManager since version 1.16 has native support for WireGuard, all it needs is the wireguard kernel module. Read the WireGuard in NetworkManager blog post for details.

Support for other VPN types is based on a plug-in system. They are provided in the following packages:

networkmanager-openconnect for OpenConnect

networkmanager-openvpn for OpenVPN

networkmanager-pptp for PPTP Client

networkmanager-strongswan for strongSwan

networkmanager-vpnc

networkmanager-fortisslvpnAUR

networkmanager-iodine-gitAUR

networkmanager-libreswanAUR

networkmanager-l2tp

networkmanager-ssh-gitAUR

network-manager-sstp

Warning: There are a lot of bugs related to VPN support. Check the daemon processes options set via the GUI correctly and double-check with each package release.

Note:

To have fully functioning DNS resolution when using VPN, you should set up conditional forwarding.

These plug-ins may not have a documented command line interface, or may not work at all without an applet running. This is not an issue if you are using a regular DE; if you are not, you should run #nm-applet while configuring or activating the connection so that you get the necessary dialogues. [1]

Usage

NetworkManager comes with nmcli(1) and nmtui(1).

nmcli examples

List nearby Wi-Fi networks:

$ nmcli device wifi list

Connect to a Wi-Fi network:

$ nmcli device wifi connect SSID_or_BSSID password password

Connect to a hidden Wi-Fi network:

$ nmcli device wifi connect SSID_or_BSSID password password hidden yes

Connect to a Wi-Fi on the wlan1 interface:

$ nmcli device wifi connect SSID_or_BSSID password password ifname wlan1 profile_name

Disconnect an interface:

$ nmcli device disconnect ifname eth0

Get a list of connections with their names, UUIDs, types and backing devices:

$ nmcli connection show

Activate a connection (i.e. connect to a network with an existing profile):

$ nmcli connection up name_or_uuid

Delete a connection:

$ nmcli connection delete name_or_uuid

See a list of network devices and their state:

$ nmcli device

Turn off Wi-Fi:

$ nmcli radio wifi off

Edit a connection

For a comprehensive list of settings, see nm-settings(5).

Firstly, you need to get a list of connections:

$ nmcli connection

NAME UUID TYPE DEVICE

Wired connection 2 e7054040-a421-3bef-965d-bb7d60b7cecf ethernet enp5s0

Wired connection 1 997f2782-f0fc-301d-bfba-15421a2735d8 ethernet enp0s25

MY-HOME-WIFI-5G 92a0f7b3-2eba-49ab-a899-24d83978f308 wifi --

Here you can use the first column as connection-id used later. In this example, we pick Wired connection 2 as a connection-id.

You have three methods to configure a connection Wired connection 2 after it has been created:

nmcli interactive editor

nmcli connection edit 'Wired connection 2'. Usage is well documented from the editor.

nmcli command line interface

nmcli connection modify 'Wired connection 2' setting.property value. See nmcli(1) for usage. For example, you can change its IPv4 route metric to 200 using nmcli connection modify 'Wired connection 2' ipv4.route-metric 200 command.

To remove a setting, pass an empty field ("") to it like this:

nmcli connection modify 'Wired connection 2' setting.property ""

Connection file

In /etc/NetworkManager/system-connections/, modify the corresponding Wired connection 2.nmconnection file . Do not forget to reload the configuration file with nmcli connection reload.

Front-ends

To provide integration with a desktop environment, most users will want to install an applet. This not only provides easy access to network selection and configuration, but also provides the agent necessary for securely storing secrets. Various desktop environments have their own applet; otherwise, you can use #nm-applet.

GNOME

GNOME has a built-in tool, accessible from the Network settings.

KDE Plasma

Install the plasma-nm package. After that, add it to the KDE taskbar via the Panel options > Add widgets > Networks menu.

nm-applet

network-manager-applet is a GTK 3 front-end which works under Xorg environments with a systray.

To store connection secrets install and configure an application which implements the Secret Service D-Bus API such as GNOME/Keyring, KDE Wallet, or KeePassXC.

Be aware that after enabling the tick-box option Make available to other users for a connection, NetworkManager stores the password in plain-text, though the respective file is accessible only to root (or other users via nm-applet). See #Encrypted Wi-Fi passwords.

In order to run nm-applet without a systray, you can use trayer or stalonetray. For example, you can add a script like this one in your path:

nmgui

#!/bin/sh

nm-applet 2>&1 > /dev/null &

stalonetray 2>&1 > /dev/null

killall nm-applet

When you close the stalonetray window, it closes nm-applet too, so no extra memory is used once you are done with network settings.

The applet can show notifications for events such as connecting to or disconnecting from a WiFi network. For these notifications to display, ensure that you have a notification server installed - see Desktop notifications. If you use the applet without a notification server, you might see some messages in stdout/stderr, and the applet might hang. See [2].

In order to run nm-applet with such notifications disabled, start the applet with the following command:

$ nm-applet --no-agent

Tip: nm-applet might be started automatically with a autostart desktop file, to add the --no-agent option modify the Exec line there, i.e.

Exec=nm-applet --no-agent

Warning: On i3, if nm-applet is started with the --no-agent option, it is not possible to connect to a new encrypted WiFi network by clicking on the item list because no password input dialogue window will pop out. journal will show no secrets: No agents were available for this request.

Appindicator

As of version 1.18.0 Appindicator support is available in the official network-manager-applet package. To use nm-applet in an Appindicator environment start the applet with the following command:

$ nm-applet --indicator

networkmanager-dmenu

Alternatively there is networkmanager-dmenu-gitAUR which is a small script to manage NetworkManager connections with dmenu or rofi instead of nm-applet. It provides all essential features such as connection to existing NetworkManager wifi or wired connections, connect to new wifi connections, requests passphrase if required, connect to existing VPN connections, enable/disable networking, launch nm-connection-editor GUI, connect to Bluetooth networks.

Configuration

NetworkManager will require some additional steps to be able run properly. Make sure you have configured /etc/hosts as described in Network configuration#Set the hostname section.

NetworkManager has a global configuration file at /etc/NetworkManager/NetworkManager.conf. Additional configuration files can be placed in /etc/NetworkManager/conf.d/. Usually no configuration needs to be done to the global defaults.

After editing a configuration file, the changes can be applied by running:

# nmcli general reload

NetworkManager-wait-online

Enabling NetworkManager.service also enables NetworkManager-wait-online.service, which is a oneshot system service that waits for the network to be configured. The latter has WantedBy=network-online.target, so it will finish only when network-online.target itself is enabled or pulled in by some other unit. See also systemd#Running services after the network is up.

By default, NetworkManager-wait-online.service waits for NetworkManager startup to complete, rather than waiting for network connectivity specifically (see nm-online(1)). If NetworkManager-wait-online.service finishes before the network is really up, resulting in failed services on boot, extend the unit to remove the -s from the ExecStart line:

[Service]

ExecStart=

ExecStart=/usr/bin/nm-online -q

Be aware that this can cause other issues.

In some cases, the service will still fail to start successfully on boot due to the timeout setting being too short. Edit the service to change NM_ONLINE_TIMEOUT from 60 to a higher value.

Set up PolicyKit permissions

By default, all users in active local sessions are allowed to change most network settings without a password. See General troubleshooting#Session permissions to check your session type. In most cases, everything should work out of the box.

Some actions (such as changing the system hostname) require an administrator password. In this case, you need to add yourself to the wheel group and run a Polkit authentication agent which will prompt for your password.

For remote sessions (e.g. headless VNC), you have several options for obtaining the necessary privileges to use NetworkManager:

Add yourself to the wheel group. You will have to enter your password for every action. Note that your user account may be granted other permissions as well, such as the ability to use sudo without entering the root password.

Add yourself to the network group and create /etc/polkit-1/rules.d/50-org.freedesktop.NetworkManager.rules with the following content: polkit.addRule(function(action, subject) {

if (action.id.indexOf("org.freedesktop.NetworkManager.") == 0 && subject.isInGroup("network")) {

return polkit.Result.YES;

}

});

All users in the network group will be able to add and remove networks without a password (which means you do not have to run a Polkit authentication agent, so this option will also work in SSH sessions).

Proxy settings

NetworkManager does not directly handle proxy settings, but if you are using GNOME or KDE, you could use proxydriverAUR which handles proxy settings using NetworkManager's information.

In order for proxydriver to be able to change the proxy settings, you would need to execute this command, as part of the GNOME startup process (see GNOME#Autostart).

$ xhost +si:localuser:username

See also Proxy settings.

Checking connectivity

NetworkManager can try to reach a webserver after connecting to a network in order to determine if it is e.g behind a captive portal. The default host (configured in /usr/lib/NetworkManager/conf.d/20-connectivity.conf) is ping.archlinux.org (a CNAME alias of redirect.archlinux.org). To use a different webserver or to disable connectivity checking, create /etc/NetworkManager/conf.d/20-connectivity.conf, see NetworkManager.conf(5) § CONNECTIVITY SECTION. Below is an example of using GNOME servers (it does not require the use of GNOME):

/etc/NetworkManager/conf.d/20-connectivity.conf

[connectivity]

uri=http://nmcheck.gnome.org/check_network_status.txt

To disable NetworkManager's connectivity check, use the following configuration. This can be useful when connected to a VPN that blocks connectivity checks.

/etc/NetworkManager/conf.d/20-connectivity.conf

[connectivity]

enabled=false

Note: Although automatic connectivity checks are a potential privacy leak, Arch Linux's default connectivity URL is committed to not logging any access. See [3] [4].

Captive portals

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Complex scripts should not be maintained on the wiki. (Discuss in Talk:NetworkManager)

For those behind a captive portal, the desktop manager may automatically open a window asking for credentials. If your desktop does not, you can use capnet-assist package (however, it currently it has a broken NetworkManager dispatcher script). Alternatively, you can create a NetworkManager dispatcher script with the following content:

/etc/NetworkManager/dispatcher.d/90-open_captive_portal

#!/bin/sh -e

# Script to dispatch NetworkManager events

#

# Runs shows a login webpage on walled garden networks.

# See NetworkManager(8) for further documentation of the dispatcher events.

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

if [ -x "/usr/bin/logger" ]; then

logger="/usr/bin/logger -s -t captive-portal"

else

logger=":"

fi

wait_for_process() {

PNAME=$1

while [ -z "$(/usr/bin/pgrep $PNAME)" ]; do

sleep 3;

done

}

#launch the browser, but on boot we need to wait that nm-applet starts

start_browser() {

local user="$1"

local display="$2"

export DISPLAY="$display"

wait_for_process nm-applet

export XAUTHORITY="/home/$user/.Xauthority"

$logger "Running browser as '$user' with display '$display' to login in captive portal"

sudo -u "$user" --preserve-env=DISPLAY,XAUTHORITY -H xdg-open http://capnet.elementary.io 2>&1 > /dev/null

}

# Run the right scripts

case "$2" in

connectivity-change)

$logger -p user.debug "dispatcher script triggered on connectivity change: $CONNECTIVITY_STATE"

if [ "$CONNECTIVITY_STATE" = "PORTAL" ]; then

# Match last column of who's output with ' :[at least one digit] '

who | awk '$NF ~ /\(:[0-9]+\)/ { print $1 " " substr($NF, 2, length($NF)-2) };' | \

while read user display; do

start_browser $user $display || $logger -p user.err "Failed for user: '$user' display: '$display'"

done

fi

 ;;

*)

# In a down phase

exit 0

 ;;

esac

You will need to restart NetworkManager.service or reboot for this to start working. Once you do, the dispatcher script should open a login window once it detects you are behind a captive portal.

Another solution is captive-browser-gitAUR based on Google Chrome.

DHCP client

By default NetworkManager uses its internal DHCP client. The internal DHCPv4 plugin is based on the nettools' n-dhcp4 library, while the internal DHCPv6 plugin is made from code based on systemd-networkd.

To use a different DHCP client install one of the alternatives:

dhclient - dhclient.

dhcpcd - dhcpcd.

To change the DHCP client backend, set the option main.dhcp=dhcp_client_name with a configuration file in /etc/NetworkManager/conf.d/. E.g.:

/etc/NetworkManager/conf.d/dhcp-client.conf

[main]

dhcp=dhclient

Note:

NetworkManger does not support using dhcpcd for IPv6. See NetworkManager issue #5. If dhcpcd is set as the DHCP client, NetworkManager will use the internal DHCP client for DHCPv6.

Do not enable the systemd units shipped with the dhclient and dhcpcd packages. They will conflict with NetworkManager, see the note in #Installation for details.

DNS management

NetworkManager's DNS management is described in the GNOME project's wiki page—Projects/NetworkManager/DNS.

DNS caching and conditional forwarding

NetworkManager has a plugin to enable DNS caching and conditional forwarding (previously called "split DNS" in NetworkManager's documentation) using dnsmasq or systemd-resolved. The advantages of this setup is that DNS lookups will be cached, shortening resolve times, and DNS lookups of VPN hosts will be routed to the relevant VPN's DNS servers. This is especially useful if you are connected to more than one VPN.

Note: If /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf, /run/systemd/resolve/resolv.conf,/lib/systemd/resolv.conf or /usr/lib/systemd/resolv.conf, NetworkManager will choose systemd-resolved automatically. To use dnsmasq, you must first remove that symlink, then restart NetworkManager.

dnsmasq

Make sure dnsmasq has been installed. Then set main.dns=dnsmasq with a configuration file in /etc/NetworkManager/conf.d/:

/etc/NetworkManager/conf.d/dns.conf

[main]

dns=dnsmasq

Now run nmcli general reload as root. NetworkManager will automatically start dnsmasq and add 127.0.0.1 to /etc/resolv.conf. The original DNS servers can be found in /run/NetworkManager/no-stub-resolv.conf. You can verify dnsmasq is being used by doing the same DNS lookup twice with drill example.com and verifying the server and query times.

Note:

You do not need to start dnsmasq.service or edit /etc/dnsmasq.conf. NetworkManager will start dnsmasq without using the systemd service and without reading the dnsmasq's default configuration file(s).

The dnsmasq instance started by NetworkManager will bind to 127.0.0.1:53, you cannot run any other software (including dnsmasq.service) on the same address and port.

Custom dnsmasq configuration

Custom configurations can be created for dnsmasq by creating configuration files in /etc/NetworkManager/dnsmasq.d/. For example, to change the size of the DNS cache (which is stored in RAM):

/etc/NetworkManager/dnsmasq.d/cache.conf

cache-size=1000

You can check the configuration file syntax with:

$ dnsmasq --test --conf-file=/dev/null --conf-dir=/etc/NetworkManager/dnsmasq.d

See dnsmasq(8) for all available options.

IPv6

The factual accuracy of this article or section is disputed.

Reason: This does not solve the issue because NetworkManager does not add ::1 to /etc/resolv.conf. Unless @::1 is manually passed to drill, it will still fail with Error: error sending query: No (valid) nameservers defined in the resolver. (Discuss in Talk:NetworkManager)

Enabling dnsmasq in NetworkManager may break IPv6-only DNS lookups (i.e. drill -6 [hostname]) which would otherwise work. In order to resolve this, creating the following file will configure dnsmasq to also listen to the IPv6 loopback:

/etc/NetworkManager/dnsmasq.d/ipv6-listen.conf

listen-address=::1

In addition, dnsmasq also does not prioritize upstream IPv6 DNS. Unfortunately NetworkManager does not do this (Ubuntu Bug). A workaround would be to disable IPv4 DNS in the NetworkManager config, assuming one exists.

DNSSEC

The dnsmasq instance started by NetworkManager by default will not validate DNSSEC since it is started with the --proxy-dnssec option. It will trust whatever DNSSEC information it gets from the upstream DNS server.

For dnsmasq to properly validate DNSSEC, thus breaking DNS resolution with name servers that do not support it, create the following configuration file:

/etc/NetworkManager/dnsmasq.d/dnssec.conf

conf-file=/usr/share/dnsmasq/trust-anchors.conf

dnssec

systemd-resolved

This article or section needs expansion.

Reason: NetworkManager 1.16 adds a new setting main.systemd-resolved[5] (enabled by default). It unconditionally sends DNS configuration to systemd-resolved. Related to "Preserving resolv.conf" from systemd-resolved#DNS? (Discuss in Talk:NetworkManager)

NetworkManager can use systemd-resolved as a DNS resolver and cache. Make sure that systemd-resolved is properly configured and that systemd-resolved.service is started before using it.

systemd-resolved will be used automatically if /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf, /run/systemd/resolve/resolv.conf or /usr/lib/systemd/resolv.conf.

You can enable it explicitly by setting main.dns=systemd-resolved with a configuration file in /etc/NetworkManager/conf.d/:

/etc/NetworkManager/conf.d/dns.conf

[main]

dns=systemd-resolved

DNS resolver with an openresolv subscriber

If openresolv has a subscriber for your local DNS resolver, set up the subscriber and configure NetworkManager to use openresolv.

Because NetworkManager advertises a single "interface" to resolvconf, it is not possible to implement conditional forwarding between two NetworkManager connections. See NetworkManager issue 153.

This can be partially mitigated if you set private_interfaces="*" in /etc/resolvconf.conf[6]. Any queries for domains that are not in search domain list will not get forwarded. They will be handled according to the local resolver's configuration, for example, forwarded to another DNS server or resolved recursively from the DNS root.

Custom DNS servers

Setting custom global DNS servers

To set DNS servers for all connections, specify them in NetworkManager.conf(5) using the syntax servers=serveripaddress1,serveripaddress2,serveripaddress3 in a section named [global-dns-domain-*]. For example:

/etc/NetworkManager/conf.d/dns-servers.conf

[global-dns-domain-*]

servers=::1,127.0.0.1

Note:

If you use NetworkManager's dnsmasq or systemd-resolved plugin or openresolv subscribers, then do not specify loopback addresses with the servers= option, it can break DNS resolution.

The specified servers do not get sent to systemd-resolved, the connection's DNS servers are used instead.

Setting custom DNS servers in a connection

Setting custom DNS servers in a connection (GUI)

Setup will depend on the type of front-end used; the process usually involves right-clicking on the applet, editing (or creating) a profile, and then choosing DHCP type as Automatic (specify addresses). The DNS addresses will need to be entered and are usually in this form: 127.0.0.1, DNS-server-one, ....

Setting custom DNS servers in a connection (nmcli / connection file)

To setup DNS Servers per connection, you can use the dns field (and the associated dns-search and dns-options) in the connection settings.

If method is set to auto (when you use DHCP), you need to set ignore-auto-dns to yes.

/etc/resolv.conf

NetworkManager's /etc/resolv.conf management mode is configured with the main.rc-manager setting. networkmanager sets it to symlink as opposed to the upstream default auto. The setting and its values are documented in the NetworkManager.conf(5) man page.

Tip: Using openresolv allows NetworkManager to coexist with other resolvconf supporting software or, for example, to run a local DNS caching and split-DNS resolver for which openresolv has a subscriber. Note that conditional forwarding is not yet fully supported when using NetworkManager with openresolv.

NetworkManager also offers hooks via so called dispatcher scripts that can be used to alter the /etc/resolv.conf after network changes. See #Network services with NetworkManager dispatcher and NetworkManager(8) for more information.

Note:

If NetworkManager is configured to use either dnsmasq or systemd-resolved, then the appropriate loopback addresses will be written to /etc/resolv.conf.

The resolv.conf file NetworkManager writes or would write to /etc/resolv.conf can be found at /run/NetworkManager/resolv.conf.

A resolv.conf file with the acquired name servers and search domains can be found at /run/NetworkManager/no-stub-resolv.conf.

Unmanaged /etc/resolv.conf

To stop NetworkManager from touching /etc/resolv.conf, set main.dns=none with a configuration file in /etc/NetworkManager/conf.d/:

/etc/NetworkManager/conf.d/dns.conf

[main]

dns=none

Tip: You might also want to set main.systemd-resolved=false, so that NetworkManager does not send the DNS configuration to systemd-resolved.

Note: See #DNS caching and conditional forwarding, to configure NetworkManager using other DNS backends like dnsmasq and systemd-resolved, instead of using main.dns=none.

After that /etc/resolv.conf might be a broken symlink that you will need to remove. Then, just create a new /etc/resolv.conf file.

Use openresolv

Note: NetworkManager does not support using systemd-resolved's resolvconf interface (resolvectl(1) § COMPATIBILITY WITH RESOLVCONF(8)) which is provided by systemd-resolvconf.

Do not set main.rc-manager=resolvconf when using systemd-resolved, instead make sure to correctly create the /etc/resolv.conf symlink or configure NetworkManager to use systemd-resolved explicitly.

Make sure the systemd-resolvconf package is not installed when systemd-resolved is not used. Unless systemd-resolved.service started, it will break all networking software (not just NetworkManager) that use resolvconf.

To configure NetworkManager to use openresolv, set main.rc-manager=resolvconf with a configuration file in /etc/NetworkManager/conf.d/:

/etc/NetworkManager/conf.d/rc-manager.conf

[main]

rc-manager=resolvconf

Firewall

You can assign a firewalld zone based on your current connection. For example a restrictive firewall when at work, and a less restrictive one when at home.

This can also be done with NetworkManager dispatcher.

Network services with NetworkManager dispatcher

There are quite a few network services that you will not want running until NetworkManager brings up an interface. NetworkManager has the ability to start services when you connect to a network and stop them when you disconnect (e.g. when using NFS, SMB and NTPd).

To activate the feature you need to enable and start the NetworkManager-dispatcher.service.

Once the service is active, scripts can be added to the /etc/NetworkManager/dispatcher.d directory.

Scripts must be owned by root, otherwise the dispatcher will not execute them. For added security, set group ownership to root as well:

# chown root:root /etc/NetworkManager/dispatcher.d/10-script.sh

Make sure the file is executable.

The scripts will be run in alphabetical order at connection time, and in reverse alphabetical order at disconnect time. To ensure what order they come up in, it is common to use numerical characters prior to the name of the script (e.g. 10-portmap or 30-netfs (which ensures that the portmapper is up before NFS mounts are attempted).

Scripts will receive the following arguments:

Interface name: e.g. eth0

Action: up, down, vpn-up, vpn-down, ... (see NetworkManager-dispatcher(8) for the complete list)

Warning: If you connect to foreign or public networks, be aware of what services you are starting and what servers you expect to be available for them to connect to. You could make a security hole by starting the wrong services while connected to a public network.

Avoiding the dispatcher timeout

If the above is working, then this section is not relevant. However, there is a general problem related to running dispatcher scripts which take longer to be executed. Initially an internal timeout of three seconds only was used. If the called script did not complete in time, it was killed. Later the timeout was extended to about 20 seconds (see the Bugtracker for more information). If the timeout still creates the problem, a work around may be to use a drop-in file for the NetworkManager-dispatcher.service to remain active after exit:

/etc/systemd/system/NetworkManager-dispatcher.service.d/remain_after_exit.conf

[Service]

RemainAfterExit=yes

Now start and enable the modified NetworkManager-dispatcher service.

Warning: Adding the RemainAfterExit line to it will prevent the dispatcher from closing. Unfortunately, the dispatcher has to close before it can run your scripts again. With it the dispatcher will not time out but it also will not close, which means that the scripts will only run once per boot. Therefore, do not add the line unless the timeout is definitely causing a problem.

Dispatcher examples

Mount remote directory with sshfs

As the script is run in a very restrictive environment, you have to export SSH_AUTH_SOCK in order to connect to your SSH agent. There are different ways to accomplish this, see this message for more information. The example below works with GNOME Keyring, and will ask you for the password if not unlocked already. In case NetworkManager connects automatically on login, it is likely gnome-keyring has not yet started and the export will fail (hence the sleep). The UUID to match can be found with the command nmcli connection status or nmcli connection list.

#!/bin/sh

USER='username'

REMOTE='user@host:/remote/path'

LOCAL='/local/path'

interface=$1 status=$2

if [ "$CONNECTION_UUID" = "uuid" ]; then

case $status in

up)

# sleep 10

SSH_AUTH_SOCK=$(find /tmp -maxdepth 1 -type s -user "$USER" -name 'ssh')

export SSH_AUTH_SOCK

su "$USER" -c "sshfs $REMOTE $LOCAL"

 ;;

down)

fusermount -u "$LOCAL"

 ;;

esac

fi

Mounting of SMB shares

Some SMB shares are only available on certain networks or locations (e.g. at home). You can use the dispatcher to only mount SMB shares that are present at your current location.

The following script will check if we connected to a specific network and mount shares accordingly:

/etc/NetworkManager/dispatcher.d/30-mount-smb.sh

#!/bin/sh

# Find the connection UUID with "nmcli connection show" in terminal.

# All NetworkManager connection types are supported: wireless, VPN, wired...

if [ "$2" = "up" ]; then

if [ "$CONNECTION_UUID" = "uuid" ]; then

mount /your/mount/point &

# add more shares as needed

fi

fi

The following script will unmount all SMB shares before a software initiated disconnect from a specific network:

/etc/NetworkManager/dispatcher.d/pre-down.d/30-umount-smb.sh

#!/bin/sh

if [ "$CONNECTION_UUID" = "uuid" ]; then

umount -a -l -t cifs

fi

Note: Make sure this script is located in the pre-down.d sub-directory as shown above, otherwise it will unmount all shares on any connection state change.

The following script will attempt to unmount all SMB shares following an unexpected disconnect from a specific network:

/etc/NetworkManager/dispatcher.d/40-umount-smb.sh

#!/bin/sh

if [ "$CONNECTION_UUID" = "uuid" ]; then

if [ "$2" = "down" ]; then

umount -a -l -t cifs

fi

fi

Note:

Since NetworkManager 0.9.8, the pre-down and down events are not executed on shutdown or restart, see this bug report for more info.

The previous umount scripts are still prone to leaving applications actually accessing the mount to 'hang'.

An alternative is to use the script as seen in NFS#Using a NetworkManager dispatcher:

/etc/NetworkManager/dispatcher.d/30-smb.sh

#!/bin/sh

# Find the connection UUID with "nmcli con show" in terminal.

# All NetworkManager connection types are supported: wireless, VPN, wired...

WANTED_CON_UUID="CHANGE-ME-NOW-9c7eff15-010a-4b1c-a786-9b4efa218ba9"

if [ "$CONNECTION_UUID" = "$WANTED_CON_UUID" ]; then

# Script parameter $1: network interface name, not used

# Script parameter $2: dispatched event

case "$2" in

"up")

mount -a -t cifs

 ;;

"down"|"pre-down"|"vpn-pre-down")

umount -l -a -t cifs >/dev/null

 ;;

esac

fi

Note: This script ignores mounts with the noauto option, remove this mount option or use auto to allow the dispatcher to manage these mounts.

Create a symlink inside /etc/NetworkManager/dispatcher.d/pre-down/ to catch the pre-down events:

# ln -s ../30-smb.sh /etc/NetworkManager/dispatcher.d/pre-down.d/30-smb.sh

Mounting of NFS shares

See NFS#Using a NetworkManager dispatcher.

Use dispatcher to automatically toggle wireless depending on LAN cable being plugged in

The idea is to only turn Wi-Fi on when the LAN cable is unplugged (for example when detaching from a laptop dock), and for Wi-Fi to be automatically disabled, once a LAN cable is plugged in again.

Create the following dispatcher script[7], replacing LAN_interface with yours.

Note that there is a fail-safe for the case when the LAN interface was connected when the computer was last on, and then disconnected while the computer was off. That would mean the radio would still be off when the computer is turned back on, and with a disconnected LAN interface, you would have no network.

/etc/NetworkManager/dispatcher.d/wlan_auto_toggle.sh

#!/bin/sh

if [ "$1" = "LAN_interface" ]; then

case "$2" in

up)

nmcli radio wifi off

 ;;

down)

nmcli radio wifi on

 ;;

esac

elif [ "$(nmcli -g GENERAL.STATE device show LAN_interface)" = "20 (unavailable)" ]; then

nmcli radio wifi on

fi

Note: You can get a list of interfaces using nmcli. The Ethernet (LAN) interfaces start with en, e.g. enp0s5

Use dispatcher to connect to a VPN after a network connection is established

In this example we want to connect automatically to a previously defined VPN connection after connecting to a specific Wi-Fi network. First thing to do is to create the dispatcher script that defines what to do after we are connected to the network.

Note: This script will require wireless_tools in order to use iwgetid.

/etc/NetworkManager/dispatcher.d/vpn-up

#!/bin/sh

VPN_NAME="name of VPN connection defined in NetworkManager"

ESSID="Wi-Fi network ESSID (not connection name)"

interface=$1 status=$2

case $status in

up|vpn-down)

if iwgetid | grep -qs ":\"$ESSID\""; then

nmcli connection up id "$VPN_NAME"

fi

 ;;

down)

if iwgetid | grep -qs ":\"$ESSID\""; then

if nmcli connection show --active | grep "$VPN_NAME"; then

nmcli connection down id "$VPN_NAME"

fi

fi

 ;;

esac

If you would like to attempt to automatically connect to VPN for all Wi-Fi networks, you can use the following definition of the ESSID: ESSID=$(iwgetid -r). Remember to set the script's permissions accordingly.

Trying to connect with the above script may still fail with NetworkManager-dispatcher.service complaining about 'no valid VPN secrets', because of the way VPN secrets are stored. Fortunately, there are different options to give the above script access to your VPN password.

1: One of them requires editing the VPN connection configuration file to make NetworkManager store the secrets by itself rather than inside a keyring that will be inaccessible for root: open up /etc/NetworkManager/system-connections/name of your VPN connection and change the password-flags and secret-flags from 1 to 0.

If that alone does not work, you may have to create a passwd-file in a safe location with the same permissions and ownership as the dispatcher script, containing the following:

/path/to/passwd-file

vpn.secrets.password:YOUR_PASSWORD

The script must be changed accordingly, so that it gets the password from the file:

/etc/NetworkManager/dispatcher.d/vpn-up

#!/bin/sh

VPN_NAME="name of VPN connection defined in NetworkManager"

ESSID="Wi-Fi network ESSID (not connection name)"

interface=$1 status=$2

case $status in

up|vpn-down)

if iwgetid | grep -qs ":\"$ESSID\""; then

nmcli connection up id "$VPN_NAME" passwd-file /path/to/passwd-file

fi

 ;;

down)

if iwgetid | grep -qs ":\"$ESSID\""; then

if nmcli connection show --active | grep "$VPN_NAME"; then

nmcli connection down id "$VPN_NAME"

fi

fi

 ;;

esac

2: Alternatively, change the password-flags and put the password directly in the configuration file adding the section vpn-secrets:

[vpn]

....

password-flags=0

[vpn-secrets]

password=your_password

Note: It may now be necessary to re-open the NetworkManager connection editor and save the VPN passwords/secrets again.

Use dispatcher to disable IPv6 on VPN provider connections

Many commercial VPN providers support only IPv4. That means all IPv6 traffic bypasses the VPN and renders it virtually useless. To avoid this, dispatcher can be used to disable all IPv6 traffic for the time a VPN connection is up.

/etc/NetworkManager/dispatcher.d/10-vpn-ipv6

#!/bin/sh

case "$2" in

vpn-up)

echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6

;;

vpn-down)

echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6

;;

esac

As an alternative, dispatcher can be used to temporarily set the IPv6 mode of the device used by the VPN connection to link-local. This will avoid NetworkManager log spam about IPv6 being disabled. This script will not work if multiple devices or connections provide IPv6 connectivity, but could be adapted to iterate over multiple devices. Note that any change to the connection (using nmcli(1) or a desktop environment) will reapply the entire connection to the device and re-enable IPv6 (if it is enabled in the connection).

/etc/NetworkManager/dispatcher.d/10-vpn-ipv6

#!/bin/sh

case "$2" in

vpn-up)

nmcli device modify "${DEVICE_IFACE}" ipv6.method link-local

;;

vpn-down)

nmcli device reapply "${DEVICE_IFACE}"

;;

esac

OpenNTPD

See OpenNTPD#Using NetworkManager dispatcher.

Dynamically set NTP servers received via DHCP with systemd-timesyncd

When roaming between different networks (e.g. a company's LAN, WiFi at home, various other WiFi now and then) you might want to set the NTP server(s) used by timesyncd to those provided by DHCP. However, NetworkManager itself is not capable to communicate with systemd-timesyncd to set the NTP server(s).

The dispatcher can work around it.

Create the overlay directory for your systemd-timesyncd configuration /etc/systemd/timesyncd.conf.d if it does not already exist. Inside /etc/NetworkManager/dispatcher.d, put the following:

/etc/NetworkManager/dispatcher.d/10-update-timesyncd

#!/bin/sh

[ -z "$CONNECTION_UUID" ] && exit 0

INTERFACE="$1"

ACTION="$2"

case $ACTION in

up | dhcp4-change | dhcp6-change)

[ -n "$DHCP4_NTP_SERVERS" ] || exit 0

mkdir -p /etc/systemd/timesyncd.conf.d

cat <<-THE_END >"/etc/systemd/timesyncd.conf.d/${CONNECTION_UUID}.conf"

[Time]

NTP=$DHCP4_NTP_SERVERS

THE_END

systemctl restart systemd-timesyncd.service

;;

down)

rm -f "/etc/systemd/timesyncd.conf.d/${CONNECTION_UUID}.conf"

systemctl restart systemd-timesyncd.service

;;

esac

Every time NetworkManager sets up a new network connection (ACTION=up) or gets some update for an existing connection (ACTION=dhcp4-change or ACTION=dhcp6-change) and the provided connection data contains information about NTP server(s) (DHCP4_NTP_SERVERS), a connection specific overlay configuration file is written to /etc/systemd/timesyncd.conf.d, containing the provided NTP server(s). Whenever a connection is taken down (ACTION=down) the connection specific overlay file is removed. After each change to the configuration of systemd-timesyncd, this service is restarted to pick up the updated configuration. The use of connection specific configuration files is intentional so that when two or more connections are managed by NetworkManager in parallel the different NTP server names in the configuration are not overwritten as up, dhcp4-change, dhcp6-change and down actions might come in in an arbitrary order.

Testing

NetworkManager applets are designed to load upon login so no further configuration should be necessary for most users. If you have already disabled your previous network settings and disconnected from your network, you can now test if NetworkManager will work. The first step is to start NetworkManager.service.

Some applets will provide you with a .desktop file so that the NetworkManager applet can be loaded through the application menu. If it does not, you are going to either have to discover the command to use or logout and login again to start the applet. Once the applet is started, it will likely begin polling network connections with for auto-configuration with a DHCP server.

To start the GNOME applet in non-xdg-compliant window managers like awesome:

nm-applet --sm-disable &

For static IP addresses, you will have to configure NetworkManager to understand them. The process usually involves right-clicking the applet and selecting something like 'Edit Connections'.

Tips and tricks

Encrypted Wi-Fi passwords

By default, NetworkManager stores passwords in clear text in the connection files at /etc/NetworkManager/system-connections/. To print the stored passwords, use the following command:

# grep -r '^psk=' /etc/NetworkManager/system-connections/

The passwords are accessible to the root user in the filesystem and to users with access to settings via the GUI (e.g. nm-applet).

It is preferable to save the passwords in encrypted form in a keyring instead of clear text. The downside to this is that the connections have to be set up for each user.

In order to read and write to the keyring, there must be a secret agent available. This can be one of:

nmcli with the --ask option

One of the graphical interfaces from #Front-ends

If you make neither of these available, then authentication will fail with the error no secrets: No agents were available for this request.

Using GNOME Keyring

The keyring daemon has to be started and the keyring needs to be unlocked for the following to work.

Furthermore, NetworkManager needs to be configured not to store the password for all users. Using GNOME's network-manager-applet, run nm-connection-editor from a terminal, select a network connection, click Edit, select the Wi-Fi Security tab and click on the right icon of password and check Store the password only for this user.

Using KDE Wallet

Using KDE's plasma-nm, click the applet, click on the top right Settings icon, click on a network connection, in the General configuration tab, untick All users may connect to this network. If the option is ticked, the passwords will still be stored in clear text, even if a keyring daemon is running.

If the option was selected previously and you un-tick it, you may have to use the reset option first to make the password disappear from the file. Alternatively, delete the connection first and set it up again.

Sharing internet connection over Wi-Fi

You can share your internet connection (e.g. 3G or wired) with a few clicks. Please note that a firewall may interfere with internet sharing.

You will need a Wi-Fi card which supports AP mode, see Software access point#Wi-Fi device must support AP mode for details.

Install the dnsmasq package to be able to actually share the connection. Note that NetworkManager starts its own instance of dnsmasq, independent of dnsmasq.service, as a DHCP server. See #dnsmasq for the caveats.

Create the shared connection:

Click on applet and choose Create new wireless network.

Follow wizard (choose WPA2 or higher, be sure to use at least 8 character long password, lower lengths will fail).

Choose either Hotspot or Ad-hoc as Wi-Fi mode.

The connection will be saved and remain stored for the next time you need it.

Note: Android does not support connecting to Ad-hoc networks. To share a connection with Android use infrastructure mode (i.e. set Wi-Fi mode to "Hotspot").

Sharing internet connection over Ethernet

Scenario: your device has internet connection over Wi-Fi and you want to share the internet connection to other devices over Ethernet.

Requirements:

Install the dnsmasq and nm-connection-editor packages to be able to actually share the connection. Note that NetworkManager starts its own instance of dnsmasq, independent of dnsmasq.service, as a DHCP server. See #dnsmasq for the caveats.

Your internet connected device and the other devices are connected over a suitable Ethernet cable (this usually means a cross over cable or a switch in between).

Internet sharing is not blocked by a firewall.

Steps:

Run nm-connection-editor from terminal.

Add a new Ethernet connection.

Give it some sensible name. For example "Shared Internet"

Go to "IPv4 Settings".

For "Method:" select "Shared to other computers".

Save

Now you should have a new option "Shared Internet" under the Wired connections in NetworkManager.

Checking if networking is up inside a cron job or script

This article or section is out of date.

Reason: nm-tool was remove from NetworkManager for long time now[8]. nmcli should be used instead. (Discuss in Talk:NetworkManager)

Some cron jobs require networking to be up to succeed. You may wish to avoid running these jobs when the network is down. To accomplish this, add an if test for networking that queries NetworkManager's nm-tool and checks the state of networking. The test shown here succeeds if any interface is up, and fails if they are all down. This is convenient for laptops that might be hardwired, might be on wireless, or might be off the network.

if [ $(nm-tool|grep State|cut -f2 -d' ') == "connected" ]; then

#Whatever you want to do if the network is online

else

#Whatever you want to do if the network is offline - note, this and the else above are optional

fi

This is useful for a cron.hourly script that runs fpupdate for the F-Prot virus scanner signature update, as an example. Another way it might be useful, with a little modification, is to differentiate between networks using various parts of the output from nm-tool; for example, since the active wireless network is denoted with an asterisk, you could grep for the network name and then grep for a literal asterisk.

Connect to network with secret on boot

By default, NetworkManager will not connect to networks requiring a secret automatically on boot. This is because it locks such connections to the user who makes it by default, only connecting after they have logged in. To change this, do the following:

Right click on the nm-applet icon in your panel and select Edit Connections and open the Wireless tab

Select the connection you want to work with and click the Edit button

Check the boxes “Connect Automatically” and “Available to all users”

Additionally, ensure that under "Wi-Fi Security", "Store password for all users (not encrypted)" is selected

Log out and log back in to complete.

OpenConnect with password in KWallet

While you may type both values at connection time, plasma-nm 0.9.3.2-1 and above are capable of retrieving OpenConnect username and password directly from KWallet.

Open "KDE Wallet Manager" and look up your OpenConnect VPN connection under "Network Management|Maps". Click "Show values" and

enter your credentials in key "VpnSecrets" in this form (replace username and password accordingly):

form:main:username%SEP%username%SEP%form:main:password%SEP%password

Next time you connect, username and password should appear in the "VPN secrets" dialog box.

Ignore specific devices

Sometimes it may be desired that NetworkManager ignores specific devices and does not try to configure addresses and routes for them. You can quickly and easily ignore devices by MAC or interface-name by using the following in /etc/NetworkManager/conf.d/unmanaged.conf:

[keyfile]

unmanaged-devices=mac:00:22:68:1c:59:b1;mac:00:1E:65:30:D1:C4;interface-name:eth0

After editing the file, run nmcli general reload as root. Afterwards you should be able to configure interfaces without NetworkManager altering what you have set.

Configuring MAC address randomization

Note: Disabling MAC address randomization may be needed to get (stable) link connection [9] and/or networks that restrict devices based on their MAC Address or have a limit network capacity.

MAC randomization can be used for increased privacy by not disclosing your real MAC address to the network.

NetworkManager supports two types MAC Address Randomization: randomization during scanning, and for network connections. Both modes can be configured by modifying /etc/NetworkManager/NetworkManager.conf or by creating a separate configuration file in /etc/NetworkManager/conf.d/ which is recommended since the aforementioned configuration file may be overwritten by NetworkManager.

Randomization during Wi-Fi scanning is enabled by default, but it may be disabled by adding the following lines to /etc/NetworkManager/NetworkManager.conf or a dedicated configuration file under /etc/NetworkManager/conf.d:

/etc/NetworkManager/conf.d/wifi_rand_mac.conf

[device]

wifi.scan-rand-mac-address=no

MAC randomization for network connections can be set to different modes for both wireless and ethernet interfaces. See the GNOME blog post for more details on the different modes.

In terms of MAC randomization the most important modes are stable and random. stable generates a random MAC address when you connect to a new network and associates the two permanently. This means that you will use the same MAC address every time you connect to that network. In contrast, random will generate a new MAC address every time you connect to a network, new or previously known. You can configure the MAC randomization by adding the desired configuration under /etc/NetworkManager/conf.d:

/etc/NetworkManager/conf.d/wifi_rand_mac.conf

[device-mac-randomization]

# "yes" is already the default for scanning

wifi.scan-rand-mac-address=yes

[connection-mac-randomization]

# Randomize MAC for every ethernet connection

ethernet.cloned-mac-address=random

# Generate a random MAC for each WiFi and associate the two permanently.

wifi.cloned-mac-address=stable

See the following GNOME blog post for more details.

Enable IPv6 Privacy Extensions

See IPv6#NetworkManager.

Configure a unique DUID per connection

The DHCPv6 Unique Identifier (DUID) is a value used by the DHCPv6 client to identify itself to DHCPv6 servers. NetworkManager supports 3 types of DUID:

DUID-UUID (RFC 6355): generated from an Universally Unique IDentifier (UUID).

DUID-LL (RFC 3315): generated from the Link-Layer address (aka MAC address).

DUID-LLT (RFC 3315): generated from the Link-Layer address plus a timestamp.

If the internal NetworkManager's DHCP client is in use (the default) it will identify itself with a global and permanent DUID-UUID generated from the machine-id (/etc/machine-id). This means that all connections share the same UUID, which may be a privacy breach.

Fortunately, NetworkManager is able to provide unique DUIDs per connection, derived from the connection's stable-id and a per-host unique key. You can enable that by adding the following configuration under /etc/NetworkManager/conf.d:

/etc/NetworkManager/conf.d/duid.conf

[connection]

ipv6.dhcp-duid=stable-uuid

The stable-ll and stable-llt values are also supported. For further information read the description for dhcp-duid in nm-settings(5) § ipv6 setting.

Working with wired connections

By default, NetworkManager generates a connection profile for each wired ethernet connection it finds. At the point when generating the connection, it does not know whether there will be more Ethernet adapters available. Hence, it calls the first wired connection "Wired connection 1". You can avoid generating this connection, by configuring no-auto-default (see NetworkManager.conf(5)), or by simply deleting it. Then NetworkManager will remember not to generate a connection for this interface again.

You can also edit the connection (and persist it to disk) or delete it. NetworkManager will not re-generate a new connection. Then you can change the name to whatever you want. You can use something like nm-connection-editor for this task.

Using iwd as the Wi-Fi backend

Note:

Do not enable iwd.service or manually configure iwd. NetworkManager will start and manage it itself.

Consider existing issues before switching to iwd.

To enable the experimental iwd backend, first install iwd and then create the following configuration file:

/etc/NetworkManager/conf.d/wifi_backend.conf

[device]

wifi.backend=iwd

Alternatively, you can install networkmanager-iwdAUR, a modified package configured to build NetworkManager working exclusively with iwd, with the main difference being that iwd is required and wpa_supplicant can be uninstalled after building.

Note: You may need to convert existing NetworkManager network profiles after switching to iwd.

Running in a network namespace

If you would like to run NetworkManager inside a network namespace (e.g., to manage a specific device which should be use by selected applications), bring the device down before moving it to the namespace:

$ ip link set dev MY_DEVICE down

$ ip link set dev MY_DEVICE netns MY_NAMESPACE

$ ip netns exec MY_NAMESPACE NetworkManager

...

$ ip netns exec MY_NAMESPACE killall NetworkManager

otherwise NetworkManager will later fail to establish the connection with a device is strictly unmanaged error.

Automatically connect to VPN

NetworkManager can be set to automatically connect to a VPN when connecting to the internet, on a per network basis. The VPN connection itself can be added in GNOME's NetworkManager front-end, but to make it automatically use the VPN nmcli must be used. Other front-ends might not have this limitation.

First, make sure to make the VPN connection available to all users. In the GNOME this is a matter of checking a box under the details tab. Under the Identity tab, in the password field, click the icon on the right side in the field, and set it to Store the password for all users.

Then find the UUID of the VPN connection, and add that to connection.secondaries of the Internet connection:

# UUID=$(nmcli --get-values connection.uuid connection show name-of-VPN-connection)

# nmcli connection modify name-of-Internet-connection connection.secondaries "$UUID"

Now when NetworkManager is restarted and you connect to the Internet connection you have configured, you should automatically get connected to the VPN.

Troubleshooting

No prompt for password of secured Wi-Fi networks

When trying to connect to a secured Wi-Fi network, no prompt for a password is shown and no connection is established. This happens when no keyring package is installed. An easy solution is to install gnome-keyring. If you want the passwords to be stored in encrypted form, follow GNOME Keyring to set up the gnome-keyring-daemon.

Network management disabled

When NetworkManager shuts down but the pid (state) file is not removed, you will see a Network management disabled message. If this happens, remove the file manually:

# rm /var/lib/NetworkManager/NetworkManager.state

Problems with internal DHCP client

If you have problems with getting an IP address using the internal DHCP client, consider using another DHCP client, see #DHCP client for instructions. This workaround might solve problems in big wireless networks like eduroam.

DHCP problems with dhclient

If you have problems with getting an IP address via DHCP, try to add the following to your /etc/dhclient.conf:

interface "eth0" {

send dhcp-client-identifier 01:aa:bb:cc:dd:ee:ff;

}

Where aa:bb:cc:dd:ee:ff is the MAC address of this NIC. The MAC address can be found using the ip link show interface command from the iproute2 package.

3G modem not detected

See Mobile broadband modem#NetworkManager.

Switching off WLAN on laptops

Sometimes NetworkManager will not work when you disable your Wi-Fi adapter with a switch on your laptop and try to enable it again afterwards. This is often a problem with rfkill. To check if the driver notifies rfkill about the wireless adapter's status, use:

$ watch -n1 rfkill list all

If one identifier stays blocked after you switch on the adapter you could try to manually unblock it with (where X is the number of the identifier provided by the above output):

# rfkill event unblock X

Static IP address settings revert to DHCP

This article or section is out of date.

Reason: This section is added in 2010 and describes an ancient version of nm-applet. Is this still relevant in 2024? (Discuss in Talk:NetworkManager)

Due to an unresolved bug, when changing default connections to a static IP address, nm-applet may not properly store the configuration change, and will revert to automatic DHCP.

To work around this issue you have to edit the default connection (e.g. "Auto eth0") in nm-applet, change the connection name (e.g. "my eth0"), uncheck the "Available to all users" checkbox, change your static IP address settings as desired, and click Apply. This will save a new connection with the given name.

Next, you will want to make the default connection not connect automatically. To do so, run nm-connection-editor (not as root). In the connection editor, edit the default connection (e.g. "Auto eth0") and uncheck "Connect automatically". Click Apply and close the connection editor.

Cannot edit connections as normal user

See #Set up PolicyKit permissions.

Forget hidden wireless network

Since hidden networks are not displayed in the selection list of the Wireless view, they cannot be forgotten (removed) with the GUI. You can delete one with the following command:

# rm /etc/NetworkManager/system-connections/SSID

This also works for any other connection.

VPN not working in GNOME

When setting up OpenConnect or vpnc connections in NetworkManager while using GNOME, you will sometimes never see the dialog box pop up and the following error appears in /var/log/errors.log:

localhost NetworkManager[399]: [1361719690.10506] [nm-vpn-connection.c:1405] get_secrets_cb(): Failed to request VPN secrets #3: (6) No agents were available for this request.

This is caused by the GNOME NetworkManager Applet expecting dialog scripts to be at /usr/lib/gnome-shell, when NetworkManager's packages put them in /usr/lib/networkmanager.

As a "temporary" fix (this bug has been around for a while now), make the following symlink(s):

For OpenConnect: ln -s /usr/lib/networkmanager/nm-openconnect-auth-dialog /usr/lib/gnome-shell/

For VPNC (i.e. Cisco VPN): ln -s /usr/lib/networkmanager/nm-vpnc-auth-dialog /usr/lib/gnome-shell/

This may need to be done for any other NetworkManager VPN plugins as well, but these are the two most common.

Unable to connect to visible European wireless networks

WLAN chips are shipped with a default regulatory domain. If your access point does not operate within these limitations, you will not be able to connect to the network. Fixing this is easy:

Install wireless-regdb.

Uncomment the correct country code in /etc/conf.d/wireless-regdom.

Reboot the system, because the setting is only read on boot.

Automatic connect to VPN on boot is not working

The problem occurs when the system (i.e. NetworkManager running as the root user) tries to establish a VPN connection, but the password is not accessible because it is stored in the GNOME Keyring of a particular user.

A solution is to keep the password to your VPN in plaintext, as described in step (2.) of #Use dispatcher to connect to a VPN after a network connection is established.

You do not need to use the dispatcher described in step (1.) to auto-connect anymore, if you use the new "auto-connect VPN" option from the nm-applet GUI.

Systemd Bottleneck

Over time the log files (/var/log/journal) can become very large. This can have a big impact on boot performance when using NetworkManager, see: Systemd#Boot time increasing over time.

Regular network disconnects, latency and lost packets (WiFi)

NetworkManager does a scan every 2 minutes.

Some WiFi drivers have issues when scanning for base stations whilst connected/associated. Symptoms include VPN disconnects/reconnects and lost packets, web pages failing to load and then refresh fine.

Running journalctl -f as root will indicate that this is taking place, messages like the following will be contained in the logs at regular intervals.

NetworkManager[410]: (wlp3s0): roamed from BSSID 00:14:48:11:20:CF (my-wifi-name) to (none) ((none))

If roaming is not important, the periodic scanning behavior can be disabled by locking the BSSID of the access point in the WiFi connection profile.

Unable to turn on Wi-Fi with Lenovo laptop (IdeaPad, Legion, etc.)

There is an issue with the ideapad_laptop module on some Lenovo models due to the Wi-Fi driver incorrectly reporting a soft block. The card can still be manipulated with netctl, but managers like NetworkManager break. You can verify that this is the problem by checking the output of rfkill list after toggling your hardware switch and seeing that the soft block persists.

The factual accuracy of this article or section is disputed.

Reason: Try to use rfkill.default_state and rfkill.master_switch_mode (see kernel-parameters.html) to fix the rfkill problem. (Discuss in Talk:NetworkManager)

Unloading the ideapad_laptop module should fix this. (warning: this may disable the laptop keyboard and touchpad also!).

Turn off hostname sending

NetworkManager by default sends the hostname to the DHCP server. Hostname sending can only be disabled per connection not globally (Issue #584).

To disable sending your hostname to the DHCP server for a specific connection, add the following to your network connection file:

/etc/NetworkManager/system-connections/your_connection_file

...

[ipv4]

dhcp-send-hostname=false

...

[ipv6]

dhcp-send-hostname=false

...

nm-applet disappears in i3wm

If you use the xfce4-notifyd.service for notifications you must edit the unit and add the following:

/etc/systemd/user/xfce4-notifyd.service.d/display_env.conf

[Service]

Environment="DISPLAY=:0.0"

After reloading the daemons restart xfce4-notifyd.service. Exit i3 and start it back up again and the applet should show on the tray.

Unit dbus-org.freedesktop.resolve1.service not found

If systemd-resolved.service is not started, NetworkManager will try to start it using D-Bus and fail:

dbus-daemon[991]: [system] Activating via systemd: service name='org.freedesktop.resolve1' unit='dbus-org.freedesktop.resolve1.service' requested by ':1.23' (uid=0 pid=1012 comm="/usr/bin/NetworkManager --no-daemon ")

dbus-daemon[991]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.resolve1.service': Unit dbus-org.freedesktop.resolve1.service not found.

dbus-daemon[991]: [system] Activating via systemd: service name='org.freedesktop.resolve1' unit='dbus-org.freedesktop.resolve1.service' requested by ':1.23' (uid=0 pid=1012 comm="/usr/bin/NetworkManager --no-daemon ")

This is because NetworkManager will try to send DNS information to systemd-resolved regardless of the main.dns= setting in NetworkManager.conf(5).[10]

This can be disabled with a configuration file in /etc/NetworkManager/conf.d/:

/etc/NetworkManager/conf.d/no-systemd-resolved.conf

[main]

systemd-resolved=false

See FS#62138.

Secrets were required, but not provided

If you received the following error when attempting to connect to a network:

$ nmcli device wifi connect SSID password password

Error: Connection activation failed: (7) Secrets were required, but not provided

This error can have numerous causes and you should read the journal (filter it with -u NetworkManager). For example, if NetworkManager took too long to establish connection, it will believe that the password is incorrect:

NetworkManager[1372]: [1643991888.3808] device (wlan0): Activation: (wifi) association took too long

NetworkManager[1372]: [1643991888.3809] device (wlan0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')

NetworkManager[1372]: [1643991888.3838] device (wlan0): Activation: (wifi) asking for new secrets

You can try deleting the connection profile and creating a new one:

$ nmcli connection delete SSID

$ nmcli device wifi connect SSID password password

You can also try disabling MAC address randomization:

/etc/NetworkManager/conf.d/wifi_rand_mac.conf

[device]

wifi.scan-rand-mac-address=no

WPA Enterprise connection with iwd

If you try to connect to an WPA Enterprise network like 'eduroam' with NetworkManager with the iwd backend then you will get the following error from NetworkManager:

Connection 'eduroam' is not avialable on device wlan0 because profile is not compatible with device (802.1x connections must have IWD provisioning files)

This is because NetworkManager can not configure a WPA Enterprise network. Therefore you have to configure it using an iwd configuration file /var/lib/iwd/essid.8021x like described in iwd#WPA Enterprise.

Failed to request VPN secrets

If you get this error:

Failed to request VPN secrets #1: No agents were available for this request.

It is either because the password is empty or you have to set up PolicyKit permissions.

OpenVPN connections fail with OpenSSL "ca md too weak" error

Since openssl was updated to version 3, certificates generated with legacy cryptographic algorithms are rejected by default. Attempting to use networkmanager-openvpn with such a setup can result in the following error in the logs:

nm-openvpn[14359]: OpenSSL: error:0A00018E:SSL routines::ca md too weak

nm-openvpn[14359]: Cannot load certificate file /home/archie/.local/share/networkmanagement/certificates/my_issued_cert.crt

nm-openvpn[14359]: Exiting due to fatal error

The correct approach is to have the OpenVPN server administrator generate and re-issue more secure certificates. However, as an immediate work-around, OpenVPN requires tls-cipher "DEFAULT:@SECLEVEL=0". This may not be possible through the plugin GUI, but it is possible with nmcli. Separately, you will also need to enable the legacy provider in OpenSSL.

Firstly, obtain the name of the VPN connection with the issue, from the output of the following:

$ nmcli connection show

Assuming the connection name is vpn.example.com, use nmcli like so:

$ nmcli connection modify vpn.example.com +vpn.data tls-cipher=DEFAULT:@SECLEVEL=0

The change should instantly be reflected in /etc/NetworkManager/system-connections/vpn.example.com.nmconnection.

As for OpenSSL, edit /etc/ssl/openssl.cnf as described on the OpenSSL wiki.

Specifically, at the end of the [provider_sect] section add legacy = legacy_sect. Under [default_sect] uncomment activate = 1. Lastly, add a new section [legacy_sect] that also contains the line activate = 1. Excluding most other preexisting configuration sections, the end result will look something like:

/etc/ssl/openssl.cnf

openssl_conf = openssl_init

[openssl_init]

providers = provider_sect

[provider_sect]

default = default_sect

legacy = legacy_sect

[default_sect]

activate = 1

[legacy_sect]

activate = 1

Finally, restart the NetworkManager.service to have the new OpenSSL configuration take effect.

WPA Enterprise connections fail to authenticate with OpenSSL "unsupported protocol" error

Since openssl was updated to version 3, "SSL 3, TLS 1.0, TLS 1.1, and DTLS 1.0 only work at security level 0" by default. Attempting to authenticate to a WiFi only supporting lower standards result in the following error in the logs:

wpa_supplicant[3320]: SSL: SSL3 alert: write (local SSL3 detected an error):fatal:protocol version

wpa_supplicant[3320]: OpenSSL: openssl_handshake - SSL_connect error:0A000102:SSL routines::unsupported protocol

wpa_supplicant[3320]: wlp3s0: CTRL-EVENT-EAP-FAILURE EAP authentication failed

The correct approach is to have the WiFi administrator support TLS 1.3 and optionally dropping support for low security standard including TLS 1.0/1.1, DTLS 1.0, SSL 1-3. However, as an immediate work-around, there are multiple ways to allow TLS 1.0 by default. One way would be to manually patch or revert the breaking change in OpenSSL ([11]). As this also lowers security for all other programs using OpenSSL level 1, it is not recommended. Instead, one can directly set the level used by wpa_supplicant, like described in BBS#286417. To only change the affected connection, it is possible to set phase1-auth-flags=32 in the [802-1x] section of the connection. This may not be possible through GUIs, but it is possible with nmcli.

Firstly, obtain the name of the WiFi connection with the issue, from the output of the following:

$ nmcli connection show

Assuming the connection name is Example WiFi, use nmcli like so:

$ nmcli connection modify Example\ WiFi 802-1x.phase1-auth-flags 32

The change should instantly be reflected in /etc/NetworkManager/system-connections/Example\ WiFi.nmconnection.

Finally, restart the NetworkManager.service to have the new OpenSSL configuration take effect.

See also

NetworkManager for Administrators Part 1

Wikipedia:NetworkManager

NetworkManager official website

Retrieved from "https://wiki.archlinux.org/index.php?title=NetworkManager&oldid=798334"

Categories: Network managersRed HatDHCPHidden categories: Pages or sections flagged with Template:MergePages or sections flagged with Template:StylePages or sections flagged with Template:AccuracyPages or sections flagged with Template:ExpansionPages or sections flagged with Template:Out of date

This page was last edited on 26 January 2024, at 14:12.

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.

Privacy policy

About ArchWiki

Disclaimers

Toggle limited content width

GitHub - khoih-prog/Ethernet_Manager: Simple Ethernet Manager for Teensy, SAM DUE, SAMD21, SAMD51, nRF52, ESP32, ESP8266, etc. boards, with or without SSL, configuration data saved in ESP8266 LittleFS, SPIFFS, nRF52 LittleFS/InternalFS, EEPROM, DueFlashStorage or SAMD FlashStorage.

GitHub - khoih-prog/Ethernet_Manager: Simple Ethernet Manager for Teensy, SAM DUE, SAMD21, SAMD51, nRF52, ESP32, ESP8266, etc. boards, with or without SSL, configuration data saved in ESP8266 LittleFS, SPIFFS, nRF52 LittleFS/InternalFS, EEPROM, DueFlashStorage or SAMD FlashStorage.

Skip to content

Toggle navigation

Sign in

Product

Actions

Automate any workflow

Packages

Host and manage packages

Security

Find and fix vulnerabilities

Codespaces

Instant dev environments

Copilot

Write better code with AI

Code review

Manage code changes

Issues

Plan and track work

Discussions

Collaborate outside of code

Explore

All features

Documentation

GitHub Skills

Blog

Solutions

For

Enterprise

Teams

Startups

Education

By Solution

CI/CD & Automation

DevOps

DevSecOps

Resources

Learning Pathways

White papers, Ebooks, Webinars

Customer Stories

Partners

Open Source

GitHub Sponsors

Fund open source developers

The ReadME Project

GitHub community articles

Repositories

Topics

Trending

Collections

Pricing

Search or jump to...

Search code, repositories, users, issues, pull requests...

Search

Clear

Search syntax tips

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Cancel

Submit feedback

Saved searches

Use saved searches to filter your results more quickly

Name

Query

To see all available qualifiers, see our documentation.

Cancel

Create saved search

Sign in

Sign up

You signed in with another tab or window. Reload to refresh your session.

You signed out in another tab or window. Reload to refresh your session.

You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

khoih-prog

/

Ethernet_Manager

Public archive

Notifications

Fork

4

Star

15

Simple Ethernet Manager for Teensy, SAM DUE, SAMD21, SAMD51, nRF52, ESP32, ESP8266, etc. boards, with or without SSL, configuration data saved in ESP8266 LittleFS, SPIFFS, nRF52 LittleFS/InternalFS, EEPROM, DueFlashStorage or SAMD FlashStorage.

License

MIT license

15

stars

4

forks

Branches

Tags

Activity

Star

Notifications

Code

Issues

0

Pull requests

0

Discussions

Actions

Projects

0

Security

Insights

Additional navigation options

Code

Issues

Pull requests

Discussions

Actions

Projects

Security

Insights

khoih-prog/Ethernet_Manager

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

 mainBranchesTagsGo to fileCodeFolders and filesNameNameLast commit messageLast commit dateLatest commit History122 Commits.github.github  LibraryPatchesLibraryPatches  Packages_PatchesPackages_Patches  examplesexamples  picspics  platformioplatformio  srcsrc  utilsutils  .codespellrc.codespellrc  .gitignore.gitignore  CONTRIBUTING.mdCONTRIBUTING.md  LICENSELICENSE  README.mdREADME.md  changelog.mdchangelog.md  keywords.txtkeywords.txt  library.jsonlibrary.json  library.propertieslibrary.properties  View all filesRepository files navigationREADMEMIT licenseEthernet_Manager Library

Table of Contents

Important Notes about Nano_RP2040_Connect

Why do we need this Ethernet_Manager library

Features

Currently supported Boards

Currently supported Ethernet shields/modules

Changelog

Prerequisites

Installation

Use Arduino Library Manager

Manual Install

VS Code & PlatformIO

Packages' Patches

1. For Adafruit nRF52840 and nRF52832 boards

2. For Teensy boards

3. For Arduino SAM DUE boards

4. For Arduino SAMD boards

For core version v1.8.10+

For core version v1.8.9-

5. For Adafruit SAMD boards

6. For Seeeduino SAMD boards

7. For STM32 boards

7.1. For STM32 boards to use LAN8720

7.2. For STM32 boards to use Serial1

8. For RP2040-based boards using Earle Philhower arduino-pico core

8.1. To use BOARD_NAME

8.2. To avoid compile error relating to microsecondsToClockCycles

9. For Portenta_H7 boards using Arduino IDE in Linux

10. For RTL8720DN boards using AmebaD core

11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core

12. For Seeeduino RP2040 boards

13. For Seeeduino nRF52840 boards

Libraries' Patches

1. For application requiring 2K+ HTML page

2. For Ethernet library

3. For EthernetLarge library

4. For Etherne2 library

5. For Ethernet3 library

6. For UIPEthernet library

7. For fixing ESP32 compile error

Note for Platform IO using ESP32 LittleFS

HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)

1. ESP32 has 2 ADCs, named ADC1 and ADC2

2. ESP32 ADCs functions

3. ESP32 WiFi uses ADC2 for WiFi functions

Important Notes

1. Using hpp files

2. Note for Adafruit nRF52

3. Note for Adafruit SAMD21 and SAMD51

4. Note for Arduino SAM DUE

5. Note for RP2040-based boards

6. Note for MBED RP2040-based boards

7. Note for MBED RP2040-based boards LittleFS usage. Important

Configuration Notes

1. How to select which built-in Ethernet or shield to use

2. How to select another CS/SS pin to use

3. How to use W5x00/ENC28J60 with ESP32

4. How to use W5x00/ENC28J60 with ESP8266

5. How to increase W5x00 TX/RX buffer

6. How to use SPI2 for ESP32 using W5x00 and Ethernet_Generic Library

7. How to use SPI1 for RP2040 using W5x00 and Ethernet_Generic Library

Not supported Libraries

How to use default Credentials and have them pre-loaded onto Config Portal

How to use

1. Basic usage

2. Add custom parameters

3. Not using custom parameters

4. To open Config Portal

5. To use custom HTML Style

6. To use custom Head Elements

7. To use CORS Header

Important Notes for using Dynamic Parameters' ids

Examples

1. AM2315_Ethernet

2. Ethernet_Generic

3. Ethernet_nRF52

4. Ethernet_RP2040. New

5. Ethernet_SAMD

6. Ethernet_SAM_DUE

7. Ethernet_Teensy

8. Ethernet_WT32_ETH01. New

9. MQTT_ThingStream_Ethernet_Generic

10. MQTT_ThingStream_Ethernet_nRF52

11. MQTT_ThingStream_Ethernet_RP2040. New

12. MQTT_ThingStream_Ethernet_SAMD

13. MQTT_ThingStream_Ethernet_SAM_DUE

14. MQTT_ThingStream_Ethernet_Teensy

15. MQTT_ThingStream_Ethernet_WT32_ETH01. New

16. QNEthernet_Teensy. New

17. MQTT_ThingStream_QNEthernet_Teensy. New

So, how it works?

Example Ethernet_Generic

1. File Ethernet_Generic.ino

2. File defines.h

3. File Credentials.h

4. File dynamicParams.h

Debug Terminal Output Samples

1. Ethernet_nRF52 on NRF52840_FEATHER_EXPRESS with W5500 using Ethernet_Generic Library

1.1 Normal run

1.2. DoubleResetDetected

1.3. Config Portal started

1.4. Credentials entered and Saved

2. Ethernet_SAMD on SeeedStudio SAMD21 SEEED_XIAO_M0 with W5500 using Ethernet_Generic Library

3. Ethernet_SAM_DUE on Arduino SAM DUE with W5100 using Ethernet_Generic Library

4. MQTT_ThingStream_Ethernet_Generic on ESP8266_NODEMCU with W5x00 using Ethernet_Generic Library

4.1. Normal run without correct ThingStream MQTT Credentials

4.2. Got correct ThingStream MQTT Credentials from Config Portal

5. MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER with ENC28J60 using EthernetENC Library

5.1. Normal run without correct ThingStream MQTT Credentials

5.2. Got correct ThingStream MQTT Credentials from Config Portal

6. MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

6.1. Normal run without correct ThingStream MQTT Credentials or DRD

6.2. Got correct ThingStream MQTT Credentials from Config Portal

7. Ethernet_RP2040 on MBED RASPBERRY_PI_PICO with W5500 using Ethernet_Generic Library

7.1. DRD => Config Portal

7.2. Data Saved => Exit Config Portal

8. MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01

8.1. Normal run with correct ThingStream MQTT Credentials

9. QNEthernet_Teensy on TEENSY 4.1 using QNEthernet

Debug

Troubleshooting

Issues

TO DO

DONE

Contributions and Thanks

Contributing

License

Copyright

Important Notes about Nano_RP2040_Connect

The LittleFS of the new Nano_RP2040_Connect board ( see New board ), using ISSI Flash chip, is currently not working with Arduino mbed_rp2040 core 2.4.1+. Please downgrade to Arduino mbed_rp2040 core 2.3.1

Check RP2040 Connect board has faulty components in newest purchase #318 for more information of when and how the issue will be fixed.

The old board ( see Old board ), using Adesto Flash chip, is currently working with Arduino mbed_rp2040 core 2.4.1+.

Why do we need this Ethernet_Manager library

Features

This is the new library, adding to the current WiFiManager sets of libraries. It's designed to help you eliminate hardcoding your Credentials in Teensy, SAM DUE, SAMD21, SAMD51, nRF52,RP2040-based, etc. boards using Ethernet shields (W5100, W5200, W5500, ENC28J60, Teensy 4.1 NativeEthernet/QNEthernet, etc). It's currently not supporting SSL. Will support soon.

It's not supporting UNO/Nano/Mega and other AVR boards for not enough memory.

You can update Credentials any time you need to change via Configure Portal. Data are saved in configurable locations in EEPROM, DueFlashStorage or FlashStorage

Teensy LC, 2.0++ and 2.0 not supported.

DoubleDetectDetector feature to force Config Portal when double reset is detected within predetermined time, default 10s.

Configurable Config Portal Title to be either BoardName or default undistinguishable names.

Examples are redesigned to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device

The RP2040-based boards, such as Nano RP2040 Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, CYTRON_MAKER_PI_RP2040, SPARKFUN_PROMICRO_RP2040, CHALLENGER_2040_WIFI_RP2040, CHALLENGER_2040_LTE_RP2040, MELOPERO_SHAKE_RP2040, UPESY_RP2040_DEVKIT, etc., are currently supported using Earle Philhower's arduino-pico core or Arduino mbed OS for RP2040/Nano boards.

New recent features:

DoubleDetectDetector feature to force Config Portal when double reset is detected within predetermined time, default 10s.

Configurable Config Portal Title to be either BoardName or default undistinguishable names.

Examples are redesigned to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device

Auto detect ESP32 core and use either built-in LittleFS or LITTLEFS library for ESP32 and WT32-ETH01.

Currently Supported Boards

This Ethernet_Manager library currently supports these following boards:

nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc.

SAM DUE

SAMD21

Arduino SAMD21: ZERO, MKRs, NANO_33_IOT, etc.

Adafruit SAMD21 (M0): ItsyBitsy M0, Feather M0, Feather M0 Express, Metro M0 Express, Circuit Playground Express, Trinket M0, PIRkey, Hallowing M0, Crickit M0, etc.

Seeeduino: LoRaWAN, Zero, Femto M0, XIAO M0, Wio GPS Board, etc.

SAMD21E1xA, SAMD21G1xA and SAMD21J1xA

SAMD51

Adafruit SAMD51 (M4): Metro M4, Grand Central M4, ItsyBitsy M4, Feather M4 Express, Trellis M4, Metro M4 AirLift Lite, MONSTER M4SK Express, Hallowing M4, etc.

Seeeduino: Wio Terminal, Grove UI Wireless

Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0, LC)

ESP32 including ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.)

ESP8266

RP2040-based boards, such as Nano RP2040 Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, ADAFRUIT_ITSYBITSY_RP2040, ADAFRUIT_QTPY_RP2040, ADAFRUIT_STEMMAFRIEND_RP2040, ADAFRUIT_TRINKEYQT_RP2040, ADAFRUIT_MACROPAD_RP2040, CYTRON_MAKER_PI_RP2040, SPARKFUN_PROMICRO_RP2040, CHALLENGER_2040_WIFI_RP2040, CHALLENGER_2040_LTE_RP2040, MELOPERO_SHAKE_RP2040, UPESY_RP2040_DEVKIT, etc., using Earle Philhower's arduino-pico core.

RP2040-based boards, such as Nano RP2040 Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Arduino-mbed RP2040 core

WT32_ETH01 boards using ESP32-based boards and LAN8720 Ethernet

Supported Ethernet shields/modules:

W5x00 using Ethernet_Generic library

ENC28J60 using EthernetENC or UIPEthernet library

Teensy 4.1 built-in Ethernet using NativeEthernet library

LAN8720 Ethernet used in WT32_ETH01 boards

Teensy 4.1 built-in Ethernet using QNEthernet library

Prerequisites

Arduino IDE 1.8.19+ for Arduino.

Arduino AVR core 1.8.6+ for Arduino (Use Arduino Board Manager) AVR boards.

Teensy core v1.57+ for Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards.

Arduino SAM DUE core v1.6.12+ for SAM DUE ARM Cortex-M3 boards.

Arduino SAMD core 1.8.13+ for SAMD ARM Cortex-M0+ boards.

Adafruit SAMD core 1.7.11+ for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.).

Seeeduino SAMD core 1.8.3+ for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.).

Adafruit nRF52 v1.3.0+ for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, NINA_B302_ublox, etc.

ESP32 Core 2.0.5+ for ESP32-based boards.

ESP8266 Core 3.0.2+ for ESP8266-based boards. . To use ESP8266 core 2.7.1+ for LittleFS.

ArduinoCore-mbed mbed_rp2040, mbed_nano, mbed_portenta core 3.4.1+ for Arduino (Use Arduino Board Manager) Portenta_H7, RP2040-based boards, such as Nano_RP2040_Connect, RASPBERRY_PI_PICO.

Earle Philhower's arduino-pico core v2.6.3+ for RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, etc.

Functional-Vlpp library v1.0.2+ to use server's lambda function. To install. check

Depending on which Ethernet card you're using:

Ethernet_Generic library v2.7.1+ for W5100, W5200 and W5500/WIZ550io/WIZ850io/USR-ES1 with Wiznet W5500 chip.

EthernetENC library v2.0.3+ for ENC28J60. . New and Better

UIPEthernet library v2.0.12+ for ENC28J60.

NativeEthernet Library version stable111+ for Teensy 4.1 built-in Ethernet.

QNEthernet Library version v0.16.0+ for Teensy 4.1 built-in Ethernet. New

Depending on which board you're using:

DueFlashStorage library v1.0.0+ for SAM DUE. To install, check

FlashStorage_SAMD library v1.3.2+ for SAMD21 and SAMD51 boards (ZERO, MKR, NANO_33_IOT, M0, M0 Pro, AdaFruit Itsy-Bitsy M4, etc.).

Adafruit's LittleFS/InternalFS for nRF52

EthernetWebServer library v2.3.0+. To install. check .

WebServer_WT32_ETH01 library v1.5.1+ for WT32_ETH01 boards. To install. check .

ESP_DoubleResetDetector library v1.3.2+ for ESP32 and ESP8266. To install. check .

DoubleResetDetector_Generic library v1.8.1+ for other boards (not ESP32 or ESP8266). To install. check .

LittleFS_esp32 v1.0.6+ for ESP32-based boards using LittleFS with ESP32 core v1.0.5-. To install, check . Notice: This LittleFS_esp32 library has been integrated to Arduino ESP32 core v1.0.6+ and you don't need to install it if using ESP32 core v1.0.6+

Installation

The suggested way to install is to:

Use Arduino Library Manager

The best way is to use Arduino Library Manager. Search for Ethernet_Manager, then select / install the latest version. You can also use this link for more detailed instructions.

Manual Install

Navigate to Ethernet_Manager page.

Download the latest release Ethernet_Manager-main.zip.

Extract the zip file to Ethernet_Manager-main directory

Copy the whole Ethernet_Manager-main folder to Arduino libraries' directory such as ~/Arduino/libraries/.

VS Code & PlatformIO

Install VS Code

Install PlatformIO

Install Ethernet_Manager library by using Library Manager. Search for Ethernet_Manager in Platform.io Author's Libraries

Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File

Packages' Patches

1. For Adafruit nRF52840 and nRF52832 boards

To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards, you have to copy the whole nRF52 Packages_Patches directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0).

Supposing the Adafruit nRF52 version is 1.3.0. These files must be copied into the directory:

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/platform.txt

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/boards.txt

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/cores/nRF5/Udp.h

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/cores/nRF5/Print.h

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/cores/nRF5/Print.cpp

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B302_ublox/variant.h

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B302_ublox/variant.cpp

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B112_ublox/variant.h

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/variants/NINA_B112_ublox/variant.cpp

~/.arduino15/packages/adafruit/hardware/nrf52/1.3.0/cores/nRF5/Udp.h

Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z

These files must be copied into the directory:

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/platform.txt

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/boards.txt

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Print.h

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Print.cpp

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.h

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.cpp

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.h

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.cpp

~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h

2. For Teensy boards

To be able to compile and run on Teensy boards, you have to copy the files in Packages_Patches for Teensy directory into Teensy hardware directory (./arduino-1.8.19/hardware/teensy/avr/boards.txt).

Supposing the Arduino version is 1.8.19. These files must be copied into the directory:

./arduino-1.8.19/hardware/teensy/avr/boards.txt

./arduino-1.8.19/hardware/teensy/avr/cores/teensy/Stream.h

./arduino-1.8.19/hardware/teensy/avr/cores/teensy3/Stream.h

./arduino-1.8.19/hardware/teensy/avr/cores/teensy4/Stream.h

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

These files must be copied into the directory:

./arduino-x.yy.zz/hardware/teensy/avr/boards.txt

./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy/Stream.h

./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy3/Stream.h

./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.h

3. For Arduino SAM DUE boards

To be able to compile and run on SAM DUE boards, you have to copy the whole SAM DUE directory into Arduino sam directory (~/.arduino15/packages/arduino/hardware/sam/1.6.12).

Supposing the Arduino SAM core version is 1.6.12. This file must be copied into the directory:

~/.arduino15/packages/arduino/hardware/sam/1.6.12/platform.txt

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

~/.arduino15/packages/arduino/hardware/sam/x.yy.zz/platform.txt

4. For Arduino SAMD boards

To be able to compile, run and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards, you have to copy the whole Arduino SAMD Packages_Patches directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.13).

For core version v1.8.10+

Supposing the Arduino SAMD version is 1.8.13. Now only one file must be copied into the directory:

~/.arduino15/packages/arduino/hardware/samd/1.8.13/platform.txt

Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

~/.arduino15/packages/arduino/hardware/samd/x.yy.zz/platform.txt

For core version v1.8.9-

Supposing the Arduino SAMD version is 1.8.9. These files must be copied into the directory:

~/.arduino15/packages/arduino/hardware/samd/1.8.9/platform.txt

~/.arduino15/packages/arduino/hardware/samd/1.8.9/cores/arduino/Arduino.h

Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z

These files must be copied into the directory:

~/.arduino15/packages/arduino/hardware/samd/x.yy.z/platform.txt

~/.arduino15/packages/arduino/hardware/samd/x.yy.z/cores/arduino/Arduino.h

This is mandatory to fix the notorious Arduino SAMD compiler error. See Improve Arduino compatibility with the STL (min and max macro)

...\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2

min(const _Tp& __a, const _Tp& __b, _Compare __comp)

Whenever the above-mentioned compiler error issue is fixed with the new Arduino SAMD release, you don't need to copy the Arduino.h file anymore.

5. For Adafruit SAMD boards

To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards, you have to copy the whole Adafruit SAMD Packages_Patches directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.11).

Supposing the Adafruit SAMD core version is 1.7.11. These files must be copied into the directory:

~/.arduino15/packages/adafruit/hardware/samd/1.7.11/platform.txt

~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.h

~/.arduino15/packages/adafruit/hardware/samd/1.7.11/cores/arduino/Print.cpp

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

These files must be copied into the directory:

~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt

~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.h

~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.cpp

6. For Seeeduino SAMD boards

To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards, you have to copy the whole Seeeduino SAMD Packages_Patches directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3).

Supposing the Seeeduino SAMD core version is 1.8.3. These files must be copied into the directory:

~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/platform.txt

~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Arduino.h

~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.h

~/.arduino15/packages/Seeeduino/hardware/samd/1.8.3/cores/arduino/Print.cpp

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

These files must be copied into the directory:

~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/platform.txt

~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Arduino.h

~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Print.h

~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Print.cpp

7. For STM32 boards

7.1 For STM32 boards to use LAN8720

To use LAN8720 on some STM32 boards

Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)

Discovery (DISCO_F746NG)

STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)

you have to copy the files stm32f4xx_hal_conf_default.h and stm32f7xx_hal_conf_default.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system) to overwrite the old files.

Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory:

~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h for STM32F4.

~/.arduino15/packages/STM32/hardware/stm32/2.3.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h for Nucleo-144 STM32F7.

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz,

these files must be copied into the corresponding directory:

~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F4xx/stm32f4xx_hal_conf_default.h

`~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F7xx/stm32f7xx_hal_conf_default.h

7.2 For STM32 boards to use Serial1

To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards, you have to copy the files STM32 variant.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.3.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.

Supposing the STM32 stm32 core version is 2.3.0. These files must be copied into the directory:

~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h for Nucleo-144 NUCLEO_F767ZI.

~/.arduino15/packages/STM32/hardware/stm32/2.3.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h for Nucleo-64 NUCLEO_L053R8.

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz,

these files must be copied into the corresponding directory:

~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h

~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h

8. For RP2040-based boards using Earle Philhower arduino-pico core

8.1 To use BOARD_NAME

To be able to automatically detect and display BOARD_NAME on RP2040-based boards (RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc) boards, you have to copy the file RP2040 platform.txt into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).

Supposing the rp2040 core version is 1.4.0. This file must be copied into the directory:

~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0/platform.txt

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

~/.arduino15/packages/rp2040/hardware/rp2040/x.yy.zz/platform.txt

With core after v1.5.0, this step is not necessary anymore thanks to the PR Add -DBOARD_NAME="{build.board}" #136.

8.2 To avoid compile error relating to microsecondsToClockCycles

Some libraries, such as Adafruit DHT-sensor-library, require the definition of microsecondsToClockCycles(). To be able to compile and run on RP2040-based boards, you have to copy the files in RP2040 Arduino.h into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).

Supposing the rp2040 core version is 1.4.0. This file must be copied to replace:

~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0/cores/rp2040/Arduino.h

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

This file must be copied to replace:

~/.arduino15/packages/rp2040/hardware/rp2040/x.yy.zz/cores/rp2040/Arduino.h

With core after v1.5.0, this step is not necessary anymore thanks to the PR Add defs for compatibility #142.

9. For Portenta_H7 boards using Arduino IDE in Linux

To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.), you have to copy the file portenta_post_install.sh into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh).

Then run the following command using sudo

$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1

$ chmod 755 portenta_post_install.sh

$ sudo ./portenta_post_install.sh

This will create the file /etc/udev/rules.d/49-portenta_h7.rules as follows:

# Portenta H7 bootloader mode UDEV rules

SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"

Supposing the ArduinoCore-mbed core version is 3.4.1. Now only one file must be copied into the directory:

~/.arduino15/packages/arduino/hardware/mbed_portenta/3.4.1/portenta_post_install.sh

Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh

10. For RTL8720DN boards using AmebaD core

To avoid compile error relating to PROGMEM, you have to copy the file Realtek AmebaD core pgmspace.h into Realtek AmebaD directory (~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h).

Supposing the Realtek AmebaD core version is 3.1.4. This file must be copied into the directory:

~/.arduino15/packages/realtek/hardware/AmebaD/3.1.4/cores/ambd/avr/pgmspace.h

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

~/.arduino15/packages/realtek/hardware/AmebaD/x.yy.zz/cores/ambd/avr/pgmspace.h

11. For SAMD21 and SAMD51 boards using ArduinoCore-fab-sam core

To avoid compile error relating to SAMD21/SAMD51, you have to copy the file ArduinoCore-fab-sam core pgmspace.h into ArduinoCore-fab-sam samd directory (~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt).

Supposing the ArduinoCore-fab-sam samd core version is 1.9.0. This file must be copied into the directory:

~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/1.9.0/boards.txt

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

This file must be copied into the directory:

~/.arduino15/packages/Fab_SAM_Arduino/hardware/samd/x.yy.zz/boards.txt

12. For Seeeduino RP2040 boards

To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino RP2040 (XIAO RP2040, Wio RP2040 Mini) boards, you have to copy the whole Seeeduino RP2040 Packages_Patches directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2).

Supposing the Seeeduino RP2040 core version is 2.7.2. These files must be copied into the directory:

~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2/boards.txt

~/.arduino15/packages/Seeeduino/hardware/rp2040/2.7.2/variants/Seeed_XIAO_RP2040/pins_arduino.h

Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz

These files must be copied into the directory:

~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/boards.txt

~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/variants/Seeed_XIAO_RP2040/pins_arduino.h

13. For Seeeduino nRF52840 boards

To be able to compile and run on Xiao nRF52840 boards, you have to copy the whole nRF52 1.0.0 directory into Seeeduino nRF52 directory (~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0).

Supposing the Seeeduino nRF52 version is 1.0.0. These files must be copied into the directory:

~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/platform.txt

~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.h

~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Print.cpp

~/.arduino15/packages/Seeeduino/hardware/nrf52/1.0.0/cores/nRF5/Udp.h

Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z

These files must be copied into the directory:

~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/platform.txt

~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.h

~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Print.cpp

~/.arduino15/packages/Seeeduino/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h

Libraries' Patches

1. For application requiring 2K+ HTML page

If your application requires 2K+ HTML page, the current Ethernet library must be modified if you are using W5200/W5500 Ethernet shields. W5100 is not supported for 2K+ buffer. If you use boards requiring different CS/SS pin for W5x00 Ethernet shield, for example ESP32, ESP8266, nRF52, etc., you also have to modify the following libraries to be able to specify the CS/SS pin correctly.

2. For Ethernet library

To fix Ethernet library, just copy these following files into the Ethernet library directory to overwrite the old files:

Ethernet.h

Ethernet.cpp

EthernetServer.cpp

w5100.h

w5100.cpp

3. For EthernetLarge library

To fix EthernetLarge library, just copy these following files into the EthernetLarge library directory to overwrite the old files:

EthernetLarge.h

EthernetLarge.cpp

EthernetServer.cpp

w5100.h

w5100.cpp

4. For Ethernet2 library

To fix Ethernet2 library, just copy these following files into the Ethernet2 library directory to overwrite the old files:

Ethernet2.h

Ethernet2.cpp

To add UDP Multicast support, necessary for the UPnP_Generic library:

EthernetUdp2.h

EthernetUdp2.cpp

5. For Ethernet3 library

To fix Ethernet3 library, just copy these following files into the Ethernet3 library directory to overwrite the old files:

Ethernet3.h

Ethernet3.cpp

6. For UIPEthernet library

To be able to compile and run on nRF52 boards with ENC28J60 using UIPEthernet library, you have to copy these following files into the UIPEthernet utility directory to overwrite the old files:

UIPEthernet.h

UIPEthernet.cpp

Enc28J60Network.h

Enc28J60Network.cpp

7. For fixing ESP32 compile error

To fix ESP32 compile error, just copy the following file into the ESP32 cores/esp32 directory (e.g. ./arduino-1.8.12/hardware/espressif/cores/esp32) to overwrite the old file:

Server.h

Note for Platform IO using ESP32 LittleFS

In Platform IO, to fix the error when using LittleFS_esp32 v1.0 for ESP32-based boards with ESP32 core v1.0.4- (ESP-IDF v3.2-), uncomment the following line

from

//#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */

to

#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */

It's advisable to use the latest LittleFS_esp32 v1.0.6+ to avoid the issue.

Thanks to Roshan to report the issue in Error esp_littlefs.c 'utime_p'

HOWTO Use analogRead() with ESP32 running WiFi and/or BlueTooth (BT/BLE)

Please have a look at ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to have more detailed description and solution of the issue.

1. ESP32 has 2 ADCs, named ADC1 and ADC2

2. ESP32 ADCs functions

ADC1 controls ADC function for pins GPIO32-GPIO39

ADC2 controls ADC function for pins GPIO0, 2, 4, 12-15, 25-27

3.. ESP32 WiFi uses ADC2 for WiFi functions

Look in file adc_common.c

In ADC2, there're two locks used for different cases:

lock shared with app and Wi-Fi:

ESP32:

When Wi-Fi using the ADC2, we assume it will never stop, so app checks the lock and returns immediately if failed.

ESP32S2:

The controller's control over the ADC is determined by the arbiter. There is no need to control by lock.

lock shared between tasks:

when several tasks sharing the ADC2, we want to guarantee

all the requests will be handled.

Since conversions are short (about 31us), app returns the lock very soon,

we use a spinlock to stand there waiting to do conversions one by one.

adc2_spinlock should be acquired first, then adc2_wifi_lock or rtc_spinlock.

In order to use ADC2 for other functions, we have to acquire complicated firmware locks and very difficult to do

So, it's not advisable to use ADC2 with WiFi/BlueTooth (BT/BLE).

Use ADC1, and pins GPIO32-GPIO39

If somehow it's a must to use those pins serviced by ADC2 (GPIO0, 2, 4, 12, 13, 14, 15, 25, 26 and 27), use the fix mentioned at the end of ESP_WiFiManager Issue 39: Not able to read analog port when using the autoconnect example to work with ESP32 WiFi/BlueTooth (BT/BLE).

Important Notes

1. Using hpp files

Code is restructured to provide flexibility to make it easy to support many more Ethernet modules/shields in the future. Please delete the *.cpp files, replaced by *.hpp files, in the src directory, if *.cpp files still exist after installing new version.

2. Note for Adafruit nRF52

For Adafruit nRF52, use the SPI's pins as follows:

SS/CS = 10

SPI_MOSI = MO(SI)

SPI_MISO = MI(SO)

SPI_SCK = SCK

3. Note for Adafruit SAMD21 and SAMD51

For Adafruit SAMD21/SAMD51, use the SPI's CS/SS pin as follows:

Itsy-Bitsy M0/M4, Feather M0 (Express), Hallowing M0 Express, Zero, Metro M0 => use CS = 16 = pin A2

Feather M4 (SAMD51) => use SS/CS = 9

Grand Central M4 => use SS/CS = 53

Hallowing M4 => use SS/CS = 10

Metro M4 AirLift => use SS/CS = 36

To know the default CS/SS pins of not listed boards, check the related variant.h files in

~/.arduino15/packages/adafruit/hardware/samd/x.y.zz/variants/board_name/variant.h

4. Note for Arduino SAM DUE

For Arduino SAM DUE, use the SPI's pins as follows:

- SS/CS = 10

- SPI_MOSI = 75 ( pin 4 @ [ICSP connector](pics/ICSP_connector.jpg) )

- SPI_MISO = 74 ( pin 1 @ [ICSP connector](pics/ICSP_connector.jpg) )

- SPI_SCK = 76 ( pin 3 @ [ICSP connector](pics/ICSP_connector.jpg) )

5. Note for RP2040-based boards

For RP2040-based boards, such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Earle Philhower's arduino-pico core, use the SPI's pins as follows:

- SS/CS = 17

- SPI_MOSI = 19

- SPI_MISO = 16

- SPI_SCK = 18

6. Note for MBED RP2040-based boards

For RP2040-based boards, such as Nano RP2040 Connect, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Arduino mbed OS for RP2040/Nano boards, use the SPI's pins as follows:

- SS/CS = 5

- SPI_MOSI = 3

- SPI_MISO = 4

- SPI_SCK = 2

7. Note for MBED RP2040-based boards LittleFS usage

Currently, the MBED RP2040-based boards share the LittleFS usage and settings with the DoubleResetDetector_Generic Library. Check the LittleFS definitions at DoubleResetDetector_Generic.h#L196-L204

#if !defined(RP2040_FS_SIZE_KB)

// Using default 16KB for LittleFS

#define RP2040_FS_SIZE_KB (64)

#endif

#if !defined(RP2040_FS_START)

#define RP2040_FS_START (RP2040_FLASH_SIZE - (RP2040_FS_SIZE_KB * 1024))

#endif

FlashIAPBlockDevice bd(XIP_BASE + RP2040_FS_START, (RP2040_FS_SIZE_KB * 1024));

You can change the LittleFS size from default 64KB to any size (from 1KB to 1MB = 1024KB) by adding a definition in your code to override the default, such as

#define RP2040_FS_SIZE_KB (512)

Be sure to have the above definition before the first inclusion of Ethernet_Manager.h

#define RP2040_FS_SIZE_KB (512)

...

#include

The end of LittleFS is set at the end of RP2040 Flash, currently 2MB

#define RP2040_FS_START (RP2040_FLASH_SIZE - (RP2040_FS_SIZE_KB * 1024))

Configuration Notes

1. How to select which built-in Ethernet or shield to use

The easiest way is to use

#define USE_ETHERNET_WRAPPER true

then select one and only one Ethernet library to use as follows:

Standard W5x00 Ethernet_Generic library is used by default, in the sketch, just be sure to comment out or leave these #defines to be false :

// Only one if the following to be true

#define USE_UIP_ETHERNET false

#define USE_ETHERNET_PORTENTA_H7 false

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET false

#define USE_ETHERNET_GENERIC false

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET false

To use W5x00 Ethernet, for example using Ethernet_Generic library

// Only one if the following to be true

#define USE_UIP_ETHERNET false

#define USE_ETHERNET_PORTENTA_H7 false

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET false

#define USE_ETHERNET_GENERIC true

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET false

To use ENC28J60 Ethernet, using EthernetENC library (NEW and Better)

// Only one if the following to be true

#define USE_UIP_ETHERNET false

#define USE_ETHERNET_PORTENTA_H7 false

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET false

#define USE_ETHERNET_GENERIC false

#define USE_ETHERNET_ENC true

#define USE_CUSTOM_ETHERNET false

To use ENC28J60 Ethernet, using UIPEthernet library:

// Only one if the following to be true

#define USE_UIP_ETHERNET true

#define USE_ETHERNET_PORTENTA_H7 false

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET false

#define USE_ETHERNET_GENERIC false

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET false

To use another Ethernet library

For example, EthernetLarge library

// Only one if the following to be true

#define USE_UIP_ETHERNET false

#define USE_ETHERNET_PORTENTA_H7 false

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET false

#define USE_ETHERNET_GENERIC false

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET true

//Must be placed before #include

#include

...

#include

Only for Teensy 4.1, to use NativeEthernet library

#if defined(__IMXRT1062__)

// For Teensy 4.1/4.0

#if defined(ARDUINO_TEENSY41)

#define BOARD_TYPE "TEENSY 4.1"

// Use true for NativeEthernet Library, false if using other Ethernet libraries

#define USE_NATIVE_ETHERNET true

#define USE_QN_ETHERNET false

#elif defined(ARDUINO_TEENSY40)

#define BOARD_TYPE "TEENSY 4.0"

#else

#define BOARD_TYPE "TEENSY 4.x"

#endif

#elif defined(__MK66FX1M0__)

....

Only for Teensy 4.1, to use another Ethernet library, for example Ethernet_Generic library

#if defined(__IMXRT1062__)

// For Teensy 4.1/4.0

#if defined(ARDUINO_TEENSY41)

#define BOARD_TYPE "TEENSY 4.1"

// Use true for NativeEthernet Library, false if using other Ethernet libraries

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET false

#elif defined(ARDUINO_TEENSY40)

#define BOARD_TYPE "TEENSY 4.0"

#else

#define BOARD_TYPE "TEENSY 4.x"

#endif

#elif defined(__MK66FX1M0__)

....

#define USE_UIP_ETHERNET false

// Only one if the following to be true

#define USE_ETHERNET_GENERIC true

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET false

Only for Teensy 4.1, to use QNEthernet library

#if ( defined(CORE_TEENSY) && defined(__IMXRT1062__) && defined(ARDUINO_TEENSY41) )

// For Teensy 4.1

#define BOARD_TYPE "TEENSY 4.1"

// Use true for NativeEthernet Library, false if using other Ethernet libraries

#define USE_NATIVE_ETHERNET false

#define USE_QN_ETHERNET true

#else

#error Only Teensy 4.1 supported

#endif

#define USE_ETHERNET_WRAPPER false

// Use true for ENC28J60 and UIPEthernet library (https://github.com/UIPEthernet/UIPEthernet)

// Use false for W5x00 and Ethernetx library (https://www.arduino.cc/en/Reference/Ethernet)

#define USE_UIP_ETHERNET false

#define USE_ETHERNET_GENERIC false

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET false

#if USE_NATIVE_ETHERNET

#include "NativeEthernet.h"

#warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error

#define SHIELD_TYPE "using NativeEthernet"

#elif USE_QN_ETHERNET

#include "QNEthernet.h"

using namespace qindesign::network;

#warning Using QNEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error

#define SHIELD_TYPE "using QNEthernet"

#endif

2. How to select another CS/SS pin to use

The default CS/SS pin is GPIO4(D2) for ESP8266, GPIO22 for ESP32, 10 for all other boards.

If the default pin is not correct, the easiest way is to change is to select the CS/SS pin (e.g. 22) to use as follows:

// To override the default CS/SS pin. Don't use unless you know exactly which pin to use

#define USE_THIS_SS_PIN 22

3. How to use W5x00/ENC28J60 with ESP32

These pins are tested OK with ESP32 and W5x00/ENC28J60:

MOSI: GPIO23

MISO: GPIO19

SCK: GPIO18

CS/SS: GPIO22

#define PIN_D18 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32

#define PIN_D19 19 // Pin D19 mapped to pin GPIO19/VSPI_MISO of ESP32

#define PIN_D23 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32

// You can use Ethernet.init(pin) to configure the CS pin

//Ethernet.init(10); // Most Arduino shields

//Ethernet.init(5); // MKR ETH shield

//Ethernet.init(0); // Teensy 2.0

//Ethernet.init(20); // Teensy++ 2.0

//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet

//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet

// Connection for ESP32

// MOSI: GPIO23, MISO: GPIO19, SCK: GPIO18, CS/SS: GPIO22

#ifndef USE_THIS_SS_PIN

#define USING_M5STACK_W5500 false

#if USING_M5STACK_W5500

#warning Using M5Stack_Core_ESP32 with W5500 module

#define USE_THIS_SS_PIN 26 // For M5Stack_Core_ESP32 with W5500 module

#else

#define USE_THIS_SS_PIN 22 // For ESP32

#endif

#endif

4. How to use W5x00/ENC28J60 with ESP8266

To avoid using the default but not-working Ethernet library of ESP8266, rename the Ethernet.h/cpp to Ethernet_ESP8266.h/cpp to avoid library conflict if you're using the Arduino Ethernet library. The Ethernet_Generic library can be used without conflict.

These pins are tested OK with ESP8266 and W5x00/ENC28J60

MOSI: D7/GPIO13

MISO: D6/GPIO12

SCK: D5/GPIO14

CS/SS: D2/GPIO4

#define PIN_D5 14 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266

#define PIN_D6 12 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266

#define PIN_D7 13 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266

// Connection for ESP8266

// MOSI: D7/GPIO13, MISO: D6/GPIO12, SCK: D5/GPIO14, CS/SS: D2/GPIO4

// For ESP8266, change for other boards if necessary

#ifndef USE_THIS_SS_PIN

#define USE_THIS_SS_PIN D2 // For ESP8266

#endif

// For ESP8266

// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8

// Ethernet 0 X X X X 0

// Ethernet2 X X X X X 0

// Ethernet3 X X X X X 0

// EthernetLarge X X X X X 0

// Ethernet_ESP8266 0 0 0 0 0 0

// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs

// Must use library patch for Ethernet, EthernetLarge libraries

//Ethernet.setCsPin (USE_THIS_SS_PIN);

Ethernet.init (USE_THIS_SS_PIN);

5. How to increase W5x00 TX/RX buffer

For Ethernet_Generic library only, simply use as follows to have large buffer similar to EthernetLarge library

#define ETHERNET_LARGE_BUFFERS

For Ethernet3 library only, use as follows

// Use MAX_SOCK_NUM = 4 for 4K, 2 for 8K, 1 for 16K RX/TX buffer

#ifndef ETHERNET3_MAX_SOCK_NUM

#define ETHERNET3_MAX_SOCK_NUM 4

#endif

Ethernet.setCsPin (USE_THIS_SS_PIN);

Ethernet.init (ETHERNET3_MAX_SOCK_NUM);

6. How to use SPI2 for ESP32 using W5x00 and Ethernet_Generic Library

For Ethernet_Generic library only, to use SPI2 for ESP32

#define USING_SPI2 true

Pin to use for SPI2

MOSI: 13

MISO: 12

SCK: 14

SS: 5

7. How to use SPI1 for RP2040 using W5x00 and Ethernet_Generic Library

For Ethernet_Generic library only, to use SPI1 for RP2040 using arduino-pico core

#define USING_SPI2 true

Pin to use for SPI1

MOSI: 15

MISO: 12

SCK: 14

SS: 13

Not supported Libraries

The Ethernet_Shield_W5200, EtherCard, EtherSia libraries are not supported. Don't use unless you know how to modify those libraries.

Requests to support for any future custom Ethernet library will be ignored. Use at your own risk.

How to use default Credentials and have them pre-loaded onto Config Portal

See this example and modify as necessary

To load Default Credentials

bool LOAD_DEFAULT_CONFIG_DATA = true;

To use system default to load "blank" when there is no valid Credentials

bool LOAD_DEFAULT_CONFIG_DATA = false;

Example of Default Credentials

/// Start Default Config Data //////////////////

/*

typedef struct Configuration

{

char header [16];

char static_IP [16];

char board_name [24];

int checkSum;

} Ethernet_Configuration;

*/

#define TO_LOAD_DEFAULT_CONFIG_DATA true

#if TO_LOAD_DEFAULT_CONFIG_DATA

bool LOAD_DEFAULT_CONFIG_DATA = false;

Ethernet_Configuration defaultConfig =

{

//char header[16], dummy, not used

#if USE_SSL

"Eth_SSL",

#else

"Eth_NonSSL",

#endif

// char static_IP [16];

//"192.168.2.230",

// Use dynamic DHCP IP

"",

//char board_name [24];

"Air-Control",

// terminate the list

//int checkSum, dummy, not used

0

/////////// End Default Config Data /////////////

};

#else

bool LOAD_DEFAULT_CONFIG_DATA = false;

Ethernet_Configuration defaultConfig;

#endif // TO_LOAD_DEFAULT_CONFIG_DATA

/////////// End Default Config Data /////////////

How to use

1. Basic usage

Include in your sketch

// Must be before #include

#include

Ethernet_Manager ethernet_manager;

2. Add custom parameters

To add custom parameters, just add

#ifndef dynamicParams_h

#define dynamicParams_h

#include "defines.h"

// USE_DYNAMIC_PARAMETERS defined in defined.h

/////////////// Start dynamic Credentials ///////////////

/**************************************

#define MAX_ID_LEN 5

#define MAX_DISPLAY_NAME_LEN 16

typedef struct

{

char id [MAX_ID_LEN + 1];

char displayName [MAX_DISPLAY_NAME_LEN + 1];

char *pdata;

uint8_t maxlen;

} MenuItem;

**************************************/

#if USE_DYNAMIC_PARAMETERS

#define MAX_MQTT_SERVER_LEN 34

char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server";

#define MAX_MQTT_PORT_LEN 6

char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883";

#define MAX_MQTT_USERNAME_LEN 34

char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username";

#define MAX_MQTT_PW_LEN 34

char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password";

#define MAX_MQTT_SUBS_TOPIC_LEN 34

char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic";

#define MAX_MQTT_PUB_TOPIC_LEN 34

char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic";

MenuItem myMenuItems [] =

{

{ "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },

{ "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN },

{ "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN },

{ "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN },

{ "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN },

{ "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN },

};

uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;

#else

MenuItem myMenuItems [] = {};

uint16_t NUM_MENU_ITEMS = 0;

#endif

/////// // End dynamic Credentials ///////////

#endif //dynamicParams_h

3. Not using custom parameters

If you don't need to add dynamic parameters, use the following in sketch

#define USE_DYNAMIC_PARAMETERS false

4. To open Config Portal

When you want to open a config portal, just add

ethernet_manager.begin();

5. To use custom HTML Style

const char NewCustomsStyle[] /*PROGMEM*/ = "";

...

ethernet_manager.setCustomsStyle(NewCustomsStyle);

6. To use custom Head Elements

ethernet_manager.setCustomsHeadElement("");

7. To use CORS Header

ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin");

While in AP mode, connect to it using its SSID (ESP_XXXXXX) / Password ("MyESP_XXXXXX"), then open a browser to the Portal AP IP, default 192.168.4.1, configure wifi then click Save. The Credentials / WiFi connection information will be saved in non-volatile memory. It will then autoconnect.

Once Credentials / WiFi network information is saved in the host non-volatile memory, it will try to autoconnect to WiFi every time it is started, without requiring any function calls in the sketch.

Important Notes for using Dynamic Parameters' ids

These ids (such as "mqtt" in example) must be unique.

Please be noted that the following reserved names are already used in library:

"ip" for Static IP Address

"nm" for Board Name

Examples

AM2315_Ethernet

Ethernet_Generic

Ethernet_nRF52

Ethernet_RP2040. New

Ethernet_SAMD

Ethernet_SAM_DUE

Ethernet_Teensy

Ethernet_WT32_ETH01. New

MQTT_ThingStream_Ethernet_Generic.

MQTT_ThingStream_Ethernet_nRF52.

MQTT_ThingStream_Ethernet_RP2040. New

MQTT_ThingStream_Ethernet_SAMD.

MQTT_ThingStream_Ethernet_SAM_DUE.

MQTT_ThingStream_Ethernet_Teensy.

MQTT_ThingStream_Ethernet_WT32_ETH01. New

QNEthernet_Teensy. New

MQTT_ThingStream_QNEthernet_Teensy. New

So, how it works?

If no valid config data are stored in EEPROM, it will switch to Configuration Mode. Connect to access point at the IP address displayed on Terminal or Router's DHCP server as in the following picture:

After you connected to, for example, 192.168.2.86, the Browser will display the following picture:

Enter your credentials (Blynk Servers/Tokens and Port). If you prefer static IP, input it (for example 192.168.2.220) in the corresponding field. Otherwise, just leave it blank or nothing to use auto IP assigned by DHCP server.

Then click Save. After the board auto-restarted, you will see if it's connected to your Blynk server successfully as in the following picture:

This ethernet_manager.run() is not a blocking call, so you can use it for critical functions requiring in loop().

In operation, if Ethernet or connection is lost, ethernet_manager.run() will try reconnecting automatically. Therefore, ethernet_manager.run() must be called in the loop() function.

void loop()

{

ethernet_manager.run();

...

}

Example Ethernet_Generic

1. File Ethernet_Generic.ino

Ethernet_Manager/examples/Ethernet_Generic/Ethernet_Generic.ino

Lines 13 to 369

in

d04bc0f

#include "defines.h"

#include "Credentials.h"

#include "dynamicParams.h"

Ethernet_Manager ethernet_manager;

IPAddress localEthernetIP;

// Use to detect W5100 shield. The linkStatus() is not working with W5100, only W5200 and W5500

// To check if W5100 using Ethernet and EthernetLarge libraries

bool isW5500 = true;

void heartBeatPrint()

{

static int num = 1;

static int linkStatus = 0;

localEthernetIP = Ethernet.localIP();

#if (USE_ETHERNET_GENERIC)

#if USE_W5100

// The linkStatus() is not working with W5100. Just using IP != 0.0.0.0

if ( (uint32_t) localEthernetIP != 0 )

#else

linkStatus = Ethernet.link();

ETM_LOGINFO1("localEthernetIP = ", localEthernetIP);

if ( ( linkStatus == 1 ) || ((uint32_t) localEthernetIP != 0) )

#endif

#else

// The linkStatus() is not working with W5100. Just using IP != 0.0.0.0

// Better to use ping for W5100

linkStatus = (int) Ethernet.linkStatus();

ETM_LOGINFO1("localEthernetIP = ", localEthernetIP);

if ( ( (linkStatus == LinkON) || !isW5500 ) || ((uint32_t) localEthernetIP != 0) )

#endif

{

Serial.print(F("H"));

}

else

Serial.print(F("F"));

if (num == 80)

{

Serial.println();

ethernet_manager.printMacAddress();

num = 1;

}

else if (num++ % 10 == 0)

{

Serial.print(F(" "));

}

}

void check_status()

{

#define STATUS_CHECK_INTERVAL 10000L

static unsigned long checkstatus_timeout = STATUS_CHECK_INTERVAL;

// Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.

if ((millis() > checkstatus_timeout))

{

heartBeatPrint();

checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;

}

}

void initEthernet()

{

#if ( defined(USE_UIP_ETHERNET) && USE_UIP_ETHERNET )

ETM_LOGWARN(F("======== USE_UIP_ETHERNET ========"));

#elif USE_NATIVE_ETHERNET

ETM_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));

#elif USE_ETHERNET_GENERIC

ETM_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));

#elif USE_ETHERNET_ENC

ETM_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));

#else

ETM_LOGWARN(F("========================="));

#endif

ETM_LOGWARN(F("Default SPI pinout:"));

ETM_LOGWARN1(F("MOSI:"), MOSI);

ETM_LOGWARN1(F("MISO:"), MISO);

ETM_LOGWARN1(F("SCK:"), SCK);

ETM_LOGWARN1(F("SS:"), SS);

ETM_LOGWARN(F("========================="));

#if defined(ESP8266)

#define PIN_D5 14 // Pin D5 mapped to pin GPIO14/HSCLK of ESP8266

#define PIN_D6 12 // Pin D6 mapped to pin GPIO12/HMISO of ESP8266

#define PIN_D7 13 // Pin D7 mapped to pin GPIO13/RXD2/HMOSI of ESP8266

// Connection for ESP8266

// MOSI: D7/GPIO13, MISO: D6/GPIO12, SCK: D5/GPIO14, CS/SS: D2/GPIO4

// For ESP8266, change for other boards if necessary

#ifndef USE_THIS_SS_PIN

#define USE_THIS_SS_PIN D2 // For ESP8266

#endif

ETM_LOGWARN1(F("ESP8266 setCsPin:"), USE_THIS_SS_PIN);

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

// For ESP8266

// Pin D0(GPIO16) D1(GPIO5) D2(GPIO4) D3(GPIO0) D4(GPIO2) D8

// Ethernet 0 X X X X 0

// Ethernet2 X X X X X 0

// Ethernet3 X X X X X 0

// EthernetLarge X X X X X 0

// Ethernet_ESP8266 0 0 0 0 0 0

// D2 is safe to used for Ethernet, Ethernet2, Ethernet3, EthernetLarge libs

// Must use library patch for Ethernet, EthernetLarge libraries

Ethernet.init (USE_THIS_SS_PIN);

#elif USE_CUSTOM_ETHERNET

// You have to add initialization for your Custom Ethernet here

// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough

Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET || USE_ETHERNET2 || USE_ETHERNET3 || USE_ETHERNET_LARGE )

#elif defined(ESP32)

#define PIN_D18 18 // Pin D18 mapped to pin GPIO18/VSPI_SCK of ESP32

#define PIN_D19 19 // Pin D19 mapped to pin GPIO19/VSPI_MISO of ESP32

#define PIN_D23 23 // Pin D23 mapped to pin GPIO23/VSPI_MOSI of ESP32

// You can use Ethernet.init(pin) to configure the CS pin

//Ethernet.init(10); // Most Arduino shields

//Ethernet.init(5); // MKR ETH shield

//Ethernet.init(0); // Teensy 2.0

//Ethernet.init(20); // Teensy++ 2.0

//Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet

//Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet

// Connection for ESP32

// MOSI: GPIO23, MISOP: GPIO19, SCK: GPIO18, CS/SS: GPIO22

#ifndef USE_THIS_SS_PIN

#define USING_M5STACK_W5500 false

#if USING_M5STACK_W5500

#warning Using M5Stack_Core_ESP32 with W5500 mudule

#define USE_THIS_SS_PIN 26 // For M5Stack_Core_ESP32 with W5500 mudule

#else

#define USE_THIS_SS_PIN 22 // For ESP32

#endif

#endif

ETM_LOGWARN1(F("ESP32 setCsPin:"), USE_THIS_SS_PIN);

// For other boards, to change if necessary

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

// Must use library patch for Ethernet, EthernetLarge libraries

// ESP32 => GPIO2,4,5,13,15,21,22 OK with Ethernet, Ethernet2, EthernetLarge

// ESP32 => GPIO2,4,5,15,21,22 OK with Ethernet3

//Ethernet.setCsPin (USE_THIS_SS_PIN);

Ethernet.init (USE_THIS_SS_PIN);

#elif USE_CUSTOM_ETHERNET

// You have to add initialization for your Custom Ethernet here

// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough

Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_LARGE )

#else //defined(ESP8266)

// unknown board, do nothing, use default SS = 10

#ifndef USE_THIS_SS_PIN

#define USE_THIS_SS_PIN 10 // For other boards

#endif

#if defined(BOARD_NAME)

ETM_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);

#else

ETM_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);

#endif

// For other boards, to change if necessary

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )

// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries

Ethernet.init (USE_THIS_SS_PIN);

#elif USE_CUSTOM_ETHERNET

// You have to add initialization for your Custom Ethernet here

// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough

Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_LARGE )

#endif //defined(ESP8266)

// Just info to know how to connect correctly

#if defined(CUR_PIN_MISO)

ETM_LOGWARN(F("Currently Used SPI pinout:"));

ETM_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);

ETM_LOGWARN1(F("MISO:"), CUR_PIN_MISO);

ETM_LOGWARN1(F("SCK:"), CUR_PIN_SCK);

ETM_LOGWARN1(F("SS:"), CUR_PIN_SS);

#else

ETM_LOGWARN(F("Currently Used SPI pinout:"));

ETM_LOGWARN1(F("MOSI:"), MOSI);

ETM_LOGWARN1(F("MISO:"), MISO);

ETM_LOGWARN1(F("SCK:"), SCK);

ETM_LOGWARN1(F("SS:"), SS);

#endif

ETM_LOGWARN(F("========================="));

}

#if USING_CUSTOMS_STYLE

const char NewCustomsStyle[] /*PROGMEM*/ = "";

#endif

void setup()

{

// Debug console

Serial.begin(115200);

while (!Serial && millis() < 5000);

delay(200);

#if ( USE_LITTLEFS || USE_SPIFFS )

Serial.println("\nStart Ethernet_Generic using " + String(CurrentFileFS) + " on " + String(BOARD_NAME));

#else

Serial.println("\nStart Ethernet_Generic on " + String(BOARD_NAME));

#endif

Serial.println("Ethernet Shield type : " + String(SHIELD_TYPE));

Serial.println(ETHERNET_MANAGER_VERSION);

#if (ESP32 || ESP8266)

Serial.println(ESP_DOUBLE_RESET_DETECTOR_VERSION);

#else

Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION);

#endif

pinMode(SDCARD_CS, OUTPUT);

digitalWrite(SDCARD_CS, HIGH); // Deselect the SD card

initEthernet();

//////////////////////////////////////////////

#if USING_CUSTOMS_STYLE

ethernet_manager.setCustomsStyle(NewCustomsStyle);

#endif

#if USING_CUSTOMS_HEAD_ELEMENT

ethernet_manager.setCustomsHeadElement("");

#endif

#if USING_CORS_FEATURE

ethernet_manager.setCORSHeader("Your Access-Control-Allow-Origin");

#endif

//////////////////////////////////////////////

#define USING_CUSTOM_MAC_ADDRESS true //false

#if USING_CUSTOM_MAC_ADDRESS

// To use your specified macAddress

byte newMacAddress[6] = { 0xFE, 0xED, 0xDE, 0xAD, 0xBE, 0xEF };

ethernet_manager.setMacAddress(newMacAddress);

#endif

//////////////////////////////////////////////

ethernet_manager.begin();

//////////////////////////////////////////////

localEthernetIP = Ethernet.localIP();

#if (USE_ETHERNET2 || USE_ETHERNET3)

// To modify Ethernet2 library

if ( (uint32_t) localEthernetIP != 0 )

#else

if ( (uint32_t) localEthernetIP != 0 )

#endif

{

Serial.print(F("Connected! IP address: "));

Serial.println(localEthernetIP);

}

else

{

Serial.println(F("Ethernet not Connected! Please check."));

}

// Detect W5100 only in Ethernet and EthernetLarge libraries

#if ( USE_ETHERNET || USE_ETHERNET_LARGE)

isW5500 = (Ethernet.hardwareStatus() == EthernetW5500);

Serial.print(F("Ethernet type is "));

Serial.println(isW5500 ? "W5500" : "W5100");

#endif

}

#if (USE_DYNAMIC_PARAMETERS)

void displayCredentials()

{

Serial.println("\nYour stored Credentials :");

for (int i = 0; i < NUM_MENU_ITEMS; i++)

{

Serial.println(String(myMenuItems[i].displayName) + " = " + myMenuItems[i].pdata);

}

}

void displayCredentialsOnce()

{

static bool displayedCredentials = false;

if (!displayedCredentials)

{

for (int i = 0; i < NUM_MENU_ITEMS; i++)

{

if (!strlen(myMenuItems[i].pdata))

{

break;

}

if ( i == (NUM_MENU_ITEMS - 1) )

{

displayedCredentials = true;

displayCredentials();

}

}

}

}

#endif

void loop()

{

ethernet_manager.run();

check_status();

#if (USE_DYNAMIC_PARAMETERS)

displayCredentialsOnce();

#endif

}

2. File defines.h

Ethernet_Manager/examples/Ethernet_Generic/defines.h

Lines 13 to 523

in

d04bc0f

#ifndef defines_h

#define defines_h

#if ( defined(ARDUINO_AVR_ADK) || defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) )

#error This code is designed to run on SAMD, SAM-DUE, Teensy platform, ESP8266, ESP32 not AVR Mega! Please check your Tools->Board setting.

#endif

/* Comment this out to disable prints and save space */

#define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4

#define _ETHERNET_WEBSERVER_LOGLEVEL_ 2

#define _ETHERNET_MANAGER_LOGLEVEL_ 2

#define DRD_GENERIC_DEBUG true

// For ESP32/ESP8266

#define DOUBLERESETDETECTOR_DEBUG true

#if ( defined(ARDUINO_SAMD_ZERO) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_MKRWIFI1010) \

|| defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_SAMD_MKRFox1200) || defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) \

|| defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(__SAMD21G18A__) \

|| defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(__SAMD21E18A__) || defined(__SAMD51__) || defined(__SAMD51J20A__) || defined(__SAMD51J19A__) \

|| defined(__SAMD51G19A__) || defined(__SAMD51P19A__) || defined(__SAMD21G18A__) )

#if defined(ETHERNET_USE_SAMD)

#undef ETHERNET_USE_SAMD

#endif

#define ETHERNET_USE_SAMD true

#define USE_DYNAMIC_PARAMETERS true

#endif

#if ( defined(NRF52840_FEATHER) || defined(NRF52832_FEATHER) || defined(NRF52_SERIES) || defined(ARDUINO_NRF52_ADAFRUIT) || \

defined(NRF52840_FEATHER_SENSE) || defined(NRF52840_ITSYBITSY) || defined(NRF52840_CIRCUITPLAY) || defined(NRF52840_CLUE) || \

defined(NRF52840_METRO) || defined(NRF52840_PCA10056) || defined(PARTICLE_XENON) || defined(NINA_B302_ublox) || defined(NINA_B112_ublox) )

#if defined(ETHERNET_USE_NRF52)

#undef ETHERNET_USE_NRF528XX

#endif

#define ETHERNET_USE_NRF528XX true

#define USE_DYNAMIC_PARAMETERS true

#endif

#if ( defined(NANO_RP2040_CONNECT) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_RASPBERRY_PI_PICO) || \

defined(ARDUINO_GENERIC_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) )

// For RPI Pico

#if defined(ETHERNET_USE_RPIPICO)

#undef ETHERNET_USE_RPIPICO

#endif

#define ETHERNET_USE_RPIPICO true

#define USE_DYNAMIC_PARAMETERS true

#endif

#if ( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) )

#if defined(ETHERNET_USE_SAM_DUE)

#undef ETHERNET_USE_SAM_DUE

#endif

#define ETHERNET_USE_SAM_DUE true

#define USE_DYNAMIC_PARAMETERS true

#endif

#if ( defined(CORE_TEENSY) && !( defined(__MKL26Z64__) || defined(__AVR_AT90USB1286__) || defined(__AVR_ATmega32U4__) ) )

// Don't support Teensy 2.x, LC

#if defined(ETHERNET_USE_TEENSY)

#undef ETHERNET_USE_TEENSY

#endif

#define ETHERNET_USE_TEENSY true

#define USE_DYNAMIC_PARAMETERS true

#endif

#if defined(ETHERNET_USE_SAMD)

// For SAMD

// Default pin SS/CS,if no SS pin, use pin 10

#if defined(PIN_SPI_MOSI)

//#warning Using SS pin

#define USE_THIS_SS_PIN 10 //SS

#else

#define USE_THIS_SS_PIN 10

#endif

#if ( defined(ARDUINO_SAMD_ZERO) && !defined(SEEED_XIAO_M0) )

#define BOARD_TYPE "SAMD Zero"

// Default to use W5100. Must change to false for W5500, W5100S, for faster SPI clock

// Must use true for SAMD21, such as Zero, SAMD_FEATHER_M0_EXPRESS, etc.

#define USE_W5100 true

// Use this for ARDUINO_SAMD_ZERO, etc. if can't print to terminal with Serial.print

#if defined(SERIAL_PORT_USBVIRTUAL)

#define Serial SERIAL_PORT_USBVIRTUAL

#warning Using SAMD Zero SerialUSB

#endif

#elif defined(ARDUINO_SAMD_MKR1000)

#define BOARD_TYPE "SAMD MKR1000"

#elif defined(ARDUINO_SAMD_MKRWIFI1010)

#define BOARD_TYPE "SAMD MKRWIFI1010"

#elif defined(ARDUINO_SAMD_NANO_33_IOT)

#define BOARD_TYPE "SAMD NANO_33_IOT"

#elif defined(ARDUINO_SAMD_MKRFox1200)

#define BOARD_TYPE "SAMD MKRFox1200"

#elif ( defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310) )

#define BOARD_TYPE "SAMD MKRWAN13X0"

#elif defined(ARDUINO_SAMD_MKRGSM1400)

#define BOARD_TYPE "SAMD MKRGSM1400"

#elif defined(ARDUINO_SAMD_MKRNB1500)

#define BOARD_TYPE "SAMD MKRNB1500"

#elif defined(ARDUINO_SAMD_MKRVIDOR4000)

#define BOARD_TYPE "SAMD MKRVIDOR4000"

#elif defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS)

#define BOARD_TYPE "SAMD ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS"

#elif defined(ADAFRUIT_FEATHER_M0_EXPRESS)

#define BOARD_TYPE "SAMD21 ADAFRUIT_FEATHER_M0_EXPRESS"

#elif defined(ADAFRUIT_METRO_M0_EXPRESS)

#define BOARD_TYPE "SAMD21 ADAFRUIT_METRO_M0_EXPRESS"

#elif defined(ADAFRUIT_CIRCUITPLAYGROUND_M0)

#define BOARD_TYPE "SAMD21 ADAFRUIT_CIRCUITPLAYGROUND_M0"

#elif defined(ADAFRUIT_GEMMA_M0)

#define BOARD_TYPE "SAMD21 ADAFRUIT_GEMMA_M0"

#elif defined(ADAFRUIT_TRINKET_M0)

#define BOARD_TYPE "SAMD21 ADAFRUIT_TRINKET_M0"

#elif defined(ADAFRUIT_ITSYBITSY_M0)

#define BOARD_TYPE "SAMD21 ADAFRUIT_ITSYBITSY_M0"

#elif defined(ARDUINO_SAMD_HALLOWING_M0)

#define BOARD_TYPE "SAMD21 ARDUINO_SAMD_HALLOWING_M0"

#elif defined(ADAFRUIT_METRO_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_EXPRESS"

#elif defined(ADAFRUIT_GRAND_CENTRAL_M4)

#define BOARD_TYPE "SAMD51 ADAFRUIT_GRAND_CENTRAL_M4"

#elif defined(ADAFRUIT_FEATHER_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_FEATHER_M4_EXPRESS"

#elif defined(ADAFRUIT_ITSYBITSY_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_ITSYBITSY_M4_EXPRESS"

#define USE_THIS_SS_PIN 10

#elif defined(ADAFRUIT_TRELLIS_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_TRELLIS_M4_EXPRESS"

#elif defined(ADAFRUIT_PYPORTAL)

#define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL"

#elif defined(ADAFRUIT_PYPORTAL_M4_TITANO)

#define BOARD_TYPE "SAMD51 ADAFRUIT_PYPORTAL_M4_TITANO"

#elif defined(ADAFRUIT_PYBADGE_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_M4_EXPRESS"

#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)

#define BOARD_TYPE "SAMD51 ADAFRUIT_METRO_M4_AIRLIFT_LITE"

#elif defined(ADAFRUIT_PYGAMER_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_M4_EXPRESS"

#elif defined(ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_PYGAMER_ADVANCE_M4_EXPRESS"

#elif defined(ADAFRUIT_PYBADGE_AIRLIFT_M4)

#define BOARD_TYPE "SAMD51 ADAFRUIT_PYBADGE_AIRLIFT_M4"

#elif defined(ADAFRUIT_MONSTER_M4SK_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_MONSTER_M4SK_EXPRESS"

#elif defined(ADAFRUIT_HALLOWING_M4_EXPRESS)

#define BOARD_TYPE "SAMD51 ADAFRUIT_HALLOWING_M4_EXPRESS"

#elif defined(SEEED_WIO_TERMINAL)

#define BOARD_TYPE "SAMD SEEED_WIO_TERMINAL"

#elif defined(SEEED_FEMTO_M0)

#define BOARD_TYPE "SAMD SEEED_FEMTO_M0"

#elif defined(SEEED_XIAO_M0)

#define BOARD_TYPE "SAMD SEEED_XIAO_M0"

#ifdef USE_THIS_SS_PIN

#undef USE_THIS_SS_PIN

#endif

#define USE_THIS_SS_PIN A1

#warning define SEEED_XIAO_M0 USE_THIS_SS_PIN == A1

#elif defined(Wio_Lite_MG126)

#define BOARD_TYPE "SAMD SEEED Wio_Lite_MG126"

#elif defined(WIO_GPS_BOARD)

#define BOARD_TYPE "SAMD SEEED WIO_GPS_BOARD"

#elif defined(SEEEDUINO_ZERO)

#define BOARD_TYPE "SAMD SEEEDUINO_ZERO"

#elif defined(SEEEDUINO_LORAWAN)

#define BOARD_TYPE "SAMD SEEEDUINO_LORAWAN"

#elif defined(SEEED_GROVE_UI_WIRELESS)

#define BOARD_TYPE "SAMD SEEED_GROVE_UI_WIRELESS"

#elif defined(__SAMD21E18A__)

#define BOARD_TYPE "SAMD21E18A"

#elif defined(__SAMD21G18A__)

#define BOARD_TYPE "SAMD21G18A"

#elif defined(__SAMD51G19A__)

#define BOARD_TYPE "SAMD51G19A"

#elif defined(__SAMD51J19A__)

#define BOARD_TYPE "SAMD51J19A"

#elif defined(__SAMD51J20A__)

#define BOARD_TYPE "SAMD51J20A"

#elif defined(__SAM3X8E__)

#define BOARD_TYPE "SAM3X8E"

#elif defined(__CPU_ARC__)

#define BOARD_TYPE "CPU_ARC"

#elif defined(__SAMD51__)

#define BOARD_TYPE "SAMD51"

#else

#define BOARD_TYPE "SAMD Unknown"

#endif

#elif (ETHERNET_USE_SAM_DUE)

// Default pin 10 to SS/CS

#define USE_THIS_SS_PIN 10

#define BOARD_TYPE "SAM DUE"

#elif (ETHERNET_USE_NRF528XX)

// Default pin 10 to SS/CS

#define USE_THIS_SS_PIN 10

#if defined(NRF52840_FEATHER)

#define BOARD_TYPE "NRF52840_FEATHER"

#elif defined(NRF52832_FEATHER)

#define BOARD_TYPE "NRF52832_FEATHER"

#elif defined(NRF52840_FEATHER_SENSE)

#define BOARD_TYPE "NRF52840_FEATHER_SENSE"

#elif defined(NRF52840_ITSYBITSY)

#define BOARD_TYPE "NRF52840_ITSYBITSY"

#define USE_THIS_SS_PIN 10 // For other boards

#elif defined(NRF52840_CIRCUITPLAY)

#define BOARD_TYPE "NRF52840_CIRCUITPLAY"

#elif defined(NRF52840_CLUE)

#define BOARD_TYPE "NRF52840_CLUE"

#elif defined(NRF52840_METRO)

#define BOARD_TYPE "NRF52840_METRO"

#elif defined(NRF52840_PCA10056)

#define BOARD_TYPE "NRF52840_PCA10056"

#elif defined(NINA_B302_ublox)

#define BOARD_TYPE "NINA_B302_ublox"

#elif defined(NINA_B112_ublox)

#define BOARD_TYPE "NINA_B112_ublox"

#elif defined(PARTICLE_XENON)

#define BOARD_TYPE "PARTICLE_XENON"

#elif defined(ARDUINO_NRF52_ADAFRUIT)

#define BOARD_TYPE "ARDUINO_NRF52_ADAFRUIT"

#else

#define BOARD_TYPE "nRF52 Unknown"

#endif

#elif ( defined(CORE_TEENSY) )

#error Teensy not supported

// Default pin 10 to SS/CS

#define USE_THIS_SS_PIN 10

#if defined(__IMXRT1062__)

// For Teensy 4.1/4.0

#if defined(ARDUINO_TEENSY41)

#define BOARD_TYPE "TEENSY 4.1"

// Use true for NativeEthernet Library, false if using other Ethernet libraries

#define USE_NATIVE_ETHERNET true

#elif defined(ARDUINO_TEENSY40)

#define BOARD_TYPE "TEENSY 4.0"

#else

#define BOARD_TYPE "TEENSY 4.x"

#endif

#elif defined(__MK66FX1M0__)

#define BOARD_TYPE "Teensy 3.6"

#elif defined(__MK64FX512__)

#define BOARD_TYPE "Teensy 3.5"

#elif defined(__MKL26Z64__)

#define BOARD_TYPE "Teensy LC"

#elif defined(__MK20DX256__)

#define BOARD_TYPE "Teensy 3.2" // and Teensy 3.1 (obsolete)

#elif defined(__MK20DX128__)

#define BOARD_TYPE "Teensy 3.0"

#elif defined(__AVR_AT90USB1286__)

#error Teensy 2.0++ not supported yet

#elif defined(__AVR_ATmega32U4__)

#error Teensy 2.0 not supported yet

#else

// For Other Boards

#define BOARD_TYPE "Unknown Teensy Board"

#endif

#elif ( defined(ESP8266) )

// For ESP8266

#warning Use ESP8266 architecture

#include

#define ETHERNET_USE_ESP8266

#define BOARD_TYPE ARDUINO_BOARD //"ESP8266"

#elif ( defined(ESP32) )

// For ESP32

#warning Use ESP32 architecture

#define ETHERNET_USE_ESP32

#define BOARD_TYPE ARDUINO_BOARD //"ESP32"

#define W5500_RST_PORT 21

#elif (ETHERNET_USE_RPIPICO)

#warning Using ETHERNET_USE_RPIPICO

// Default pin 5 (in Mbed) or 17 to SS/CS

#if defined(ARDUINO_ARCH_MBED)

// For RPI Pico using Arduino Mbed RP2040 core

// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5

#define USE_THIS_SS_PIN 17

#if ( defined(NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO) || \

defined(ARDUINO_GENERIC_RP2040) || defined(ARDUINO_ADAFRUIT_FEATHER_RP2040) )

// Only undef known BOARD_NAME to use better one

#undef BOARD_NAME

#endif

#if defined(ARDUINO_RASPBERRY_PI_PICO)

#define BOARD_NAME "MBED RASPBERRY_PI_PICO"

#elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2040)

#define BOARD_NAME "MBED ADAFRUIT_FEATHER_RP2040"

#elif defined(ARDUINO_GENERIC_RP2040)

#define BOARD_NAME "MBED GENERIC_RP2040"

#elif defined(NANO_RP2040_CONNECT)

#define BOARD_NAME "MBED NANO_RP2040_CONNECT"

#else

// Use default BOARD_NAME if exists

#if !defined(BOARD_NAME)

#define BOARD_NAME "MBED Unknown RP2040"

#endif

#endif

#else

// For RPI Pico using E. Philhower RP2040 core

// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17

#define USE_THIS_SS_PIN 17

#warning Using SS pin 17 For RPI Pico

#endif

#else

// For Mega

// Default pin 10 to SS/CS

#define USE_THIS_SS_PIN 10

// Reduce size for Mega

#define SENDCONTENT_P_BUFFER_SZ 512

#define BOARD_TYPE "AVR Mega"

#endif

#ifndef BOARD_NAME

#define BOARD_NAME BOARD_TYPE

#endif

#include

// Use true for ENC28J60 and UIPEthernet library (https://github.com/UIPEthernet/UIPEthernet)

// Use false for W5x00 and Ethernetx library (https://www.arduino.cc/en/Reference/Ethernet)

//#define USE_UIP_ETHERNET true

#define USE_UIP_ETHERNET false

#if ( !defined(USE_UIP_ETHERNET) || !USE_UIP_ETHERNET )

// To override the default CS/SS pin. Don't use unless you know exactly which pin to use

// You can define here or customize for each board at same place with BOARD_TYPE

// Check @ defined(SEEED_XIAO_M0)

//#define USE_THIS_SS_PIN 22 //21 //5 //4 //2 //15

// Only one if the following to be true

#define USE_ETHERNET_GENERIC true

#define USE_ETHERNET_ENC false

#define USE_CUSTOM_ETHERNET false

#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )

#ifdef USE_CUSTOM_ETHERNET

#undef USE_CUSTOM_ETHERNET

#endif

#define USE_CUSTOM_ETHERNET false

#endif

#if USE_NATIVE_ETHERNET

#include "NativeEthernet.h"

#warning Using NativeEthernet lib for Teensy 4.1. Must also use Teensy Packages Patch or error

#define SHIELD_TYPE "Custom Ethernet using Teensy 4.1 NativeEthernet Library"

#elif USE_ETHERNET_GENERIC

#if USING_SPI2

#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI1"

#else

#define SHIELD_TYPE "W5x00 using Ethernet_Generic Library on SPI0/SPI"

#endif

#define ETHERNET_LARGE_BUFFERS

#define _ETG_LOGLEVEL_ 1

#include "Ethernet_Generic.h"

#warning Using Ethernet_Generic lib

#elif USE_ETHERNET_ENC

#include "EthernetENC.h"

#warning Using EthernetENC lib

#define SHIELD_TYPE "ENC28J60 using EthernetENC Library"

#elif USE_CUSTOM_ETHERNET

//#include "Ethernet_XYZ.h"

#include "EthernetENC.h"

#warning Using Custom Ethernet library. You must include a library and initialize.

#define SHIELD_TYPE "Custom Ethernet using Ethernet_XYZ Library"

#else

#ifdef USE_ETHERNET_GENERIC

#undef USE_ETHERNET_GENERIC

#endif

#define USE_ETHERNET_GENERIC true

#include "Ethernet_Generic.h"

#warning Using default Ethernet_Generic lib

#define SHIELD_TYPE "W5x00 using default Ethernet_Generic Library"

#endif

// Ethernet_Shield_W5200, EtherCard, EtherSia not supported

// Select just 1 of the following #include if uncomment #define USE_CUSTOM_ETHERNET

// Otherwise, standard Ethernet library will be used for W5x00

#elif USE_UIP_ETHERNET

#include "UIPEthernet.h"

#warning Using UIPEthernet library

#define SHIELD_TYPE "ENC28J60 using UIPEthernet Library"

#endif // #if !USE_UIP_ETHERNET

#ifndef SHIELD_TYPE

#define SHIELD_TYPE "Unknown Ethernet shield/library"

#endif

//////////////////////////////////////////

// Not use #define USE_SPIFFS => using EEPROM for configuration data in Ethernet_Manager

// #define USE_SPIFFS false => using EEPROM for configuration data in Ethernet_Manager

// #define USE_SPIFFS true => using SPIFFS for configuration data in Ethernet_Manager

// Be sure to define USE_SPIFFS before #include

// Start location in EEPROM to store config data. Default 0

// Config data Size currently is 128 bytes w/o chksum, 132 with chksum)

//#define EEPROM_START 1024

#if ( defined(ESP32) || defined(ESP8266) )

#if defined(ESP8266)

// #define USE_SPIFFS and USE_LITTLEFS false => using EEPROM for configuration data in WiFiManager

// #define USE_LITTLEFS true => using LITTLEFS for configuration data in WiFiManager

// #define USE_LITTLEFS false and USE_SPIFFS true => using SPIFFS for configuration data in WiFiManager

// Be sure to define USE_LITTLEFS and USE_SPIFFS before #include

// From ESP8266 core 2.7.1, SPIFFS will be deprecated and to be replaced by LittleFS

// Select USE_LITTLEFS (higher priority) or USE_SPIFFS

#define USE_LITTLEFS false

#define USE_SPIFFS false

#if USE_LITTLEFS

//LittleFS has higher priority

#define CurrentFileFS "LittleFS"

#ifdef USE_SPIFFS

#undef USE_SPIFFS

#endif

#define USE_SPIFFS false

#elif USE_SPIFFS

#define CurrentFileFS "SPIFFS"

#endif

#else //#if defined(ESP8266)

// TODO, to add ESP32 LittleFS support

// For ESP32

#define USE_LITTLEFS false

#define USE_SPIFFS false

#if USE_LITTLEFS

//LittleFS has higher priority

#define CurrentFileFS "LittleFS"

#ifdef USE_SPIFFS

#undef USE_SPIFFS

#endif

#define USE_SPIFFS false

#elif USE_SPIFFS

#define CurrentFileFS "SPIFFS"

#endif

#endif //#if defined(ESP8266)

#else //#if ( defined(ESP32) || defined(ESP8266) )

#define USE_SPIFFS false

#endif //#if ( defined(ESP32) || defined(ESP8266) )

#if !( USE_LITTLEFS || USE_SPIFFS)

#if !( defined(ARDUINO_SAM_DUE) || defined(__SAM3X8E__) )

// EEPROM_SIZE must be <= 2048 and >= CONFIG_DATA_SIZE (currently 172 bytes)

#if !defined(EEPROM_SIZE)

#define EEPROM_SIZE (2 * 1024)

#endif

#endif

// EEPROM_START + CONFIG_DATA_SIZE must be <= EEPROM_SIZE

#define EEPROM_START 0

#endif

/////////////////////////////////////////////

// Add customs headers from v1.2.0

#define USING_CUSTOMS_STYLE true

#define USING_CUSTOMS_HEAD_ELEMENT true

#define USING_CORS_FEATURE true

/////////////////////////////////////////////

// Config Timeout 120s (default 60s)

#define CONFIG_TIMEOUT 120000L

#define USE_DYNAMIC_PARAMETERS true

//////////////////////////////////////////

#include

#define W5100_CS 10

#define SDCARD_CS 4

#define ETHERNET_HOST_NAME "Generic-Ethernet"

#endif //defines_h

3. File Credentials.h

Ethernet_Manager/examples/Ethernet_Generic/Credentials.h

Lines 13 to 67

in

d04bc0f

#ifndef Credentials_h

#define Credentials_h

#include "defines.h"

/// Start Default Config Data //////////////////

/*

typedef struct Configuration

{

char header [16];

char static_IP [16];

char board_name [24];

int checkSum;

} Ethernet_Configuration;

*/

#define TO_LOAD_DEFAULT_CONFIG_DATA true

#if TO_LOAD_DEFAULT_CONFIG_DATA

bool LOAD_DEFAULT_CONFIG_DATA = false;

Ethernet_Configuration defaultConfig =

{

//char header[16], dummy, not used

#if USE_SSL

"Eth_SSL",

#else

"Eth_NonSSL",

#endif

// char static_IP [16];

//"192.168.2.230",

// Use dynamic DHCP IP

"",

//char board_name [24];

"Air-Control",

// terminate the list

//int checkSum, dummy, not used

0

/////////// End Default Config Data /////////////

};

#else

bool LOAD_DEFAULT_CONFIG_DATA = false;

Ethernet_Configuration defaultConfig;

#endif // TO_LOAD_DEFAULT_CONFIG_DATA

/////////// End Default Config Data /////////////

#endif //Credentials_h

4. File dynamicParams.h

Ethernet_Manager/examples/Ethernet_Generic/dynamicParams.h

Lines 13 to 76

in

d04bc0f

#ifndef dynamicParams_h

#define dynamicParams_h

#include "defines.h"

// USE_DYNAMIC_PARAMETERS defined in defined.h

/////////////// Start dynamic Credentials ///////////////

/**************************************

#define MAX_ID_LEN 5

#define MAX_DISPLAY_NAME_LEN 16

typedef struct

{

char id [MAX_ID_LEN + 1];

char displayName [MAX_DISPLAY_NAME_LEN + 1];

char *pdata;

uint8_t maxlen;

} MenuItem;

**************************************/

#if USE_DYNAMIC_PARAMETERS

#define MAX_MQTT_SERVER_LEN 34

char MQTT_Server [MAX_MQTT_SERVER_LEN + 1] = "default-mqtt-server";

#define MAX_MQTT_PORT_LEN 6

char MQTT_Port [MAX_MQTT_PORT_LEN + 1] = "1883";

#define MAX_MQTT_USERNAME_LEN 34

char MQTT_UserName [MAX_MQTT_USERNAME_LEN + 1] = "default-mqtt-username";

#define MAX_MQTT_PW_LEN 34

char MQTT_PW [MAX_MQTT_PW_LEN + 1] = "default-mqtt-password";

#define MAX_MQTT_SUBS_TOPIC_LEN 34

char MQTT_SubsTopic [MAX_MQTT_SUBS_TOPIC_LEN + 1] = "default-mqtt-SubTopic";

#define MAX_MQTT_PUB_TOPIC_LEN 34

char MQTT_PubTopic [MAX_MQTT_PUB_TOPIC_LEN + 1] = "default-mqtt-PubTopic";

MenuItem myMenuItems [] =

{

{ "mqtt", "MQTT Server", MQTT_Server, MAX_MQTT_SERVER_LEN },

{ "mqpt", "Port", MQTT_Port, MAX_MQTT_PORT_LEN },

{ "user", "MQTT UserName", MQTT_UserName, MAX_MQTT_USERNAME_LEN },

{ "mqpw", "MQTT PWD", MQTT_PW, MAX_MQTT_PW_LEN },

{ "subs", "Subs Topics", MQTT_SubsTopic, MAX_MQTT_SUBS_TOPIC_LEN },

{ "pubs", "Pubs Topics", MQTT_PubTopic, MAX_MQTT_PUB_TOPIC_LEN },

};

uint16_t NUM_MENU_ITEMS = sizeof(myMenuItems) / sizeof(MenuItem); //MenuItemSize;

#else

MenuItem myMenuItems [] = {};

uint16_t NUM_MENU_ITEMS = 0;

#endif

/////// // End dynamic Credentials ///////////

#endif //dynamicParams_h

Debug Terminal Output Samples

1. Ethernet_nRF52 on NRF52840_FEATHER_EXPRESS with W5500 using Ethernet_Generic Library

This is the terminal output of an Adafruit NRF52840_FEATHER board with W5500 Ethernet shield using Ethernet_Generic Library, running Ethernet_nRF52 example when no doubleResetDetected.

1.1 Normal run

Start Ethernet_nRF52 on NRF52840_FEATHER

Ethernet Shield type W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[EWS] =========== USE_ETHERNET_GENERIC ===========

[EWS] Default SPI pinout:

[EWS] MOSI: 25

[EWS] MISO: 24

[EWS] SCK: 26

[EWS] SS: 5

[EWS] =========================

[EWS] Board : NRF52840_FEATHER , setCsPin: 10

[EWS] =========================

[EWS] Currently Used SPI pinout:

[EWS] MOSI: 25

[EWS] MISO: 24

[EWS] SCK: 26

[EWS] SS: 5

[EWS] =========================

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= Air-Control

[ETM] StaticIP=

[ETM] i= 0 ,id= mqtt

[ETM] data= default-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= default-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= default-mqtt-password

[ETM] i= 4 ,id= subs

[ETM] data= default-mqtt-SubTopic

[ETM] i= 5 ,id= pubs

[ETM] data= default-mqtt-PubTopic

[ETM] LoadCfgFile

[ETM] OK

[ETM] LoadCredFile

[ETM] ChkCrR: Buffer allocated, Sz= 35

[ETM] ChkCrR:pdata= new-mqtt-server ,len= 34

[ETM] ChkCrR:pdata= 1883 ,len= 6

[ETM] ChkCrR:pdata= new-mqtt-username ,len= 34

[ETM] ChkCrR:pdata= old-mqtt-password ,len= 34

[ETM] ChkCrR:pdata= old-mqtt-SubTopic ,len= 34

[ETM] ChkCrR:pdata= old-mqtt-PubTopic ,len= 34

[ETM] OK

[ETM] CrCCSum=0x 217e ,CrRCSum=0x 217e

[ETM] Buffer freed

[ETM] CCSum=0x 6e7 ,RCSum=0x 6e7

[ETM] LoadCredFile

[ETM] CrR:pdata= new-mqtt-server ,len= 34

[ETM] CrR:pdata= 1883 ,len= 6

[ETM] CrR:pdata= new-mqtt-username ,len= 34

[ETM] CrR:pdata= old-mqtt-password ,len= 34

[ETM] CrR:pdata= old-mqtt-SubTopic ,len= 34

[ETM] CrR:pdata= old-mqtt-PubTopic ,len= 34

[ETM] OK

[ETM] CrCCSum=0x 217e ,CrRCSum=0x 217e

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= nRF52 , BoardName= nRF52_W5500

[ETM] StaticIP= 192.168.2.222

[ETM] i= 0 ,id= mqtt

[ETM] data= new-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= new-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= old-mqtt-password

[ETM] i= 4 ,id= subs

[ETM] data= old-mqtt-SubTopic

[ETM] i= 5 ,id= pubs

[ETM] data= old-mqtt-PubTopic

[ETM] Start connectEthernet using Static IP = 192.168.2.222

[ETM] MAC:FE-9F-FA-D8-DC-BA

[ETM] IP: 192.168.2.222

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.222

H

Your stored Credentials :

MQTT Server = new-mqtt-server

Port = 1883

MQTT UserName = new-mqtt-username

MQTT PWD = old-mqtt-password

Subs Topics = old-mqtt-SubTopic

Pubs Topics = old-mqtt-PubTopic

1.2. DoubleResetDetected

Start Ethernet_nRF52 on NRF52840_FEATHER

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[EWS] =========== USE_ETHERNET_GENERIC ===========

[EWS] Default SPI pinout:

[EWS] MOSI: 25

[EWS] MISO: 24

[EWS] SCK: 26

[EWS] SS: 5

[EWS] =========================

[EWS] Board : NRF52840_FEATHER , setCsPin: 10

[EWS] =========================

[EWS] Currently Used SPI pinout:

[EWS] MOSI: 25

[EWS] MISO: 24

[EWS] SCK: 26

[EWS] SS: 5

[EWS] =========================

LittleFS Flag read = 0xd0d01234

Flag read = 0xd0d01234

doubleResetDetected

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

[ETM] =====================

[ETM] DRD. Run ConfigPortal

[ETM] =====================

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= Air-Control

[ETM] StaticIP=

[ETM] i= 0 ,id= mqtt

[ETM] data= default-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= default-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= default-mqtt-password

[ETM] i= 4 ,id= subs

[ETM] data= default-mqtt-SubTopic

[ETM] i= 5 ,id= pubs

[ETM] data= default-mqtt-PubTopic

[ETM] LoadCfgFile

[ETM] OK

[ETM] LoadCredFile

[ETM] ChkCrR: Buffer allocated, Sz= 35

[ETM] ChkCrR:pdata= new-mqtt-server ,len= 34

[ETM] ChkCrR:pdata= 1883 ,len= 6

[ETM] ChkCrR:pdata= new-mqtt-username ,len= 34

[ETM] ChkCrR:pdata= old-mqtt-password ,len= 34

[ETM] ChkCrR:pdata= old-mqtt-SubTopic ,len= 34

[ETM] ChkCrR:pdata= old-mqtt-PubTopic ,len= 34

[ETM] OK

[ETM] CrCCSum=0x 217e ,CrRCSum=0x 217e

[ETM] Buffer freed

[ETM] CCSum=0x 6e7 ,RCSum=0x 6e7

[ETM] LoadCredFile

[ETM] CrR:pdata= new-mqtt-server ,len= 34

[ETM] CrR:pdata= 1883 ,len= 6

[ETM] CrR:pdata= new-mqtt-username ,len= 34

[ETM] CrR:pdata= old-mqtt-password ,len= 34

[ETM] CrR:pdata= old-mqtt-SubTopic ,len= 34

[ETM] CrR:pdata= old-mqtt-PubTopic ,len= 34

[ETM] OK

[ETM] CrCCSum=0x 217e ,CrRCSum=0x 217e

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= nRF52 , BoardName= nRF52_W5500

[ETM] StaticIP= 192.168.2.222

[ETM] i= 0 ,id= mqtt

[ETM] data= new-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= new-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= old-mqtt-password

[ETM] i= 4 ,id= subs

[ETM] data= old-mqtt-SubTopic

[ETM] i= 5 ,id= pubs

[ETM] data= old-mqtt-PubTopic

[ETM] Start connectEthernet using Static IP = 192.168.2.222

[ETM] MAC:FE-99-F8-DF-DA-BA

[ETM] IP: 192.168.2.222

[ETM] begin:Stay in CfgPortal: DRD

[ETM] CfgIP= 192.168.2.222

Connected! IP address: 192.168.2.222

H

Your stored Credentials :

MQTT Server = new-mqtt-server

Port = 1883

MQTT UserName = new-mqtt-username

MQTT PWD = old-mqtt-password

Subs Topics = old-mqtt-SubTopic

Pubs Topics = old-mqtt-PubTopic

HHHH

Your stored Credentials :

MQTT Server = new-mqtt-server

Port = 1883

MQTT UserName = new-mqtt-username

MQTT PWD = old-mqtt-password

Subs Topics = old-mqtt-SubTopic

Pubs Topics = old-mqtt-PubTopic

HHHH

1.3. Config Portal started

[ETM] h1:myMenuItems[ 0 ]= new-mqtt-server

[ETM] h1:myMenuItems[ 1 ]= 1883

[ETM] h1:myMenuItems[ 2 ]= new-mqtt-username

[ETM] h1:myMenuItems[ 3 ]= old-mqtt-password

[ETM] h1:myMenuItems[ 4 ]= old-mqtt-SubTopic

[ETM] h1:myMenuItems[ 5 ]= old-mqtt-PubTopic

HHHHH HHHHHHH

1.4. Credentials entered and Saved

[ETM] h:items updated = 0

[ETM] h:key = ip , value = 192.168.2.223

[ETM] h:ip

[ETM] h:items updated = 1

[ETM] h:key = nm , value = nRF52_W5500

[ETM] h:nm

[ETM] h:items updated = 2

[ETM] h:key = mqtt , value = new-mqtt-server

[ETM] h2:myMenuItems[ 0 ]= new-mqtt-server

[ETM] h:items updated = 3

[ETM] h:key = mqpt , value = 1883

[ETM] h2:myMenuItems[ 1 ]= 1883

[ETM] h:items updated = 4

[ETM] h:key = user , value = new-mqtt-username

[ETM] h2:myMenuItems[ 2 ]= new-mqtt-username

[ETM] h:items updated = 5

[ETM] h:key = mqpw , value = old-mqtt-password

[ETM] h2:myMenuItems[ 3 ]= old-mqtt-password

[ETM] h:items updated = 6

[ETM] h:key = subs , value = old-mqtt-SubTopic

[ETM] h2:myMenuItems[ 4 ]= old-mqtt-SubTopic

[ETM] h:items updated = 7

[ETM] h:key = pubs , value = old-mqtt-PubTopic

[ETM] h2:myMenuItems[ 5 ]= old-mqtt-PubTopic

[ETM] h:Updating EEPROM. Please wait for reset

[ETM] SaveCfgFile

[ETM] WCSum=0x 6e8

[ETM] OK

[ETM] SaveBkUpCfgFile

[ETM] OK

[ETM] SaveCredFile

[ETM] CW1:pdata= new-mqtt-server ,len= 34

[ETM] CW1:pdata= 1883 ,len= 6

[ETM] CW1:pdata= new-mqtt-username ,len= 34

[ETM] CW1:pdata= old-mqtt-password ,len= 34

[ETM] CW1:pdata= old-mqtt-SubTopic ,len= 34

[ETM] CW1:pdata= old-mqtt-PubTopic ,len= 34

[ETM] OK

[ETM] CrWCSum= 217e

[ETM] SaveBkUpCredFile

[ETM] CW2:pdata= new-mqtt-server ,len= 34

[ETM] CW2:pdata= 1883 ,len= 6

[ETM] CW2:pdata= new-mqtt-username ,len= 34

[ETM] CW2:pdata= old-mqtt-password ,len= 34

[ETM] CW2:pdata= old-mqtt-SubTopic ,len= 34

[ETM] CW2:pdata= old-mqtt-PubTopic ,len= 34

[ETM] OK

[ETM] h:Rst

2. Ethernet_SAMD on SeeedStudio SAMD21 SEEED_XIAO_M0 with W5500 using Ethernet_Generic Library

This is the terminal output of an SeeedStudio SAMD21 SEEED_XIAO_M0 board with W5500 Ethernet shield using Ethernet_Generic Library, running Ethernet_SAMD example when no doubleResetDetected.

Start Ethernet_SAMD on SEEED_XIAO_M0

Ethernet Shield type : W5x00 using Ethernet Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

Flag read = 0xffffffff

No doubleResetDetected

SetFlag write = 0xd0d01234

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= Air-Control

[ETM] StaticIP=

[ETM] i= 0 ,id= mqtt

[ETM] data= default-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= default-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= default-mqtt-password

[ETM] i= 4 ,id= subs

[ETM] data= default-mqtt-SubTopic

[ETM] i= 5 ,id= pubs

[ETM] data= default-mqtt-PubTopic

[ETM] ChkCrR:CrCCSum=0x af50 ,CrRCSum=0x ffffffff

[ETM] CCSum=0x 0 ,RCSum=0x 0

[ETM] Invalid Stored Dynamic Data. Load default from Sketch

[ETM] SaveEEPROM,Sz= 1024

[ETM] DataSz= 0 ,WCSum=0x 71e

[ETM] pdata= default-mqtt-server ,len= 34

[ETM] pdata= 1883 ,len= 6

[ETM] pdata= default-mqtt-username ,len= 34

[ETM] pdata= default-mqtt-password ,len= 34

[ETM] pdata= default-mqtt-SubTopic ,len= 34

[ETM] pdata= default-mqtt-PubTopic ,len= 34

[ETM] CrCCSum=0x 29a6

[ETM] Header= SAMD , BoardName= Air-Control

[ETM] StaticIP=

[ETM] i= 0 ,id= mqtt

[ETM] data= default-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= default-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= default-mqtt-password

[ETM] i= 4 ,id= subs

[ETM] data= default-mqtt-SubTopic

[ETM] i= 5 ,id= pubs

[ETM] data= default-mqtt-PubTopic

[ETM] Start connectEthernet using DHCP

[ETM] MAC:FE-9A-F4-DB-DC-BA

W5100 init, using SS_PIN_DEFAULT = 10, new ss_pin = 10, W5100Class::ss_pin = 1

W5100::init: W5500, SSIZE =4096

Done

[ETM] IP: 192.168.2.199

[ETM] begin:Stay in CfgPortal: No CfgDat

[ETM] CfgIP= 192.168.2.199

Connected! IP address: 192.168.2.199

Your stored Credentials :

MQTT Server = default-mqtt-server

Port = 1883

MQTT UserName = default-mqtt-username

MQTT PWD = default-mqtt-password

Subs Topics = default-mqtt-SubTopic

Pubs Topics = default-mqtt-PubTopic

HStop doubleResetDetecting

ClearFlag write = 0xd0d04321

3. Ethernet_SAM_DUE on Arduino SAM DUE with W5100 using Ethernet_Generic Library

This is the terminal output of an Arduino SAM DUE board with W5100 Ethernet shield using Ethernet_Generic Library, running Ethernet_SAM_DUE example when no doubleResetDetected.

Start Ethernet_SAM_DUE on SAM DUE

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

Flag read = 0xd0d01234

doubleResetDetected

ClearFlag write = 0xd0d04321

[ETM] =====================

[ETM] DRD. Run ConfigPortal

[ETM] =====================

[ETM] ======= Start Default Config Data =======

[ETM] Header= , BoardName=

[ETM] StaticIP=

[ETM] Invalid Stored Dynamic Data. Load default from Sketch

[ETM] Header= SAMDUE , BoardName=

[ETM] StaticIP=

[ETM] Start connectEthernet using DHCP

[ETM] MAC:FE-9A-FD-DB-DE-BA

_pinCS = 0

W5100 init, using SS_PIN_DEFAULT = 10, new ss_pin = 10, W5100Class::ss_pin = 10

W5100::init: W5100, SSIZE =4096

[ETM] IP: 192.168.2.228

[ETM] begin:Stay in CfgPortal: DRD

[ETM] CfgIP= 192.168.2.228

Connected! IP address: 192.168.2.228

Ethernet type is W5100

Your stored Credentials :

MQTT Server = default-mqtt-server

Port = 1883

MQTT UserName = default-mqtt-username

MQTT PWD = default-mqtt-password

Subs Topics = default-mqtt-SubTopic

Pubs Topics = default-mqtt-PubTopic

HHH[ETM] h:Updating EEPROM. Please wait for reset

Start Ethernet_SAM_DUE on SAM DUE

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.1.0

Flag read = 0xd0d04321

No doubleResetDetected

SetFlag write = 0xd0d01234

[ETM] ======= Start Default Config Data =======

[ETM] Header= , BoardName=

[ETM] StaticIP=

[ETM] Header= SAMDUE , BoardName= DUE_ETM

[ETM] StaticIP= 192.168.2.222

[ETM] Start connectEthernet using Static IP = 192.168.2.222

[ETM] MAC:FE-9A-FD-DD-D9-BA

W5100 init, using SS_PIN_DEFAULT = 10, new ss_pin = 10, W5100Class::ss_pin = 10

W5100::init: W5100, SSIZE =4096

[ETM] IP: 192.168.2.222

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.222

Ethernet type is W5100

Your stored Credentials :

MQTT Server = new-mqtt-server

Port = 1883

MQTT UserName = default-mqtt-username

MQTT PWD = default-mqtt-password

Subs Topics = default-mqtt-SubTopic

Pubs Topics = default-mqtt-PubTopic

Stop doubleResetDetecting

ClearFlag write = 0xd0d04321

HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH HHHHHHHHHH

4. MQTT_ThingStream_Ethernet_Generic on ESP8266_NODEMCU with W5x00 using Ethernet_Generic Library

This is the terminal output of ESP8266_NODEMCU board with W5x00 using Ethernet_Generic Library, running complex MQTT_ThingStream_Ethernet_Generic example to demonstrate how to use dynamic parameters, entered via Config Portal, to connect to ThingStream MQTT Server.

4.1. Normal run without correct ThingStream MQTT Credentials

If no valid config data are stored in EEPROM, it will switch to Configuration Mode. Connect to access point at the IP address displayed on Terminal or Router's DHCP server as in the following picture:

Start MQTT_ThingStream_Ethernet_Generic using LittleFS on ESP8266_NODEMCU

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

ESP_DoubleResetDetector v1.3.2

=========================

Currently Used SPI pinout:

MOSI:13

MISO:12

SCK:14

SS:15

=========================

LittleFS Flag read = 0xd0d04321

No doubleResetDetected

Saving config file...

Saving config file OK

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= Generic-Ethernet

[ETM] StaticIP=

[ETM] CCSum=0x 9a7 ,RCSum=0x 9a7

[ETM] Invalid Stored Dynamic Data. Load default from Sketch

[ETM] Header= ESP8266 , BoardName= Generic-Ethernet

[ETM] StaticIP=

[ETM] Start connectEthernet using DHCP

[ETM] MAC:FE-AB-CD-EF-ED-BA

[ETM] IP: 192.168.2.62

[ETM] begin:Stay in CfgPortal: No CfgDat

[ETM] CfgIP= 192.168.2.62

Connected! IP address: 192.168.2.62

***************************************

esp32-sniffer/12345678/ble

***************************************

Stop doubleResetDetecting

Saving config file...

Saving config file OK

[ETM] h:Updating LittleFS: /etm_config.dat

[ETM] h:Rst

4.2. Got correct ThingStream MQTT Credentials from Config Portal

Enter your credentials (Blynk Servers/Tokens and Port). If you prefer static IP, input it (for example 192.168.2.220) in the corresponding field. Otherwise, just leave it blank or nothing to use auto IP assigned by DHCP server.

Start MQTT_ThingStream_Ethernet_Generic using LittleFS on ESP8266_NODEMCU

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

ESP_DoubleResetDetector v1.3.2

=========================

Currently Used SPI pinout:

MOSI:13

MISO:12

SCK:14

SS:15

=========================

LittleFS Flag read = 0xd0d04321

No doubleResetDetected

Saving config file...

Saving config file OK

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= Generic-Ethernet

[ETM] StaticIP=

[ETM] CCSum=0x 975 ,RCSum=0x 975

[ETM] ======= Start Stored Config Data =======

[ETM] Header= ESP8266 , BoardName= ESP8266-Ethernet

[ETM] StaticIP= 192.168.2.222

[ETM] Start connectEthernet using Static IP = 192.168.2.222

[ETM] MAC:FE-AB-CD-EF-ED-BA

[ETM] IP: 192.168.2.222

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.222

***************************************

esp32-sniffer/12345678/ble

***************************************

Attempting MQTT connection to mqtt.thingstream.io

...connected

Published connection message successfully!

Subscribed to: esp32-sniffer/12345678/ble

Your stored Credentials :

MQTT Server = mqtt.thingstream.io

Port = 1883

MQTT UserName = user_name

MQTT PWD = user_pwd

Client ID = client_ID

HStop doubleResetDetecting

Saving config file...

Saving config file OK

MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on ESP8266_NODEMCU with W5x00 using Ethernet_Generic Library

H

MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on ESP8266_NODEMCU with W5x00 using Ethernet_Generic Library

H

5. MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER with ENC28J60 using EthernetENC Library

This is the terminal output of NRF52840_FEATHER board with ENC28J60 using EthernetENC Library, running complex MQTT_ThingStream_Ethernet_Generic example to demonstrate how to use dynamic parameters, entered via Config Portal, to connect to ThingStream MQTT Server.

5.1. Normal run without correct ThingStream MQTT Credentials

Start MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER

Ethernet Shield type : ENC28J60 using EthernetENC Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

LittleFS Flag read = 0xd0d01234

Flag read = 0xd0d01234

doubleResetDetected

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

[ETM] =====================

[ETM] DRD. Run ConfigPortal

[ETM] =====================

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= nRF52-Ethernet

[ETM] StaticIP=

[ETM] CCSum=0x 7a6 ,RCSum=0x 7a6

[ETM] ======= Start Stored Config Data =======

[ETM] Header= nRF52 , BoardName= nRF52-Ethernet

[ETM] StaticIP=

[ETM] Start connectEthernet using DHCP

[ETM] MAC:FE-33-78-EF-ED-BA

[ETM] IP: 192.168.2.89

[ETM] begin:Stay in CfgPortal: DRD

[ETM] CfgIP= 192.168.2.89

Connected! IP address: 192.168.2.89

***************************************

esp32-sniffer/12345678/ble

***************************************

[ETM] h:Updating EEPROM. Please wait for reset

[ETM] h:Rst

5.2. Got correct ThingStream MQTT Credentials from Config Portal

Start MQTT_ThingStream_Ethernet_Generic on NRF52840_FEATHER

Ethernet Shield type : ENC28J60 using EthernetENC Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

LittleFS Flag read = 0xd0d04321

Flag read = 0xd0d04321

No doubleResetDetected

Saving DOUBLERESETDETECTOR_FLAG to DRD file : 0xd0d01234

Saving DRD file OK

SetFlag write = 0xd0d01234

[ETM] ======= Start Default Config Data =======

[ETM] Header= Eth_NonSSL , BoardName= nRF52-Ethernet

[ETM] StaticIP=

[ETM] CCSum=0x 8d3 ,RCSum=0x 8d3

[ETM] ======= Start Stored Config Data =======

[ETM] Header= nRF52 , BoardName= nRF52-Ethernet

[ETM] StaticIP= 192.168.2.222

[ETM] Start connectEthernet using Static IP = 192.168.2.222

[ETM] MAC:FE-33-78-EF-ED-BA

[ETM] IP: 192.168.2.222

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.222

***************************************

esp32-sniffer/12345678/ble

***************************************

Attempting MQTT connection to mqtt.thingstream.io

...connected

Published connection message successfully!

Subscribed to: esp32-sniffer/12345678/ble

Your stored Credentials :

MQTT Server = mqtt.thingstream.io

Port = 1883

MQTT UserName = I7UPHZWCKHZASRDIOME9

MQTT PWD = k8UJuIOtke4yXeF1lY9mXbbCxTovHAAgE3CViJ/4

Client ID = device:352fc9a7-3211-4e46-8a9a-a390f2e4ca86

HStop doubleResetDetecting

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on NRF52840_FEATHER with ENC28J60 using EthernetENC Library

H

MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on NRF52840_FEATHER with ENC28J60 using EthernetENC Library

H

6. MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

This is the terminal output of RASPBERRY_PI_PICO board with W5x00 using Ethernet_Generic Library, running complex MQTT_ThingStream_Ethernet_RP2040 example to demonstrate how to use dynamic parameters, entered via Config Portal, to connect to ThingStream MQTT Server.

6.1. Normal run without correct ThingStream MQTT Credentials or DRD

Start MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[EWS] =========== USE_ETHERNET_GENERIC ===========

[EWS] Default SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

[EWS] RPIPICO setCsPin: 17

[EWS] =========================

[EWS] Currently Used SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

LittleFS Flag read = 0xd0d01234

Flag read = 0xd0d01234

doubleResetDetected

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

[ETM] =====================

[ETM] DRD. Run ConfigPortal

[ETM] =====================

[ETM] CCSum=0x 8cb ,RCSum=0x 8cb

[ETM] CrCCsum=0x 2785 ,CrRCsum=0x 2785

[ETM] CrCCsum=0x 2785 ,CrRCsum=0x 2785

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= RP2040 , BoardName= RP2040-Ethernet

[ETM] StaticIP= 192.168.2.233

[ETM] Start connectEthernet using Static IP = 192.168.2.233

[ETM] MAC:FE-99-F5-DF-DB-BA

[ETM] IP: 192.168.2.233

[ETM] bg: isForcedConfigPortal = false

[ETM] bg:Stay forever in CP: DRD/MRD

[ETM] clearForcedCP

[ETM] SaveCPFile

[ETM] OK

[ETM] SaveBkUpCPFile

[ETM] OK

[ETM] CfgIP= 192.168.2.233

Connected! IP address: 192.168.2.233

Ethernet type is W5500

***************************************

esp32-sniffer/12345678/ble

***************************************

6.2. Got correct ThingStream MQTT Credentials from Config Portal

Start MQTT_ThingStream_Ethernet_RP2040 on RASPBERRY_PI_PICO

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[EWS] =========== USE_ETHERNET_GENERIC ===========

[EWS] Default SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

[EWS] RPIPICO setCsPin: 17

[EWS] =========================

[EWS] Currently Used SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

LittleFS Flag read = 0xd0d04321

Flag read = 0xd0d04321

No doubleResetDetected

Saving DOUBLERESETDETECTOR_FLAG to DRD file : 0xd0d01234

Saving DRD file OK

SetFlag write = 0xd0d01234

[ETM] CCSum=0x 8cb ,RCSum=0x 8cb

[ETM] CrCCsum=0x 2785 ,CrRCsum=0x 2785

[ETM] CrCCsum=0x 2785 ,CrRCsum=0x 2785

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= RP2040 , BoardName= RP2040-Ethernet

[ETM] StaticIP= 192.168.2.233

[ETM] Start connectEthernet using Static IP = 192.168.2.233

[ETM] MAC:FE-9A-FB-DD-DB-8E

[ETM] IP: 192.168.2.233

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.233

Ethernet type is W5500

***************************************

esp32-sniffer/12345678/ble

***************************************

Stop doubleResetDetecting

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

Attempting MQTT connection to mqtt.thingstream.io

...connected

Published connection message successfully!

Subscribed to: esp32-sniffer/12345678/ble

H

Your stored Credentials :

MQTT Server = mqtt.thingstream.io

Port = 1883

MQTT UserName = User_name

MQTT PWD = password

Client ID = device_id

MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on RASPBERRY_PI_PICO with W5x00 using Ethernet_Generic Library

H

7. Ethernet_RP2040 on MBED RASPBERRY_PI_PICO with W5500 using Ethernet_Generic Library

This is the terminal output of an MBED RASPBERRY_PI_PICO board with W5500 Ethernet shield using Ethernet_Generic Library, running Ethernet_RP2040 example with doubleResetDetected.

7.1 DRD => Config Portal

Start Ethernet_RP2040 on MBED RASPBERRY_PI_PICO

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[[EWS] =========== USE_ETHERNET_GENERIC ===========

[EWS] Default SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

[EWS] RPIPICO setCsPin: 17

[EWS] =========================

[EWS] Currently Used SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

LittleFS size (KB) = 64

LittleFS Mount OK

LittleFS Flag read = 0xd0d01234

Flag read = 0xd0d01234

doubleResetDetected

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

[ETM] =====================

[ETM] DRD. Run ConfigPortal

[ETM] =====================

[ETM] CCSum=0x 477 ,RCSum=0x 477

[ETM] CrCCsum=0x 219f ,CrRCsum=0x 219f

[ETM] CrCCsum=0x 219f ,CrRCsum=0x 219f

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= RP2040 , BoardName= MBED_RP2040

[ETM] StaticIP= 0

[ETM] Start connectEthernet using DHCP

[ETM] MAC:FE-99-FD-D7-DA-BA

_pinCS = 0

W5100 init, using SS_PIN_DEFAULT = 5, new ss_pin = 10, W5100Class::ss_pin = 5

W5100::init: W5500, SSIZE =8192

[ETM] IP: 192.168.2.185

[ETM] bg: isForcedConfigPortal = false

[ETM] bg:Stay forever in CP: DRD/MRD

[ETM] clearForcedCP

[ETM] SaveCPFile

[ETM] OK

[ETM] SaveBkUpCPFile

[ETM] OK

[ETM] CfgIP= 192.168.2.185

Connected! IP address: 192.168.2.185

Ethernet type is W5500

Your stored Credentials :

MQTT Server = new-mqtt-server

Port = 1883

MQTT UserName = new-mqtt-username

MQTT PWD = new-mqtt-password

Subs Topics = new-mqtt-SubTopic

Pubs Topics = new-mqtt-PubTopic

HHHH[ETM] h:Updating LittleFS: /fs/etm_config.dat

[ETM] WCSum=0x 477

[ETM] CrWCSum=0x 219f

[ETM] h:Rst

7.2 Data Saved => Exit Config Portal

Start Ethernet_RP2040 on MBED RASPBERRY_PI_PICO

Ethernet Shield type : W5x00 using Ethernet_Generic Library

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[EWS] =========== USE_ETHERNET_GENERIC ===========

[EWS] Default SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

[EWS] RPIPICO setCsPin: 17

[EWS] =========================

[EWS] Currently Used SPI pinout:

[EWS] MOSI: 19

[EWS] MISO: 16

[EWS] SCK: 18

[EWS] SS: 17

[EWS] =========================

LittleFS size (KB) = 64

LittleFS Mount OK

LittleFS Flag read = 0xd0d04321

Flag read = 0xd0d04321

No doubleResetDetected

Saving DOUBLERESETDETECTOR_FLAG to DRD file : 0xd0d01234

Saving DRD file OK

SetFlag write = 0xd0d01234

[ETM] CCSum=0x 477 ,RCSum=0x 477

[ETM] CrCCsum=0x 219f ,CrRCsum=0x 219f

[ETM] CrCCsum=0x 219f ,CrRCsum=0x 219f

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= RP2040 , BoardName= MBED_RP2040

[ETM] StaticIP= 0

[ETM] Start connectEthernet using DHCP

[ETM] MAC:FE-9A-FB-D7-D8-BA

_pinCS = 0

W5100 init, using SS_PIN_DEFAULT = 5, new ss_pin = 10, W5100Class::ss_pin = 5

W5100::init: W5500, SSIZE =8192

[ETM] IP: 192.168.2.183

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.183

Ethernet type is W5500

Your stored Credentials :

MQTT Server = new-mqtt-server

Port = 1883

MQTT UserName = new-mqtt-username

MQTT PWD = new-mqtt-password

Subs Topics = new-mqtt-SubTopic

Pubs Topics = new-mqtt-PubTopic

HStop doubleResetDetecting

Saving to DRD file : 0xd0d04321

Saving DRD file OK

LittleFS Flag read = 0xd0d04321

ClearFlag write = 0xd0d04321

HHHHHH

8. MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01

This is the terminal output of WT32-ETH01 board with LAN8720 Ethernet, running complex MQTT_ThingStream_Ethernet_WT32_ETH01 example to demonstrate how to use dynamic parameters, entered via Config Portal, to connect to ThingStream MQTT Server.

8.1. Normal run with correct ThingStream MQTT Credentials

Start MQTT_ThingStream_Ethernet_WT32_ETH01 on WT32-ETH01

Ethernet Shield type : ETH_PHY_LAN8720

WebServer_WT32_ETH01 v1.5.0

Ethernet_Manager v1.8.1

ESP_DoubleResetDetector v1.3.2

[ETM] Set CustomsStyle to :

[ETM] Set CustomsHeadElement to :

[ETM] Set CORS Header to : Your Access-Control-Allow-Origin

LittleFS Flag read = 0xD0D04321

No doubleResetDetected

Saving config file...

Saving config file OK

[ETM] LoadCfgFile

[ETM] OK

[ETM] ======= Start Stored Config Data =======

[ETM] Header= WT32_ETH01 , BoardName= WT32_ETH01

[ETM] StaticIP= 192.168.2.232

[ETM] i= 0 ,id= mqtt

[ETM] data= default-mqtt-server

[ETM] i= 1 ,id= mqpt

[ETM] data= 1883

[ETM] i= 2 ,id= user

[ETM] data= default-mqtt-username

[ETM] i= 3 ,id= mqpw

[ETM] data= default-mqtt-password

[ETM] i= 4 ,id= clid

[ETM] data= default-mqtt-clientID

[ETM] CCSum=0x 7f0 ,RCSum=0x 7f0

[ETM] LoadCredFile

[ETM] CrR:pdata= mqtt.thingstream.io ,len= 48

[ETM] CrR:pdata= 1883 ,len= 6

[ETM] CrR:pdata= mqtt_user ,len= 34

[ETM] CrR:pdata= mqtt_pass ,len= 48

[ETM] CrR:pdata= client_ID ,len= 48

[ETM] OK

[ETM] CrCCsum=0x 2785 ,CrRCsum=0x 2785

[ETM] Valid Stored Dynamic Data

[ETM] Start connectEthernet using Static IP = 192.168.2.232

[ETM] myGW IP = 192.168.2.1

[ETM] ETH Started

[ETM] ETH MAC: A8:03:2A:A1:61:73 , IPv4: 192.168.2.232

[ETM] FULL_DUPLEX, Link Speed (Mbps) 100

[ETM] IP: 192.168.2.232

[ETM] Check if isForcedCP

[ETM] LoadCPFile

[ETM] OK

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.232

***************************************

esp32-sniffer/12345678/ble

***************************************

Connecting to MQTT_SERVER = mqtt.thingstream.io, MQTT_PORT= 1883

Attempting MQTT connection to mqtt.thingstream.io

MQTT_CLIENT_ID = client_ID

MQTT_USER = mqtt_user

MQTT_PASS = mqtt_pass

...connected

Published connection message successfully!

Subscribed to: esp32-sniffer/12345678/ble

Your stored Credentials :

MQTT Server = mqtt.thingstream.io

Port = 1883

MQTT UserName = mqtt_user

MQTT PWD = mqtt_pass

Client ID = client_ID

HStop doubleResetDetecting

Saving config file...

Saving config file OK

MQTT Message Send : esp32-sniffer/12345678/ble => Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720

H

MQTT Message receive [esp32-sniffer/12345678/ble] Hello from MQTT_ThingStream on WT32-ETH01 with ETH_PHY_LAN8720

H

9. QNEthernet_Teensy on TEENSY 4.1 using QNEthernet

This is the terminal output of Teensy 4.1 board with built-in Ethernet, using QNEthernet Library, running QNEthernet_Teensy example when no doubleResetDetected.

Starting QNEthernet_Teensy on TEENSY 4.1 using QNEthernet

Ethernet_Manager v1.8.1

DoubleResetDetector_Generic v1.8.1

[EWS] =========== USE_QN_ETHERNET ===========

QNEthernet using static IP

EEPROM size = 4284, start = 0

Flag read = 0xD0D04321

No doubleResetDetected

SetFlag write = 0xD0D01234

[ETM] Header= Teensy , BoardName= Teensy

[ETM] StaticIP= 192.168.2.232

[ETM] CCSum=0x 77e ,RCSum=0x 77e

[ETM] Header= Teensy , BoardName= Teensy

[ETM] StaticIP= 192.168.2.232

[ETM] ChkCrR:CrCCsum=0x 101b ,CrRCsum=0x 101b

[ETM] CrCCsum=0x 101b ,CrRCsum=0x 101b

[ETM] Valid Stored Dynamic Data

[ETM] ======= Start Stored Config Data =======

[ETM] Header= Teensy , BoardName= Teensy

[ETM] StaticIP= 192.168.2.232

[ETM] Start connectEthernet using Static IP = 192.168.2.232

[ETM] IP: 192.168.2.222

[ETM] begin:Ethernet Connected.

Connected! IP address: 192.168.2.222

Your stored Credentials :

MQTT Server = mqtt_server

Port = 1883

MQTT UserName = mqtt_user

MQTT PWD = mqtt_pwd

Subs Topics = Subs

Pubs Topics = Pubs

Stop doubleResetDetecting

ClearFlag write = 0xD0D04321

HHHH

Debug

Debug is enabled by default on Serial.

You can also change the debugging level from 0 to 4

/* Comment this out to disable prints and save space */

#define DEBUG_ETHERNET_WEBSERVER_PORT Serial

// Debug Level from 0 to 4

#define _ETHERNET_WEBSERVER_LOGLEVEL_ 0

#define _ETHERNET_MANAGER_LOGLEVEL_ 2

Troubleshooting

If you get compilation errors, more often than not, you may need to install a newer version of the core for Arduino boards.

Sometimes, the library will only work if you update the board core to the latest version because I am using newly added functions.

Issues

Submit issues to: Ethernet_Manager issues

TO DO

Same features for other boards with new Ethernet shields.

Add SSL/TLS feature.

Bug Searching and Killing

Support more non-compatible Ethernet Libraries such as Ethernet_Shield_W5200, EtherCard, EtherSia.

DONE

Permit EEPROM size and location configurable to avoid conflict with others.

More flexible to configure reconnection timeout.

For fresh config data, don't need to wait for connecting timeout before entering config portal.

If the config data not entered completely (Serves, HardwarePort and Blynk tokens), entering config portal

Change Synch XMLHttpRequest to Async

Reduce memory usage.

Support ENC28J60 as well as W5100/W5200/W5500 Ethernet shields

Add checksums

Support SAM DUE, SAMD, Teensy boards

Easy-to-use Dynamic Parameters without the necessity to write complicated ArduinoJSon functions

Permit to input special chars such as % and # into data fields.

Support more types of boards using Ethernet shields : nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, etc.

Default Credentials and dynamic parameters

DoubleDetectDetector to force Config Portal when double reset is detected within predetermined time, default 10s.

Configurable Config Portal Title

Re-structure all examples to separate Credentials / Defines / Dynamic Params / Code so that you can change Credentials / Dynamic Params quickly for each device.

Add LittleFS support to ESP8266 as SPIFFS deprecated since ESP8266 core 2.7.1.

Add support to new EthernetENC library for ENC28J60.

Add support to new NativeEthernet Library version stable111+ for Teensy 4.1.

Add support ESP32/ESP8266 boards

Add Table of Contents and Version String

Configurable Customs HTML Headers, including Customs Style, Customs Head Elements, CORS Header

Add support to ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.)

Add support to RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Earle Philhower's arduino-pico core and LittleFS.

Add support to RP2040-based boards, such as Nano RP2040 Connect, using Arduino mbed OS for Nano boards and LittleFS.

Add support to RP2040-based boards, such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Arduino-mbed RP2040 v2.1.0+ core and LittleFS.

Add support to WT32_ETH01 boards using ESP32-based boards and LAN8720 Ethernet

Add support to Teensy 4.1 built-in Ethernet using QNEthernet library

Auto detect ESP32 core and use either built-in LittleFS or LITTLEFS library for ESP32 and WT32-ETH01.

Fix QNEthernet-related linkStatus.

Add support to many more RP2040 boards

Add support to generic SAMD21 : __SAMD21E1xA__, __SAMD21G1xA__ and __SAMD21J1xA__

Update to be compatible with new FlashStorage_SAMD library version

Use new Ethernet_Generic library as default for W5x00.

Support SPI2 for ESP32

Add support to SPI1 for RP2040 using arduino-pico core

Drop EthernetWrapper

Fix macAddress bug. Check Unable so set MAC Address #2

Permit setting macAddress for supporting Ethernet shields W5x00 and ENC28J60

Add functions relating to macAddress

Fix chipID and add getChipID(), getChipOUI() for ESP32 and WT32_ETH01

Contributions and Thanks

Thanks to Miguel Alexandre Wisintainer for initiating, inspriring, working with, developing, debugging and testing

Thanks to sahlex to report issue Unable so set MAC Address #2 leading to version v1.8.0

⭐️ Miguel Wisintainer

sahlex

Contributing

If you want to contribute to this project:

Report bugs and errors

Ask for enhancements

Create issues and pull requests

Tell other people about this library

License

The library is licensed under MIT

Copyright

Copyright (c) 2020- Khoi Hoang

About

Simple Ethernet Manager for Teensy, SAM DUE, SAMD21, SAMD51, nRF52, ESP32, ESP8266, etc. boards, with or without SSL, configuration data saved in ESP8266 LittleFS, SPIFFS, nRF52 LittleFS/InternalFS, EEPROM, DueFlashStorage or SAMD FlashStorage.

Topics

mqtt

teensy

websockets

stm32

ethernet

samd

enc28j60

credential-manager

nrf52

w5x00

rp2040

teensy41

native-ethernet

wt32-eth01

thingstream

qn-ethernet

ethernet-manager

ethernet-webserver

ethernet-generic

Resources

Readme

License

MIT license

Activity

Stars

15

stars

Watchers

3

watching

Forks

4

forks

Report repository

Releases

14

v1.8.1 to fix chipID and add getChipID(), getChipOUI() for `ESP32` and `WT32_ETH01`

Latest

Sep 10, 2022

+ 13 releases

Packages

0

No packages published

Languages

C++

73.2%

C

26.6%

Shell

0.2%

Footer

© 2024 GitHub, Inc.

Footer navigation

Terms

Privacy

Security

Status

Docs

Contact

Manage cookies

Do not share my personal information

You can’t perform that action at this time.