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

Define Template in "user_config_override.h" #8464

Closed
Cerothen opened this issue May 17, 2020 · 15 comments
Closed

Define Template in "user_config_override.h" #8464

Cerothen opened this issue May 17, 2020 · 15 comments
Assignees
Labels
enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended

Comments

@Cerothen
Copy link

Cerothen commented May 17, 2020

Have you looked for this feature in other issues and in the docs?
Yes
Is your feature request related to a problem? Please describe.
Currently there is no way to specify a customized PIN/module configuration from the config override file.

This situation has been requested multiple times in the past though not specifically using templating as the solution:
#5068
#3747
#3258
Describe the solution you'd like
If the ability to define the default template was added to this file it would be a single option to configure:

#undef TEMPLATESTR
#define TEMPLATESTR "{\"NAME\":\"Generic\",\"GPIO\":[255,255,255,255,255,255,255,255,255,255,255,255,255],\"FLAG\":15,\"BASE\":18}"

Then individuals compiling the firmware could set the module to 255 to enable that template as the default when initially flashing or when resetting the configuration.

#undef MODULE
#define MODULE 255

Describe alternatives you've considered
I have reviewed the suggestions in similar requests and the proposed solutions such as "creating something separate to automatically set the settings via serial or otherwise; Setting up a device then backup, restore to each device; Flash one device, set it up and read the flash back to then write to other devices as the firmware. None of these are as elegant as specifying a template in the user_config_override file and setting the template as the active module.

Additional context
The main reason for this is to create firmware where the device is fully configured for that use case to offset issues with an unexpected reset (either by someone holding the button for too long [kids...], or if the device was to spontaneously reset (as was indicated in one of those linked issues)

(Please, remember to close the issue when the problem has been addressed)

@ascillato2 ascillato2 added feature request (devs?) Action - awaiting response from developers duplicated Result - Duplicated Issue labels May 18, 2020
@curzon01
Copy link
Contributor

I know it's not exactly what you requested but may be decode-config would help?

Create a JSON text file e.g. tempate.json only containing the related settings:

{
  "user_template": {
    "base": 18, 
    "flag": {
      "adc0": 15
    }, 
    "gpio": [255,255,255,255,255,255,255,255,255,255,255,255,255], 
    "name": "mytemplate"
  }, 
  "last_module": 255
}

then load this config part using
decode-config -d <yourdevice> -i template.json
into each device you want.

@Cerothen
Copy link
Author

Not a bad solution however it would be less effort to edit the template and check off "activate" within the "Configure Other" menu when setting the display name. The main goal is for the device to function in its normal operating state should it get accidentally reset or spontaneously reset. I had noticed that it had been requested a few times but I think those were all before templates existed. If its a lot of work then it certainly isn't a necessity it would just really give people that are compiling firmware more options for firmware customization. Especially considering the number of devices on the blackadder site.

@stale
Copy link

stale bot commented Jun 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Action - Issue left behind - Used by the BOT to call for attention label Jun 12, 2020
@arendst
Copy link
Owner

arendst commented Jun 17, 2020

Will have a look...

@stale stale bot removed the stale Action - Issue left behind - Used by the BOT to call for attention label Jun 17, 2020
@arendst arendst self-assigned this Jun 17, 2020
@arendst
Copy link
Owner

arendst commented Jun 17, 2020

The main reason for this is to create firmware where the device is fully configured for that use case to offset issues with an unexpected reset (either by someone holding the button for too long [kids...], or if the device was to spontaneously reset (as was indicated in one of those linked issues)

The main goal is for the device to function in its normal operating state should it get accidentally reset or spontaneously reset.

Indeed currently it will be reset to a Sonoff Basic on multiple power drops and/or restarts.

As implementing a fixed template in user_config_override.h will take some additional code I think it's more realistic to make the auto fallback to Sonoff Basic optional. I think I'll implement an option to switch between either Sonoff Basic (Module 1) OR the active template (Module 0). This way no fixed template needs to be compiled while there is a solution for the case where the Sonoff Basic module won't work as fallback module (like an ESP32 ethernet device ;-)

@Cerothen
Copy link
Author

That would be good, For devices that don't have the same pinout of the Sonoff Basic it would allow the user to still be able to interact with the button to get the multiple click actions

@meingraham
Copy link
Collaborator

For the choice between module (1 - basic) or the active template, would module 18 - Generic be the safest fallback?

arendst added a commit that referenced this issue Jun 17, 2020
Add command ``Module2`` to configure fallback module on fast reboot (#8464)
arendst added a commit that referenced this issue Jun 17, 2020
Make FALLBACK_MODULE configurable (#8464)
@arendst
Copy link
Owner

arendst commented Jun 17, 2020

Good question. For now the default is SONOFF_BASIC for ESP8266 and WEMOS for ESP32. It can be changed in my_user_config.h with define FALLBACK_MODULE

@ascillato2 ascillato2 added enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended and removed duplicated Result - Duplicated Issue feature request (devs?) Action - awaiting response from developers labels Jun 19, 2020
@ramanraja
Copy link

I have a custom hardware module for which I configure a custom template derived from Generic 18.
I enter the template in user_config_override.h and compile. It works well.
However, after I have upload the firmware, I have to activate the template manually either by checking the 'activate' box on the web interface, or issue the command 'module 0' through serial port.
Is there a way to avoid this extra step ? I just want to define the template in source code and simultaneously activate it, all at compile time.

@adelafug
Copy link

@ramanraja you solves problem for activate user template in reset?

@barbudor
Copy link
Contributor

#define MODULE USER_MODULE

@adelafug
Copy link

Thanks, works fine!!

@rklasen
Copy link

rklasen commented Feb 22, 2022

I like that. So I can define the template at compile time and have it be activated automatically after I uploaded the firmware? Just to be sure, would adding this to user_config_override.h work?

#undef USER_TEMPLATE
#define USER_TEMPLATE "{\"NAME\":\"ESP01-Dimmer\",\"GPIO\":[1,1,416,1,1,1,1,1,1,1,1,1,1,1],\"FLAG\":0,\"BASE\":18}"

@ascillato
Copy link
Contributor

ascillato commented Feb 22, 2022

Just to be sure, would adding this to user_config_override.h work?

That will only add a template, but that is not activated. If you want to also activate it, you must do the following in user_config_override.h:

#ifdef MODULE
#undef MODULE
#endif
#define MODULE                 USER_MODULE   // [Module] Select default model (the list is kModuleNiceList() in file tasmota_template.h) USER_MODULE is the TEMPLATE

#ifdef FALLBACK_MODULE
#undef FALLBACK_MODULE
#endif
#define FALLBACK_MODULE        USER_MODULE   // to Select the default model as FALLBACK when the user does a RESET 1 

#ifdef USER_TEMPLATE
#undef USER_TEMPLATE
#endif
#define USER_TEMPLATE          "{\"NAME\":\"ESP01-Dimmer\",\"GPIO\":[1,1,416,1,1,1,1,1,1,1,1,1,1,1],\"FLAG\":0,\"BASE\":18}" // [Template] Set JSON template

Remember that if the device is blank, the template will be activated. But if the device is not blank (It has an older version of Tasmota) you must do a ´reset 1´ in the console to reset all settings to default and make the device to start using the template defined as default in your firmware.

@rklasen
Copy link

rklasen commented Feb 22, 2022

Thank you for the help and the quick reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Type - Enhancement that will be worked on fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

10 participants