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

Should {hostname} be replaced with hostname? #131

Open
2 tasks done
pskowronek opened this issue Jan 28, 2024 · 6 comments
Open
2 tasks done

Should {hostname} be replaced with hostname? #131

pskowronek opened this issue Jan 28, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@pskowronek
Copy link

pskowronek commented Jan 28, 2024

Checklist:

  • I updated to the latest version available
  • I checked that my MQTT broker is otherwise working

Release with the issue:

2024.01.28 master

Last working release (if known):
N/A

Hardware, Operating System, Python version:

RPi zeros, Raspbian 11

Description of problem:

I've tried to setup this project on 3 RPi I got - 2 had no problem displaying their name (hostname -f), 1 had such a problem. However, to be sure in config.ini I set fallback to their names.
When running systemctl status I see for all of them the following:

systemctl status isp-rpi-reporter.service
● isp-rpi-reporter.service - RPi Reporter MQTT Client/Daemon
     Loaded: loaded (/opt/RPi-Reporter-MQTT2HA-Daemon/isp-rpi-reporter.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2024-01-28 00:59:41 GMT; 2s ago
       Docs: https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon
   Main PID: 28680 (python3)
     Status: "Jan 28 00:59:40 - * NOTIFY: on_message() Topic=[home/rpi-nodes/command/rpi-{hostname}/status] payload=[b'offline'] command=[status]."
      Tasks: 4 (limit: 414)
        CPU: 13.648s
     CGroup: /system.slice/isp-rpi-reporter.service
             └─28680 /usr/bin/python3 -u /opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py

In Status line I see "rpi-{hostname}" - is this correct? I mean, since this is my first setup with this project, I had the following doubts:

  1. the hostname was not found and was not replaced
  2. I should have replaced {hostname} in config.ini with real name (it is not so obvious)
  3. the log shows topic before evaluation of the placeholder and there's nothing to worry about

Expectations:

  • I think in status (logs) one should see the final result
  • example config.ini.dist should have additional explanation above topic that {hostname} will be replaced with a proper hostname (using fallback if required)
  • If there was a problem with hostname resolution, the topic nor the name should not contain no_address_associated_with_hostname, but something like fqdn-unknown or fqdn-unknown-IP (where IP is the IP :) ). The sensor name looks like this (even if I fixed the problem hostname resolution /I guess I need to reset sth and re-add it to HA): sensor.rpi_my_raspberrypi_rpi_monitor_hostname_no_address_associated_with_hostname. And btw, why hostname is present in two times in entity name (on the beginning and at the end)?
@pskowronek pskowronek added the bug Something isn't working label Jan 28, 2024
@pskowronek
Copy link
Author

obraz

When I leave {hostname} in configuration. Still I don't know if it should be replaced automatically, or I should edit that.

@bsimmo
Copy link

bsimmo commented Jan 28, 2024 via email

@bsimmo
Copy link

bsimmo commented Jan 28, 2024

Are you using RaspberryPi OS from RaspberryPi.com / Pi Imager or some other version of it?

PiOS '11' is Bullseye so should just work.

Hostname it retrieved from
/bin/hostname -f
If that doesn't work, try fix that.

If you cannot then you change
# default domain to use when hostname -f doesn't return a proper fqdn
#fallback_domain = home

Remove the # and change home to whatever you want.

@pskowronek
Copy link
Author

Are you using RaspberryPi OS from RaspberryPi.com / Pi Imager or some other version of it?

I have bullseye RaspberryPi OS.

PiOS '11' is Bullseye so should just work.

Hostname it retrieved from /bin/hostname -f If that doesn't work, try fix that.

I've already mentioned that I've fixed the problem with hostname -f.

If you cannot then you change # default domain to use when hostname -f doesn't return a proper fqdn #fallback_domain = home

The comment in config.ini.dist above sensor_name should better state this:
"Should be left as is with the # to have it ignored in the program and send
the hostname the Pi itself has been given by you. "

Otherwise one may think that sensor_name = rpi-{hostname} must be un-commented, and {hostname} will be replaced in runtime either by hostname or fallback_domain.

Remove the # and change home to whatever you want.

Thanks. But what I aim here is to make this behavior more obvious - both in README.md (installation part) and in config.ini.dist .

@bsimmo
Copy link

bsimmo commented Jan 28, 2024 via email

@pskowronek
Copy link
Author

pskowronek commented Jan 28, 2024

Remember this is his project for something he wanted, everything else is a bonus and tagged on for others :)

Yup, and this is very great project! I've already submitted 2 PR to it to make it more easier to use :)

First I wanted to see whether {hostname} should be dereferenced or not. I see those PR you have mentioned @bsimmo - Let's wait for PR review. Personally I would add better comments to config.ini.dist to explain the behavior and what's the default.

Maybe let's keep this "bug" open so it could be discussed how to make it more obvious how to use it.

ironsheep added a commit that referenced this issue Apr 24, 2024
Always update sensor_name after resolving hostname
This solution may affect issues (#122 , #131 , and #142)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants