Skip to content

Add enableScenes API in Rainmaker #7436

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

Merged
merged 4 commits into from
Nov 14, 2022
Merged
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
18 changes: 15 additions & 3 deletions docs/source/api/rainmaker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ The key features of ESP RainMaker are:

Additional information about ESP RainMaker can be found `here <https://rainmaker.espressif.com/>`__.

#########################
Arduino ESP Rainmaker API
#########################

ESP RainMaker Agent API
-----------------------
Expand Down Expand Up @@ -127,6 +124,21 @@ This function will return
1. `ESP_OK` : On success
2. Error in case of failure

RMaker.enableScenes
*******************

This API enables the Scenes service for the node. It should be called after `RMaker.initNode()` and before `RMaker.start()`.
For more information, check `here <https://rainmaker.espressif.com/docs/scenes.html>`__.

.. code-block:: arduino

esp_err_t enableScenes()

This function will return

1. `ESP_OK` : On success
2. Error in case of failure

RMaker.setTimeZone
******************

Expand Down
16 changes: 9 additions & 7 deletions libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ static Device my_device("Dimmer", "custom.device.dimmer", &gpio_dimmer);

void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#endif
#endif
break;
default:;
}
Expand Down Expand Up @@ -63,7 +63,7 @@ void setup()
pinMode(gpio_dimmer, OUTPUT);
digitalWrite(gpio_dimmer, DEFAULT_POWER_MODE);

Node my_node;
Node my_node;
my_node = RMaker.initNode("ESP RainMaker Node");

//Create custom dimmer device
Expand All @@ -78,20 +78,22 @@ void setup()
my_device.addParam(level_param);

my_device.addCb(write_callback);
//Add custom dimmer device to the node

//Add custom dimmer device to the node
my_node.addDevice(my_device);

//This is optional
//This is optional
RMaker.enableOTA(OTA_USING_PARAMS);
//If you want to enable scheduling, set time zone for your region using setTimeZone().
//If you want to enable scheduling, set time zone for your region using setTimeZone().
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
// RMaker.setTimeZone("Asia/Shanghai");
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
RMaker.enableTZService();

RMaker.enableSchedule();

RMaker.enableScenes();

RMaker.start();

WiFi.onEvent(sysProvEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ static Device my_device("Air Cooler", "my.device.air-cooler", NULL);

void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#endif
#endif
break;
default:;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ void setup()
pinMode(gpio_speed, OUTPUT);
analogWrite(gpio_speed, DEFAULT_SPEED);

Node my_node;
Node my_node;
my_node = RMaker.initNode("ESP RainMaker Node");

//Create custom air cooler device
Expand All @@ -138,20 +138,22 @@ void setup()
my_device.addParam(mode_param);

my_device.addCb(write_callback);
//Add custom Air Cooler device to the node

//Add custom Air Cooler device to the node
my_node.addDevice(my_device);

//This is optional
//This is optional
// RMaker.enableOTA(OTA_USING_PARAMS);
//If you want to enable scheduling, set time zone for your region using setTimeZone().
//If you want to enable scheduling, set time zone for your region using setTimeZone().
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
// RMaker.setTimeZone("Asia/Shanghai");
//Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
// RMaker.enableTZService();

RMaker.enableSchedule();

RMaker.enableScenes();

RMaker.start();

WiFi.onEvent(sysProvEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void setup()
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
RMaker.enableTZService();
RMaker.enableSchedule();
RMaker.enableScenes();

//Service Name
for(int i=0; i<17; i=i+8) {
Expand Down
2 changes: 2 additions & 0 deletions libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ void setup()

RMaker.enableSchedule();

RMaker.enableScenes();

RMaker.start();

WiFi.onEvent(sysProvEvent);
Expand Down
13 changes: 11 additions & 2 deletions libraries/RainMaker/src/RMaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "RMaker.h"
#include <esp_rmaker_schedule.h>
#include <esp_rmaker_utils.h>
#include <esp_rmaker_scenes.h>
bool wifiLowLevelInit(bool persistent);
static esp_err_t err;

Expand All @@ -28,12 +29,12 @@ static void event_handler(void *arg, esp_event_base_t event_base, int32_t event_
log_i("Unhandled RainMaker Event:");
}
} else if (event_base == RMAKER_OTA_EVENT) {
if(event_data == NULL){
if (event_data == NULL) {
event_data = (void*)"";
}
switch(event_id) {
case RMAKER_OTA_EVENT_STARTING:
log_i("Starting OTA : %s", (char*)event_data);
log_i("Starting OTA");
break;
case RMAKER_OTA_EVENT_IN_PROGRESS:
log_i("OTA in progress : %s", (char*)event_data);
Expand Down Expand Up @@ -146,5 +147,13 @@ esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert)
return err;
}

esp_err_t RMakerClass::enableScenes()
{
err = esp_rmaker_scenes_enable();
if (err != ESP_OK) {
log_e("Scenes enable failed");
}
return err;
}
RMakerClass RMaker;
#endif
5 changes: 3 additions & 2 deletions libraries/RainMaker/src/RMaker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ class RMakerClass
{
private:
esp_rmaker_config_t rainmaker_cfg = {false};

public:

void setTimeSync(bool val);
Node initNode(const char *name, const char *type = "ESP RainMaker with Arduino");
esp_err_t deinitNode(Node node);
esp_err_t setTimeZone(const char *tz = "Asia/Shanghai");
esp_err_t enableSchedule();
esp_err_t enableTZService();
esp_err_t enableOTA(ota_type_t type, const char *cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT);
esp_err_t enableScenes();
esp_err_t start();
esp_err_t stop();
};
Expand Down