mirror of
https://github.com/alexandrebobkov/ESP-Nodes.git
synced 2025-08-08 03:42:24 +00:00
Rainmaker Lights Switch
This commit is contained in:
13
RainMaker_Table-Lights/.devcontainer/Dockerfile
Normal file
13
RainMaker_Table-Lights/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
||||
ARG DOCKER_TAG=latest
|
||||
FROM espressif/idf:${DOCKER_TAG}
|
||||
|
||||
ENV LC_ALL=C.UTF-8
|
||||
ENV LANG=C.UTF-8
|
||||
|
||||
RUN apt-get update -y && apt-get install udev -y
|
||||
|
||||
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
|
||||
|
||||
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
|
||||
|
||||
CMD ["/bin/bash", "-c"]
|
21
RainMaker_Table-Lights/.devcontainer/devcontainer.json
Normal file
21
RainMaker_Table-Lights/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "ESP-IDF QEMU",
|
||||
"build": {
|
||||
"dockerfile": "Dockerfile"
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"settings": {
|
||||
"terminal.integrated.defaultProfile.linux": "bash",
|
||||
"idf.espIdfPath": "/opt/esp/idf",
|
||||
"idf.toolsPath": "/opt/esp",
|
||||
"idf.gitPath": "/usr/bin/git"
|
||||
},
|
||||
"extensions": [
|
||||
"espressif.esp-idf-extension",
|
||||
"espressif.esp-idf-web"
|
||||
]
|
||||
}
|
||||
},
|
||||
"runArgs": ["--privileged"]
|
||||
}
|
16
RainMaker_Table-Lights/CMakeLists.txt
Normal file
16
RainMaker_Table-Lights/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
||||
# The following lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
if(DEFINED ENV{RMAKER_PATH})
|
||||
set(RMAKER_PATH $ENV{RMAKER_PATH})
|
||||
else()
|
||||
set(RMAKER_PATH ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||
endif(DEFINED ENV{RMAKER_PATH})
|
||||
|
||||
# Add RainMaker components and other common application components
|
||||
set(EXTRA_COMPONENT_DIRS ${RMAKER_PATH}/examples/common)
|
||||
|
||||
set(PROJECT_VER "1.0")
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(RainMaker_Table-Lights)
|
12
RainMaker_Table-Lights/Makefile
Normal file
12
RainMaker_Table-Lights/Makefile
Normal file
@@ -0,0 +1,12 @@
|
||||
#
|
||||
# This is a project Makefile. It is assumed the directory this Makefile resides in is a
|
||||
# project subdirectory.
|
||||
#
|
||||
|
||||
PROJECT_NAME := switch
|
||||
PROJECT_VER := 1.0
|
||||
|
||||
# Add RainMaker components and other common application components
|
||||
EXTRA_COMPONENT_DIRS += $(PROJECT_PATH)/../../components $(PROJECT_PATH)/../common
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
24
RainMaker_Table-Lights/README.md
Normal file
24
RainMaker_Table-Lights/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Switch Example
|
||||
|
||||
## Build and Flash firmware
|
||||
|
||||
Follow the ESP RainMaker Documentation [Get Started](https://rainmaker.espressif.com/docs/get-started.html) section to build and flash this firmware. Just note the path of this example.
|
||||
|
||||
## What to expect in this example?
|
||||
|
||||
- This example uses the BOOT button and RGB LED on the ESP32-S2-Saola-1/ESP32-C3-DevKitC board to demonstrate a switch.
|
||||
- The LED state (green color) indicates the state of the switch.
|
||||
- Pressing the BOOT button will toggle the state of the switch and hence the LED. This will also reflect on the phone app.
|
||||
- Toggling the button on the phone app should toggle the LED on your board, and also print messages like these on the ESP32-S2 monitor:
|
||||
|
||||
```
|
||||
I (16073) app_main: Received value = true for Switch - power
|
||||
```
|
||||
|
||||
### LED not working?
|
||||
|
||||
The ESP32-S2-Saola-1 board has the RGB LED connected to GPIO 18. However, a few earlier boards may have it on GPIO 17. Please use `CONFIG_WS2812_LED_GPIO` to set the appropriate value.
|
||||
|
||||
### Reset to Factory
|
||||
|
||||
Press and hold the BOOT button for more than 3 seconds to reset the board to factory defaults. You will have to provision the board again to use it.
|
2
RainMaker_Table-Lights/main/CMakeLists.txt
Normal file
2
RainMaker_Table-Lights/main/CMakeLists.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS ./app_driver.c ./app_main.c
|
||||
INCLUDE_DIRS ".")
|
27
RainMaker_Table-Lights/main/Kconfig.projbuild
Normal file
27
RainMaker_Table-Lights/main/Kconfig.projbuild
Normal file
@@ -0,0 +1,27 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_BOARD_BUTTON_GPIO
|
||||
int "Boot Button GPIO"
|
||||
default 28 if IDF_TARGET_ESP32C5
|
||||
default 9 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32H2
|
||||
default 0
|
||||
help
|
||||
GPIO number on which the "Boot" button is connected. This is generally used
|
||||
by the application for custom operations like toggling states, resetting to defaults, etc.
|
||||
|
||||
config EXAMPLE_ENABLE_TEST_NOTIFICATIONS
|
||||
bool "Test Notifications"
|
||||
default n
|
||||
help
|
||||
Enable this option to test mobile push notifications. When enabled, turning on the switch using
|
||||
push button will trigger a parameter notification {"Switch":{"Power":true}} and turning off will
|
||||
trigger an alert "Switch was turned off".
|
||||
|
||||
config EXAMPLE_OUTPUT_GPIO
|
||||
int "Output GPIO"
|
||||
default 19
|
||||
help
|
||||
This is an output GPIO that will be connected to a relay or other driver circuit in most cases.
|
||||
If the power changes, this GPIO output level will also change.
|
||||
|
||||
endmenu
|
116
RainMaker_Table-Lights/main/app_driver.c
Normal file
116
RainMaker_Table-Lights/main/app_driver.c
Normal file
@@ -0,0 +1,116 @@
|
||||
/* Switch demo implementation using button and RGB LED
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <sdkconfig.h>
|
||||
|
||||
#include <iot_button.h>
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
|
||||
#include <app_reset.h>
|
||||
#include <ws2812_led.h>
|
||||
#include "app_priv.h"
|
||||
|
||||
/* This is the button that is used for toggling the power */
|
||||
#define BUTTON_GPIO CONFIG_EXAMPLE_BOARD_BUTTON_GPIO
|
||||
#define BUTTON_ACTIVE_LEVEL 0
|
||||
|
||||
/* This is the GPIO on which the power will be set */
|
||||
#define OUTPUT_GPIO CONFIG_EXAMPLE_OUTPUT_GPIO
|
||||
static bool g_power_state = DEFAULT_POWER;
|
||||
|
||||
/* These values correspoind to H,S,V = 120,100,10 */
|
||||
#define DEFAULT_RED 0
|
||||
#define DEFAULT_GREEN 25
|
||||
#define DEFAULT_BLUE 0
|
||||
|
||||
#define WIFI_RESET_BUTTON_TIMEOUT 3
|
||||
#define FACTORY_RESET_BUTTON_TIMEOUT 10
|
||||
|
||||
static void app_indicator_set(bool state)
|
||||
{
|
||||
if (state) {
|
||||
ws2812_led_set_rgb(DEFAULT_RED, DEFAULT_GREEN, DEFAULT_BLUE);
|
||||
} else {
|
||||
ws2812_led_clear();
|
||||
}
|
||||
}
|
||||
|
||||
static void app_indicator_init(void)
|
||||
{
|
||||
ws2812_led_init();
|
||||
app_indicator_set(g_power_state);
|
||||
}
|
||||
static void push_btn_cb(void *arg)
|
||||
{
|
||||
bool new_state = !g_power_state;
|
||||
app_driver_set_state(new_state);
|
||||
#ifdef CONFIG_EXAMPLE_ENABLE_TEST_NOTIFICATIONS
|
||||
/* This snippet has been added just to demonstrate how the APIs esp_rmaker_param_update_and_notify()
|
||||
* and esp_rmaker_raise_alert() can be used to trigger push notifications on the phone apps.
|
||||
* Normally, there should not be a need to use these APIs for such simple operations. Please check
|
||||
* API documentation for details.
|
||||
*/
|
||||
if (new_state) {
|
||||
esp_rmaker_param_update_and_notify(
|
||||
esp_rmaker_device_get_param_by_name(switch_device, ESP_RMAKER_DEF_POWER_NAME),
|
||||
esp_rmaker_bool(new_state));
|
||||
} else {
|
||||
esp_rmaker_param_update_and_report(
|
||||
esp_rmaker_device_get_param_by_name(switch_device, ESP_RMAKER_DEF_POWER_NAME),
|
||||
esp_rmaker_bool(new_state));
|
||||
esp_rmaker_raise_alert("Switch was turned off");
|
||||
}
|
||||
#else
|
||||
esp_rmaker_param_update_and_report(
|
||||
esp_rmaker_device_get_param_by_name(switch_device, ESP_RMAKER_DEF_POWER_NAME),
|
||||
esp_rmaker_bool(new_state));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void set_power_state(bool target)
|
||||
{
|
||||
gpio_set_level(OUTPUT_GPIO, target);
|
||||
app_indicator_set(target);
|
||||
}
|
||||
|
||||
void app_driver_init()
|
||||
{
|
||||
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
|
||||
if (btn_handle) {
|
||||
/* Register a callback for a button tap (short press) event */
|
||||
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
|
||||
/* Register Wi-Fi reset and factory reset functionality on same button */
|
||||
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
|
||||
}
|
||||
|
||||
/* Configure power */
|
||||
gpio_config_t io_conf = {
|
||||
.mode = GPIO_MODE_OUTPUT,
|
||||
.pull_up_en = 1,
|
||||
};
|
||||
io_conf.pin_bit_mask = ((uint64_t)1 << OUTPUT_GPIO);
|
||||
/* Configure the GPIO */
|
||||
gpio_config(&io_conf);
|
||||
app_indicator_init();
|
||||
}
|
||||
|
||||
int IRAM_ATTR app_driver_set_state(bool state)
|
||||
{
|
||||
if(g_power_state != state) {
|
||||
g_power_state = state;
|
||||
set_power_state(g_power_state);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
bool app_driver_get_state(void)
|
||||
{
|
||||
return g_power_state;
|
||||
}
|
255
RainMaker_Table-Lights/main/app_main.c
Normal file
255
RainMaker_Table-Lights/main/app_main.c
Normal file
@@ -0,0 +1,255 @@
|
||||
/* Switch Example
|
||||
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_event.h>
|
||||
#include <nvs_flash.h>
|
||||
|
||||
#include <esp_rmaker_core.h>
|
||||
#include <esp_rmaker_standard_types.h>
|
||||
#include <esp_rmaker_standard_params.h>
|
||||
#include <esp_rmaker_standard_devices.h>
|
||||
#include <esp_rmaker_schedule.h>
|
||||
#include <esp_rmaker_scenes.h>
|
||||
#include <esp_rmaker_console.h>
|
||||
#include <esp_rmaker_ota.h>
|
||||
|
||||
#include <esp_rmaker_common_events.h>
|
||||
|
||||
#include <app_network.h>
|
||||
#include <app_insights.h>
|
||||
|
||||
#include "app_priv.h"
|
||||
|
||||
static const char *TAG = "app_main";
|
||||
esp_rmaker_device_t *switch_device;
|
||||
|
||||
/* Callback to handle commands received from the RainMaker cloud */
|
||||
static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param,
|
||||
const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx)
|
||||
{
|
||||
if (ctx) {
|
||||
ESP_LOGI(TAG, "Received write request via : %s", esp_rmaker_device_cb_src_to_str(ctx->src));
|
||||
}
|
||||
if (strcmp(esp_rmaker_param_get_name(param), ESP_RMAKER_DEF_POWER_NAME) == 0) {
|
||||
ESP_LOGI(TAG, "Received value = %s for %s - %s",
|
||||
val.val.b? "true" : "false", esp_rmaker_device_get_name(device),
|
||||
esp_rmaker_param_get_name(param));
|
||||
app_driver_set_state(val.val.b);
|
||||
esp_rmaker_param_update(param, val);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
/* Event handler for catching RainMaker events */
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == RMAKER_EVENT) {
|
||||
switch (event_id) {
|
||||
case RMAKER_EVENT_INIT_DONE:
|
||||
ESP_LOGI(TAG, "RainMaker Initialised.");
|
||||
break;
|
||||
case RMAKER_EVENT_CLAIM_STARTED:
|
||||
ESP_LOGI(TAG, "RainMaker Claim Started.");
|
||||
break;
|
||||
case RMAKER_EVENT_CLAIM_SUCCESSFUL:
|
||||
ESP_LOGI(TAG, "RainMaker Claim Successful.");
|
||||
break;
|
||||
case RMAKER_EVENT_CLAIM_FAILED:
|
||||
ESP_LOGI(TAG, "RainMaker Claim Failed.");
|
||||
break;
|
||||
case RMAKER_EVENT_LOCAL_CTRL_STARTED:
|
||||
ESP_LOGI(TAG, "Local Control Started.");
|
||||
break;
|
||||
case RMAKER_EVENT_LOCAL_CTRL_STOPPED:
|
||||
ESP_LOGI(TAG, "Local Control Stopped.");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "Unhandled RainMaker Event: %"PRIi32, event_id);
|
||||
}
|
||||
} else if (event_base == RMAKER_COMMON_EVENT) {
|
||||
switch (event_id) {
|
||||
case RMAKER_EVENT_REBOOT:
|
||||
ESP_LOGI(TAG, "Rebooting in %d seconds.", *((uint8_t *)event_data));
|
||||
break;
|
||||
case RMAKER_EVENT_WIFI_RESET:
|
||||
ESP_LOGI(TAG, "Wi-Fi credentials reset.");
|
||||
break;
|
||||
case RMAKER_EVENT_FACTORY_RESET:
|
||||
ESP_LOGI(TAG, "Node reset to factory defaults.");
|
||||
break;
|
||||
case RMAKER_MQTT_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "MQTT Connected.");
|
||||
break;
|
||||
case RMAKER_MQTT_EVENT_DISCONNECTED:
|
||||
ESP_LOGI(TAG, "MQTT Disconnected.");
|
||||
break;
|
||||
case RMAKER_MQTT_EVENT_PUBLISHED:
|
||||
ESP_LOGI(TAG, "MQTT Published. Msg id: %d.", *((int *)event_data));
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "Unhandled RainMaker Common Event: %"PRIi32, event_id);
|
||||
}
|
||||
} else if (event_base == APP_NETWORK_EVENT) {
|
||||
switch (event_id) {
|
||||
case APP_NETWORK_EVENT_QR_DISPLAY:
|
||||
ESP_LOGI(TAG, "Provisioning QR : %s", (char *)event_data);
|
||||
break;
|
||||
case APP_NETWORK_EVENT_PROV_TIMEOUT:
|
||||
ESP_LOGI(TAG, "Provisioning Timed Out. Please reboot.");
|
||||
break;
|
||||
case APP_NETWORK_EVENT_PROV_RESTART:
|
||||
ESP_LOGI(TAG, "Provisioning has restarted due to failures.");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "Unhandled App Wi-Fi Event: %"PRIi32, event_id);
|
||||
break;
|
||||
}
|
||||
} else if (event_base == RMAKER_OTA_EVENT) {
|
||||
switch(event_id) {
|
||||
case RMAKER_OTA_EVENT_STARTING:
|
||||
ESP_LOGI(TAG, "Starting OTA.");
|
||||
break;
|
||||
case RMAKER_OTA_EVENT_IN_PROGRESS:
|
||||
ESP_LOGI(TAG, "OTA is in progress.");
|
||||
break;
|
||||
case RMAKER_OTA_EVENT_SUCCESSFUL:
|
||||
ESP_LOGI(TAG, "OTA successful.");
|
||||
break;
|
||||
case RMAKER_OTA_EVENT_FAILED:
|
||||
ESP_LOGI(TAG, "OTA Failed.");
|
||||
break;
|
||||
case RMAKER_OTA_EVENT_REJECTED:
|
||||
ESP_LOGI(TAG, "OTA Rejected.");
|
||||
break;
|
||||
case RMAKER_OTA_EVENT_DELAYED:
|
||||
ESP_LOGI(TAG, "OTA Delayed.");
|
||||
break;
|
||||
case RMAKER_OTA_EVENT_REQ_FOR_REBOOT:
|
||||
ESP_LOGI(TAG, "Firmware image downloaded. Please reboot your device to apply the upgrade.");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGW(TAG, "Unhandled OTA Event: %"PRIi32, event_id);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Invalid event received!");
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
/* Initialize Application specific hardware drivers and
|
||||
* set initial state.
|
||||
*/
|
||||
esp_rmaker_console_init();
|
||||
app_driver_init();
|
||||
app_driver_set_state(DEFAULT_POWER);
|
||||
|
||||
/* Initialize NVS. */
|
||||
esp_err_t err = nvs_flash_init();
|
||||
if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
err = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK( err );
|
||||
|
||||
/* Initialize Wi-Fi. Note that, this should be called before esp_rmaker_node_init()
|
||||
*/
|
||||
app_network_init();
|
||||
|
||||
/* Register an event handler to catch RainMaker events */
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(APP_NETWORK_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(RMAKER_OTA_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
|
||||
/* Initialize the ESP RainMaker Agent.
|
||||
* Note that this should be called after app_network_init() but before app_nenetworkk_start()
|
||||
* */
|
||||
esp_rmaker_config_t rainmaker_cfg = {
|
||||
.enable_time_sync = false,
|
||||
};
|
||||
esp_rmaker_node_t *node = esp_rmaker_node_init(&rainmaker_cfg, "ESP RainMaker Device", "Switch");
|
||||
if (!node) {
|
||||
ESP_LOGE(TAG, "Could not initialise node. Aborting!!!");
|
||||
vTaskDelay(5000/portTICK_PERIOD_MS);
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Create a Switch device.
|
||||
* You can optionally use the helper API esp_rmaker_switch_device_create() to
|
||||
* avoid writing code for adding the name and power parameters.
|
||||
*/
|
||||
switch_device = esp_rmaker_device_create("Switch", ESP_RMAKER_DEVICE_SWITCH, NULL);
|
||||
|
||||
/* Add the write callback for the device. We aren't registering any read callback yet as
|
||||
* it is for future use.
|
||||
*/
|
||||
esp_rmaker_device_add_cb(switch_device, write_cb, NULL);
|
||||
|
||||
/* Add the standard name parameter (type: esp.param.name), which allows setting a persistent,
|
||||
* user friendly custom name from the phone apps. All devices are recommended to have this
|
||||
* parameter.
|
||||
*/
|
||||
esp_rmaker_device_add_param(switch_device, esp_rmaker_name_param_create(ESP_RMAKER_DEF_NAME_PARAM, "Switch"));
|
||||
|
||||
/* Add the standard power parameter (type: esp.param.power), which adds a boolean param
|
||||
* with a toggle switch ui-type.
|
||||
*/
|
||||
esp_rmaker_param_t *power_param = esp_rmaker_power_param_create(ESP_RMAKER_DEF_POWER_NAME, DEFAULT_POWER);
|
||||
esp_rmaker_device_add_param(switch_device, power_param);
|
||||
|
||||
/* Assign the power parameter as the primary, so that it can be controlled from the
|
||||
* home screen of the phone apps.
|
||||
*/
|
||||
esp_rmaker_device_assign_primary_param(switch_device, power_param);
|
||||
|
||||
/* Add this switch device to the node */
|
||||
esp_rmaker_node_add_device(node, switch_device);
|
||||
|
||||
/* Enable OTA */
|
||||
esp_rmaker_ota_enable_default();
|
||||
|
||||
/* Enable timezone service which will be require for setting appropriate timezone
|
||||
* from the phone apps for scheduling to work correctly.
|
||||
* For more information on the various ways of setting timezone, please check
|
||||
* https://rainmaker.espressif.com/docs/time-service.html.
|
||||
*/
|
||||
esp_rmaker_timezone_service_enable();
|
||||
|
||||
/* Enable scheduling. */
|
||||
esp_rmaker_schedule_enable();
|
||||
|
||||
/* Enable Scenes */
|
||||
esp_rmaker_scenes_enable();
|
||||
|
||||
/* Enable Insights. Requires CONFIG_ESP_INSIGHTS_ENABLED=y */
|
||||
app_insights_enable();
|
||||
|
||||
/* Start the ESP RainMaker Agent */
|
||||
esp_rmaker_start();
|
||||
|
||||
err = app_network_set_custom_mfg_data(MGF_DATA_DEVICE_TYPE_SWITCH, MFG_DATA_DEVICE_SUBTYPE_SWITCH);
|
||||
/* Start the Wi-Fi.
|
||||
* If the node is provisioned, it will start connection attempts,
|
||||
* else, it will start Wi-Fi provisioning. The function will return
|
||||
* after a connection has been successfully established
|
||||
*/
|
||||
err = app_network_start(POP_TYPE_RANDOM);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Could not start Wifi. Aborting!!!");
|
||||
vTaskDelay(5000/portTICK_PERIOD_MS);
|
||||
abort();
|
||||
}
|
||||
}
|
16
RainMaker_Table-Lights/main/app_priv.h
Normal file
16
RainMaker_Table-Lights/main/app_priv.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||
|
||||
Unless required by applicable law or agreed to in writing, this
|
||||
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||
CONDITIONS OF ANY KIND, either express or implied.
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DEFAULT_POWER true
|
||||
extern esp_rmaker_device_t *switch_device;
|
||||
void app_driver_init(void);
|
||||
int app_driver_set_state(bool state);
|
||||
bool app_driver_get_state(void);
|
4
RainMaker_Table-Lights/main/component.mk
Normal file
4
RainMaker_Table-Lights/main/component.mk
Normal file
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# "main" pseudo-component makefile.
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
8
RainMaker_Table-Lights/main/idf_component.yml
Normal file
8
RainMaker_Table-Lights/main/idf_component.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
## IDF Component Manager Manifest File
|
||||
dependencies:
|
||||
## Required IDF version
|
||||
idf:
|
||||
version: ">=5.0.0"
|
||||
espressif/esp_rainmaker:
|
||||
version: ">=1.0"
|
||||
override_path: '../../../components/esp_rainmaker/'
|
10
RainMaker_Table-Lights/partitions.csv
Normal file
10
RainMaker_Table-Lights/partitions.csv
Normal file
@@ -0,0 +1,10 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table
|
||||
esp_secure_cert, 0x3F, , 0xD000, 0x2000, encrypted
|
||||
nvs_key, data, nvs_keys, 0xF000, 0x1000, encrypted
|
||||
nvs, data, nvs, 0x10000, 0x6000,
|
||||
otadata, data, ota, , 0x2000
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, 0x20000, 1600K,
|
||||
ota_1, app, ota_1, , 1600K,
|
||||
fctry, data, nvs, 0x340000, 0x6000
|
|
11
RainMaker_Table-Lights/partitions_4mb_optimised.csv
Normal file
11
RainMaker_Table-Lights/partitions_4mb_optimised.csv
Normal file
@@ -0,0 +1,11 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table
|
||||
esp_secure_cert, 0x3F, , 0xD000, 0x2000, encrypted
|
||||
nvs_key, data, nvs_keys, 0xF000, 0x1000, encrypted
|
||||
nvs, data, nvs, 0x10000, 0x6000,
|
||||
otadata, data, ota, , 0x2000
|
||||
phy_init, data, phy, , 0x1000,
|
||||
ota_0, app, ota_0, 0x20000, 0x1E0000,
|
||||
ota_1, app, ota_1, 0x200000, 0x1E0000,
|
||||
reserved, 0x06, , 0x3E0000, 0x1A000,
|
||||
fctry, data, nvs, 0x3FA000, 0x6000
|
|
41
RainMaker_Table-Lights/sdkconfig.defaults
Normal file
41
RainMaker_Table-Lights/sdkconfig.defaults
Normal file
@@ -0,0 +1,41 @@
|
||||
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
|
||||
|
||||
#
|
||||
# Use partition table which makes use of flash to the fullest
|
||||
# Can be used for other platforms as well. But please keep in mind that fctry partition address is
|
||||
# different than default, and the new address needs to be specified to `rainmaker.py claim`
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_4mb_optimised.csv"
|
||||
|
||||
# To accomodate security features
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0xc000
|
||||
|
||||
# mbedtls
|
||||
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
|
||||
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
|
||||
|
||||
# For BLE Provisioning using NimBLE stack (Not applicable for ESP32-S2)
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
# Temporary Fix for Timer Overflows
|
||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120
|
||||
|
||||
# For additional security on reset to factory
|
||||
CONFIG_ESP_RMAKER_USER_ID_CHECK=y
|
||||
|
||||
# Secure Local Control
|
||||
CONFIG_ESP_RMAKER_LOCAL_CTRL_AUTO_ENABLE=y
|
||||
#CONFIG_ESP_RMAKER_LOCAL_CTRL_ENABLE is deprecated but will continue to work
|
||||
CONFIG_ESP_RMAKER_LOCAL_CTRL_SECURITY_1=y
|
||||
|
||||
# Application Rollback
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
|
||||
# If ESP-Insights is enabled, we need MQTT transport selected
|
||||
# Takes out manual efforts to enable this option
|
||||
CONFIG_ESP_INSIGHTS_TRANSPORT_MQTT=y
|
1
RainMaker_Table-Lights/sdkconfig.defaults.esp32
Normal file
1
RainMaker_Table-Lights/sdkconfig.defaults.esp32
Normal file
@@ -0,0 +1 @@
|
||||
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
|
121
RainMaker_Table-Lights/sdkconfig.defaults.esp32c2
Normal file
121
RainMaker_Table-Lights/sdkconfig.defaults.esp32c2
Normal file
@@ -0,0 +1,121 @@
|
||||
# Bluetooth
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BT_RELEASE_IRAM=y
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
## NimBLE Options
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=2
|
||||
CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=3072
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_COUNT=10
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_SIZE=100
|
||||
CONFIG_BT_NIMBLE_MSYS_2_BLOCK_COUNT=4
|
||||
CONFIG_BT_NIMBLE_ACL_BUF_COUNT=5
|
||||
CONFIG_BT_NIMBLE_HCI_EVT_HI_BUF_COUNT=5
|
||||
CONFIG_BT_NIMBLE_HCI_EVT_LO_BUF_COUNT=3
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=n
|
||||
CONFIG_BT_NIMBLE_WHITELIST_SIZE=1
|
||||
## Controller Options
|
||||
CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE=3072
|
||||
CONFIG_BT_LE_LL_RESOLV_LIST_SIZE=1
|
||||
CONFIG_BT_LE_LL_DUP_SCAN_LIST_COUNT=1
|
||||
|
||||
# SPI Configuration
|
||||
CONFIG_SPI_MASTER_ISR_IN_IRAM=n
|
||||
CONFIG_SPI_SLAVE_ISR_IN_IRAM=n
|
||||
|
||||
# Ethernet
|
||||
CONFIG_ETH_USE_SPI_ETHERNET=n
|
||||
|
||||
# Event Loop Library
|
||||
CONFIG_ESP_EVENT_POST_FROM_ISR=n
|
||||
|
||||
# Chip revision
|
||||
CONFIG_ESP32C2_REV2_DEVELOPMENT=y
|
||||
|
||||
# ESP Ringbuf
|
||||
CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y
|
||||
CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH=y
|
||||
|
||||
# ESP System Settings
|
||||
CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=16
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=3072
|
||||
|
||||
# Bypass a bug. Use 26M XTAL Freq
|
||||
CONFIG_XTAL_FREQ_26=y
|
||||
|
||||
## Memory protection
|
||||
CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n
|
||||
|
||||
# High resolution timer (esp_timer)
|
||||
CONFIG_ESP_TIMER_TASK_STACK_SIZE=2048
|
||||
|
||||
# Wi-Fi
|
||||
CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=n
|
||||
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=3
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=6
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=6
|
||||
CONFIG_ESP32_WIFI_IRAM_OPT=n
|
||||
CONFIG_ESP32_WIFI_RX_IRAM_OPT=n
|
||||
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=n
|
||||
CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=n
|
||||
CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=n
|
||||
|
||||
# FreeRTOS
|
||||
## Kernel
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y
|
||||
## Port
|
||||
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=n
|
||||
CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y
|
||||
CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y
|
||||
|
||||
# Hardware Abstraction Layer (HAL) and Low Level (LL)
|
||||
CONFIG_HAL_ASSERTION_DISABLE=y
|
||||
|
||||
# LWIP
|
||||
CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16
|
||||
CONFIG_LWIP_DHCPS=n
|
||||
CONFIG_LWIP_IPV6_AUTOCONFIG=y
|
||||
CONFIG_LWIP_MAX_ACTIVE_TCP=5
|
||||
CONFIG_LWIP_MAX_LISTENING_TCP=5
|
||||
CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION=n
|
||||
CONFIG_LWIP_TCP_SYNMAXRTX=12
|
||||
CONFIG_LWIP_TCP_MSL=40000
|
||||
CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT=16000
|
||||
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=4096
|
||||
CONFIG_LWIP_TCP_WND_DEFAULT=2440
|
||||
CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS=y
|
||||
CONFIG_LWIP_TCP_RTO_TIME=1500
|
||||
CONFIG_LWIP_MAX_UDP_PCBS=8
|
||||
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=2560
|
||||
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
|
||||
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
|
||||
|
||||
# mbedTLS
|
||||
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y
|
||||
CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=n
|
||||
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
|
||||
|
||||
# SPI Flash driver
|
||||
CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=n
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
|
||||
# Websocket
|
||||
CONFIG_WS_TRANSPORT=n
|
||||
|
||||
# Virtual file system
|
||||
CONFIG_VFS_SUPPORT_DIR=n
|
||||
CONFIG_VFS_SUPPORT_SELECT=n
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
|
||||
# Wear Levelling
|
||||
CONFIG_WL_SECTOR_SIZE_512=y
|
10
RainMaker_Table-Lights/sdkconfig.defaults.esp32c6
Normal file
10
RainMaker_Table-Lights/sdkconfig.defaults.esp32c6
Normal file
@@ -0,0 +1,10 @@
|
||||
#
|
||||
# Use partition table which makes use of flash to the fullest
|
||||
# Can be used for other platforms as well. But please keep in mind that fctry partition address is
|
||||
# different than default, and the new address needs to be specified to `rainmaker.py claim`
|
||||
#
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_4mb_optimised.csv"
|
||||
|
||||
# To accomodate security features
|
||||
CONFIG_PARTITION_TABLE_OFFSET=0xc000
|
14
RainMaker_Table-Lights/sdkconfig.defaults.esp32h2
Normal file
14
RainMaker_Table-Lights/sdkconfig.defaults.esp32h2
Normal file
@@ -0,0 +1,14 @@
|
||||
# Enable OpenThread
|
||||
CONFIG_OPENTHREAD_ENABLED=y
|
||||
CONFIG_OPENTHREAD_CLI=n
|
||||
|
||||
# Enable DNS64 client and Network connection resolve hook
|
||||
CONFIG_OPENTHREAD_DNS64_CLIENT=y
|
||||
CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT=y
|
||||
|
||||
# Increase network provisioning scan entries
|
||||
CONFIG_NETWORK_PROV_SCAN_MAX_ENTRIES=64
|
||||
|
||||
# Use 4MB optimised partition
|
||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_4mb_optimised.csv"
|
4
RainMaker_Table-Lights/sdkconfig.defaults.esp32s2
Normal file
4
RainMaker_Table-Lights/sdkconfig.defaults.esp32s2
Normal file
@@ -0,0 +1,4 @@
|
||||
#
|
||||
# Bluetooth
|
||||
#
|
||||
CONFIG_BT_ENABLED=n
|
Reference in New Issue
Block a user