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

HOSTNAME with serial number as decimal and without MQTT_TOPIC #5991

Closed
0n3-70uch opened this issue Jun 28, 2019 · 19 comments
Closed

HOSTNAME with serial number as decimal and without MQTT_TOPIC #5991

0n3-70uch opened this issue Jun 28, 2019 · 19 comments
Labels
question Type - Asking for Information

Comments

@0n3-70uch
Copy link

Have you look for this feature in other issues and in the wiki?
Yes. Wiki and Discord.

Is your feature request related to a problem? Please describe.
No. Only bad charactes in the hostname (like: "_").

Describe the solution you'd like
Change the MQTT_TOPIC to "PROJECT "_%06X"" in user_config_override.h. Now the Hostname is like "sonoff_E92J29-2383". Please add an option to set the hostname back to normal. Example:

#undef HOSTNAME
#define HOSTNAME     Project "-%04d"
@ascillato
Copy link
Contributor

Hi,

Please add an option to set the hostname back to normal.

It is already available the console command hostname for changing it.

@0n3-70uch
Copy link
Author

No. Not working if the "MQTT_TOPIC" is changed.

@ascillato
Copy link
Contributor

ascillato commented Jun 28, 2019

Sorry, I could not reproduce the problem.

I have just tested hostname command and works fine in latest version. Hostname 1 put the default defined in my_user_config.h (or in user_config_override.h. if it is used)

@0n3-70uch
Copy link
Author

0n3-70uch commented Jun 28, 2019

Ok please try this:

Add this in your user_config_override.h

#undef MQTT_TOPIC
#define MQTT_TOPIC   PROJECT "_%06X"

Then it isn't possible to change the HOSTNAME back to "sonoff-1234" via the user_config_override.h.

PS: You can manual rename the hostname. But this is very uncomfortable.

@meingraham
Copy link
Collaborator

Is the problem that you have a space in the definition of your MQTT_TOPIC? Topics cannot have any whitespace.

@0n3-70uch
Copy link
Author

0n3-70uch commented Jun 28, 2019

No there isn't any space. My MQTT_TOPIC is absolutely fine with "sonoff_A1B2C3". But the hostname is generated by my MQTT_TOPIC. And so I have this hostname: "sonoff_A1B2C3-1234". It's impossible to remove the unecessary "_A1B2C3" via the user_config_override.h.

PS: No issue. Just a missing configuration option for HOSTNAME in user_config_override.h.

@agreen
Copy link

agreen commented Jun 28, 2019

This confused me a bit at first.

I wanted to change my mqtt topics to match the hostname I was currently seeing, so I changed the mqtt_topic to sonoff-%04d Now my hostname is actually sonoff-%04d-%04d (sonoff-8001-8001). What I was expecting is to have the mqtt topic and the hostname match exactly. In @0n3-70uch's case, I think he wants to have his hostname be the default "sonoff-8001" and his MQTT topic be "sonoff_E92J29".

I've even tried setting my hostname to "sonoff-%04d" and I STILL get "sonoff-8001-8001" as my actual hostname.

I would suggest a mode or some other feature to have your hostname and MQTT name match exactly and as well have the hostname NOT contain the %04d automatically as is the case currently.

@ascillato
Copy link
Contributor

ascillato commented Jun 29, 2019

Ok please try this:

Add this in your user_config_override.h

#undef MQTT_TOPIC
#define MQTT_TOPIC PROJECT "_%06X"
Then it isn't possible to change the HOSTNAME back to "sonoff-1234" via the user_config_override.h.

PS: You can manual rename the hostname. But this is very uncomfortable.

I already try that as my previous comment, and the command hostname works fine in the console. You can set whatever you want as hostname (using hostname command) and as mqtt topic (using topic command).

You want your hostname to be equal to your mqtt_topic, right?
Actually, Tasmota default config does automatically the other way round. It uses by default your mqtt topic to make your hostname name.
Hostname is defined in the config as %s-%04d in line 78 of the file sonoff.h https://github.com/arendst/Sonoff-Tasmota/blob/6ac1904e2822859f9e8913d21e697156c8f34c41/sonoff/sonoff.h#L78
That means that your hostname will be [TOPIC]-[last 4 digits of the MAC]
So, you are just changing your topic to be SONOFF_MAC, producing a hostname SONOFF_MAC-MAC

If you want to define a MQTT_TOPIC and make your HOSTNAME equals to your MQTT_TOPIC, and you want to make it configurable from user_config_override.h or my_user_config.h file, just:

1- Comment or delete line 78 of sonoff.h
2- Add in your user_config_override.h or my_user_config.h file, the following line:
#define WIFI_HOSTNAME "%s"
(Tasmota will replace the %s with your mqtt topic)

This might not be added to the actual repository due to #36

@ascillato2 ascillato2 added the question Type - Asking for Information label Jun 29, 2019
@0n3-70uch
Copy link
Author

0n3-70uch commented Jun 30, 2019

Hi, thanks for your very helpful answere. I changed my sonoff.h to this:

//const char WIFI_HOSTNAME[] = "%s-%04d";     // Expands to <MQTT_TOPIC>-<last 4 decimal chars of MAC address>
const char WIFI_HOSTNAME[] = "sonoff-%04d";

The HOSTNAME is someting like this now: sonoff-1073680949
How I can reduce the HOSTNAME to this: sonoff-1073

Greetings Fabian

@ascillato
Copy link
Contributor

Which esp8266 core version are you using?

@0n3-70uch
Copy link
Author

0n3-70uch commented Jun 30, 2019

I use 2.5.2 (platformio).
By the way: the id "1073680949" isn't the correct serial number. I flashed another device and it's the same number.

@ascillato
Copy link
Contributor

Please try with core 2.3.0 so as to test. I tested on 2.3.0 and %04d gives me the last 4 digits of the mac correctly

@0n3-70uch
Copy link
Author

0n3-70uch commented Jun 30, 2019

Ok I will try it later. I get a compiler error with 2.3.0 at the moment.

@0n3-70uch
Copy link
Author

Hi, I compiled it with core 2.3.0. Still the same problem.

@ascillato
Copy link
Contributor

Hi,

Sorry for the late reply. I have missed your comment.

Please, erase the flash before flashing (or do a reset 5 in the console), seems that there is wrong data left on your device.

@0n3-70uch
Copy link
Author

Hi, no problem. Thanks for your help. I erased the devices several times with reset 2.
And I reflashed one device (esptool.py -p /dev/ttyUSB0 erase_flash and esptool.py -p /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x00000 'sonoff.bin'). Still the same problem...

@ed-holland
Copy link

I'm having the same problem. I'm building tasmota.bin using 8.1 with only changes in my_user_config.
#define WIFI_HOSTNAME "sonoff-s20-%04d"
results in "sonoff-s20-1073681064" instead of "sonoff-s20-5014". Resetting does not help.

The resolving of "%04d" does not seem to show the result in the ui. I'm using it for the friendly name, mqtt-topic also. The UI shows it without resolving.

Any update / workaround?

I would like to use this binary for all my S20s.

@mgaueca
Copy link

mgaueca commented Mar 4, 2022

same problem here, %04d" doesn't works...any workaround?

@barbudor
Copy link
Contributor

barbudor commented Mar 4, 2022

It works as documented. Did you took the time to read the docs?

If hostname contains % it will be reset to the default instead.

So having % in the name does the same 'hostname 1'
Nowhere it is written that '%04d' would be substituted

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

No branches or pull requests

8 participants