57 return "DHCP (assigned by the server)";
59 return "recovery (no DHCP server answered; reflash only)";
83 byte mac[6] = {0, 0, 0, 0, 0, 0};
105 for (
int i = 0; i < 6; i++) {
157 Serial.print(
"[NET] server learned: ");
158 Serial.println(remote_ip);
182 Serial.println(
"[NET] requesting an address by DHCP...");
188 Serial.print(
"[NET] server assigned us ");
195 Serial.print(
"[NET] no DHCP server answered -- on the recovery address ");
197 Serial.println(
" (reflash only); asking again every few seconds.");
222 Serial.print(
"[NET] DHCP answered at last -- server assigned us ");
static EthernetClass Ethernet
IPAddress dns(192, 168, 2, 1)
IPAddress serverIP(192, 168, 2, 20)
IPAddress gateway(0, 0, 0, 0)
#define SENSOR_ETH_DHCP_RETRY_TIMEOUT_MS
#define SENSOR_ZEROCONF_SERVER_SILENCE_MS
#define SENSOR_ETH_DHCP_RETRY_INTERVAL_MS
#define SENSOR_ETH_DHCP_RESPONSE_TIMEOUT_MS
#define SENSOR_ETH_DHCP_TIMEOUT_MS
*brief append another JSON pointer at the end of this JSON pointer *sa ptr reference_tokens begin()
Board networking — the ground station decides addresses, not the board.
void configure(State &s, const byte mac[6])
void printMac(const State &s)
Print the MAC as aa:bb:cc:dd:ee:ff.
IPAddress recoveryAddress(const byte mac[6])
The board's recovery address, from its MAC: 169.254.
void useRecoveryAddress(State &s, IPAddress dns, IPAddress gateway)
uint8_t boardId(const State &s)
The board's ID: the last octet of the address the server assigned (192.168.2.31 -> 31).
void beginOtaHold(State &s)
Called when an OTA transfer starts, so the address cannot move under it.
bool retryDhcp(State &s, IPAddress dns, IPAddress gateway)
On the recovery address, ask for a lease again every SENSOR_ETH_DHCP_RETRY_INTERVAL_MS.
bool usingDhcp(const State &s)
bool serverWentSilent(const State &s)
Server has stopped talking — forget it and resume discovery broadcasts.
IPAddress recoverySubnet()
Subnet of the recovery address: link-local, 169.254.0.0/16.
AddressSource
How the board ended up with the address it is using.
@ Recovery
no DHCP answer: 169.254.x.y from the MAC, reflash-only
@ Dhcp
assigned by the ground station — the normal case
bool onServerPacket(State &s, IPAddress remote_ip, IPAddress &serverIP)
A server packet arrived from remote_ip; adopt it as the server address.
void maintainLease(State &s)
Renew the lease as it expires.
bool hasAddress(const State &s)
const char * sourceName(AddressSource s)
bool otaHold
suppress lease renewal during a flash
bool serverLearned
server IP adopted from an inbound packet
unsigned long lastServerPacketMillis
unsigned long lastDhcpAttemptMillis