PiBrewing / craftbeerpi4

GNU General Public License v3.0
57 stars 29 forks source link

Issues with Plugin Development and Loading for CraftBeerPi4 #144

Closed brackendalebrewing closed 4 weeks ago

brackendalebrewing commented 1 month ago

Description: I've been working on updating some of my plugins for CraftBeerPi4. I have developed a plugin that allows CBPI4 to be used by an Ubuntu-based PC, with GPIO provided by an Arduino using Telemetrix-AIO. This plugin has not been tested on a Raspberry Pi. During the development, I encountered two significant issues that make plugin development difficult.

Observations:

  1. Plugin Template Setup File Issues: ◦ The plugin template setup file is missing both insertion points and keywords. ◦ Without insertion points, the plugin loading fails with little or no log evidence. ◦ Using the verbose -v option during installation provided some insight, and once corrected, plugins load properly.
  2. Plugin Loading Dependency on Installation Source: ◦ After reconfiguring the plugin with the changes in the setup file, the plugin will load and run properly only if the CBPI4 instance is installed from a remote repository (either GitHub or PyPI). ◦ The plugin fails to load into a CBPI4 instance created from a local repository, although plugins can still be installed successfully from remote plugin repositories.

Steps to Reproduce:

  1. Develop a plugin for CBPI4 using the provided template setup file.
  2. Attempt to load the plugin without insertion points and keywords.
  3. Install CBPI4 from a local repository and attempt to load the plugin.
  4. Install CBPI4 from a remote repository and attempt to load the plugin. Expected Behaviour: • The plugin should load without issues, regardless of the source from which CBPI4 is installed. • The plugin template setup file should include insertion points and keywords to prevent loading failures. Actual Behaviour: • Plugins fail to load without insertion points and keywords in the setup file. • Plugins only load properly when CBPI4 is installed from a remote repository. Environment: • CraftBeerPi4 version: 4.1.rc1 • OS: Ubuntu 24.04,22.04

Additional Context: These issues significantly hinder plugin development, especially for those using local repositories for development and testing. This really is very much out of my scope and ability. I am a older heavy equipment operator who likes making beer and tinkering with code. I hope this is helpful

avollkopf commented 1 month ago

Not sure if I understand you correctly.

First of all, you should use the latest version of cbpi which is not 4.1...... Are you using the plugin template from github directly to create a plugin?

brackendalebrewing commented 1 month ago

Hi

I’ve created a fork of CraftBeerPi4 to address a couple of specific needs in my development. The modifications I made include:

1.

Increasing Max Power:

  I’ve increased the max power to 255 to allow for finer-grained
  control over PWM. This change is essential for achieving more precise
  control in my brewing setup.
  2.

Altering Plugin Load Order:

  I’ve adjusted the plugin load order to ensure that the CBPiExtension
  loads first. Although I’m not entirely certain if this change is

necessary, I made this adjustment to avoid any potential initialization issues that could arise from dependencies on this extension.

Additionally, while examining the cbpi.create method, I noticed that it uses curl to download the plugin scaffold. This dependency is partly why I’m reaching out at this point.

I’d appreciate any insights or feedback you might have on these changes, particularly regarding the load order adjustment. If there are any best practices or additional considerations I should be aware of, I’d be grateful for your guidance.

Thank you for your time and assistance!

Best regards, Andy ( jan on the facebook group, my wife :) )

On Sat, 13 Jul 2024 at 11:04, Alexander Vollkopf @.***> wrote:

Not sure if I understand you correctly.

First of all, you should use the latest version of cbpi which is not 4.1...... Are you using the plugin template from github directly to create a plugin?

— Reply to this email directly, view it on GitHub https://github.com/PiBrewing/craftbeerpi4/issues/144#issuecomment-2227034114, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUAW6WCSFRUAGH564GWCYLZMFT4NAVCNFSM6AAAAABK2NR75GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRXGAZTIMJRGQ . You are receiving this because you authored the thread.Message ID: @.***>

avollkopf commented 1 month ago

Starting with Register:

Example from the SCD30 plugin:

def setup(cbpi):
    cbpi.plugin.register("SCD30 Sensor", SCD30Sensor)
    cbpi.plugin.register("SDC30 Config", SCD30_Config)
    pass

The plugin itself is calling the register function -> Hence, the order of calling your classes must be defined there anyhow. But plenty of the extension plugins are working partly asynchronous and therefore, you cannot really rely on the fact that one function is called before the other one to have something accomplished before the other plugins starts. Could be done somehow similar to the SCD30 plugin where it has to wait until the sensor activation is done.

Power values larger than 100:

This is not an option for implementation as power vales are defined in % and a scale of 100% is more than sufficient for a water heating process.

Rough Example: 100 Liters of water with a 10 kw heater -> start at 70°C and stop at 70.2°C

-> requires 1.4kw to heat it up within one minute (in an ideal world with 100% efficiency) -> 14% of your max power

Increased precision is there, not really required.

In addition to that, plenty of other plugins depend on the % definition.

brackendalebrewing commented 1 month ago

Hi

Thank you for your response. The plugin suggestion was very informative, and I am using that methodology for implementing delays.

However, I believe our use cases are substantially different. Let me elaborate on my brewery setup:

-

Brewery Details:

  *Capacity:* 120L (1bbl)
  -

  *Heating:* Gas-fired PID controlled
  -

  *System:* HERMS (Heat Exchanged Recirculating Mash System) with three
  vessels
  -

     *Heat Exchanger:* Temperature controlled with a PWM proportional
     valve and PID, always recirculating, splitting the

recirculation through the coil, remixing, and returning to the mash tun.

  *Pump:* VFD controlled with PID (modified Chugger Max with a 3-phase
  motor, surprisingly easy to do)
  -

  *Flow Meter:* SM6004, testing pump control via flow
  -

  *Chiller:* Plate chiller, temperature regulated via pump and PID
  -

Why CraftBeerPi:

  I have been brewing since about 2000 and started using "Strange Brew
  Elsinor" by Doug Eddy around 2010.
  -

  Transitioned to CBPi3 after the demise of Strange Brew, modifying it
  for true PWM.
  -

  Adopted CBPi4 on release and modified it with true PWM and a max
  power of 255.

I believe that CBPi4 is excellent. While I understand the rationale for using a Raspberry Pi and have done so myself, I moved to a PC for several reasons:

-

Pis are easy to damage and have poor software PWM and limited GPIOs.

PCs, even from scrap piles, are cheap and powerful.

Arduino Megas are cheap and always available.

Telemetrix-AIO:

  Asynchronous
  -

  Can be accessed via USB, Ethernet, and WiFi
  -

  The same installation can access multiple Arduinos in multiple
  locations
  -

     Currently using USB but planning to switch to Ethernet soon, which
     should be straightforward to implement.

I believe that with this slight modification, CBPi4 could be successful in a commercial application if desired. I only intend to use it in my home brewery. A separate fork is unnecessary. What I think is truly required is a changeable global max power setting. I personally will increase it from 254 to 1023 to match 10-bit ADCs. I've recently discovered that Telemetrix and my VFD can accommodate 19,999 steps, but if I go that far, it will be internal to the motor controller.

I understand that others have moved to a paid Windows application, which looks good but is a deal-breaker for me due to being closed-source and Windows-based.

Thank you, Andrew Cooper

On Sun, 14 Jul 2024 at 22:38, Alexander Vollkopf @.***> wrote:

Starting with Register:

Example from the SCD30 plugin:

def setup(cbpi): cbpi.plugin.register("SCD30 Sensor", SCD30Sensor) cbpi.plugin.register("SDC30 Config", SCD30_Config) pass

The plugin itself is calling the register function -> Hence, the order of calling your classes must be defined there anyhow. But plenty of the extension plugins are working partly asynchronous and therefore, you cannot really rely on the fact that one function is called before the other one to have something accomplished before the other plugins starts. Could be done somehow similar to the SCD3 plugin where it has to wait until the sensor activation is done.

Power values larger than 100:

This is not an option for implementation as power vales are defined in % and a scale of 100% is more than sufficient for a water heating process.

Rough Example: 100 Liters of water with a 10 kw heater -> start at 70°C and stop at 70.2°C

-> requires 1.4kw to heat it up within one minute (in an idea world with 100% efficiency) -> 14% of your max power

Increased precision is there not really required.

I addition to that, plenty of other plugins are depending on the % definition.

— Reply to this email directly, view it on GitHub https://github.com/PiBrewing/craftbeerpi4/issues/144#issuecomment-2227732311, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUAW6VFEMYAK6GMUGH4BGDZMNN5BAVCNFSM6AAAAABK2NR75GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRXG4ZTEMZRGE . You are receiving this because you authored the thread.Message ID: @.***>

avollkopf commented 4 weeks ago

The Power definition within cbpi and the UI is defined as '%' and can't have a value of 1000+ by definition of '%'... Not sure about the windows applications you are referring to, but I am talking for instance about the esp based (arduino libraries) mqtt device which can be used for brewing but also for fermentation. It is connected via mqtt and also here, power @ 100% tells the esp to go to the max setting of whatever device is hooked up. power @ 0% tells the esp to set the hooked up adc, ... to go to 0. Everything in between is just a question of the resolution and as mentioned above is not relevant to heat up water with 0.0001 watt precision for a few seconds.

How the power % is translated into an adc value or whatever has to be done in a corresponding actor or logic plugin.

brackendalebrewing commented 4 weeks ago

1024/1024 is as much 100% as 100/100

On Wed, Jul 24, 2024, 2:28 AM Alexander Vollkopf @.***> wrote:

The Power definition within cbpi and the UI is defined as '%' and can't have a value of 1000+ by definition of '%'... Not sure about the windows applications you are referring to, but I am talking for instance about the esp based (arduino libraries) mqtt device which can be used for brewing but also for fermentation. It is connected via mqtt and also here, power @ 100% tells the esp to go to the max setting of whatever device is hooked up. power @ 0% tells the esp to set the hooked up adc, ... to go to 0. Everything in between is just a question of the resolution and as mentioned above is not relevant to heat up water with 0.0001 watt precision for a few seconds.

How the power % is translated into an adc value or whatever has to be done in a corresponding actor or logic plugin.

— Reply to this email directly, view it on GitHub https://github.com/PiBrewing/craftbeerpi4/issues/144#issuecomment-2247355102, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUAW6TXCXPJW64R2CQPDZLZN5XTZAVCNFSM6AAAAABK2NR75GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBXGM2TKMJQGI . You are receiving this because you authored the thread.Message ID: @.***>

avollkopf commented 4 weeks ago

1024/1024 is as much 100% as 100/100

But that's what I am saying. The calculation can be done in the actor plugin / mqtt device / arduino,.... as the "% resolution" is more than sufficient for the application.

brackendalebrewing commented 4 weeks ago

Hi

This is where we differ. I use PWM in a fundamentally different way to control motors and valves, not for heating water with an electric element . Resolution is critical in my use and must be passed through the system. Otherwise, kettle logic, brew steps, and control systems do not function properly for my use. The devices I control are not linear but can be precisely managed on specific curves.

For instance, a proportionally controlled 3-way mixing valve must be controlled with a high degree of accuracy. A 1% change on a scale of 100 is significant in a system where the control may be primarily in the first and last 5%. A 1% change could result in a 15% change in flow, and the power value cannot be as precise as 1.01%

I use this setup in my personal repository for my brewery. I mentioned it because I thought you might be interested in a different brewing process.

I originally posted because of a problem with the installation and the CBPI create process. If you do not observe these problems on a Pi, I would like to know.

Thank you, Andrew Cooper

brackendalebrewing commented 4 weeks ago

Hi I would like to add that if you have any ideas or suggestions to overcome my issues with precision control over my devices I would be more than happy to hear from you. thanks again

On Wed, 24 Jul 2024 at 12:08, a Coop @.***> wrote:

Hi

This is where we differ. I use PWM in a fundamentally different way to control motors and valves, not for heating water with an electric element . Resolution is critical in my use and must be passed through the system. Otherwise, kettle logic, brew steps, and control systems do not function properly for my use. The devices I control are not linear but can be precisely managed on specific curves.

For instance, a proportionally controlled 3-way mixing valve must be controlled with a high degree of accuracy. A 1% change on a scale of 100 is significant in a system where the control may be primarily in the first and last 5%. A 1% change could result in a 15% change in flow, and the power value cannot be as precise as 1.01%

I use this setup in my personal repository for my brewery. I mentioned it because I thought you might be interested in a different brewing process.

I originally posted because of a problem with the installation and the CBPI create process. If you do not observe these problems on a Pi, I would like to know.

Thank you, Andrew Cooper

avollkopf commented 4 weeks ago

I think, I get more insight into your request.

I need to think about it in more detail, but I still don't think, that the power parameter should be changed. It could be probably handled with an additional parameter such as resolution.....

Your actor plugin could use the resolution paramter and is regulated via the resolution -> Power is calculated from resolution and remains between 0 and 100.

The open question is still on how you control the PWM / resolution for your desired actor? Within your actor plugin?

brackendalebrewing commented 4 weeks ago

Hi

I long ago modified CBPi to use power values between 0-255 (8-bit resolution). It was very simple to do, requiring just a couple of lines of code. The power setting then passes cleanly through the system, and the actor initializes a pin as an analog output, writing a value between 0-255. This approach works perfectly with steps, kettle logic, and any other plugins, such as the grouped power actor, which do not have internal power checking.

In the past, I used PID outside of my actors. I believe that the actor must be able to act independently and retain sufficient resolution to brew manually, which I sometimes do. I have used kettle logic to implement PID, which, while not ideal, works. Recently, I discovered that my GPIO manager supports not only 8-bit (256) control but also a second method that allows 15-bit resolution (0-19,999). I believe that scenario is best handled with an actor with built-in PID, but for manual brewing, 8-bit (256) resolution is clearly necessary based on my personal experience.

Intuitively, I do not believe that a resolution parameter can fix the granularity issue. However, changing power to a float or real type certainly would.

I have a question for you: When you first turn on CBPi4, do digital GPIO actors work without needing to be re-saved? For me, they do not, but PWM actors work without any issues. This was true four years ago and is still true for me. I am curious about how it behaves on the Pi.

I have a workaround, but I am still very interested in your experience.

Thank you, Andrew Cooper

On Wed, 24 Jul 2024 at 12:35, Alexander Vollkopf @.***> wrote:

I think, I get more insight into your request.

I need to think about it in more detail, but I still don't think, that the power parameter should be changed. It could be probably handled with an additional parameter such as resolution.....

Your actor plugin could use the resolution paramter and is regulated via the resolution -> Power is calculated from resolution and remains between 0 and 100.

The open question is still on how you control the PWM / resolution for your desired actor? Within your actor plugin?

— Reply to this email directly, view it on GitHub https://github.com/PiBrewing/craftbeerpi4/issues/144#issuecomment-2248759514, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJUAW6Q6JUTI4LULKP4L33TZN76WPAVCNFSM6AAAAABK2NR75GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBYG42TSNJRGQ . You are receiving this because you authored the thread.Message ID: @.***>

avollkopf commented 4 weeks ago

Well, first of all, this issue is going to mix up plenty of different topics. Hence, i am going to close it.

On the resolution of the 'power' a new topic must be openend. I already thought about changing it to float. I've had a discussion on that in the past with someone and he mentioned it should remain at int...

Anyhow, the definition of the power parameter is not going to be changed as it may break plenty of other things/dependencies (not only in the cbpi server itself). As already mentioned, I will think about a solution that should work also for the existing environment. I have extremely bad experience by just changing a few lines and an existing definition of a parameter.

On the GPIO topic I assume you are talking about the regular GPIO actors in cbpi. They work as expected and never have to be re-saved. I start the Pi, download a recipe and start brewing. No need to fiddle with hardware or the settings prior each process.