-
Notifications
You must be signed in to change notification settings - Fork 639
3rd Party Plugins
espurna includes integration hooks for custom code and 3rd party modules integration. This attached template files, to help integrating or 3rd party code. Please also take a look at the attached files for inline help documentation, describing the different optionsand features. The main concept is to allow adding new functionality to espurna with zero to minimal code changes to espurna core system (just adding the new files and integrating by setting a build flag only).
-
custom.h - this is the generic espurna custom header include file (included by all.h based on USE_CUSTOM_H build flag) allows setting and overriding espurna core flags definitions. This file includes the plugin activation code and a single integration (include in load image) enable flag for each plugin.
-
plugin1.h - The plugin header file (to be placed in config folder) includes plugin specific defines. this header is included by custom.h based on the plugin include flag (INCLUDE_PLUGINx in custom.h) to allow switching on/off integration of multiple plugins.
-
plugin1.ino - The plugin template (to be placed in code folder). this template enables writing a plugin and use all espurna services and utils (the template file will be enhanced over time).
In development phase, working, limited tresting.
- Due to current frontend structure, I did not add the HTML/JS/CSS files, since I did not want to change core files, so in case of frontend need for plugin, you need to add the plugin page, but all the web services hooks included in the template (don't forget to gulp).
- A more generic hook system that will enable a tightly coupled plugins (that will get callbacks from different espurna internal hook points) is under development.
(All inline documented ) Like any other espurna module, includes Helper functions, setup and main loop:
- Helper functions you can copy/add any the template includes a single main loop sample function _plugin1Function1(); with all possible services hooks, you can copy it. Other helper functions are utils used by setup or loop function (like set a relay or read sensor).
- Setup function (pluginxSetup()) called by extraSetup() defined in custom.h. extraSetup() is called by espura.ino setup function based on USE_EXTRA flag (this is the generic espurna 3rd party code integration hook).
- Plugin main loop called by espurna loop (via callback function registrations array). plugin loop is registered by pluginsetup function.
(services enabled by the plugin template), most code is commented out, to allow uncomment/delete needed/unneeded code. The services are all public espurna functions to be used for the specific plugin needs logic and data.
- Main loop features
- Get sensors data
- Set relays
- Factory reset
- AP mode
- System reset
- Setter/Getter for plugin params
- Broker publish
- MQTT publish
- DOMOTICZ publish
- INFLUXDB publish
- THINGSPEAK publish
- Copy the custom.h
- Copy plugin1.h files into lib/plugin1 folder (create plugin1 folder in existing lib)
- Copy the plugin1.ino file to espurna folder
- Build with -DUSE_CUSTOM_H flag
- See on debug (web/serial/telnet) a loop counter (every PLUGIN_REPORT_EVERY param -5 sec)
- Terminal command "plugin1 0" will stop plugin execution and "plugin1 1" start
- API command "/plugin1?apikey=xxxxx&value=0" stop, "/plugin1?apikey=xxxxx&value=1" start
- Read plugin1.ino and plugin1.h inline documentation and write your espurna magic
(folders structure may depend on your framework and development environment, if you get compile/link error regarding existence of these files, please refer to your specific build settings documentation)
If you're looking for support:
- Issues: this is the most dynamic channel at the moment, you might find an answer to your question by searching open or closed issues.
- Wiki pages: might not be as up-to-date as we all would like (hey, you can also contribute in the documentation!).
- Gitter channel: you have better chances to get fast answers from project contributors or other ESPurna users. (also available with any Matrix client!)
- Issue a question: as a last resort, you can open new question issue on GitHub. Just remember: the more info you provide the more chances you'll have to get an accurate answer.
- Backup the stock firmware
- Flash a pre-built binary image
- Flash a virgin Itead Sonoff device without opening
- Flash TUYA-based device without opening
- Flash Shelly device without opening
- Using PlatformIO
- from Visual Studio Code
- Using Arduino IDE
- Build the Web Interface
- Over-the-air updates
- Two-step updates
- ESPurna OTA Manager
- NoFUSS
- Troubleshooting
- MQTT
- REST API
- Domoticz
- Home Assistant
- InfluxDB
- Prometheus metrics
- Thingspeak
- Alexa
- Google Home
- Architecture
- 3rd Party Plugins
- Coding style
- Pull Requests