Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power metering (MEGH-3343) #121

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ docs/docusaurus/website/node_modules
# cli logs
**/logs

# generated docs
docs/doxygen-warning-log.txt
docs/man/
docs/xml/

# IDF package manager
**/managed_components/
*.lock
18 changes: 9 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[submodule "cli"]
path = cli
url = https://github.com/espressif/esp-rainmaker-cli.git
[submodule "components/rmaker_common"]
path = components/rmaker_common
url = https://github.com/espressif/esp-rainmaker-common.git
[submodule "components/esp-insights"]
path = components/esp-insights
url = https://github.com/espressif/esp-insights.git
[submodule "components/json_parser/upstream"]
path = components/json_parser/upstream
url = https://github.com/espressif/json_parser.git
[submodule "components/json_generator/upstream"]
path = components/json_generator/upstream
url = https://github.com/espressif/json_generator.git
[submodule "components/rmaker_common"]
path = components/rmaker_common
url = ../esp-rainmaker-common.git
[submodule "cli"]
path = cli
url = ../esp-rainmaker-cli.git
[submodule "components/esp-insights"]
path = components/esp-insights
url = ../esp-insights.git
2 changes: 1 addition & 1 deletion components/esp-insights
17 changes: 17 additions & 0 deletions components/esp_rainmaker/include/esp_rmaker_standard_devices.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ esp_rmaker_device_t *esp_rmaker_fan_device_create(const char *dev_name,
esp_rmaker_device_t *esp_rmaker_temp_sensor_device_create(const char *dev_name,
void *priv_data, float temperature);

/** Create a standard Power Meter Sensor device
*
* This creates a Power Meter Sensor device with the mandatory parameters and also assigns
* the primary parameter. The default parameter names will be used.
* Refer \ref esp_rmaker_standard_params.h for default names.
*
* @param[in] dev_name The unique device name
* @param[in] priv_data (Optional) Private data associated with the device. This should stay
* allocated throughout the lifetime of the device
* @param[in] power Default value of the mandatory parameter "power"
*
* @return Device handle on success.
* @return NULL in case of failures.
*/
esp_rmaker_device_t *esp_rmaker_power_meter_sensor_device_create(const char *dev_name,
void *priv_data, int power);

#ifdef __cplusplus
}
#endif
18 changes: 16 additions & 2 deletions components/esp_rainmaker/include/esp_rmaker_standard_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ extern "C"
*/

#define ESP_RMAKER_DEF_NAME_PARAM "Name"
#define ESP_RMAKER_DEF_POWER_NAME "Power"
#define ESP_RMAKER_DEF_POWER_NAME "Power" // "on/off" state
#define ESP_RMAKER_DEF_POWER_METER_NAME "Power Meter" // Watts, Volts, Amperes
#define ESP_RMAKER_DEF_BRIGHTNESS_NAME "Brightness"
#define ESP_RMAKER_DEF_HUE_NAME "Hue"
#define ESP_RMAKER_DEF_SATURATION_NAME "Saturation"
Expand Down Expand Up @@ -71,7 +72,7 @@ extern "C"
esp_rmaker_param_t *esp_rmaker_name_param_create(const char *param_name, const char *val);

/**
* Create standard Power param
* Create standard Power on/off state param
*
* This will create the standard power parameter.
*
Expand All @@ -83,6 +84,19 @@ esp_rmaker_param_t *esp_rmaker_name_param_create(const char *param_name, const c
*/
esp_rmaker_param_t *esp_rmaker_power_param_create(const char *param_name, bool val);

/**
* Create standard Power metering param
*
* This will create power metering parameter(s).
*
* @param[in] param_name Name of the parameter
* @param[in] val Default Value of the parameter
*
* @return Parameter handle on success.
* @return NULL in case of failures.
*/
esp_rmaker_param_t *esp_rmaker_power_meter_param_create(const char *param_name, int val);

/**
* Create standard Brightness param
*
Expand Down
2 changes: 2 additions & 0 deletions components/esp_rainmaker/include/esp_rmaker_standard_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ extern "C"

#define ESP_RMAKER_PARAM_NAME "esp.param.name"
#define ESP_RMAKER_PARAM_POWER "esp.param.power"
#define ESP_RMAKER_PARAM_POWER_METER "esp.param.power-meter"
#define ESP_RMAKER_PARAM_BRIGHTNESS "esp.param.brightness"
#define ESP_RMAKER_PARAM_HUE "esp.param.hue"
#define ESP_RMAKER_PARAM_SATURATION "esp.param.saturation"
Expand Down Expand Up @@ -69,6 +70,7 @@ extern "C"
#define ESP_RMAKER_DEVICE_LIGHTBULB "esp.device.lightbulb"
#define ESP_RMAKER_DEVICE_FAN "esp.device.fan"
#define ESP_RMAKER_DEVICE_TEMP_SENSOR "esp.device.temperature-sensor"
#define ESP_RMAKER_DEVICE_POWER_METER_SENSOR "esp.device.power-meter-sensor"
#define ESP_RMAKER_DEVICE_LIGHT "esp.device.light"
#define ESP_RMAKER_DEVICE_OUTLET "esp.device.outlet"
#define ESP_RMAKER_DEVICE_PLUG "esp.device.plug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <string.h>
#include <esp_log.h>
#include <nvs.h>
#include <lwip/apps/sntp.h>
#include <esp_sntp.h>

#include <esp_rmaker_standard_types.h>
#include <esp_rmaker_standard_services.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ esp_rmaker_device_t *esp_rmaker_temp_sensor_device_create(const char *dev_name,
}
return device;
}

esp_rmaker_device_t *esp_rmaker_power_meter_sensor_device_create(const char *dev_name,
void *priv_data, int power)
{
esp_rmaker_device_t *device = esp_rmaker_device_create(dev_name, ESP_RMAKER_DEVICE_POWER_METER_SENSOR, priv_data);
if (device) {
esp_rmaker_device_add_param(device, esp_rmaker_name_param_create(ESP_RMAKER_DEF_NAME_PARAM, dev_name));
esp_rmaker_param_t *primary = esp_rmaker_power_meter_param_create(ESP_RMAKER_DEF_POWER_METER_NAME, power);
esp_rmaker_device_add_param(device, primary);
esp_rmaker_device_assign_primary_param(device, primary);
}
return device;
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ esp_rmaker_param_t *esp_rmaker_power_param_create(const char *param_name, bool v
return param;
}

esp_rmaker_param_t *esp_rmaker_power_meter_param_create(const char *param_name, float val)
{
esp_rmaker_param_t *param = esp_rmaker_param_create(param_name, ESP_RMAKER_PARAM_POWER_METER,
esp_rmaker_float(val), PROP_FLAG_READ | PROP_FLAG_WRITE | PROP_FLAG_TIME_SERIES);
if (param) {
esp_rmaker_param_add_ui_type(param, ESP_RMAKER_UI_TEXT);
}
return param;
}

esp_rmaker_param_t *esp_rmaker_brightness_param_create(const char *param_name, int val)
{
esp_rmaker_param_t *param = esp_rmaker_param_create(param_name, ESP_RMAKER_PARAM_BRIGHTNESS,
Expand Down
2 changes: 1 addition & 1 deletion components/esp_schedule/src/esp_schedule.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ esp_schedule_handle_t esp_schedule_create(esp_schedule_config_t *schedule_config

esp_schedule_handle_t *esp_schedule_init(bool enable_nvs, char *nvs_partition, uint8_t *schedule_count)
{
if (!sntp_enabled()) {
if (!esp_sntp_enabled()) {
ESP_LOGI(TAG, "Initializing SNTP");
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org");
Expand Down
2 changes: 1 addition & 1 deletion components/rmaker_common