ESP32 and app status gets out of sync

Tranzmetro
Posts: 9
Joined: Fri Jan 05, 2018 1:38 am

ESP32 and app status gets out of sync

Postby Tranzmetro » Thu Jan 12, 2023 3:29 am

I am having an issue with my esp32 and the app status getting out of sync.
I am setting up a button to open my garage door. This needs to be a momentary button but I can't find one in Rainmaker so I am simulating it by turning a switch on for a few seconds then turning it off. This works, press the app button, the esp32 switch (LED) turns on, the app status updates to on, wait for a few seconds then the switch (LED) turns off and the app status updates to off however almost immediately the app status turns on again but the LED stays off.

I preset the switch status to off and update the app status when first connected to WiFi.

This is the Serial.println output from the callback code below:

Starting ESP-RainMaker
E (87) wifi_prov_scheme_ble: bt_mem_release of classic BT failed 259
E (182) wifi_prov_scheme_ble: bt_mem_release of BTDM failed 259

Connected to Wi-Fi!
Startup state: 0
Startup LED to LOW
Received value = true for Button - Power
Incoming state: True
Changed LED to HIGH
Changed LED to LOW

This is correct but is not reflected in the app status which returns to on.

Below is my callback code.

Code: Untitled.cpp Select all


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

if (strcmp(device_name, "Button") == 0)
{
if (strcmp(param_name, "Power") == 0)
{
Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name);
if (val.val.b)
{
Serial.println("Incoming state: True");
digitalWrite(ButtonPin, HIGH);
GarageDoorButton.updateAndReportParam("Power", true);
Serial.println("Changed LED to HIGH");
delay(5000);
digitalWrite(ButtonPin, LOW);
GarageDoorButton.updateAndReportParam("Power", false);
Serial.println("Changed LED to LOW");
}
else
{
digitalWrite(ButtonPin, LOW);
GarageDoorButton.updateAndReportParam("Power", false);
Serial.println("Reset to LOW");
}
}
}
}
Any help would be gratefully received, thanks.

Tranzmetro
Posts: 9
Joined: Fri Jan 05, 2018 1:38 am

Re: ESP32 and app status gets out of sync

Postby Tranzmetro » Thu Jan 19, 2023 9:54 pm

I solved the problem by taking the switching statements out of the callback. I set a flag in the callback then change the status in the main loop.

cloudmiracle
Posts: 8
Joined: Sat Aug 26, 2023 6:43 am

Re: ESP32 and app status gets out of sync

Postby cloudmiracle » Sat Aug 26, 2023 6:49 am

@Transmetro. Can you please share the code. I am trying to operate relay momentary on esp32 Arduino Rainmaker code many options but not successful

Who is online

Users browsing this forum: No registered users and 0 guests