Page 1 of 1
Help needed with plugin startup code
Posted: 18 Apr 2017, 09:47
by orbitcoms
Hi,
I need to modify the thermocouple plugin (P0035) so it can be used for talking to the MAX31856 (as opposed to the MAX31855).
When the device starts, I need to write values to 3 registers in the MAX31856.
How do you set up plugin code that only runs once (when system boots)? Do I use "rules" and call a routine n the plug-in or is there some area in the plugin that you can put code that acts a bit like Setup()?
Thanks
Regards
David
Re: Help needed with plugin startup code
Posted: 18 Apr 2017, 16:55
by toffel969
If you want to modify the plugin itself (it sounds like this is what you need to do), you need to download the ESPEasy sources, change the part that is required in the "Plugin...ino" source code and compile for your platform. Then either upload from Arduino IDE or create bin file that can be OTA flashed
If you just want to execute something on the esp when booting, you can use rules:
Code: Select all
On system#boot do
whatever you like
endon
However, I think you need to go to the source
Re: Help needed with plugin startup code
Posted: 18 Apr 2017, 21:04
by orbitcoms
So, I can have a routine within the plugin that writes to the appropriate registers vis SPI - let's say I call it "Initialize_Max31856()".
Then the rule simply does "whatever I like", like this for instance:
On system#boot do
Initialize_Max31856();
endon
Are statements within the block standard "C" code syntax?
Re: Help needed with plugin startup code
Posted: 18 Apr 2017, 21:32
by Martinus
The rules engine can only perform commands that are known to the framework or any of the plugins that support the 'write' plugin call. So you cannot call C functions from within rules...
But if you need to customize the setup code for a specific plugin, you should make changes inside the PLUGIN_INIT sections like this example:
Code: Select all
case PLUGIN_INIT:
{
// Get CS Pin
// If no Pin is in Config we use 15 as default -> Hardware Chip Select on ESP8266
if (Settings.TaskDevicePin1[event->TaskIndex] != 0)
{
// Konvert the GPIO Pin to a Dogotal Puin Number first ...
Plugin_039_SPI_CS_Pin = Settings.TaskDevicePin1[event->TaskIndex];
}
// set the slaveSelectPin as an output:
pinMode(Plugin_039_SPI_CS_Pin, OUTPUT);
// initialize SPI:
SPI.setHwCs(false);
SPI.begin();
addLog(LOG_LEVEL_INFO, (char*)"P039 : SPI Init");
success = true;
break;
}
Re: Help needed with plugin startup code
Posted: 18 Apr 2017, 21:39
by orbitcoms
Thanks, that is what I was looking for.