SignalK / SensESP

Universal Signal K sensor framework for the ESP32 platform
https://signalk.org/SensESP/
Apache License 2.0
145 stars 79 forks source link

added constant_sensor class #661

Closed mestafin closed 1 year ago

mestafin commented 1 year ago

constant_sensor Library for sensESP to add virtual sensors that emit a constant value

Overview This library add a virtual sensors that periodically emit a constant value.

The virtual sensors are typically used to send a constant value to SignalK. Typical example is the capacity of a tank.

The sensors can be connected to all the standar SKOutput consumers.

The value of the sensor can be se via the web configuration page of sensESP;

Sensor Types:

ConstantFloat
ConstantInt
ConstantString

How to Use

Example: send the water tank capacity every 30 seconds to SignalK:

    int send_delay = 30; 
    const char* config_path = "/tanks.water_capacity";
    auto *capacity = new ConstantFloat(send_delay,config_path);
    capacity->connect_to(new SKOutputFloat(sk_path, sk_config_path, sk_metadata));

To set or get the the value of the virtual sensor for use in your code:

    capacity->set(value);

    value = capacity->get();
mairas commented 1 year ago

I couldn't initially understand the use case for a constant value sensor but the tank volume example hit the spot!

The PR description with the usage examples is very good; ~it'd be shame if anything happened to it~ it'd be great to have it included in the project documentation. Could you copy-paste it to the doc comment of ConstantSensor? Doxygen supports Markdown, so no additional formatting should be required.

https://www.doxygen.nl/manual/docblocks.html

mestafin commented 1 year ago

It is already in the @brief comment of the constant_sensor.h source file.

Or am I missing something?

Johan

On 22 Jun 2023, at 10:52, Matti Airas @.***> wrote:

I couldn't initially understand the use case for a constant value sensor but the tank volume example hit the spot!

The PR description with the usage examples is very good; it'd be shame if anything happened to it it'd be great to have it included in the project documentation. Could you copy-paste it to the doc comment of ConstantSensor? Doxygen supports Markdown, so no additional formatting should be required.

https://www.doxygen.nl/manual/docblocks.html

— Reply to this email directly, view it on GitHub https://github.com/SignalK/SensESP/pull/661#issuecomment-1602261312, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAP3DTP5L53EEXZIGBMWZLDXMQBVPANCNFSM6AAAAAAZPEDLPA. You are receiving this because you authored the thread.

mairas commented 1 year ago

It is already in the @brief comment of the constant_sensor.h source file.

Or am I missing something?

I was just thinking about the usage examples; they're really good to have.

mairas commented 1 year ago

Your template code was quite close. C++ has a lot of quirks and baggage accumulated over time. One such thing is that template method definitions need to be in the header file and not in the .cpp file. I changed that and did a bit of other cleanups. I'll need to test the code on an actual device before merging.

mairas commented 1 year ago

Oh, and there seems to be some build issue in CI, too.

mairas commented 1 year ago

There were some minor issues in the class implementation (changes I made) and the example had a few notable omissions. Fixed now, and the value is properly transmitted. Merging.

Thanks, @mestafin, for the PR!

mestafin commented 1 year ago

Thanks for your help with the C++ quirks