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.
- 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");
- }
- }
- }
- }