diff --git a/CMakeLists.txt b/CMakeLists.txt index 32d17e5f68d..3dd870eb759 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,6 @@ set(ARDUINO_ALL_LIBRARIES OpenThread PPP Preferences - RainMaker SD_MMC SD SimpleBLE @@ -191,15 +190,6 @@ set(ARDUINO_LIBRARY_PPP_SRCS set(ARDUINO_LIBRARY_Preferences_SRCS libraries/Preferences/src/Preferences.cpp) -set(ARDUINO_LIBRARY_RainMaker_SRCS - libraries/RainMaker/src/RMaker.cpp - libraries/RainMaker/src/RMakerNode.cpp - libraries/RainMaker/src/RMakerParam.cpp - libraries/RainMaker/src/RMakerDevice.cpp - libraries/RainMaker/src/RMakerType.cpp - libraries/RainMaker/src/RMakerQR.cpp - libraries/RainMaker/src/RMakerUtils.cpp - libraries/RainMaker/src/AppInsights.cpp) set(ARDUINO_LIBRARY_SD_MMC_SRCS libraries/SD_MMC/src/SD_MMC.cpp) diff --git a/libraries/RainMaker/README.md b/libraries/RainMaker/README.md deleted file mode 100644 index 2bfe7dd1a06..00000000000 --- a/libraries/RainMaker/README.md +++ /dev/null @@ -1,483 +0,0 @@ -# ESP RainMaker library for Arduino -This library allows to work with ESP RainMaker. - -ESP RainMaker is an end-to-end solution offered by Espressif to enable remote control and monitoring for ESP32-S2 and ESP32 based products without any configuration required in the Cloud. The primary components of this solution are: - -- Claiming Service (to get the Cloud connectivity credentials) -- RainMaker library (i.e. this library, to develop the firmware) -- RainMaker Cloud (backend, offering remote connectivity) -- RainMaker Phone App/CLI (Client utilities for remote access) - -The key features of ESP RainMaker are: - -1. Ability to define own devices and parameters, of any type, in the firmware. -2. Zero configuration required on the Cloud. -3. Phone apps that dynamically render the UI as per the device information. - -This ESP RainMaker library is built using esp-rainmaker component. - -#### Repository Source - -- [ESP RainMaker](https://github.com/espressif/esp-rainmaker) - -## Phone Apps - -#### Android - -- [Google PlayStore](https://play.google.com/store/apps/details?id=com.espressif.rainmaker) -- [Direct APK](https://github.com/espressif/esp-rainmaker/wiki) -- [Source Code](https://github.com/espressif/esp-rainmaker-android) - -#### iOS -- [Apple App Store](https://apps.apple.com/app/esp-rainmaker/id1497491540) -- [Source Code](https://github.com/espressif/esp-rainmaker-ios) - -## Documentation - -Additional information about ESP RainMaker can be found [here](https://rainmaker.espressif.com/) - -NOTE : ESP RainMaker library is currently supported for ESP32 board only. - -## ESP RainMaker Agent API - -### RMaker.initNode() -This initializes the ESP RainMaker agent, Wi-Fi and creates the node. -``` -Node initNode(const char *name, const char *type); -``` -* **Parameters** -1. `name`: Name of the node -2. `type`: Type of the node - -* **Return** -1. Object of Node. - -* You can also set the configuration of the node using the following API - 1. RMaker.setTimeSync(bool val) -> NOTE: If you want to set the configuration for the node then these configuration API must be called before `RMaker.initNode()`. - -### RMaker.start() -It starts the ESP RainMaker agent. -``` -esp_err_t start() -``` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -> NOTE : -> 1. ESP RainMaker agent should be initialized before this call. -> 2. Once ESP RainMaker agent starts, compulsorily call `WiFi.beginProvision()` API. - -### RMaker.stop() -It stops the ESP RainMaker agent which was started using `RMaker.start()`. -``` -esp_err_t stop() -``` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.deinitNode() -It deinitializes the ESP RainMaker agent and the node created using `RMaker.initNode()`. -``` -esp_err_t deinitNode(Node node) -``` -* **Parameter** -1. `node` : Node object created using `RMaker.initNode()` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.enableOTA() -It enables OTA as per the ESP RainMaker Specification. For more details refer ESP RainMaker documentation. check [here](https://rainmaker.espressif.com/docs/ota.html) -``` -esp_err_t enableOTA(ota_type_t type); -``` -* **Parameter** -1. `type` : The OTA workflow type. - - OTA_USING_PARAMS - - OTA_USING_TOPICS -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.enableSchedule() -This API enables the scheduling service for the node. For more information, check [here](https://rainmaker.espressif.com/docs/scheduling.html). -``` -esp_err_t enableSchedule(); -``` -* **Return** -1. ESP_OK : On success -2. Error in case of failure - -### RMaker.setTimeZone() -This API set's the timezone as a user friendly location string. Check [here](https://rainmaker.espressif.com/docs/time-service.html) for a list of valid values. -``` -esp_err_t setTimeZone(const char *tz); -``` -* **Parameter** -1. `tz' : Valid values as specified in documentation. - -* **Return** -1. ESP_OK : On success -2. Error in case of failure -> NOTE : default value is "Asia/Shanghai". -> This API comes into picture only when working with scheduling. - -## ESP RainMaker NODE APIs -`Node` class expose API's for node. -> NOTE : my_node is the object of Node class. - -### my_node.getNodeID() -It returns the unique node_id assigned to the node. This node_id is usually the MAC address of the board. -``` -char * getNodeID() -``` -* **Return** -1. `char * ` : Pointer to a NULL terminated node_id string. - -### my_node.getNodeInfo() -It returns pointer to the node_info_t as configured during node initialization. -``` -node_info_t * getNodeInfo(); -``` -* **Return** -1. `node_info_t` : Pointer to the structure node_info_t on success. -2. `NULL` : On failure. - -* **ESP RainMaker node info** -It has following data member -1. char * name -2. char * type -3. char * fw_version -4. char * model - -### my_node.addNodeAttr() -It adds a new attribute as the metadata to the node. -``` -esp_err_t addNodeAttr(const char *attr_name, const char *val); -``` -* **Parameters** -1. `attr_name` : Name of the attribute -2. `val` : Value of the attribute - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -> NOTE : Only string values are allowed. - -### my_node.addDevice() -It adds a device to the node. -``` -esp_err_t addDevice(Device device); -``` -* **Parameter** -1. `device` : Device object - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -> NOTE : -> - This is the mandatory API to register device to node. -> - Single Node can have multiple devices. -> - Device name should be unique for each device. - -### my_node.removeDevice() -It removes a device from the node. -``` -esp_err_t removeDevice(Device device); -``` -* **Parameter** -1. `device` : Device object - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -## ESP RainMaker DEVICE API's -`Device` class expose API's for virtual devices on the node. -Parameterized constructor is defined which creates the virtual device on the node. Using Device class object you can create your own device. -> NOTE : my_device is the object of Device class -``` -Device my_device(const char *dev_name, const char *dev_type, void *priv_data); -``` -* **Parameters** -1. `dev_name` : Unique device name -2. `dev_type` : Optional device type. It can be kept NULL. - * Standard Device Types - * ESP_RMAKER_DEVICE_SWITCH - * ESP_RMAKER_DEVICE_LIGHTBULB - * ESP_RMAKER_DEVICE_FAN - * ESP_RMAKER_DEVICE_TEMP_SENSOR -3. `priv_data` : Private data associated with the device. This will be passed to the callbacks. - -> NOTE : This created device should be added to the node using `my_node.addDevice(my_device)`. - -- Sample example -``` -Device my_device("Switch"); -Device my_device("Switch1", NULL, NULL); -``` -> Here, dev_name is compulsory, rest are optional. -> Node can have multiple device, each device should have unique device name. - -### Standard Device -- Classes are defined for the standard devices. -- Creating object of these class creates the standard device with default parameters to it. -- Class for standard devices - * Switch - * LightBulb - * TemperatureSensor - * Fan -``` -Switch my_switch(const char *dev_name, void *priv_data, bool power); -``` -* **Parameters** -1. `dev_name` : Unique device name by default it is "switch" for switch device. -2. `priv_data` : Private data associated with the device. This will be passed to the callbacks. -3. `power` : It is the value that can be set for primary parameter. - -- Sample example for standard device. -``` -Switch switch1; -Switch switch2("switch2", NULL, true); -``` -`"switch2"` : Name for standard device. - -`NULL` : Private data for the device, which will be used in callback. - -`true` : Default value for the primary param, in case of switch it is power. - -> NOTE : No parameter are compulsory for standard devices. However if you are creating two objects of same standard class then in that case you will have to set the device name, if not then both device will have same name which is set by default, hence device will not get create. Device name should be unique for each device. - -### my_device.getDeviceName() -It returns the name of the Device. -``` -const char * getDeviceName(); -``` -* **Return** -1. `char *`: Returns Device name. - -> NOTE : Each device on the node should have unique device name. - -### my_device.addDeviceAttr() -It adds attribute to the device. Device attributes are reported only once after a boot-up as part of the node configuration. Eg. Serial Number -``` -esp_err_t addDeviceAttr(const char *attr_name, const char *val); -``` -* **Parameters** -1. `attr_name` : Name of the attribute -2. `val` : Value of the attribute - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -### my_device.deleteDevice() -It deletes the device created using parameterized constructor. This device should be first removed from the node using `my_node.removeDevice(my_device)`. -``` -esp_err_t deleteDevice(); -``` -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -### my_device.addXParam() -It adds standard parameter to the device. -> NOTE : X is the default name by which parameter is referred, you can specify your own name to each parameter. - -> Default - -> Eg. `my_device.addPowerParam(true)` here power parameter is referred with name Power. -> Eg. `my_device.addHueParam(12)` here hue parameter is referred with name Hue. - -> You can specify your own name to each parameter - -> Eg. `my_device.addNameParam("NickName")` here name parameter is referred with name NickName. -> Eg. `my_device.addPowerParam(true, "FanPower")` here power parameter is referred with name FanPower. - -``` -esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM); -esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME); -esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME); -esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME); -esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME); -esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME); -esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME); -esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME); -esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME); -esp_err_t addTemperatureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME); -``` -* **Standard Parameters** - -* These are the standard parameters. - * Name : ESP_RMAKER_DEF_NAME_PARAM - * Power : ESP_RMAKER_DEF_POWER_NAME - * Brightness : ESP_RMAKER_DEF_BRIGHTNESS_NAME - * Hue : ESP_RMAKER_DEF_HUE_NAME - * Saturation : ESP_RMAKER_DEF_SATURATION_NAME - * Intensity : ESP_RMAKER_DEF_INTENSITY_NAME - * CCT : ESP_RMAKER_DEF_CCT_NAME - * Direction : ESP_RMAKER_DEF_DIRECTION_NAME - * Speed : ESP_RMAKER_DEF_SPEED_NAME - * Temperature : ESP_RMAKER_DEF_TEMPERATURE_NAME -> NOTE : Care should be taken while accessing name of parameter. Above mentioned are the two ways using which default name of parameters can be accessed. Either LHS or RHS. - -### my_device.assignPrimaryParam() -It assigns a parameter (already added using addXParam() or addParam()) as a primary parameter, which can be used by clients (phone apps specifically) to give prominence to it. -``` -esp_err_t assignPrimaryParam(param_handle_t *param); -``` -* **Parameter** -1. `param` : Handle of the parameter. It is obtained using `my_device.getParamByName()`. -``` -param_handle_t * getParamByName(const char *param_name); -``` -> NOTE : -> `param_name` : It is the name of the parameter which was added using addXparam() or addParam(). - -### my_device.addParam() -It allows user to add custom parameter to the device created using `Param` class. -``` -esp_err_t addParam(Param parameter); -``` -* **Parameter** -1. `parameter` : Object of Param - -* **Return** -1. ESP_OK : On success -2. Error in case of failure -> NOTE : Param class exposes API's to create the custom parameter. - -### my_device.updateAndReportParam() -It updates the parameter assosicated with particular device on ESP RainMaker cloud. -``` -esp_err_t updateAndReportParam(const char *param_name, value); -``` -* **Parameters** -1. `param_name` : Name of the parameter -2. `value` : Value to be updated. It can be int, bool, char * , float. - -* **Return** -1. `ESP_OK` : On success -2. Error in case of failure - -### my_device.addCb() -It registers read and write callback for the device which will be invoked as per requests received from the cloud (or other paths as may be added in future). -``` -void addCb(deviceWriteCb write_cb, deviceReadCb read_cb); -``` -* **Parameters** -1. `write_cb` : Function with signature [ func_name(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx); ] -2. `read_cb` : Function with signature [ func_name(Device *device, Param *param, void *priv_data, read_ctx_t *ctx); ] - -* **param_val_t val** -Value can be accessed as below -1. `bool` : val.val.b -2. `integer` : val.val.i -3. `float` : val.val.f -4. `char *` : val.val.s - -## ESP RainMaker PARAM API's -`Param` class expose API's for creating custom parameters for the devices and report and update values associated with parameter to the ESP RainMaker cloud. Parameterized constructor is defined which creates custom parameter. -> NOTE : my_param is the object of Param class. - -``` -Param my_param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties); -``` -* **Parameters** -1. `param_name` : Name of the parameter -2. `param_type` : Type of the parameter. It is optional can be kept NULL. -3. `val` : Define the default value for the parameter. It should be defined using `value(int ival)` , `value(bool bval)` , `value(float fval)` , `value(char *sval)`. -4. `properties` : Properties of the parameter, which will be a logical OR of flags. - * Flags - * PROP_FLAG_WRITE - * PROP_FLAG_READ - * PROP_FLAG_TIME_SERIES - * PROP_FLAG_PERSIST - -`Sample example : Param my_param("bright", NULL, value(30), PROP_FLAG_READ | PROP_FLAG_WRITE | PROP_FLAG_PERSIST);` -> NOTE : Parameter created using Param class should be added to the device using `my_device.addParam(my_param);` - -### my_param.addUIType() -Add a UI type to the parameter. This will be used by the Phone apps (or other clients) to render appropriate UI for the given parameter. Please refer the RainMaker documentation [here](https://rainmaker.espressif.com/docs/standard-types.html#ui-elements) for supported UI Types. -``` -esp_err_t addUIType(const char *ui_type); -``` -* **Parameter** -1. `ui_type` : String describing the UI Type. - * Standard UI Types - * ESP_RMAKER_UI_TOGGLE - * ESP_RMAKER_UI_SLIDER - * ESP_RMAKER_UI_DROPDOWN - * ESP_RMAKER_UI_TEXT - -* **Returns** -1. ESP_OK : On success. -2. Error in case of failure. - -### my_param.addBounds() -Add bounds for an integer/float parameter. This can be used to add bounds (min/max values) for a given integer/float parameter. Eg. brightness will have bounds as 0 and 100 if it is a percentage. -``` -esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); -``` -* **Parameters** -1. `min` : Minimum value -2. `max` : Maximum value -3. `step` : step Minimum stepping - -* **Returns** -1. ESP_OK : On success. -2. Error in case of failure. - -`Sample example : my_param.addBounds(value(0), value(100), value(5));` - -### my_param.updateAndReport() -It updates the parameter and report it to ESP RainMaker cloud. This is called in callback. -``` -esp_err_t updateAndReport(param_val_t val); -``` -* **Parameters** -1. `val` : New value of the parameter - -* **Return** -1. ESP_OK : On success. -2. Error in case of failure. - -> NOTE : -> - This API should always be called inside device write callback, if you aimed at updating n reporting parameter values, changed via RainMaker Client (Phone App), to the ESP RainMaker cloud. -> - If not called then parameter values will not be updated to the ESP RainMaker cloud. - -### printQR() -This API displays QR code, which is used in provisioning. -``` -printQR(const char *serv_name, const char *pop, const char *transport); -``` -* **Parameters** -1. `name` : Service name used in provisioning API. -2. `pop` : Proof of possession used in provisioning API. -3. `transport` : - 1. `softap` : In case of provisioning using SOFTAP. - 2. `ble` : In case of provisioning using BLE. - -### RMakerFactoryReset() -Reset the device to factory defaults. - -``` -RMakerFactoryReset(2); -``` -* **Parameters** -1. `seconds` : Time in seconds after which the chip should reboot after doing a factory reset. - - -### RMakerWiFiReset() -Reset Wi-Fi credentials. -``` -RMakerWiFiReset(2); -``` - -* **Parameters** -1. `seconds` : Time in seconds after which the chip should reboot after doing a Wi-Fi reset. diff --git a/libraries/RainMaker/examples/README.md b/libraries/RainMaker/examples/README.md deleted file mode 100644 index f838736dad8..00000000000 --- a/libraries/RainMaker/examples/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# ESP RainMaker Examples - -While building any examples for ESP RainMaker, take care of the following: - -1. Change the partition scheme that fits your flash size in Arduino IDE to `RainMaker 4MB`, `RainMaker 4MB no OTA` or `RainMaker 8MB` (Tools -> Partition Scheme -> RainMaker). -2. Once ESP RainMaker gets started, compulsorily call `WiFi.beginProvision()` which is responsible for user-node mapping. -3. Use the appropriate provisioning scheme as per the board. - - ESP32 Board: BLE Provisioning - - ESP32-C3 Board: BLE Provisioning - - ESP32-S3 Board: BLE Provisioning - - ESP32-S2 Board: SoftAP Provisioning - - ESP32-C6 Board: BLE Provisioning - - ESP32-H2 Board: BLE Provisioning -4. Set debug level to Info (Tools -> Core Debug Level -> Info). This is the recommended debug level but not mandatory to run RainMaker. diff --git a/libraries/RainMaker/examples/RMakerCustom/README.md b/libraries/RainMaker/examples/RMakerCustom/README.md deleted file mode 100644 index b6b17052827..00000000000 --- a/libraries/RainMaker/examples/RMakerCustom/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# ESP RainMaker Custom Device - -This example demonstrates how to build a custom device to be used with ESP RainMaker. - -## What to expect in this example? - -- This example sketch uses the on board Boot button and GPIO16 to demonstrate an ESP RainMaker AC dimmer device. -- After compiling and flashing the example, add your device using the [ESP RainMaker phone apps](https://rainmaker.espressif.com/docs/quick-links.html#phone-apps) by scanning the QR code. -- Toggling the state from the phone app will toggle the dimmer state (GPIO16). -- Pressing the Boot button will toggle the dimmer state (GPIO16) and the same will reflect on the phone app. -- You can also change the Level from the phone app and see it reflect on the device as a print message. - -### Output - -``` -[ 87][I][RMaker.cpp:13] event_handler(): RainMaker Initialized. -[ 94][I][WiFiProv.cpp:158] beginProvision(): Already Provisioned -[ 95][I][WiFiProv.cpp:162] beginProvision(): Attempting connect to AP: Viking007_2GEXT - -Received value = false for Dimmer - Power -Toggle State to true. -[ 22532][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Dimmer, Param Name : Power, Val : true - -Received value = 73 for Dimmer - Level -``` - -### Resetting the device -- Press and Hold the Boot button for more than 3 seconds and then release to reset Wi-Fi configuration. -- Press and Hold the Boot button for more than 10 seconds and then release to reset to factory defaults. diff --git a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino b/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino deleted file mode 100644 index a652f55ac34..00000000000 --- a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino +++ /dev/null @@ -1,140 +0,0 @@ -//This example demonstrates the ESP RainMaker with a custom device -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" - -#define DEFAULT_POWER_MODE true -#define DEFAULT_DIMMER_LEVEL 50 -const char *service_name = "PROV_1234"; -const char *pop = "abcd1234"; - -//GPIO for push button -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 -static int gpio_0 = 9; -static int gpio_dimmer = 7; -#else -//GPIO for virtual device -static int gpio_0 = 0; -static int gpio_dimmer = 16; -#endif - -bool dimmer_state = true; - -// The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. -// But, you can also define custom devices using the 'Device' base class object, as shown here -static Device *my_device = NULL; - -// WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) { - 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); - WiFiProv.printQR(service_name, pop, "softap"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - WiFiProv.printQR(service_name, pop, "ble"); -#endif - break; - case ARDUINO_EVENT_PROV_INIT: WiFiProv.disableAutoStop(10000); break; - case ARDUINO_EVENT_PROV_CRED_SUCCESS: WiFiProv.endProvision(); break; - default: ; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - dimmer_state = val.val.b; - (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Level") == 0) { - Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); - param->updateAndReport(val); - } -} - -void setup() { - Serial.begin(115200); - pinMode(gpio_0, INPUT); - pinMode(gpio_dimmer, OUTPUT); - digitalWrite(gpio_dimmer, DEFAULT_POWER_MODE); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - my_device = new Device("Dimmer", "custom.device.dimmer", &gpio_dimmer); - if (!my_device) { - return; - } - //Create custom dimmer device - my_device->addNameParam(); - my_device->addPowerParam(DEFAULT_POWER_MODE); - my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME)); - - //Create and add a custom level parameter - Param level_param("Level", "custom.param.level", value(DEFAULT_DIMMER_LEVEL), PROP_FLAG_READ | PROP_FLAG_WRITE); - level_param.addBounds(value(0), value(100), value(1)); - level_param.addUIType(ESP_RMAKER_UI_SLIDER); - my_device->addParam(level_param); - - my_device->addCb(write_callback); - - //Add custom dimmer device to the node - my_node.addDevice(*my_device); - - //This is optional - RMaker.enableOTA(OTA_USING_TOPICS); - //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); // Will call sysProvEvent() from another thread. -#if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE, NETWORK_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM, NETWORK_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() { - if (digitalRead(gpio_0) == LOW) { //Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_0) == LOW) { - delay(50); - } - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - dimmer_state = !dimmer_state; - Serial.printf("Toggle State to %s.\n", dimmer_state ? "true" : "false"); - if (my_device) { - my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, dimmer_state); - } - (dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH); - } - } - delay(100); -} diff --git a/libraries/RainMaker/examples/RMakerCustom/ci.json b/libraries/RainMaker/examples/RMakerCustom/ci.json deleted file mode 100644 index 1c80eda1d90..00000000000 --- a/libraries/RainMaker/examples/RMakerCustom/ci.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "fqbn_append": "PartitionScheme=rainmaker_4MB", - "requires": [ - "CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK=[1-9][0-9]*" - ], - "requires_any": [ - "CONFIG_SOC_WIFI_SUPPORTED=y", - "CONFIG_ESP_WIFI_REMOTE_ENABLED=y" - ] -} diff --git a/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md b/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md deleted file mode 100644 index 2f20e45bfec..00000000000 --- a/libraries/RainMaker/examples/RMakerCustomAirCooler/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# ESP RainMaker Custom Device - -This example demonstrates how to build a custom device to be used with ESP RainMaker using Mode, Range and Toggle Parameters. - -## What to expect in this example? - -- This example sketch uses the on board Boot button and GPIOs 16, 17, 18, 19, 21, 22 to demonstrate an ESP RainMaker AirCooler device. -- After compiling and flashing the example, add your device using the [ESP RainMaker phone apps](https://rainmaker.espressif.com/docs/quick-links.html#phone-apps) by scanning the QR code. -- Toggling the power state from the phone app will toggle GPIO 16. -- Pressing the Boot button will toggle the power state (GPIO 16) and the same will reflect on the phone app. -- Toggling the swing state from the phone app will toggle GPIO 17. -- Changing the mode from the phone app will toggle the GPIOs 18 (auto), 19 (cool) and 21 (heat) -- Changing the Speed slider from the phone app will dimming GPIO 22 -- You can also change the Level from the phone app and see it reflect on the device as a print message. - -### Output - -``` -Received value = true for Air Cooler - Power -Received value = false for Air Cooler - Power -Received value = true for Air Cooler - Swing -Received value = false for Air Cooler - Swing -Received value = 0 for Air Cooler - Speed -Received value = 255 for Air Cooler - Speed -Received value = Auto for Air Cooler - Mode -Received value = Cool for Air Cooler - Mode -Received value = Heat for Air Cooler - Mode -Toggle power state to false. -Toggle power state to false. -``` - -### Resetting the device -- Press and Hold the Boot button for more than 3 seconds and then release to reset Wi-Fi configuration. -- Press and Hold the Boot button for more than 10 seconds and then release to reset to factory defaults. diff --git a/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino b/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino deleted file mode 100644 index 559d73e771c..00000000000 --- a/libraries/RainMaker/examples/RMakerCustomAirCooler/RMakerCustomAirCooler.ino +++ /dev/null @@ -1,205 +0,0 @@ -//This example demonstrates the ESP RainMaker with a custom Air Cooler device -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" - -#define DEFAULT_POWER_MODE true -#define DEFAULT_SWING false -#define DEFAULT_SPEED 0 -#define DEFAULT_MODE "Auto" - -const char *service_name = "PROV_1234"; -const char *pop = "abcd1234"; - -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 -//GPIO for push button -static int gpio_reset = 9; -//GPIO for virtual device -static int gpio_power = 7; -static int gpio_swing = 3; -static int gpio_mode_auto = 4; -static int gpio_mode_cool = 5; -static int gpio_mode_heat = 6; -static int gpio_speed = 10; - -#else -//GPIO for push button -static int gpio_reset = 0; -//GPIO for virtual device -static int gpio_power = 16; -static int gpio_swing = 17; -static int gpio_mode_auto = 18; -static int gpio_mode_cool = 19; -static int gpio_mode_heat = 21; -static int gpio_speed = 22; -#endif - -bool power_state = true; - -// The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. -// But, you can also define custom devices using the 'Device' base class object, as shown here -static Device *my_device = NULL; - -// WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) { - 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); - WiFiProv.printQR(service_name, pop, "softap"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - WiFiProv.printQR(service_name, pop, "ble"); -#endif - break; - case ARDUINO_EVENT_PROV_INIT: WiFiProv.disableAutoStop(10000); break; - case ARDUINO_EVENT_PROV_CRED_SUCCESS: WiFiProv.endProvision(); break; - default: ; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - power_state = val.val.b; - (power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Swing") == 0) { - Serial.printf("\nReceived value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - bool swing = val.val.b; - (swing == false) ? digitalWrite(gpio_swing, LOW) : digitalWrite(gpio_swing, HIGH); - param->updateAndReport(val); - } else if (strcmp(param_name, "Speed") == 0) { - Serial.printf("\nReceived value = %d for %s - %s\n", val.val.i, device_name, param_name); - int speed = val.val.i; - analogWrite(gpio_speed, speed); - param->updateAndReport(val); - } else if (strcmp(param_name, "Mode") == 0) { - const char *mode = val.val.s; - if (strcmp(mode, "Auto") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - digitalWrite(gpio_mode_heat, LOW); - digitalWrite(gpio_mode_cool, LOW); - } else if (strcmp(mode, "Heat") == 0) { - digitalWrite(gpio_mode_auto, LOW); - digitalWrite(gpio_mode_heat, HIGH); - digitalWrite(gpio_mode_cool, LOW); - } else if (strcmp(mode, "Cool") == 0) { - digitalWrite(gpio_mode_auto, LOW); - digitalWrite(gpio_mode_heat, LOW); - digitalWrite(gpio_mode_cool, HIGH); - } - Serial.printf("\nReceived value = %s for %s - %s\n", val.val.s, device_name, param_name); - param->updateAndReport(val); - } -} - -void setup() { - Serial.begin(115200); - pinMode(gpio_reset, INPUT_PULLUP); - pinMode(gpio_power, OUTPUT); - digitalWrite(gpio_power, DEFAULT_POWER_MODE); - pinMode(gpio_swing, OUTPUT); - digitalWrite(gpio_swing, DEFAULT_SWING); - pinMode(gpio_mode_auto, OUTPUT); - if (strcmp(DEFAULT_MODE, "Auto") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - } - pinMode(gpio_mode_cool, OUTPUT); - if (strcmp(DEFAULT_MODE, "Cool") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - } - pinMode(gpio_mode_heat, OUTPUT); - if (strcmp(DEFAULT_MODE, "Heat") == 0) { - digitalWrite(gpio_mode_auto, HIGH); - } - pinMode(gpio_speed, OUTPUT); - analogWrite(gpio_speed, DEFAULT_SPEED); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - my_device = new Device("Air Cooler", "my.device.air-cooler", NULL); - if (!my_device) { - return; - } - //Create custom air cooler device - my_device->addNameParam(); - my_device->addPowerParam(DEFAULT_POWER_MODE); - my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME)); - - Param swing("Swing", ESP_RMAKER_PARAM_TOGGLE, value(DEFAULT_SWING), PROP_FLAG_READ | PROP_FLAG_WRITE); - swing.addUIType(ESP_RMAKER_UI_TOGGLE); - my_device->addParam(swing); - - Param speed("Speed", ESP_RMAKER_PARAM_RANGE, value(DEFAULT_SPEED), PROP_FLAG_READ | PROP_FLAG_WRITE); - speed.addUIType(ESP_RMAKER_UI_SLIDER); - speed.addBounds(value(0), value(255), value(1)); - my_device->addParam(speed); - - static const char *modes[] = {"Auto", "Cool", "Heat"}; - Param mode_param("Mode", ESP_RMAKER_PARAM_MODE, value("Auto"), PROP_FLAG_READ | PROP_FLAG_WRITE); - mode_param.addValidStrList(modes, 3); - mode_param.addUIType(ESP_RMAKER_UI_DROPDOWN); - my_device->addParam(mode_param); - - my_device->addCb(write_callback); - - //Add custom Air Cooler device to the node - my_node.addDevice(*my_device); - - //This is optional - // RMaker.enableOTA(OTA_USING_TOPICS); - //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); // Will call sysProvEvent() from another thread. -#if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE, NETWORK_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM, NETWORK_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() { - if (digitalRead(gpio_reset) == LOW) { //Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_reset) == LOW) { - delay(50); - } - int press_duration = millis() - startTime; - - if (press_duration > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if (press_duration > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - power_state = !power_state; - Serial.printf("Toggle power state to %s.\n", power_state ? "true" : "false"); - if (my_device) { - my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, power_state); - } - (power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH); - } - } - delay(100); -} diff --git a/libraries/RainMaker/examples/RMakerCustomAirCooler/ci.json b/libraries/RainMaker/examples/RMakerCustomAirCooler/ci.json deleted file mode 100644 index ce63fe9ccf0..00000000000 --- a/libraries/RainMaker/examples/RMakerCustomAirCooler/ci.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "targets": { - "esp32": false - }, - "fqbn_append": "PartitionScheme=rainmaker_4MB", - "requires": [ - "CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK=[1-9][0-9]*" - ], - "requires_any": [ - "CONFIG_SOC_WIFI_SUPPORTED=y", - "CONFIG_ESP_WIFI_REMOTE_ENABLED=y" - ] -} diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino deleted file mode 100644 index 014da25c8f6..00000000000 --- a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino +++ /dev/null @@ -1,206 +0,0 @@ -//This example demonstrates the ESP RainMaker with a standard Switch device. -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" - -#define DEFAULT_POWER_MODE false -const char *service_name = "PROV_SONOFF_DUALR3"; -const char *pop = "123456"; - -// GPIO for push button -static uint8_t gpio_reset = 0; -// GPIO for switch -static uint8_t gpio_switch1 = 32; -static uint8_t gpio_switch2 = 33; -// GPIO for virtual device -static uint8_t gpio_relay1 = 27; -static uint8_t gpio_relay2 = 14; -/* Variable for reading pin status*/ -bool switch_state_ch1 = true; -bool switch_state_ch2 = true; -// GPIO for link status LED -static uint8_t gpio_led = 13; - -struct LightSwitch { - const uint8_t pin; - bool pressed; -}; - -// Define the light switches for channel 1 and 2 -LightSwitch switch_ch1 = {gpio_switch1, false}; -LightSwitch switch_ch2 = {gpio_switch2, false}; - -//The framework provides some standard device types like switch, lightbulb, fan, temperature sensor. -static Switch *my_switch1 = NULL; -static Switch *my_switch2 = NULL; - -// WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) { - switch (sys_event->event_id) { - case ARDUINO_EVENT_PROV_START: -#if CONFIG_IDF_TARGET_ESP32 - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - WiFiProv.printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - WiFiProv.printQR(service_name, pop, "softap"); -#endif - break; - case ARDUINO_EVENT_WIFI_STA_CONNECTED: - Serial.printf("\nConnected to Wi-Fi!\n"); - digitalWrite(gpio_led, true); - break; - case ARDUINO_EVENT_PROV_INIT: WiFiProv.disableAutoStop(10000); break; - case ARDUINO_EVENT_PROV_CRED_SUCCESS: WiFiProv.endProvision(); break; - default: ; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(device_name, "Switch_ch1") == 0) { - - Serial.printf("Lightbulb = %s\n", val.val.b ? "true" : "false"); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - switch_state_ch1 = val.val.b; - (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); - param->updateAndReport(val); - } - - } else if (strcmp(device_name, "Switch_ch2") == 0) { - - Serial.printf("Switch value = %s\n", val.val.b ? "true" : "false"); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - switch_state_ch2 = val.val.b; - (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); - param->updateAndReport(val); - } - } -} - -void ARDUINO_ISR_ATTR isr(void *arg) { - LightSwitch *s = static_cast(arg); - s->pressed = true; -} - -void setup() { - - uint32_t chipId = 0; - - Serial.begin(115200); - - // Configure the input GPIOs - pinMode(gpio_reset, INPUT); - pinMode(switch_ch1.pin, INPUT_PULLUP); - attachInterruptArg(switch_ch1.pin, isr, &switch_ch1, CHANGE); - pinMode(switch_ch2.pin, INPUT_PULLUP); - attachInterruptArg(switch_ch2.pin, isr, &switch_ch2, CHANGE); - - // Set the Relays GPIOs as output mode - pinMode(gpio_relay1, OUTPUT); - pinMode(gpio_relay2, OUTPUT); - pinMode(gpio_led, OUTPUT); - // Write to the GPIOs the default state on booting - digitalWrite(gpio_relay1, DEFAULT_POWER_MODE); - digitalWrite(gpio_relay2, DEFAULT_POWER_MODE); - digitalWrite(gpio_led, false); - - Node my_node; - my_node = RMaker.initNode("Sonoff Dual R3"); - - //Initialize switch device - my_switch1 = new Switch("Switch_ch1", &gpio_relay1); - my_switch2 = new Switch("Switch_ch2", &gpio_relay2); - - if (!my_switch1 || !my_switch2) { - return; - } - //Standard switch device - my_switch1->addCb(write_callback); - my_switch2->addCb(write_callback); - - //Add switch device to the node - my_node.addDevice(*my_switch1); - my_node.addDevice(*my_switch2); - - //This is optional - RMaker.enableOTA(OTA_USING_TOPICS); - //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(); - - //Service Name - for (int i = 0; i < 17; i = i + 8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } - - Serial.printf("\nChip ID: %lu Service Name: %s\n", chipId, service_name); - - Serial.printf("\nStarting ESP-RainMaker\n"); - RMaker.start(); - - WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM, NETWORK_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE, NETWORK_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() { - - if (switch_ch1.pressed) { - Serial.printf("Switch 1 has been changed\n"); - switch_ch1.pressed = false; - // Toggle switch 1 device state - switch_state_ch1 = !switch_state_ch1; - Serial.printf("Toggle State to %s.\n", switch_state_ch1 ? "true" : "false"); - if (my_switch1) { - my_switch1->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch1); - } - (switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH); - } else if (switch_ch2.pressed) { - Serial.printf("Switch 2 has been changed\n"); - switch_ch2.pressed = false; - // Toggle switch 2 device state - switch_state_ch2 = !switch_state_ch2; - Serial.printf("Toggle State to %s.\n", switch_state_ch2 ? "true" : "false"); - if (my_switch2) { - my_switch2->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch2); - } - (switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH); - } - - // Read GPIO0 (external button to reset device - if (digitalRead(gpio_reset) == LOW) { //Push button pressed - Serial.printf("Reset Button Pressed!\n"); - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_reset) == LOW) { - delay(50); - } - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } - } - delay(100); -} diff --git a/libraries/RainMaker/examples/RMakerSonoffDualR3/ci.json b/libraries/RainMaker/examples/RMakerSonoffDualR3/ci.json deleted file mode 100644 index ce63fe9ccf0..00000000000 --- a/libraries/RainMaker/examples/RMakerSonoffDualR3/ci.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "targets": { - "esp32": false - }, - "fqbn_append": "PartitionScheme=rainmaker_4MB", - "requires": [ - "CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK=[1-9][0-9]*" - ], - "requires_any": [ - "CONFIG_SOC_WIFI_SUPPORTED=y", - "CONFIG_ESP_WIFI_REMOTE_ENABLED=y" - ] -} diff --git a/libraries/RainMaker/examples/RMakerSwitch/README.md b/libraries/RainMaker/examples/RMakerSwitch/README.md deleted file mode 100644 index 4d8a38d8ad0..00000000000 --- a/libraries/RainMaker/examples/RMakerSwitch/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# ESP RainMaker Switch - -This example demonstrates how to build a switch device to be used with ESP RainMaker. - -## What to expect in this example? - -- This example sketch uses the on board Boot button and GPIO16 to demonstrate an ESP RainMaker switch device. -- After compiling and flashing the example, add your device using the [ESP RainMaker phone apps](https://rainmaker.espressif.com/docs/quick-links.html#phone-apps) by scanning the QR code. -- Toggling the state from the phone app will toggle the switch state (GPIO16). -- Pressing the Boot button will toggle the switch state (GPIO16) and the same will reflect on the phone app. - -### Output - -``` -[ 63][I][RMaker.cpp:13] event_handler(): RainMaker Initialized. -[ 69][I][WiFiProv.cpp:158] beginProvision(): Already Provisioned -[ 69][I][WiFiProv.cpp:162] beginProvision(): Attempting connect to AP: Viking007_2GEXT - -Toggle State to false. -[ 8182][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Switch, Param Name : Power, Val : false -Toggle State to true. -[ 9835][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Switch, Param Name : Power, Val : true -Received value = false for Switch - Power -Received value = true for Switch - Power -Toggle State to false. -[ 29937][I][RMakerDevice.cpp:162] updateAndReportParam(): Device : Switch, Param Name : Power, Val : false -``` - -### Resetting the device -- Press and Hold the Boot button for more than 3 seconds and then release to reset Wi-Fi configuration. -- Press and Hold the Boot button for more than 10 seconds and then release to reset to factory defaults. diff --git a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino b/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino deleted file mode 100644 index 21fe9cb064b..00000000000 --- a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino +++ /dev/null @@ -1,143 +0,0 @@ -// This example demonstrates the ESP RainMaker with a standard Switch device. -#include "RMaker.h" -#include "WiFi.h" -#include "WiFiProv.h" -#include "AppInsights.h" - -#define DEFAULT_POWER_MODE true -const char *service_name = "PROV_1234"; -const char *pop = "abcd1234"; - -// GPIO for push button -#if CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C6 -static int gpio_0 = 9; -static int gpio_switch = 7; -#else -// GPIO for virtual device -static int gpio_0 = 0; -static int gpio_switch = 16; -#endif - -/* Variable for reading pin status*/ -bool switch_state = true; - -// The framework provides some standard device types like switch, lightbulb, -// fan, temperaturesensor. -static Switch *my_switch = NULL; - -// WARNING: sysProvEvent is called from a separate FreeRTOS task (thread)! -void sysProvEvent(arduino_event_t *sys_event) { - 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); - WiFiProv.printQR(service_name, pop, "softap"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop); - WiFiProv.printQR(service_name, pop, "ble"); -#endif - break; - case ARDUINO_EVENT_PROV_INIT: WiFiProv.disableAutoStop(10000); break; - case ARDUINO_EVENT_PROV_CRED_SUCCESS: WiFiProv.endProvision(); break; - default: ; - } -} - -void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx) { - const char *device_name = device->getDeviceName(); - const char *param_name = param->getParamName(); - - if (strcmp(param_name, "Power") == 0) { - Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name); - switch_state = val.val.b; - (switch_state == false) ? digitalWrite(gpio_switch, LOW) : digitalWrite(gpio_switch, HIGH); - param->updateAndReport(val); - } -} - -void setup() { - Serial.begin(115200); - pinMode(gpio_0, INPUT); - pinMode(gpio_switch, OUTPUT); - digitalWrite(gpio_switch, DEFAULT_POWER_MODE); - - Node my_node; - my_node = RMaker.initNode("ESP RainMaker Node"); - - // Initialize switch device - my_switch = new Switch("Switch", &gpio_switch); - if (!my_switch) { - return; - } - // Standard switch device - my_switch->addCb(write_callback); - - // Add switch device to the node - my_node.addDevice(*my_switch); - - // This is optional - RMaker.enableOTA(OTA_USING_TOPICS); - // 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(); - // Enable ESP Insights. Insteads of using the default http transport, this function will - // reuse the existing MQTT connection of Rainmaker, thereby saving memory space. - initAppInsights(); - - RMaker.enableSystemService(SYSTEM_SERV_FLAGS_ALL, 2, 2, 2); - -#if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.initProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE); -#else - WiFiProv.initProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM); -#endif - - RMaker.start(); - - WiFi.onEvent(sysProvEvent); // Will call sysProvEvent() from another thread. -#if CONFIG_IDF_TARGET_ESP32S2 - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_SOFTAP, NETWORK_PROV_SCHEME_HANDLER_NONE, NETWORK_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(NETWORK_PROV_SCHEME_BLE, NETWORK_PROV_SCHEME_HANDLER_FREE_BTDM, NETWORK_PROV_SECURITY_1, pop, service_name); -#endif -} - -void loop() { - if (digitalRead(gpio_0) == LOW) { // Push button pressed - - // Key debounce handling - delay(100); - int startTime = millis(); - while (digitalRead(gpio_0) == LOW) { - delay(50); - } - int endTime = millis(); - - if ((endTime - startTime) > 10000) { - // If key pressed for more than 10secs, reset all - Serial.printf("Reset to factory.\n"); - RMakerFactoryReset(2); - } else if ((endTime - startTime) > 3000) { - Serial.printf("Reset Wi-Fi.\n"); - // If key pressed for more than 3secs, but less than 10, reset Wi-Fi - RMakerWiFiReset(2); - } else { - // Toggle device state - switch_state = !switch_state; - Serial.printf("Toggle State to %s.\n", switch_state ? "true" : "false"); - if (my_switch) { - my_switch->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state); - } - (switch_state == false) ? digitalWrite(gpio_switch, LOW) : digitalWrite(gpio_switch, HIGH); - } - } - delay(100); -} diff --git a/libraries/RainMaker/examples/RMakerSwitch/ci.json b/libraries/RainMaker/examples/RMakerSwitch/ci.json deleted file mode 100644 index 1c80eda1d90..00000000000 --- a/libraries/RainMaker/examples/RMakerSwitch/ci.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "fqbn_append": "PartitionScheme=rainmaker_4MB", - "requires": [ - "CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK=[1-9][0-9]*" - ], - "requires_any": [ - "CONFIG_SOC_WIFI_SUPPORTED=y", - "CONFIG_ESP_WIFI_REMOTE_ENABLED=y" - ] -} diff --git a/libraries/RainMaker/library.properties b/libraries/RainMaker/library.properties deleted file mode 100644 index 95ce14d6708..00000000000 --- a/libraries/RainMaker/library.properties +++ /dev/null @@ -1,8 +0,0 @@ -name=ESP RainMaker -version=3.2.0 -author=Sweety Mhaiske -maintainer=Hristo Gochkov -sentence=ESP RainMaker Support -paragraph=With this library you can build connected devices and access them via phone apps without having to manage the infrastructure. -url=https://rainmaker.espressif.com -architectures=esp32,esp32s2 diff --git a/libraries/RainMaker/src/AppInsights.cpp b/libraries/RainMaker/src/AppInsights.cpp deleted file mode 100644 index 85361b93873..00000000000 --- a/libraries/RainMaker/src/AppInsights.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "sdkconfig.h" -#include -#if defined(CONFIG_ESP_INSIGHTS_ENABLED) && defined(CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK) -#include "Arduino.h" -#include "AppInsights.h" -#include "Insights.h" -#include -#include -#include -#include -#include - -extern "C" { -bool esp_rmaker_mqtt_is_budget_available(); -} - -#define INSIGHTS_TOPIC_SUFFIX "diagnostics/from-node" -#define INSIGHTS_TOPIC_RULE "insights_message_delivery" - -static void _rmakerCommonEventHandler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) { - if (event_base != RMAKER_COMMON_EVENT) { - return; - } - esp_insights_transport_event_data_t data; - switch (event_id) { - case RMAKER_MQTT_EVENT_PUBLISHED: - memset(&data, 0, sizeof(data)); - data.msg_id = *(int *)event_data; - esp_event_post(INSIGHTS_EVENT, INSIGHTS_EVENT_TRANSPORT_SEND_SUCCESS, &data, sizeof(data), portMAX_DELAY); - break; - default: break; - } -} - -static int _appInsightsDataSend(void *data, size_t len) { - char topic[128]; - int msg_id = -1; - if (data == NULL) { - return 0; - } - char *node_id = esp_rmaker_get_node_id(); - if (!node_id) { - return -1; - } - if (esp_rmaker_mqtt_is_budget_available() == false) { - return ESP_FAIL; - } - esp_rmaker_create_mqtt_topic(topic, sizeof(topic), INSIGHTS_TOPIC_SUFFIX, INSIGHTS_TOPIC_RULE); - esp_rmaker_mqtt_publish(topic, data, len, RMAKER_MQTT_QOS1, &msg_id); - return msg_id; -} - -bool initAppInsights(uint32_t log_type, bool alloc_ext_ram) { - char *node_id = esp_rmaker_get_node_id(); - esp_insights_transport_config_t transport; - transport.userdata = NULL; - transport.callbacks.data_send = _appInsightsDataSend; - transport.callbacks.init = NULL; - transport.callbacks.deinit = NULL; - transport.callbacks.connect = NULL; - transport.callbacks.disconnect = NULL; - esp_insights_transport_register(&transport); - esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, _rmakerCommonEventHandler, NULL); - return Insights.begin(NULL, node_id, log_type, alloc_ext_ram, false); -} -#else -bool initAppInsights(uint32_t log_type, bool alloc_ext_ram) { - return false; -} -#endif diff --git a/libraries/RainMaker/src/AppInsights.h b/libraries/RainMaker/src/AppInsights.h deleted file mode 100644 index ddb32f1e266..00000000000 --- a/libraries/RainMaker/src/AppInsights.h +++ /dev/null @@ -1,12 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once -#include "sdkconfig.h" -#include "Arduino.h" -#include - -bool initAppInsights(uint32_t log_type = 0xffffffff, bool alloc_ext_ram = false); diff --git a/libraries/RainMaker/src/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp deleted file mode 100644 index 0f8f276cbb9..00000000000 --- a/libraries/RainMaker/src/RMaker.cpp +++ /dev/null @@ -1,144 +0,0 @@ -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMaker.h" -#include -#include -#include -#include -bool wifiLowLevelInit(bool persistent); -static esp_err_t err; - -extern "C" bool verifyRollbackLater() { - return true; -} - -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: log_i("RainMaker Initialized."); break; - case RMAKER_EVENT_CLAIM_STARTED: log_i("RainMaker Claim Started."); break; - case RMAKER_EVENT_CLAIM_SUCCESSFUL: log_i("RainMaker Claim Successful."); break; - case RMAKER_EVENT_CLAIM_FAILED: log_i("RainMaker Claim Failed."); break; - default: log_i("Unhandled RainMaker Event:"); - } - } else if (event_base == RMAKER_COMMON_EVENT) { - switch (event_id) { - case RMAKER_EVENT_REBOOT: log_i("Rebooting in %d seconds.", *((uint8_t *)event_data)); break; - case RMAKER_EVENT_WIFI_RESET: log_i("Wi-Fi credentials reset."); break; - case RMAKER_EVENT_FACTORY_RESET: log_i("Node reset to factory defaults."); break; - case RMAKER_MQTT_EVENT_CONNECTED: log_i("MQTT Connected."); break; - case RMAKER_MQTT_EVENT_DISCONNECTED: log_i("MQTT Disconnected."); break; - case RMAKER_MQTT_EVENT_PUBLISHED: log_i("MQTT Published. Msg id: %d.", *((int *)event_data)); break; - default: log_w("Unhandled RainMaker Common Event: %" PRIi32, event_id); - } - } else if (event_base == RMAKER_OTA_EVENT) { - if (event_data == NULL) { - event_data = (void *)""; - } - switch (event_id) { - case RMAKER_OTA_EVENT_STARTING: log_i("Starting OTA"); break; - case RMAKER_OTA_EVENT_IN_PROGRESS: log_i("OTA in progress : %s", (char *)event_data); break; - case RMAKER_OTA_EVENT_SUCCESSFUL: log_i("OTA Successful : %s", (char *)event_data); break; - case RMAKER_OTA_EVENT_FAILED: log_i("OTA Failed : %s", (char *)event_data); break; - case RMAKER_OTA_EVENT_DELAYED: log_i("OTA Delayed : %s", (char *)event_data); break; - case RMAKER_OTA_EVENT_REJECTED: log_i("OTA Rejected : %s", (char *)event_data); break; - default: log_i("Unhandled OTA Event"); break; - } - } -} - -void RMakerClass::setTimeSync(bool val) { - rainmaker_cfg.enable_time_sync = val; -} - -Node RMakerClass::initNode(const char *name, const char *type) { - wifiLowLevelInit(true); - Node node; - esp_rmaker_node_t *rnode = NULL; - esp_event_handler_register(RMAKER_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); - esp_event_handler_register(RMAKER_OTA_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); - esp_event_handler_register(RMAKER_COMMON_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL); - rnode = esp_rmaker_node_init(&rainmaker_cfg, name, type); - if (!rnode) { - log_e("Node init failed"); - return node; - } - node.setNodeHandle(rnode); - return node; -} - -esp_err_t RMakerClass::start() { - err = esp_rmaker_start(); - if (err != ESP_OK) { - log_e("ESP RainMaker core task failed"); - } - return err; -} - -esp_err_t RMakerClass::stop() { - err = esp_rmaker_stop(); - if (err != ESP_OK) { - log_e("ESP RainMaker stop error"); - } - return err; -} - -esp_err_t RMakerClass::deinitNode(Node rnode) { - err = esp_rmaker_node_deinit(rnode.getNodeHandle()); - if (err != ESP_OK) { - log_e("Node deinit failed"); - } - return err; -} - -esp_err_t RMakerClass::setTimeZone(const char *tz) { - err = esp_rmaker_time_set_timezone(tz); - if (err != ESP_OK) { - log_e("Setting time zone error"); - } - return err; -} - -esp_err_t RMakerClass::enableSchedule() { - err = esp_rmaker_schedule_enable(); - if (err != ESP_OK) { - log_e("Schedule enable failed"); - } - return err; -} - -esp_err_t RMakerClass::enableTZService() { - err = esp_rmaker_timezone_service_enable(); - if (err != ESP_OK) { - log_e("Timezone service enable failed"); - } - return err; -} - -esp_err_t RMakerClass::enableOTA(ota_type_t type, const char *cert) { - esp_rmaker_ota_config_t ota_config = {.ota_cb = NULL, .ota_diag = NULL, .server_cert = cert, .priv = NULL}; - err = esp_rmaker_ota_enable(&ota_config, type); - if (err != ESP_OK) { - log_e("OTA enable failed"); - } - return err; -} - -esp_err_t RMakerClass::enableScenes() { - err = esp_rmaker_scenes_enable(); - if (err != ESP_OK) { - log_e("Scenes enable failed"); - } - return err; -} - -esp_err_t RMakerClass::enableSystemService(uint16_t flags, int8_t reboot_seconds, int8_t reset_seconds, int8_t reset_reboot_seconds) { - esp_rmaker_system_serv_config_t config = { - .flags = flags, .reboot_seconds = reboot_seconds, .reset_seconds = reset_seconds, .reset_reboot_seconds = reset_reboot_seconds - }; - err = esp_rmaker_system_service_enable(&config); - return err; -} - -RMakerClass RMaker; -#endif diff --git a/libraries/RainMaker/src/RMaker.h b/libraries/RainMaker/src/RMaker.h deleted file mode 100644 index 21c5b0d1832..00000000000 --- a/libraries/RainMaker/src/RMaker.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "esp_system.h" -#include "Arduino.h" -#include "RMakerNode.h" -#include "RMakerQR.h" -#include "RMakerUtils.h" -#include - -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 enableSystemService(uint16_t flags, int8_t reboot_seconds = 2, int8_t reset_seconds = 2, int8_t reset_reboot_seconds = 2); - esp_err_t start(); - esp_err_t stop(); -}; - -extern RMakerClass RMaker; -#endif diff --git a/libraries/RainMaker/src/RMakerDevice.cpp b/libraries/RainMaker/src/RMakerDevice.cpp deleted file mode 100644 index db431ba10c1..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.cpp +++ /dev/null @@ -1,190 +0,0 @@ -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMakerDevice.h" - -static esp_err_t err; -typedef void (*deviceWriteCb)(Device *, Param *, const param_val_t val, void *priv_data, write_ctx_t *ctx); -typedef void (*deviceReadCb)(Device *, Param *, void *priv_data, read_ctx_t *ctx); -typedef struct { - void *priv_data; - deviceWriteCb write_cb; - deviceReadCb read_cb; -} RMakerDevicePrivT; - -static esp_err_t write_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, const param_val_t val, void *priv_data, write_ctx_t *ctx) { - Device device; - Param param; - device.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - deviceWriteCb cb = ((RMakerDevicePrivT *)priv_data)->write_cb; - cb(&device, ¶m, val, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx); - return ESP_OK; -} - -static esp_err_t read_callback(const device_handle_t *dev_handle, const param_handle_t *par_handle, void *priv_data, read_ctx_t *ctx) { - Device device; - Param param; - device.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - deviceReadCb cb = ((RMakerDevicePrivT *)priv_data)->read_cb; - cb(&device, ¶m, ((RMakerDevicePrivT *)priv_data)->priv_data, ctx); - return ESP_OK; -} - -esp_err_t Device::deleteDevice() { - err = esp_rmaker_device_delete(getDeviceHandle()); - if (err != ESP_OK) { - log_e("Failed to delete device"); - return err; - } - return ESP_OK; -} - -void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb) { - this->private_data.write_cb = writeCb; - this->private_data.read_cb = readCb; - err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback); - if (err != ESP_OK) { - log_e("Failed to register callback"); - } -} - -esp_err_t Device::addDeviceAttr(const char *attr_name, const char *val) { - err = esp_rmaker_device_add_attribute(getDeviceHandle(), attr_name, val); - if (err != ESP_OK) { - log_e("Failed to add attribute to the device"); - return err; - } - return ESP_OK; -} - -//Generic Parameter -esp_err_t Device::addParam(Param parameter) { - err = esp_rmaker_device_add_param(getDeviceHandle(), parameter.getParamHandle()); - if (err != ESP_OK) { - log_e("Failed to add custom parameter"); - return err; - } - return ESP_OK; -} - -//Standard Device Parameter -esp_err_t Device::addNameParam(const char *param_name) { - param_handle_t *param = esp_rmaker_name_param_create(param_name, getDeviceName()); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addPowerParam(bool val, const char *param_name) { - param_handle_t *param = esp_rmaker_power_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addBrightnessParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_brightness_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addHueParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_hue_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addSaturationParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_saturation_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addIntensityParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_intensity_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addCCTParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_cct_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addDirectionParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_direction_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addSpeedParam(int val, const char *param_name) { - param_handle_t *param = esp_rmaker_speed_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -esp_err_t Device::addTemperatureParam(float val, const char *param_name) { - param_handle_t *param = esp_rmaker_temperature_param_create(param_name, val); - return esp_rmaker_device_add_param(getDeviceHandle(), param); -} - -param_handle_t *Device::getParamByName(const char *param_name) { - return esp_rmaker_device_get_param_by_name(getDeviceHandle(), param_name); -} - -esp_err_t Device::assignPrimaryParam(param_handle_t *param) { - err = esp_rmaker_device_assign_primary_param(getDeviceHandle(), param); - if (err != ESP_OK) { - log_e("Failed to assign primary parameter"); - } - return err; -} - -const param_handle_t *getParamHandlebyName(const esp_rmaker_device_t *device_handle, const char *param_name) { - const param_handle_t *param = esp_rmaker_device_get_param_by_name(device_handle, param_name); - return param; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, bool my_val) { - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_bool(my_val); - err = esp_rmaker_param_update_and_report(param, val); - if (err != ESP_OK) { - log_e("Update parameter failed"); - return err; - } else { - log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val ? "true" : "false"); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, int my_val) { - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_int(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if (err != ESP_OK) { - log_e("Update parameter failed"); - return err; - } else { - log_i("Device : %s, Param Name : %s, Val : %d", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, float my_val) { - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_float(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if (err != ESP_OK) { - log_e("Update parameter failed"); - return err; - } else { - log_i("Device : %s, Param Name : %s, Val : %f", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} - -esp_err_t Device::updateAndReportParam(const char *param_name, const char *my_val) { - const param_handle_t *param = getParamHandlebyName(getDeviceHandle(), param_name); - param_val_t val = esp_rmaker_str(my_val); - esp_err_t err = esp_rmaker_param_update_and_report(param, val); - if (err != ESP_OK) { - log_e("Update parameter failed"); - return err; - } else { - log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val); - } - return ESP_OK; -} -#endif diff --git a/libraries/RainMaker/src/RMakerDevice.h b/libraries/RainMaker/src/RMakerDevice.h deleted file mode 100644 index 29f9f1950e6..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.h +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "esp_system.h" -#include "RMakerParam.h" -#include -#include - -class Device { -public: - typedef void (*deviceWriteCb)(Device *, Param *, const param_val_t val, void *priv_data, write_ctx_t *ctx); - typedef void (*deviceReadCb)(Device *, Param *, void *priv_data, read_ctx_t *ctx); - typedef struct { - void *priv_data; - deviceWriteCb write_cb; - deviceReadCb read_cb; - } RMakerDevicePrivT; - -private: - const device_handle_t *device_handle; - RMakerDevicePrivT private_data; - -protected: - void setPrivateData(void *priv_data) { - this->private_data.priv_data = priv_data; - } - - const RMakerDevicePrivT *getDevicePrivateData() { - return &this->private_data; - } - -public: - Device() { - device_handle = NULL; - this->private_data.priv_data = NULL; - this->private_data.write_cb = NULL; - this->private_data.read_cb = NULL; - } - - Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL) { - this->private_data.priv_data = priv_data; - this->private_data.write_cb = NULL; - this->private_data.read_cb = NULL; - device_handle = esp_rmaker_device_create(dev_name, dev_type, &this->private_data); - if (device_handle == NULL) { - log_e("Device create error"); - } - } - void setDeviceHandle(const esp_rmaker_device_t *device_handle) { - this->device_handle = device_handle; - } - const char *getDeviceName() { - return esp_rmaker_device_get_name(device_handle); - } - const esp_rmaker_device_t *getDeviceHandle() { - return device_handle; - } - - esp_err_t deleteDevice(); - void addCb(deviceWriteCb write_cb, deviceReadCb read_cb = NULL); - esp_err_t addDeviceAttr(const char *attr_name, const char *val); - param_handle_t *getParamByName(const char *param_name); - esp_err_t assignPrimaryParam(param_handle_t *param); - - //Generic Device Parameter - esp_err_t addParam(Param parameter); - - //Standard Device Parameter - esp_err_t addNameParam(const char *param_name = ESP_RMAKER_DEF_NAME_PARAM); - esp_err_t addPowerParam(bool val, const char *param_name = ESP_RMAKER_DEF_POWER_NAME); - esp_err_t addBrightnessParam(int val, const char *param_name = ESP_RMAKER_DEF_BRIGHTNESS_NAME); - esp_err_t addHueParam(int val, const char *param_name = ESP_RMAKER_DEF_HUE_NAME); - esp_err_t addSaturationParam(int val, const char *param_name = ESP_RMAKER_DEF_SATURATION_NAME); - esp_err_t addIntensityParam(int val, const char *param_name = ESP_RMAKER_DEF_INTENSITY_NAME); - esp_err_t addCCTParam(int val, const char *param_name = ESP_RMAKER_DEF_CCT_NAME); - esp_err_t addDirectionParam(int val, const char *param_name = ESP_RMAKER_DEF_DIRECTION_NAME); - esp_err_t addSpeedParam(int val, const char *param_name = ESP_RMAKER_DEF_SPEED_NAME); - esp_err_t addTemperatureParam(float val, const char *param_name = ESP_RMAKER_DEF_TEMPERATURE_NAME); - - //Update Parameter - esp_err_t updateAndReportParam(const char *param_name, bool val); - esp_err_t updateAndReportParam(const char *param_name, int val); - esp_err_t updateAndReportParam(const char *param_name, float val); - esp_err_t updateAndReportParam(const char *param_name, const char *val); -}; - -class Switch : public Device { -public: - Switch() { - standardSwitchDevice("Switch", NULL, true); - } - Switch(const char *dev_name, void *priv_data = NULL, bool power = true) { - standardSwitchDevice(dev_name, priv_data, power); - } - void standardSwitchDevice(const char *dev_name, void *priv_data, bool power) { - this->setPrivateData(priv_data); - esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, (void *)this->getDevicePrivateData(), power); - setDeviceHandle(dev_handle); - if (dev_handle == NULL) { - log_e("Switch device not created"); - } - } -}; - -class LightBulb : public Device { -public: - LightBulb() { - standardLightBulbDevice("Light", NULL, true); - } - LightBulb(const char *dev_name, void *priv_data = NULL, bool power = true) { - standardLightBulbDevice(dev_name, priv_data, power); - } - void standardLightBulbDevice(const char *dev_name, void *priv_data, bool power) { - this->setPrivateData(priv_data); - esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, (void *)this->getDevicePrivateData(), power); - setDeviceHandle(dev_handle); - if (dev_handle == NULL) { - log_e("Light device not created"); - } - } -}; - -class Fan : public Device { -public: - Fan() { - standardFanDevice("Fan", NULL, true); - } - Fan(const char *dev_name, void *priv_data = NULL, bool power = true) { - standardFanDevice(dev_name, priv_data, power); - } - void standardFanDevice(const char *dev_name, void *priv_data, bool power) { - esp_rmaker_device_t *dev_handle = esp_rmaker_fan_device_create(dev_name, priv_data, power); - setDeviceHandle(dev_handle); - if (dev_handle == NULL) { - log_e("Fan device not created"); - } - } -}; - -class TemperatureSensor : public Device { -public: - TemperatureSensor() { - standardTemperatureSensorDevice("Temperature-Sensor", NULL, 25.0); - } - TemperatureSensor(const char *dev_name, void *priv_data = NULL, float temp = 25.0) { - standardTemperatureSensorDevice(dev_name, priv_data, temp); - } - void standardTemperatureSensorDevice(const char *dev_name, void *priv_data, float temp) { - this->setPrivateData(priv_data); - esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, (void *)this->getDevicePrivateData(), temp); - setDeviceHandle(dev_handle); - if (dev_handle == NULL) { - log_e("Temperature Sensor device not created"); - } - } -}; -#endif diff --git a/libraries/RainMaker/src/RMakerNode.cpp b/libraries/RainMaker/src/RMakerNode.cpp deleted file mode 100644 index 9c237fa5999..00000000000 --- a/libraries/RainMaker/src/RMakerNode.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMakerNode.h" -static esp_err_t err; - -esp_err_t Node::addDevice(Device device) { - err = esp_rmaker_node_add_device(node, device.getDeviceHandle()); - if (err != ESP_OK) { - log_e("Device was not added to the Node"); - } - return err; -} - -esp_err_t Node::removeDevice(Device device) { - err = esp_rmaker_node_remove_device(node, device.getDeviceHandle()); - if (err != ESP_OK) { - log_e("Device was not removed from the Node"); - } - return err; -} - -char *Node::getNodeID() { - return esp_rmaker_get_node_id(); -} - -node_info_t *Node::getNodeInfo() { - return esp_rmaker_node_get_info(node); -} - -esp_err_t Node::addNodeAttr(const char *attr_name, const char *val) { - err = esp_rmaker_node_add_attribute(node, attr_name, val); - if (err != ESP_OK) { - log_e("Failed to add attribute to the Node"); - } - return err; -} -#endif diff --git a/libraries/RainMaker/src/RMakerNode.h b/libraries/RainMaker/src/RMakerNode.h deleted file mode 100644 index a2236a6f7c4..00000000000 --- a/libraries/RainMaker/src/RMakerNode.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "esp_system.h" -#include "RMakerDevice.h" - -class Node { -private: - esp_rmaker_node_t *node; - -public: - Node() { - node = NULL; - } - void setNodeHandle(esp_rmaker_node_t *rnode) { - node = rnode; - } - esp_rmaker_node_t *getNodeHandle() { - return node; - } - - esp_err_t addDevice(Device device); - esp_err_t removeDevice(Device device); - - char *getNodeID(); - node_info_t *getNodeInfo(); - esp_err_t addNodeAttr(const char *attr_name, const char *val); -}; -#endif diff --git a/libraries/RainMaker/src/RMakerParam.cpp b/libraries/RainMaker/src/RMakerParam.cpp deleted file mode 100644 index 1b30a77782e..00000000000 --- a/libraries/RainMaker/src/RMakerParam.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMakerParam.h" - -static esp_err_t err; - -esp_err_t Param::addUIType(const char *ui_type) { - err = esp_rmaker_param_add_ui_type(param_handle, ui_type); - if (err != ESP_OK) { - log_e("Add UI type error"); - } - return err; -} - -esp_err_t Param::addBounds(param_val_t min, param_val_t max, param_val_t step) { - err = esp_rmaker_param_add_bounds(param_handle, min, max, step); - if (err != ESP_OK) { - log_e("Add Bounds error"); - } - return err; -} - -esp_err_t Param::updateAndReport(param_val_t val) { - err = esp_rmaker_param_update_and_report(getParamHandle(), val); - if (err != ESP_OK) { - log_e("Update and Report param failed"); - } - return err; -} - -esp_err_t Param::addValidStrList(const char **string_list, uint8_t count) { - esp_err_t err = esp_rmaker_param_add_valid_str_list(getParamHandle(), string_list, count); - if (err != ESP_OK) { - log_e("Add valid string list error"); - } - return err; -} -#endif diff --git a/libraries/RainMaker/src/RMakerParam.h b/libraries/RainMaker/src/RMakerParam.h deleted file mode 100644 index 55bb03cb6ec..00000000000 --- a/libraries/RainMaker/src/RMakerParam.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "esp_system.h" -#include "RMakerType.h" - -class Param { -private: - const param_handle_t *param_handle; - -public: - Param() { - param_handle = NULL; - } - Param(const char *param_name, const char *param_type, param_val_t val, uint8_t properties) { - param_handle = esp_rmaker_param_create(param_name, param_type, val, properties); - } - void setParamHandle(const param_handle_t *param_handle) { - this->param_handle = param_handle; - } - const char *getParamName() { - return esp_rmaker_param_get_name(param_handle); - } - const param_handle_t *getParamHandle() { - return param_handle; - } - - esp_err_t addUIType(const char *ui_type); - esp_err_t addBounds(param_val_t min, param_val_t max, param_val_t step); - esp_err_t updateAndReport(param_val_t val); - esp_err_t addValidStrList(const char **string_list, uint8_t count); -}; -#endif diff --git a/libraries/RainMaker/src/RMakerQR.cpp b/libraries/RainMaker/src/RMakerQR.cpp deleted file mode 100644 index 1b6b010dd4b..00000000000 --- a/libraries/RainMaker/src/RMakerQR.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include "RMakerQR.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -void printQR(const char *name, const char *pop, const char *transport) { - if (!name || !pop || !transport) { - log_w("Cannot generate QR code payload. Data missing."); - return; - } - char payload[150] = {0}; - snprintf( - payload, sizeof(payload), - "{\"ver\":\"%s\",\"name\":\"%s\"" - ",\"pop\":\"%s\",\"transport\":\"%s\"}", - PROV_QR_VERSION, name, pop, transport - ); - if (Serial) { - Serial.printf("Scan this QR code from the ESP RainMaker phone app.\n"); - } - //qrcode_display(payload); // deprecated! - esp_qrcode_config_t cfg = ESP_QRCODE_CONFIG_DEFAULT(); - esp_qrcode_generate(&cfg, payload); - if (Serial) { - Serial.printf("If QR code is not visible, copy paste the below URL in a browser.\n%s?data=%s\n", QRCODE_BASE_URL, payload); - } -} -#endif diff --git a/libraries/RainMaker/src/RMakerQR.h b/libraries/RainMaker/src/RMakerQR.h deleted file mode 100644 index a2e12e410d2..00000000000 --- a/libraries/RainMaker/src/RMakerQR.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMaker.h" -#include "esp_system.h" -#include - -#define PROV_QR_VERSION "v1" -#define QRCODE_BASE_URL "https://rainmaker.espressif.com/qrcode.html" - -void printQR(const char *name, const char *pop, const char *transport); -#endif diff --git a/libraries/RainMaker/src/RMakerType.cpp b/libraries/RainMaker/src/RMakerType.cpp deleted file mode 100644 index a2846fc782a..00000000000 --- a/libraries/RainMaker/src/RMakerType.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMakerType.h" - -param_val_t value(int ival) { - return esp_rmaker_int(ival); -} - -param_val_t value(bool bval) { - return esp_rmaker_bool(bval); -} - -param_val_t value(char *sval) { - return esp_rmaker_str(sval); -} - -param_val_t value(float fval) { - return esp_rmaker_float(fval); -} - -param_val_t value(const char *sval) { - return esp_rmaker_str(sval); -} -#endif diff --git a/libraries/RainMaker/src/RMakerType.h b/libraries/RainMaker/src/RMakerType.h deleted file mode 100644 index daf9b193881..00000000000 --- a/libraries/RainMaker/src/RMakerType.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "esp_system.h" -#include -#include -#include -#include - -typedef esp_rmaker_node_t *node_t; -typedef esp_rmaker_node_info_t node_info_t; -typedef esp_rmaker_param_val_t param_val_t; -typedef esp_rmaker_write_ctx_t write_ctx_t; -typedef esp_rmaker_read_ctx_t read_ctx_t; -typedef esp_rmaker_device_t device_handle_t; -typedef esp_rmaker_param_t param_handle_t; -typedef esp_rmaker_ota_type_t ota_type_t; - -param_val_t value(int); -param_val_t value(bool); -param_val_t value(char *); -param_val_t value(float); -param_val_t value(const char *); -#endif diff --git a/libraries/RainMaker/src/RMakerUtils.cpp b/libraries/RainMaker/src/RMakerUtils.cpp deleted file mode 100644 index 7027686fb14..00000000000 --- a/libraries/RainMaker/src/RMakerUtils.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "RMakerUtils.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#define RESET_DELAY_SEC 2 -void RMakerFactoryReset(int reboot_seconds) { - esp_rmaker_factory_reset(RESET_DELAY_SEC, reboot_seconds); -} - -void RMakerWiFiReset(int reboot_seconds) { - esp_rmaker_wifi_reset(RESET_DELAY_SEC, reboot_seconds); -} -#endif diff --git a/libraries/RainMaker/src/RMakerUtils.h b/libraries/RainMaker/src/RMakerUtils.h deleted file mode 100644 index 5896a825b9f..00000000000 --- a/libraries/RainMaker/src/RMakerUtils.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMaker.h" -#include "esp_system.h" -#include - -void RMakerFactoryReset(int seconds); -void RMakerWiFiReset(int seconds); -#endif