Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotAnIssueButMaybeAFeatureRequest - DHCP: Changing IP address of gateway #138

Open
guykes83 opened this issue Aug 18, 2021 · 1 comment
Open

Comments

@guykes83
Copy link

Firstly, I'd like to thank you for your hard work in this project. I enjoy it everyday!

I'm not sure if this really is an issue, maybe it just depends on the combination of network-devices I use at my home. If so, feel free to close this thread.

In my situation, I use my provider's modem/router combination, and connect the gateway directly to it. Since the provider doesn't allow (nor IKEA) me to set a fixed ip-address, the gateway gets one assigned more or less randomly. So, I'm stuck with DHCP, which is not ideal for automation and availability. This happens whenever I restart the gateway or the router/modem combination, maybe even when I replug a cable.

Of course, when this happens, I'll have to remember to update the config.json file, or half my home's automation will stop working (including some wall buttons, which is not very convenient).
In order to do this, first I'll have to identify what's the gateways newly assinged IP-address and then update the config.json file with the new ip-address. Weirdly enough, the range of the newly assigned addresses is always very close, ie. 192.168.0.137, 192.168.0.138 and 192.168.0.139.

To work around this, I created a shell-script that is being run every hour and updates the ip-address in the config.json file:

str=$(arp -a | grep "00:00:00:00:00:00")
ip=$(echo $str | awk -v FS="(\(|\))" '{print $2}')
sed -i 's/192.168.0.137/'$ip'/g' /home/pi/domoticz/plugins/IKEA-Tradfri/config.json
sed -i 's/192.168.0.138/'$ip'/g' /home/pi/domoticz/plugins/IKEA-Tradfri/config.json
sed -i 's/192.168.0.139/'$ip'/g' /home/pi/domoticz/plugins/IKEA-Tradfri/config.json

What it does:

  • line 1: I use the mac address to find the ip address in the arp-table. (replace 00:00:00.. with your own MAC-address)
  • line 2: extract the ip-adress from the string value returned by the first line
  • line 3, 4, 5: updates the config.json file with the newly found ip-address. Admittedly, it would probably be better to use a for-loop here.

Then, what's left are my actual questions:

  • I'm I the only one to face this 'issue'? If not:
  • Would it be feasible to integrate this type of functionality in the project, one way or the other?
  • Or would it be feasible to create a sort of backup-ip-list, if the first address isn't responding, try the 2nd, and so on?

Many thanks in advance!

@moroen
Copy link
Owner

moroen commented Aug 18, 2021

Glad you're getting some use of this! :)

It's possible to add a "auto detect the IKEA-gateway" for instance on startup, it's just not high on my personal priority list.

But I'll keep in in mind with the new, totally rewritten plugin, which is inching ever so slowly towards beta status. If you, or someone else want's to implement it in this current version, I'll be more than happy to accept a pull request (but I suspect it might take some work, down to the gocoap library on which py3coap is based...)

Regards,
M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants