#if defined(CONFIG_MOTION_FIRST_ENABLED) || defined(CONFIG_MOTION_SECOND_ENABLED)
static QueueHandle_t motion_queue;
static QueueHandle_t check_queue;
+static int64_t last_motion_true_time = 0;
+static int64_t last_motion_false_time = 0;
+int64_t MOTION_SEND_BACKOFF_MS = 5000;
static int prev_motion[2] = {0, 0};
static int motion_pins[2] = {0, 0};
#if defined(CONFIG_WIFI_ENABLED) || defined(CONFIG_OT_ENABLED)
#if defined(CONFIG_MOTION_FIRST_ENABLED) || defined(CONFIG_MOTION_SECOND_ENABLED)
static void send_report_motion(bool motion){
+ // set the current motion variable regardless of what we do subsequently
xSemaphoreTake(report_data.mutex, portMAX_DELAY);
report_data.motion = motion;
xSemaphoreGive(report_data.mutex);
+ // this section is meant to squelch rapidly oscilating GPIOs so that we don't
+ // spam mqtt. separated into true and false times just so you don't have a false stamp out
+ // a subsequent true (and have to wait for the summary report to realize you moved)
+
+
+ // microseconds
+ int64_t cur_uptime = esp_timer_get_time();
+ if ( motion == true ){
+ if (cur_uptime < last_motion_true_time + MOTION_SEND_BACKOFF_MS*1000){
+ // we recently sent out a motion true event on mqtt, ignore and return
+ return;
+ } else {
+ last_motion_true_time = cur_uptime;
+ }
+ } else {
+ if (cur_uptime < last_motion_false_time + MOTION_SEND_BACKOFF_MS*1000){
+ // we recently sent out a motion false event on mqtt, ignore and return
+ return;
+ } else {
+ last_motion_false_time = cur_uptime;
+ }
+ }
+
+ // if we got here we actually do want to send the data
ESP_LOGI(TAG, "send_report_motion was called!");
cJSON *root;
root = cJSON_CreateObject();