├── README.md ├── main.cpp └── platformio.ini /README.md: -------------------------------------------------------------------------------- 1 | # ESP32-code 2 | Here is the code I'm running on my ESP32 as of Summer 2024 (This is based on V2 of SensESP) 3 | 4 | The setup is using examples found on the excellent SensESP pages here - https://github.com/SignalK/SensESP 5 | 6 | I now have engine temperature, exhaust temp & Oil Temp, engine RPM, engine room environmental, engine runtime using the ESP uptime and (estimated) fuel consumption which is using the engine RPM and fuel burn info from the Volvo Penta documents. I have recently added a bilge monitor to this project. 7 | 8 | Please make sure you add the following additional dependencies to your platformio.ini file, located under 'lib_deps', also check the latest version of these dependencies (Thanks Techstyle). I've uploaded my file as a reference. 9 | 10 | SensESP/OneWire@^2.0.0 11 | 12 | adafruit/Adafruit BMP280 Library @ ^2.5.0 13 | 14 | Videos of my setup can be found on our YouTube channel - https://www.youtube.com/c/BoatingwiththeBaileys 15 | 16 | Hope this is helpful and my thanks to all the talented people writing the code and continuing to develop these projects! 17 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // SenESP Engine Sensors 2 | //Code - June 2023 3 | //Change - Updated fuel used l/m info to fuel rate to Cubic m per second 4 | 5 | #include 6 | #include 7 | 8 | #include "sensesp_onewire/onewire_temperature.h" 9 | 10 | #include 11 | 12 | #include "sensesp/sensors/analog_input.h" 13 | #include "sensesp/sensors/sensor.h" 14 | #include "sensesp/signalk/signalk_output.h" 15 | #include "sensesp/system/lambda_consumer.h" 16 | #include "sensesp_app_builder.h" 17 | #include "sensesp/transforms/linear.h" 18 | #include "sensesp/transforms/moving_average.h" 19 | #include "sensesp/transforms/analogvoltage.h" 20 | #include "sensesp/transforms/curveinterpolator.h" 21 | #include "sensesp/transforms/voltagedivider.h" 22 | #include "sensesp/sensors/digital_input.h" 23 | #include "sensesp/transforms/frequency.h" 24 | 25 | 26 | using namespace sensesp; 27 | 28 | class TemperatureInterpreter : public CurveInterpolator { 29 | public: 30 | TemperatureInterpreter(String config_path = "") 31 | : CurveInterpolator(NULL, config_path) { 32 | // Populate a lookup table to translate the ohm values returned by 33 | // our temperature sender to degrees Kelvin 34 | clear_samples(); 35 | // addSample(CurveInterpolator::Sample(knownOhmValue, knownKelvin)); 36 | add_sample(CurveInterpolator::Sample(20, 393.15)); 37 | add_sample(CurveInterpolator::Sample(30, 383.15)); 38 | add_sample(CurveInterpolator::Sample(40, 373.15)); 39 | add_sample(CurveInterpolator::Sample(55, 363.15)); 40 | add_sample(CurveInterpolator::Sample(70, 353.15)); 41 | add_sample(CurveInterpolator::Sample(100, 343.15)); 42 | add_sample(CurveInterpolator::Sample(140, 333.15)); 43 | add_sample(CurveInterpolator::Sample(200, 323.15)); 44 | add_sample(CurveInterpolator::Sample(300, 317.15)); 45 | add_sample(CurveInterpolator::Sample(400, 313.15)); 46 | } 47 | }; 48 | 49 | class FuelInterpreter : public CurveInterpolator { 50 | public: 51 | FuelInterpreter(String config_path = "") 52 | : CurveInterpolator(NULL, config_path) { 53 | // Populate a lookup table to translate RPM to m3/s 54 | clear_samples(); 55 | // addSample(CurveInterpolator::Sample(RPM, m3/s)); 56 | add_sample(CurveInterpolator::Sample(500, 0.00000011)); 57 | add_sample(CurveInterpolator::Sample(1000, 0.00000019)); 58 | add_sample(CurveInterpolator::Sample(1500, 0.0000003)); 59 | add_sample(CurveInterpolator::Sample(1800, 0.00000041)); 60 | add_sample(CurveInterpolator::Sample(2000, 0.00000052)); 61 | add_sample(CurveInterpolator::Sample(2200, 0.00000066)); 62 | add_sample(CurveInterpolator::Sample(2400, 0.00000079)); 63 | add_sample(CurveInterpolator::Sample(2600, 0.00000097)); 64 | add_sample(CurveInterpolator::Sample(2800, 0.00000124)); 65 | add_sample(CurveInterpolator::Sample(3000, 0.00000153)); 66 | add_sample(CurveInterpolator::Sample(3200, 0.00000183)); 67 | add_sample(CurveInterpolator::Sample(3400, 0.000002)); 68 | add_sample(CurveInterpolator::Sample(3800, 0.00000205)); 69 | } 70 | }; 71 | 72 | reactesp::ReactESP app; 73 | 74 | Adafruit_BMP280 bmp280; 75 | 76 | float read_temp_callback() { return (bmp280.readTemperature() + 273.15);} 77 | float read_pressure_callback() { return (bmp280.readPressure());} 78 | 79 | // The setup function performs one-time application initialization. 80 | void setup() { 81 | #ifndef SERIAL_DEBUG_DISABLED 82 | SetupSerialDebug(115200); 83 | #endif 84 | 85 | // Construct the global SensESPApp() object 86 | SensESPAppBuilder builder; 87 | sensesp_app = (&builder) 88 | // Set a custom hostname for the app. 89 | ->set_hostname("SensESP") 90 | // Optionally, hard-code the WiFi and Signal K server 91 | // settings. This is normally not needed. 92 | //->set_wifi("My WiFi SSID", "my_wifi_password") 93 | //->set_sk_server("192.168.10.3", 80) 94 | ->enable_uptime_sensor() 95 | // ->enable_ota("raspberry") 96 | ->get_app(); 97 | 98 | 99 | /// 1-Wire Temp Sensors - Exhaust Temp & Oil Temp Sensors /// 100 | 101 | DallasTemperatureSensors* dts = new DallasTemperatureSensors(17); 102 | 103 | //exhaust 104 | auto* exhaust_temp = 105 | new OneWireTemperature(dts, 1000, "/Exhaust Temperature/oneWire"); 106 | //oil config (remove if not required, can also be copied for more sensors) 107 | auto* oil_temp = 108 | new OneWireTemperature(dts, 1000, "/Oil Temperature/oneWire"); 109 | //exhaust 110 | exhaust_temp->connect_to(new Linear(1.0, 0.0, "/Exhaust Temperature/linear")) 111 | ->connect_to( 112 | new SKOutputFloat("propulsion.engine.1.exhaustTemperature","/Exhaust Temperature/sk_path")); 113 | //oil (remove if not required, can also be copied for more sensors) 114 | oil_temp->connect_to(new Linear(1.0, 0.0, "/Oil Temperature/linear")) 115 | ->connect_to( 116 | new SKOutputFloat("propulsion.engine.1.oilTemperature","/Oil Temperature/sk_path")); 117 | 118 | //RPM Application///// 119 | 120 | const char* config_path_calibrate = "/Engine RPM/calibrate"; 121 | const char* config_path_skpath = "/Engine RPM/sk_path"; 122 | const float multiplier = 1.0; 123 | 124 | auto* sensor = new DigitalInputCounter(16, INPUT_PULLUP, RISING, 500); 125 | 126 | sensor->connect_to(new Frequency(multiplier, config_path_calibrate)) 127 | // connect the output of sensor to the input of Frequency() 128 | ->connect_to(new MovingAverage(2, 1.0,"/Engine RPM/movingAVG")) 129 | ->connect_to(new SKOutputFloat("propulsion.engine.revolutions", config_path_skpath)); 130 | // connect the output of Frequency() to a Signal K Output as a number 131 | 132 | sensor->connect_to(new Frequency(6)) 133 | // times by 6 to go from Hz to RPM 134 | ->connect_to(new MovingAverage(4, 1.0,"/Engine Fuel/movingAVG")) 135 | ->connect_to(new FuelInterpreter("/Engine Fuel/curve")) 136 | ->connect_to(new SKOutputFloat("propulsion.engine.fuel.rate", "/Engine Fuel/sk_path")); 137 | 138 | /// BMP280 SENSOR CODE - Engine Room Temp Sensor //// 139 | 140 | // 0x77 is the default address. Some chips use 0x76, which is shown here. 141 | // If you need to use the TwoWire library instead of the Wire library, there 142 | // is a different constructor: see bmp280.h 143 | 144 | bmp280.begin(0x76); 145 | 146 | // Create a RepeatSensor with float output that reads the temperature 147 | // using the function defined above. 148 | auto* engine_room_temp = 149 | new RepeatSensor(5000, read_temp_callback); 150 | 151 | auto* engine_room_pressure = 152 | new RepeatSensor(60000, read_pressure_callback); 153 | 154 | // Send the temperature to the Signal K server as a Float 155 | engine_room_temp->connect_to(new SKOutputFloat("propulsion.engineRoom.temperature")); 156 | 157 | engine_room_pressure->connect_to(new SKOutputFloat("propulsion.engineRoom.pressure")); 158 | 159 | //// Engine Temp Config //// 160 | 161 | const float Vin = 3.5; 162 | const float R1 = 120.0; 163 | auto* analog_input = new AnalogInput(36, 2000); 164 | 165 | analog_input->connect_to(new AnalogVoltage(Vin, Vin)) 166 | ->connect_to(new VoltageDividerR2(R1, Vin, "/Engine Temp/sender")) 167 | ->connect_to(new TemperatureInterpreter("/Engine Temp/curve")) 168 | ->connect_to(new Linear(1.0, 0.9, "/Engine Temp/calibrate")) 169 | ->connect_to(new MovingAverage(4, 1.0,"/Engine Temp/movingAVG")) 170 | ->connect_to(new SKOutputFloat("propulsion.engine.temperature", "/Engine Temp/sk_path")); 171 | 172 | analog_input->connect_to(new AnalogVoltage(Vin, Vin)) 173 | ->connect_to(new VoltageDividerR2(R1, Vin, "/Engine Temp/sender")) 174 | ->connect_to(new SKOutputFloat("propulsion.engine.temperature.raw")); 175 | 176 | //// Bilge Monitor ///// 177 | 178 | auto* bilge = new DigitalInputState(25, INPUT_PULLUP, 5000); 179 | 180 | auto int_to_string_function = [](int input) ->String { 181 | if (input == 1) { 182 | return "Water present!"; 183 | } 184 | else { // input == 0 185 | return "bilge clear"; 186 | } 187 | }; 188 | 189 | auto int_to_string_transform = new LambdaTransform(int_to_string_function); 190 | 191 | bilge->connect_to(int_to_string_transform) 192 | ->connect_to(new SKOutputString("propulsion.engine.bilge")); 193 | 194 | bilge->connect_to(new SKOutputString("propulsion.engine.bilge.raw")); 195 | 196 | // Start networking, SK server connections and other SensESP internals 197 | sensesp_app->start(); 198 | } 199 | 200 | void loop() { app.tick(); } 201 | -------------------------------------------------------------------------------- /platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Please visit documentation for the other options and examples 4 | ; https://docs.platformio.org/page/projectconf.html 5 | 6 | [platformio] 7 | ;set default_envs to whichever board(s) you use. Build/Run/etc processes those envs 8 | default_envs = 9 | esp32dev 10 | 11 | [env] 12 | ; Global data for all [env:***] 13 | framework = arduino 14 | lib_ldf_mode = deep 15 | monitor_speed = 115200 16 | lib_deps = 17 | ; Peg the SensESP version to 2.0.0 and compatible versions 18 | SignalK/SensESP @ ^2.0.0 19 | 20 | ; Add any additional dependencies here 21 | SensESP/OneWire@^2.0.0 22 | adafruit/Adafruit BMP280 Library @ ^2.5.0 23 | 24 | [espressif32_base] 25 | ;this section has config items common to all ESP32 boards 26 | platform = espressif32 27 | build_unflags = 28 | -Werror=reorder 29 | board_build.partitions = min_spiffs.csv 30 | monitor_filters = esp32_exception_decoder 31 | 32 | [env:esp32dev] 33 | extends = espressif32_base 34 | board = esp32dev 35 | build_flags = 36 | -D LED_BUILTIN=2 37 | ; Uncomment the following to disable debug output altogether 38 | ;-D DEBUG_DISABLED 39 | ; Uncomment the following to enable the remote debug telnet interface on port 23 40 | ;-D REMOTE_DEBUG 41 | 42 | ;; Uncomment and change these if PlatformIO can't auto-detect the ports 43 | ;upload_port = /dev/tty.SLAB_USBtoUART 44 | ;monitor_port = /dev/tty.SLAB_USBtoUART 45 | 46 | ;; Uncomment the following lines to use Over-the-air (OTA) Updates 47 | ;upload_protocol = espota 48 | ;upload_port = IP_ADDRESS_OF_ESP_HERE 49 | ;upload_flags = 50 | ; --auth=YOUR_OTA_PASSWORD 51 | --------------------------------------------------------------------------------