Sensor values ​​stop updating and freeze after a while in espRainmaker app

Bortolin
Posts: 4
Joined: Sun Mar 09, 2025 10:09 pm

Sensor values ​​stop updating and freeze after a while in espRainmaker app

Postby Bortolin » Tue Mar 18, 2025 2:03 pm

I developed a project with ESP32 using EspRainMaker, reading two humidity and temperature sensors. After a while the values ​​stop updating and freeze. I checked on the Arduino IDE serial monitor and the values ​​are being updated but not in the app anymore.
Can you help me?

Piyush
Espressif staff
Espressif staff
Posts: 372
Joined: Wed Feb 20, 2019 7:02 am

Re: Sensor values ​​stop updating and freeze after a while in espRainmaker app

Postby Piyush » Wed Mar 19, 2025 2:41 pm

Are these regular parameters or time series parameters? At what frequency are you updating them? If frequency is high enough, the MQTT budgeting could be restricting the updates. You should not exceed 1 message per 5 seconds. If your parameters are time series parameters, updating them will require 2 messages each. So both param updates = 4 messages. If you are updating them within 20 seconds, the budgeting will restrict some updates. You can check out this video snippet to understand the budgeting concept.

Bortolin
Posts: 4
Joined: Sun Mar 09, 2025 10:09 pm

Re: Sensor values ​​stop updating and freeze after a while in espRainmaker app

Postby Bortolin » Thu Mar 20, 2025 8:13 pm

The sensor reading update and sending time is 5 seconds.
below is the code I am using

#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
#include <Wire.h>
#include <Adafruit_SHT31.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define DEFAULT_POWER_MODE true
const char *service_name = "PROV_1234";
const char *pop = "abcd1234";

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// GPIOs para relés e LED
static int gpio_manual_relay1 = 25;
static int gpio_manual_relay2 = 26;
static int gpio_led = 27;
static int gpio_reset = 0;

bool manual_switch_state1 = false;
bool manual_switch_state2 = false;

Adafruit_SHT31 sht31 = Adafruit_SHT31();

// Dispositivos RainMaker
static Switch manual_switch1("Relay 1", &gpio_manual_relay1);
static Switch manual_switch2("Relay 2", &gpio_manual_relay2);
static TemperatureSensor temperature_device("Temperature");
static Device humidity_sensor("Humidity Sensor");
static TemperatureSensor humidity("Humidity");

static Param humidity_param("Humidity", "humidity", esp_rmaker_float(0.0), PROP_FLAG_READ);
static Param temperature_param("Temperature", "temperature", esp_rmaker_float(0.0), PROP_FLAG_READ);

unsigned long previousMillis = 0;
const long sensorInterval = 3000; // Intervalo de leitura do sensor

void sysProvEvent(arduino_event_t *sys_event) {
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
digitalWrite(gpio_led, HIGH);
break;
case ARDUINO_EVENT_PROV_END:
Serial.println("\nProvisioning ended.");
digitalWrite(gpio_led, LOW);
break;
default:
break;
}
}

void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) {
const char *param_name = param->getParamName();

if (strcmp(param_name, "Power") == 0) {
if (strcmp(device->getDeviceName(), "Relay 1") == 0) {
manual_switch_state1 = val.val.b;
digitalWrite(gpio_manual_relay1, manual_switch_state1 ? HIGH : LOW);
} else if (strcmp(device->getDeviceName(), "Relay 2") == 0) {
manual_switch_state2 = val.val.b;
digitalWrite(gpio_manual_relay2, manual_switch_state2 ? HIGH : LOW);
}
param->updateAndReport(val);
}
}

void setup() {
Serial.begin(115200);
pinMode(gpio_manual_relay1, OUTPUT);
pinMode(gpio_manual_relay2, OUTPUT);
pinMode(gpio_led, OUTPUT);
pinMode(gpio_reset, INPUT);
digitalWrite(gpio_manual_relay1, LOW);
digitalWrite(gpio_manual_relay2, LOW);
digitalWrite(gpio_led, LOW);

if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("Falha ao iniciar o display OLED");
return;
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 2);
display.println("Lelo Foods");
display.setTextSize(1);
display.setCursor(0, 30);
display.println("Inicializando...");
display.display();

Wire.begin();
if (!sht31.begin(0x44)) {
Serial.println("Sensor SHT30 não encontrado!");
}

Node my_node = RMaker.initNode("Lelo Foods Sala 1");
manual_switch1.addCb(write_callback);
manual_switch2.addCb(write_callback);
my_node.addDevice(manual_switch1);
my_node.addDevice(manual_switch2);

my_node.addDevice(temperature_device);
humidity.addParam(humidity_param); // Adiciona o parâmetro de umidade
humidity.addCb(write_callback);
my_node.addDevice(humidity_device);

RMaker.enableOTA(OTA_USING_PARAMS);
RMaker.enableTZService();
RMaker.enableSchedule();
RMaker.start();

WiFi.onEvent(sysProvEvent);
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name);
}

void loop() {
if (digitalRead(gpio_reset) == LOW) {
delay(100);
int startTime = millis();
while (digitalRead(gpio_reset) == LOW) {
delay(50);
}
int endTime = millis();
if ((endTime - startTime) > 10000) {
Serial.println("Reset de fábrica.");
RMakerFactoryReset(2);
} else if ((endTime - startTime) > 3000) {
Serial.println("Reset Wi-Fi.");
RMakerWiFiReset(2);
}
delay(100);
}

unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= sensorInterval) {
previousMillis = currentMillis;
float temperature = sht31.readTemperature();
float humidity = sht31.readHumidity();

if (!isnan(temperature) && !isnan(humidity)) {
Serial.printf("Temp: %.2f°C\n", temperature);
Serial.printf("Umidade: %.2f%%\n", humidity);

display.clearDisplay();
display.setTextSize(2);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 2);
display.println("Lelo Foods");

display.setTextSize(1,1);
display.setCursor(0, 30);
display.printf("Temp: %.2f°C\n", temperature);
display.setCursor(0, 50);
display.printf("Umidade: %.2f%%\n", humidity);
display.display();

temperature_device.updateAndReportParam("Temperature", (float)temperature);
humidity_param.updateAndReport(esp_rmaker_float(humidity));
humudity_device.updateAndReportParam("Temperature", (float)humidty);

} else {
Serial.println("Erro ao ler SHT30!");
}
}
}

Piyush
Espressif staff
Espressif staff
Posts: 372
Joined: Wed Feb 20, 2019 7:02 am

Re: Sensor values ​​stop updating and freeze after a while in espRainmaker app

Postby Piyush » Mon Mar 24, 2025 1:20 pm

I see sensorInterval set as 3000, so as that every 3 seconds? That is quite fast. It will not only finish up the budget, but may result into the node getting deactivated for violating the ESP RainMaker fair usage policy. Can you increase the interval to 1 minute?

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest