Skip to content

Commit 18d133e

Browse files
committed
Add test for esp_rainmaker
1 parent 56e9d38 commit 18d133e

File tree

6 files changed

+421
-0
lines changed

6 files changed

+421
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
idf_component_register(SRCS "test_rmaker.c" "app_driver.c"
2+
INCLUDE_DIRS "."
3+
PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR}
4+
PRIV_REQUIRES unity nvs_flash esp_rainmaker gpio_button app_reset ws2812_led app_network app_insights test_utils espressif__network_provisioning)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
menu "Example Configuration"
2+
3+
config EXAMPLE_BOARD_BUTTON_GPIO
4+
int "Boot Button GPIO"
5+
default 9 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C2
6+
default 0
7+
help
8+
GPIO number on which the "Boot" button is connected. This is generally used
9+
by the application for custom operations like toggling states, resetting to defaults, etc.
10+
11+
endmenu
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# esp_rainmaker unit tests
2+
3+
Please take a look at how to build, flash, and run [esp-idf unit tests](https://github.com/espressif/esp-idf/tree/master/tools/unit-test-app#unit-test-app).
4+
5+
Follow the steps mentioned below to unit test the esp_rainmaker
6+
7+
* Change to the unit test app directory
8+
```
9+
cd $IDF_PATH/tools/unit-test-app
10+
```
11+
12+
* Set RMAKER_PATH to esp-rainmaker directory
13+
* Note: This is cloned `espressif/esp-rainmaker` directory and not its internal component `esp_rainmaker`
14+
```
15+
export RMAKER_PATH=/path/to/esp-rainmaker
16+
```
17+
18+
* Add following line to partition table csv file
19+
```
20+
fctry, data, nvs, , 0x6000
21+
```
22+
23+
* Copy following contents into `sdkconfig.defaults`
24+
```
25+
CONFIG_PARTITION_TABLE_CUSTOM=y
26+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partition_table_unit_test_app.csv"
27+
28+
# mbedtls
29+
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
30+
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
31+
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
32+
CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y
33+
34+
# For BLE Provisioning using NimBLE stack (Not applicable for ESP32-S2)
35+
CONFIG_BT_ENABLED=y
36+
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
37+
CONFIG_BT_NIMBLE_ENABLED=y
38+
39+
# Temporary Fix for Timer Overflows
40+
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=3120
41+
42+
# For additional security on reset to factory
43+
CONFIG_ESP_RMAKER_USER_ID_CHECK=y
44+
45+
# Secure Local Control
46+
CONFIG_ESP_RMAKER_LOCAL_CTRL_AUTO_ENABLE=y
47+
#CONFIG_ESP_RMAKER_LOCAL_CTRL_ENABLE is deprecated but will continue to work
48+
CONFIG_ESP_RMAKER_LOCAL_CTRL_SECURITY_1=y
49+
50+
# Application Rollback
51+
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
52+
53+
# If ESP-Insights is enabled, we need MQTT transport selected
54+
# Takes out manual efforts to enable this option
55+
CONFIG_ESP_INSIGHTS_TRANSPORT_MQTT=y
56+
57+
```
58+
* Append `/path/to/esp-rainmaker/components` and `/path/to/esp-rainmaker/examples/common` directory to `EXTRA_COMPONENT_DIRS` in `CMakeLists.txt`
59+
60+
## Build, flash and run tests
61+
```
62+
# Clean any previous configuration and builds
63+
rm -r sdkconfig build
64+
65+
# Set the target
66+
idf.py set-target esp32s3
67+
68+
# Building the firmware
69+
idf.py -T esp_rainmaker build
70+
71+
# Flash and run the test cases
72+
idf.py -p <serial-port> -T esp_rainmaker flash monitor
73+
```
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/* LED Lightbulb demo implementation using RGB LED
2+
3+
This example code is in the Public Domain (or CC0 licensed, at your option.)
4+
5+
Unless required by applicable law or agreed to in writing, this
6+
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
7+
CONDITIONS OF ANY KIND, either express or implied.
8+
*/
9+
10+
#include <sdkconfig.h>
11+
#include <esp_log.h>
12+
#include <iot_button.h>
13+
#include <esp_rmaker_core.h>
14+
#include <esp_rmaker_standard_types.h>
15+
#include <esp_rmaker_standard_params.h>
16+
17+
#include <app_reset.h>
18+
19+
#if CONFIG_IDF_TARGET_ESP32C2
20+
#include <ledc_driver.h>
21+
#else
22+
#include <ws2812_led.h>
23+
#endif
24+
25+
#include "app_priv.h"
26+
27+
/* This is the button that is used for toggling the power */
28+
#define BUTTON_GPIO CONFIG_EXAMPLE_BOARD_BUTTON_GPIO
29+
#define BUTTON_ACTIVE_LEVEL 0
30+
31+
#define WIFI_RESET_BUTTON_TIMEOUT 3
32+
#define FACTORY_RESET_BUTTON_TIMEOUT 10
33+
34+
static uint16_t g_hue = DEFAULT_HUE;
35+
static uint16_t g_saturation = DEFAULT_SATURATION;
36+
static uint16_t g_value = DEFAULT_BRIGHTNESS;
37+
static bool g_power = DEFAULT_POWER;
38+
39+
#if CONFIG_IDF_TARGET_ESP32C2
40+
esp_err_t app_light_set_led(uint32_t hue, uint32_t saturation, uint32_t brightness)
41+
{
42+
/* Whenever this function is called, light power will be ON */
43+
if (!g_power) {
44+
g_power = true;
45+
esp_rmaker_param_update_and_report(
46+
esp_rmaker_device_get_param_by_type(light_device, ESP_RMAKER_PARAM_POWER),
47+
esp_rmaker_bool(g_power));
48+
}
49+
ledc_set_hsv(hue, saturation, brightness);
50+
return ESP_OK;
51+
}
52+
53+
esp_err_t app_light_set_power(bool power)
54+
{
55+
g_power = power;
56+
if (power) {
57+
ledc_set_hsv(g_hue, g_saturation, g_value);
58+
} else {
59+
ledc_clear();
60+
}
61+
return ESP_OK;
62+
}
63+
64+
esp_err_t app_light_init(void)
65+
{
66+
ledc_init();
67+
return ESP_OK;
68+
}
69+
#else
70+
esp_err_t app_light_set_led(uint32_t hue, uint32_t saturation, uint32_t brightness)
71+
{
72+
/* Whenever this function is called, light power will be ON */
73+
if (!g_power) {
74+
g_power = true;
75+
esp_rmaker_param_update_and_report(
76+
esp_rmaker_device_get_param_by_type(light_device, ESP_RMAKER_PARAM_POWER),
77+
esp_rmaker_bool(g_power));
78+
}
79+
return ws2812_led_set_hsv(hue, saturation, brightness);
80+
}
81+
82+
esp_err_t app_light_set_power(bool power)
83+
{
84+
g_power = power;
85+
if (power) {
86+
ws2812_led_set_hsv(g_hue, g_saturation, g_value);
87+
} else {
88+
ws2812_led_clear();
89+
}
90+
return ESP_OK;
91+
}
92+
93+
esp_err_t app_light_init(void)
94+
{
95+
esp_err_t err = ws2812_led_init();
96+
if (err != ESP_OK) {
97+
return err;
98+
}
99+
if (g_power) {
100+
ws2812_led_set_hsv(g_hue, g_saturation, g_value);
101+
} else {
102+
ws2812_led_clear();
103+
}
104+
return ESP_OK;
105+
}
106+
#endif
107+
108+
esp_err_t app_light_set_brightness(uint16_t brightness)
109+
{
110+
g_value = brightness;
111+
return app_light_set_led(g_hue, g_saturation, g_value);
112+
}
113+
esp_err_t app_light_set_hue(uint16_t hue)
114+
{
115+
g_hue = hue;
116+
return app_light_set_led(g_hue, g_saturation, g_value);
117+
}
118+
esp_err_t app_light_set_saturation(uint16_t saturation)
119+
{
120+
g_saturation = saturation;
121+
return app_light_set_led(g_hue, g_saturation, g_value);
122+
}
123+
124+
static void push_btn_cb(void *arg)
125+
{
126+
app_light_set_power(!g_power);
127+
esp_rmaker_param_update_and_report(
128+
esp_rmaker_device_get_param_by_type(light_device, ESP_RMAKER_PARAM_POWER),
129+
esp_rmaker_bool(g_power));
130+
}
131+
132+
void app_driver_init()
133+
{
134+
app_light_init();
135+
button_handle_t btn_handle = iot_button_create(BUTTON_GPIO, BUTTON_ACTIVE_LEVEL);
136+
if (btn_handle) {
137+
/* Register a callback for a button tap (short press) event */
138+
iot_button_set_evt_cb(btn_handle, BUTTON_CB_TAP, push_btn_cb, NULL);
139+
/* Register Wi-Fi reset and factory reset functionality on same button */
140+
app_reset_button_register(btn_handle, WIFI_RESET_BUTTON_TIMEOUT, FACTORY_RESET_BUTTON_TIMEOUT);
141+
}
142+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
This example code is in the Public Domain (or CC0 licensed, at your option.)
3+
4+
Unless required by applicable law or agreed to in writing, this
5+
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
6+
CONDITIONS OF ANY KIND, either express or implied.
7+
*/
8+
#pragma once
9+
#include <stdint.h>
10+
#include <stdbool.h>
11+
12+
#define DEFAULT_POWER true
13+
#define DEFAULT_HUE 180
14+
#define DEFAULT_SATURATION 100
15+
#define DEFAULT_BRIGHTNESS 25
16+
17+
extern esp_rmaker_device_t *light_device;
18+
19+
void app_driver_init(void);
20+
esp_err_t app_light_set(uint32_t hue, uint32_t saturation, uint32_t brightness);
21+
esp_err_t app_light_set_power(bool power);
22+
esp_err_t app_light_set_brightness(uint16_t brightness);
23+
esp_err_t app_light_set_hue(uint16_t hue);
24+
esp_err_t app_light_set_saturation(uint16_t saturation);

0 commit comments

Comments
 (0)