FlyingK - First of all thank you much for the g...

First of all thank you much for the great project! I managed to use SensESP to send temperature, pressure and humidity data (bme280 sensor) to SignalK (running on an rpi5 with openplotter) from an ESP32-E microcontroller powered by a lipo battery. I'm also able to show the measurements on an e-paper display as I want to have an energy efficient display on my boat when the pi is not running. To reduce the power consumption of the esp32 I planned to use deep sleep mode and only send new deltas every few minutes. I am struggling to find a way to use SensESP to check if the openplotter AP is up and running, connect to SignalK send new deltas and then go to deep sleep again. Deep sleep usually only operates in the setup function and loop is never executed which doesn't fit the design concept of SensESP. Any ideas if it possible to use SenseESP and deep sleep?
13 Replies
Matti Airas
Matti Airas4mo ago
I haven't tried it myself, but you should be able to go to deep sleep with SensESP, but you have to do it using a ValueConsumer or a ReactESP onDelay reaction. The trick is to figure out when to do that. For example, you could connect a LambdaConsumer to the SystemStatusController object and when that reports that a websocket connection to Signal K has been established, trigger an onDelay reaction with, say, 2000 ms delay. That onDelay callback function would then make the device go sleep.
FlyingK
FlyingK4mo ago
Thx for the idea. I will check if I am able to implement something with onDelay ReactESP I've managed to rewrite my code from the mix and match style from the SensESP tutorial to a more ReactESP like style from the BMP tutorial. Now I have to figure out the LambdaConsumer on the SystemStatusController. Based on my current knowledge I will have to write two consumers. The first one will start deep sleep after the websocket client connected and sensor data has been sent and the second one will have to trigger if no connection can be established because openplotter will not be running 24/7.
Matti Airas
Matti Airas4mo ago
Makes sense. Can you share the code once you get it going? This sounds like great tutorial/example material because you're working with new concepts here. If the code is very specific to your use case, I/we/someone can the generalize it to better show the deep sleep concepts.
FlyingK
FlyingK4mo ago
Sure no problem. My GitHub repo currently is private but I will share once I made enough progress and got a stable beta version. I am struggling to get a LambdaConsumer connected to the SystemStatusController. Here is the code snippet I came up with: auto* system_status_controller = sensesp_app->get_system_status_controller(); system_status_controller->connect_to(new LambdaConsumer<SystemStatus>([](SystemStatus input) { debugD("Got system status: %d", (int)input); })); But this ends up in an endless software reset loop. Any ideas what's wrong with this? rst:0x3 (SW_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) configsip: 0, SPIWP:0xee clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 mode:DIO, clock div:2 load:0x3fff0030,len:1184 load:0x40078000,len:13232 load:0x40080400,len:3028 entry 0x400805e4 ets Jul 29 2019 12:21:46
Matti Airas
Matti Airas4mo ago
And you're certain it is that piece of code that causes the barf? It looks fine to me. 🤔 Did you get any stack trace that would help? BTW, are you using the release version or the dev-3 branch?
FlyingK
FlyingK4mo ago
I am using the release version and It breaks when I add the second part of the code. Just getting the status controller works I will try to run in debug mode but I don't have an ESP-Prog
Matti Airas
Matti Airas4mo ago
I don't get it. system_status_controller_ is a member variable of SensESPApp, meaning that there's no way it is uninstantiated, meaning that your system_status_controller pointer has got to be valid. Your LambdaConsumer is something I do all the time, and the lambda function looks totally benign as well. I need to experiment myself tomorrow.
FlyingK
FlyingK4mo ago
I will strip down my code to a bare minimum as well to test tomorrow
#include "sensesp_app_builder.h"
#include "sensesp/controllers/system_status_controller.h"
#include "sensesp/system/lambda_consumer.h"

using namespace sensesp;

reactesp::ReactESP app;

void setup() {
Serial.begin(115200);
delay(100);
Serial.println("--- starting setup ---");

SensESPAppBuilder builder;
sensesp_app = (&builder)
->set_hostname("sensesp-bme280")
->get_app();

sensesp_app->start();

// fiddling around with SystemStatusControllers and LambdaConsumers
auto* system_status_controller = sensesp_app->get_system_status_controller();
system_status_controller->connect_to(new LambdaConsumer<SystemStatus>([](SystemStatus input) {
Serial.printf("Got system status: %d", (int)input);
}));

Serial.println("--- setup done ---");
}

void loop() {
app.tick();
}
#include "sensesp_app_builder.h"
#include "sensesp/controllers/system_status_controller.h"
#include "sensesp/system/lambda_consumer.h"

using namespace sensesp;

reactesp::ReactESP app;

void setup() {
Serial.begin(115200);
delay(100);
Serial.println("--- starting setup ---");

SensESPAppBuilder builder;
sensesp_app = (&builder)
->set_hostname("sensesp-bme280")
->get_app();

sensesp_app->start();

// fiddling around with SystemStatusControllers and LambdaConsumers
auto* system_status_controller = sensesp_app->get_system_status_controller();
system_status_controller->connect_to(new LambdaConsumer<SystemStatus>([](SystemStatus input) {
Serial.printf("Got system status: %d", (int)input);
}));

Serial.println("--- setup done ---");
}

void loop() {
app.tick();
}
This is my bare minimum code and it's working. So I will gradually add code and see where it breaks OK I got it. It's a stupid rookie mistake as this is my first microcontroller project. The app was getting to big, so adding any code did break it. I had to set board_build.partitions = huge_app.csv in platformio.ini to allocate more space. I am not used to having to write efficient code 😅
Matti Airas
Matti Airas4mo ago
Heh, cool that you figured it out. min_spiffs.csv is the one used in the templates - that still allows OTA upgrades.
FlyingK
FlyingK4mo ago
I managed to get my first version up and running and it successfully sends sensor values to SignalK and goes to deep sleep afterwards 😁 The current version got me thinking. When SignalK is reachable I will be on the boat as the pi is running and I will have access to shore power most likely to recharge. I probably will rewrite my code to go to deep sleep when SignalK can't be reached but stay connected when SignalK can be reached. This will save energy while not being on the boat, which was the main idea behing deep sleep anyway.
FlyingK
FlyingK4mo ago
No description
FlyingK
FlyingK4mo ago
Getting there. All sensor values are sent to SignalK and printed on the e-paper display. If SignalK is not reachable the esp32 will go to deep sleep for 5min and retry but the values are still readable on the display
Matti Airas
Matti Airas4mo ago
Looks great. I've been planning to do something similar above my boat's nav table - now I get to mimic yours!
Want results from more Discord servers?
Add your server