Help needed with plugin startup code

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
orbitcoms
Normal user
Posts: 28
Joined: 01 Apr 2017, 06:12

Help needed with plugin startup code

#1 Post by orbitcoms » 18 Apr 2017, 09:47

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

User avatar
toffel969
Normal user
Posts: 469
Joined: 03 Jan 2017, 10:58
Location: Germany

Re: Help needed with plugin startup code

#2 Post by toffel969 » 18 Apr 2017, 16:55

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
Domoticz on Raspi 2 -- 14 ESP units (hacked Sonoff,NodeMCUs, Wemos, self-built units) running with RC140- Mega 2.0.0 dev8

orbitcoms
Normal user
Posts: 28
Joined: 01 Apr 2017, 06:12

Re: Help needed with plugin startup code

#3 Post by orbitcoms » 18 Apr 2017, 21:04

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?

Martinus

Re: Help needed with plugin startup code

#4 Post by Martinus » 18 Apr 2017, 21:32

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;
      }

orbitcoms
Normal user
Posts: 28
Joined: 01 Apr 2017, 06:12

Re: Help needed with plugin startup code

#5 Post by orbitcoms » 18 Apr 2017, 21:39

Thanks, that is what I was looking for.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest