Dwi259eti Firmware ✮
void my_feature_task(void *arg)
nvs_handle_t h; ESP_ERROR_CHECK(nvs_open("my_feat", NVS_READWRITE, &h)); ESP_ERROR_CHECK(nvs_set_blob(h, "threshold", &thr, sizeof(thr))); ESP_ERROR_CHECK(nvs_commit(h)); nvs_close(h); return ESP_OK;
static void at_cmd_temp_handler(at_cmd_ctx_t *ctx, const char *params) Dwi259eti Firmware
at_register_command("AT+TEMP?", at_cmd_temp_handler, AT_CMD_TYPE_QUERY);
while (1) float temp; if (my_feature_get_temperature(&temp) == 0) ESP_LOGI(TAG, "Temp = %.2f°C", temp); // Optionally publish via MQTT vTaskDelay(pdMS_TO_TICKS(10000)); // 10 s interval void my_feature_task(void *arg) nvs_handle_t h
/* Example: read a temperature sensor on I2C address 0x48 */ int my_feature_get_temperature(float *temp_c) I2C_MASTER_WRITE, true); i2c_master_write_byte(cmd, 0x00, true); // register address i2c_master_stop(cmd); esp_err_t err = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_PERIOD_MS); i2c_cmd_link_delete(cmd); if (err != ESP_OK) return -1;
If the feature is periodic, spawn a FreeRTOS task: static void at_cmd_temp_handler(at_cmd_ctx_t *ctx
// registration – called from at_init() void at_register_my_feature(void)