DHCP with static IP fallback macro
-
Hey folks,
Is it possible to configure a timeout for DHCP and have a Duet3 fallback to a static IP if it doesn't receive an IP from a DHCP server? I've looked through the documentation and there doesn't seem to be a way of doing this directly. I did some experiments configuring both a static IP and DHCP in the config file but that didn't work (as you might expect).
Are there any commands which return DHCP status specifically? I can't seem to find one - so I figured it might be possible to have a macro which:
- Sets the network config to DHCP
- Waits a little while to see if it gets an IP (by running M552 with no arguments and getting the network status back)
- If it doesn't get an IP (i.e the result of M552 is still 0.0.0.0), switch off networking and switch it back on again with the pre-set static IP config instead
And have this run at startup as part of config.g
Is this the 'most correct' approach or should I be using meta commands to query the object model? I could look at network.interfaces[].actualIP to see if the IP is still 0.0.0.0 perhaps? I also saw that network.interfaces[].state can have a state of 'obtainingIP' but I'm not sure if that means that DHCP has started and the duet is waiting to get an IP or that the link is active and the duet is waiting for the DHCP process to start. If it were the latter I could check this status after a few seconds and toggle to a static IP if nothing happens.
Any guidance is much appreciated,
D -
If you are OK having it "fall back" to a static IP why not just use that?
Thanks.
Frederick
-
You could run this check in the daemon.g file, which runs in a loop in the background.
-
I'll take a look at daemon.g thanks Phaedrux - do you have any advice as to whether this is best done by looking at the object model or by looking at what M522 returns?
@fcwilt - the machine isn't static and is sometimes set up on networks which we don't control. The flexibility of DHCP here is really useful - but - I'd like to have a static fallback IP which I can use for commissioning in the workshop or if I'm connected directly to the controller because the local network is down/unavailable.
Currently, I'm using a USB cable to toggle the network settings back and forth over the serial link in this instance but it would be nice to side step this if possible.
-
The object model would be the way to go.