8#include <ArduinoJson.h>
20#ifdef ANABRID_SKIP_ETHERNET
22 LOG_ALWAYS(
"Skipping Ethernet due to build flag ANABRID_ETHERNET");
29#ifdef ANABRID_SKIP_DHCP
31 LOG_ALWAYS(
"Skipping DHCP due to build flag ANABRID_SKIP_DHCP");
41 sprintf(mac_str,
"lucidac-%02X-%02X-%02X",
mac[3],
mac[4],
mac[5]);
79 if (hostname.length() > 250)
80 hostname = hostname.substr(0, 250);
101 if (!enable_ethernet) {
102 LOG_ALWAYS(
"Ethernet disabled by user setting");
113 net::Ethernet.setMACAddress(mac.mac);
121 LOG2(
"DHCP with Hostname: ", hostname.c_str());
122 net::Ethernet.setHostname(hostname.c_str());
123 if (!net::Ethernet.begin()) {
124 LOG_ERROR(
"Error starting ethernet DHCP client.");
127 LOG(ANABRID_DEBUG_INIT,
"Waiting for IP address on ethernet...");
128 if (!net::Ethernet.waitForLocalIP(10 * 1000 )) {
133 if (!
valid(static_ipaddr) || !
valid(static_netmask) || !
valid(static_gw)) {
134 LOG_ERROR(
"Illegal ipaddr/netmask/gw. Recovering with defaults.");
136 static_ipaddr = defaults.static_ipaddr;
137 static_netmask = defaults.static_netmask;
138 static_gw = defaults.static_gw;
140 if (!net::Ethernet.begin(static_ipaddr, static_netmask, static_gw)) {
141 LOG_ERROR(
"Error starting ethernet with static IP address.");
144 if (!
valid(static_dns)) {
145 LOG_ERROR(
"Illegal dns server. Recovering with defaults.")
147 static_dns = defaults.static_dns;
149 net::Ethernet.setDnsServerIP(static_dns);
152 LOG4(
"JSONL Listening on ", net::Ethernet.localIP(),
":", jsonl_port);
157 MDNS.begin(hostname.c_str());
159 MDNS.addService(
"_lucijsonl",
"_tcp", jsonl_port);
160 if (enable_webserver)
161 MDNS.addService(
"_http",
"_tcp", webserver_port);
170 msg_out[
"interfaceStatus"] = net::Ethernet.interfaceStatus();
175 auto ip = msg_out.createNestedObject(
"ip");
176 ip[
"local"] = net::Ethernet.localIP();
177 ip[
"broadcast"] = net::Ethernet.broadcastIP();
178 ip[
"gateway"] = net::Ethernet.gatewayIP();
180 auto dhcp = msg_out.createNestedObject(
"dhcp");
181 dhcp[
"active"] = net::Ethernet.isDHCPActive();
182 dhcp[
"enabled"] = net::Ethernet.isDHCPEnabled();
184 auto link = msg_out.createNestedObject(
"link");
185 link[
"state"] = net::Ethernet.linkState();
186 link[
"speed"] = net::Ethernet.linkSpeed();
187 link[
"isCrossover"] = net::Ethernet.linkIsCrossover();
188 link[
"isFullDuplex"] = net::Ethernet.linkIsFullDuplex();
Persistent user-defined ethernet settings which is mostly relevant only during startup as the informa...
bool enable_ethernet
Turn on/off networking completely.
int begin_ip()
Calls net::Ethernet.begin, sets IP address.
void toJson(JsonObject target, nvmconfig::Context c=nvmconfig::Context::Flash) const override
void fromJson(JsonObjectConst src, nvmconfig::Context c=nvmconfig::Context::Flash) override
IPAddress static_netmask
netmask; used only when use_dhcp=false
int jsonl_port
TCP port for jsonl server.
void begin_mdns()
Calls net::MDNS.begin.
IPAddress static_dns
DNS server address; used only when use_dhcp=false.
bool enable_mdns
Enable mDNS/zeroconf multicast service discovery.
bool enable_dhcp
DHCP client vs static IP configuration.
bool enable_webserver
Enable embedded webserver for REST access.
bool enable_websockets
Enable websocket server ontop of webserver.
int webserver_port
TCP port for webserver.
IPAddress static_ipaddr
own ip address, used only when use_dhcp=false
MacAddress mac
Custom MAC address. Defaults to original permanent system Mac.
uint8_t max_connections
(Runtime-changable) Maximum number of parallel connections accepted
std::string hostname
used only for DHCP client. Maximum 250 characters.
IPAddress static_gw
gateway address; used only when use_dhcp=false
uint32_t connection_timeout_ms
(Runtime-changable) Time after idling connections time out.
bool enable_jsonl
Enable the JSONL TCP/IP server.
#define JSON_GET(src, key)
#define JSON_GET_AS(src, key, type)
#define JSON_SET(target, key)
#define LOG_ERROR(message)
#define LOG(LOG_FLAG, message)
#define LOG_ALWAYS(message)
void status(JsonObject &msg_out)
This status contains only "static" QNEthernet information, unrelated to UserDefinedEthernet instances...
std::string toString(const MacAddress &mac, char sep='-')
EUI48/MAC Canonical Format AA-BB-CC-DD-EE-FF.
bool valid(const MacAddress &mac)
All zero mac bytes considered invalid (0-0-0-0-0-0)
void reset()
set to system default (stored in teensy HW_OCOTP_MAC1 and ...MAC0)
static MacAddress otp()
Handy access to system default/permanent mac address (one time programmed)