ESP Easy: how to develop its own plugins [Exclusive Guide]
in tutorial previous , we have seen how to customize the firmware ESP Easy from the plugins Playground , the sandbox that allows any developer to offer additional modules. I am preparing a small project to monitor the indoor air quality using a probe MQ135 . How there is no module for this sensor, I started in my own module development. I want to share my experience. There is no official documentation (yet), a large part of the information so obtained by deduction and trial and error.
for this tutorial, we will develop a new plugin for the MQ135. As no 135 plugin does still exist in the playground, I took the opportunity.
in the header of the plugin, we can define bookstores to possibly include
then, all modules must be identified by a series of keys. It is important to well assigned the ID chose to all keys so that the plugin works.
|#define PLUGIN_135||ID of the plugin|
|#define PLUGIN_ID_135 135||the ID of the plugin|
|#define PLUGIN_NAME_135 “Indoor Air Quality – MQ135”||the wording that will be displayed in the selection list|
|#define PLUGIN_VALUENAME1_135 “CO2”||the plugin output Variable. Wording displayed in quotes|
if the module for more than one output value, it simply adds a new key by incrementing the counter. For example PLUGIN_VALUENAME2_135, PLUGIN_VALUENAME3_135
the plugin is wrapped in a function. This function takes several parameters just to test. ESP Easy engine start at regular intervals plugins associated with the configured Devices.
boolean Plugin_135 [19459033
by convention, called the plugin by Plugin_ID_DU_PLUGIN
the first method (PLUGIN_DEVICE_ADD) to set parameters that are common to all Device
box PLUGIN_DEVICE_ADD :
Device [ ++ deviceCount ] . } Number = PLUGIN_ID_135 ;
Device [ deviceCount ] . Type = DEVICE_TYPE_ANALOG ;
Device [ deviceCount ] . VType = SENSOR_TYPE_SINGLE ;
Device [ deviceCount ] . Ports = 0 ;
Device [ deviceCount ] . PullUpOption = false ;
Device [ deviceCount ] . InverseLogicOption = false ;
Device [ deviceCount ] . FormulaOption = true ;
Device [ deviceCount ] . ValueCount = 1 ;
Device [ deviceCount ] . SendDataOption = true ;
Device [ deviceCount ] . TimerOption = true ;
Device [ deviceCount ] . GlobalSyncOption = true ;
the main parameters are
- Type: the type of material connected. One can choose from
- DEVICE_TYPE_SINGLE: (1) connected to a digital input (datapin)
- DEVICE_TYPE_I2C (2): the device communicates with the ESP via the I2C bus
- DEVICE_TYPE_ANALOG 3: using the ESP8266 (pine, for example A0) A/D converter
- DEVICE_TYPE_DUAL (4): device connected using 2 entry digital
- DEVICE_TYPE_DUMMY (99) : logical device without physical connection (Dummy device). Read article for more
- VType. What kind of value will return the plugin. One can choose from
- SENSOR_TYPE_SINGLE (1): an output
- SENSOR_TYPE_TEMP_HUM (2): 2. outputs of type temperature & humidity (DHT11 or DHT22)
- SENSOR_TYPE_TEMP_BARO (3): 2. outputs of type temperature & pressure (BMP180)
- SENSOR_TYPE_TEMP_HUM_BARO (4): 3. outputs, temperature, humidity, atmospheric pressure (BME280)
- SENSOR_TYPE_DUAL (5). : generic, 2 outputs
- SENSOR_TYPE_TRIPLE (6): generic, 3 outputs
- SENSOR_TYPE_SWITCH (10): 2 States, switch
- SENSOR_TYPE_DIMMER (11): 1 output inverter
- SENSOR_TYPE_LONG (20): 1 output
- ValueCount: number of output variable. This counter should match the number of key PLUGIN_VALUENAME1_xxx
this method return the name of the Device.
this method is called at the opening of the module configuration page. It allows to add a new line for each variable outpute of the plugin (Optional Settings). For example here is what you get.
this method is called at initialization of the plugin. For example, we can reload parameters.
the method must end in success = true;
this method is called at the opening of the module configuration page. It allows to build the configuration options (with the exception of the settings common to all modules) of the module. The method must return a string (string) that contains the HTML code of the rows to be added.
is an array. Each line (
here is an example that allows you to add a line to define the level of CO2 of reference. Here are a few explanations for those who discover the HTML:
: it adds a row to the table. : Add a column
- CO2 Level REF. : the text displayed in the first column. The wording of the parameter
: added a 2nd column
- < input type = ‘text’ name = ‘value plugin_135_ATMOCO2′ =’ : the 2nd column consists of a field of type text (text). We can recover the contents of the field by name ( name =’plugin_135_ATMOCO2′ ).
- were built by default by going to read her back in the settings of the module: Settings.TaskDevicePluginConfigFloat [event->TaskIndex]  . It is located at index 4. We will see later how it stores the settings of the plugin.
- Finally we close the column F(«’>»)