Loading [MathJax]/extensions/tex2jax.js
SensESP 3.1.0
Universal Signal K sensor toolkit ESP32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
main.cpp
Go to the documentation of this file.
1#include <Arduino.h>
2
3// #define SERIAL_DEBUG_DISABLED
4
9
10using namespace sensesp;
11
12void setup() {
14
15 SensESPAppBuilder builder;
16 sensesp_app = builder.get_app();
17
18 // The "Signal K path" identifies the output of the sensor to the Signal K
19 // network. If you have multiple sensors connected to your microcontoller
20 // (ESP), each one of them will (probably) have its own Signal K path
21 // variable. For example, if you have two propulsion engines, and you want the
22 // RPM of each of them to go to Signal K, you might have sk_path_portEngine =
23 // "propulsion.port.revolutions" and sk_path_starboardEngine =
24 // "propulsion.starboard.revolutions" In this example, there is only one
25 // propulsion engine, and its RPM is the only thing being reported to Signal
26 // K. To find valid Signal K Paths that fits your need you look at this link:
27 // https://signalk.org/specification/1.4.0/doc/vesselsBranch.html
28 const char* sk_path = "propulsion.main.revolutions";
29
30 // The "Configuration path" is combined with "/config" to formulate a URL
31 // used by the RESTful API for retrieving or setting configuration data.
32 // It is ALSO used to specify a path to the SPIFFS file system
33 // where configuration data is saved on the microcontroller. It should
34 // ALWAYS start with a forward slash if specified. If left blank,
35 // that indicates this sensor or transform does not have any
36 // configuration to save.
37 // Note that if you want to be able to change the sk_path at runtime,
38 // you will need to specify a configuration path.
39 // As with the Signal K path, if you have multiple configurable sensors
40 // connected to the microcontroller, you will have a configuration path
41 // for each of them, such as config_path_portEngine =
42 // "/sensors/portEngine/rpm" and config_path_starboardEngine =
43 // "/sensor/starboardEngine/rpm".
44 const char* config_path = "/sensors/engine_rpm";
45
46 // These two are necessary until a method is created to synthesize them.
47 // Everything after "/sensors" in each of these ("/engine_rpm/calibrate" and
48 // "/engine_rpm/sk") is simply a label to display what you're configuring in
49 // the Configuration UI.
50 const char* config_path_calibrate = "/sensors/engine_rpm/calibrate";
51 const char* config_path_skpath = "/sensors/engine_rpm/sk";
52
54 // connect a RPM meter. A DigitalInputPcntCounter implements
55 // access to a pulse counter peripheral. Every read_delay ms, it
56 // reads the number of pulses that have occurred since the last
57 // read, and reports that number (500ms in the example). A Frequency
58 // transform takes a number of pulses and converts that into
59 // a frequency. The sample multiplier converts the 97 tooth
60 // tach output into Hz, SK native units.
61 const float multiplier = 1.0 / 97.0;
62 const unsigned int read_delay = 500;
63
64 // Wire it all up by connecting the producer directly to the consumer
65 // ESP32 pins are specified as just the X in GPIOX
66 uint8_t pin = 4;
67
68 auto* sensor = new DigitalInputCounter(pin, INPUT_PULLUP, RISING, read_delay);
69
70 auto frequency = new Frequency(multiplier, config_path_calibrate);
71
72 ConfigItem(frequency)
73 ->set_title("Frequency")
74 ->set_description("Frequency of the engine RPM signal")
75 ->set_sort_order(1000);
76
77 auto frequency_sk_output = new SKOutput<float>(sk_path, config_path_skpath);
78
79 ConfigItem(frequency_sk_output)
80 ->set_title("Frequency SK Output Path")
81 ->set_sort_order(1001);
82
83 sensor
84 ->connect_to(frequency) // connect the output of sensor
85 // to the input of Frequency()
86 ->connect_to(frequency_sk_output); // connect the output of Frequency()
87 // to a Signal K Output as a number
88}
89
90void loop() { event_loop()->tick(); }
DigitalInputCounter counts interrupts and reports the count every read_delay ms.
Transforms its input into frequency (Hz: cycles per second)
Definition frequency.h:22
A specialized transform whose primary purpose is to output Signal K data on the Signal K network.
A class for quickly configuring a SensESP application object before wiring up your sensors.
std::shared_ptr< SensESPApp > get_app()
Get the SensESPApp object.
void setup()
Definition main.cpp:12
void loop()
Definition main.cpp:90
std::shared_ptr< reactesp::EventLoop > event_loop()
Definition sensesp.cpp:9
std::shared_ptr< SensESPApp > sensesp_app
std::shared_ptr< ConfigItemT< T > > ConfigItem(std::shared_ptr< T >)
Register a ConfigItemT with the ConfigItemBase.
void SetupLogging(esp_log_level_t default_level=ESP_LOG_DEBUG)