geerlingguy / airgradient-prometheus

AirGradient Prometheus exporter.
MIT License
174 stars 59 forks source link

Update AirGradient-DIY.ino #11

Closed Makr91 closed 2 years ago

Makr91 commented 2 years ago

Update Hostname for automatic Dynamic DNS/DHCP address assignment for services like Pi-Hole

geerlingguy commented 2 years ago

Would this make it so you can access the device over [device-id-here].local using mDNS?

Makr91 commented 2 years ago

This doesn't enable MDNS, but that Arduino Library can be added.

If you have a Pi-Hole instance, the device will always show up with it's programmed Hostname (Usually something like ESP-XXXX) in your DHCP interface list of clients.

If you're Pi-hole or DNS server does automatically append a search domain onto your hostnames. Then yes, theoretically this should work to allow you to access it via a hostname of your choice.

So for example, I set the device ID on my AirGradient Wemos to 'air-sensor-01' and since I have not yet added it to a static DNS entry in Pi-Hole or via my other upstream servers, and Since the Pi-hole does append my internal domain, I can access it anywhere inside my local environment that uses the Pi-Hole DNS, for example the following address:

http://air-sensor-01.int.dc-01.m4kr.net:9926/

Mark Gilbert Systems Administrator | Cloud Engineer Primary mobile: +1-918-917-9378 FCC Technician License: KF5NTR

On Sat, Dec 25, 2021 at 12:04 AM Jeff Geerling @.***> wrote:

Would this make it so you can access the device over [device-id-here].local using mDNS?

— Reply to this email directly, view it on GitHub https://github.com/geerlingguy/airgradient-prometheus/pull/11#issuecomment-1000979633, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUAUFF4TEAJUNNECIQZ32TUSVNILANCNFSM5KWJ72JQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

Makr91 commented 2 years ago

I am pseudo-familiar with mDNS, if you want I can add that before we commit this.

geerlingguy commented 2 years ago

@Makr91 - No, I'd be okay without it; didn't think about how it would show up in Pi-hole!

geerlingguy commented 2 years ago

@Makr91 - One quick question, didn't think about this until just now — if the deviceId is set to empty string, it shouldn't be used for the hostname. Could you do a follow-up PR to put an if around the set hostname bit and make sure the deviceId isn't empty?