diff --git a/.github/scripts/install-arduino-core-esp32.sh b/.github/scripts/install-arduino-core-esp32.sh index 8584da5b6e2..cc685711e15 100755 --- a/.github/scripts/install-arduino-core-esp32.sh +++ b/.github/scripts/install-arduino-core-esp32.sh @@ -20,7 +20,7 @@ if [ ! -d "$ARDUINO_ESP32_PATH" ]; then ln -s $GITHUB_WORKSPACE esp32 else echo "Cloning Core Repository..." - git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1 + git clone https://github.com/tasmota/arduino-esp32.git esp32 > /dev/null 2>&1 fi #echo "Updating Submodules ..." diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b0300fc743..e5819d55a25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,11 +90,6 @@ set(LIBRARY_SRCS libraries/I2S/src/I2S.cpp libraries/NetBIOS/src/NetBIOS.cpp libraries/Preferences/src/Preferences.cpp - 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/SD_MMC/src/SD_MMC.cpp libraries/SD/src/SD.cpp libraries/SD/src/sd_diskio.cpp @@ -184,7 +179,6 @@ set(includedirs libraries/I2S/src libraries/NetBIOS/src libraries/Preferences/src - libraries/RainMaker/src libraries/SD_MMC/src libraries/SD/src libraries/SimpleBLE/src @@ -239,10 +233,6 @@ endfunction() maybe_add_component(esp-dsp) -if(CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK) - maybe_add_component(esp_rainmaker) - maybe_add_component(qrcode) -endif() if(IDF_TARGET MATCHES "esp32s2|esp32s3" AND CONFIG_TINYUSB_ENABLED) maybe_add_component(arduino_tinyusb) endif() diff --git a/cores/esp32/Esp.cpp b/cores/esp32/Esp.cpp index 6cca85ac64c..7dd9a929f4e 100644 --- a/cores/esp32/Esp.cpp +++ b/cores/esp32/Esp.cpp @@ -47,7 +47,7 @@ extern "C" { #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/rom/spi_flash.h" #define ESP_FLASH_IMAGE_BASE 0x0000 // Esp32c3 is located at 0x0000 -#else +#else #error Target CONFIG_IDF_TARGET is not supported #endif #else // ESP32 Before IDF 4.0 @@ -192,7 +192,7 @@ static uint32_t sketchSize(sketchSize_t response) { return data.image_len; } } - + uint32_t EspClass::getSketchSize () { return sketchSize(SKETCH_SIZE_TOTAL); } @@ -231,6 +231,10 @@ String EspClass::getSketchMD5() md5.add(buf.get(), readBytes); lengthLeft -= readBytes; offset += readBytes; + + #if CONFIG_FREERTOS_UNICORE + delay(1); // Fix solo WDT + #endif } md5.calculate(); result = md5.toString(); @@ -391,17 +395,17 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) return spi_flash_read(offset, (uint32_t*) data, size) == ESP_OK; } -bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size) +bool EspClass::partitionEraseRange(const esp_partition_t *partition, uint32_t offset, size_t size) { return esp_partition_erase_range(partition, offset, size) == ESP_OK; } -bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) +bool EspClass::partitionWrite(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) { return esp_partition_write(partition, offset, data, size) == ESP_OK; } -bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) +bool EspClass::partitionRead(const esp_partition_t *partition, uint32_t offset, uint32_t *data, size_t size) { return esp_partition_read(partition, offset, data, size) == ESP_OK; } diff --git a/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino b/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino index de28da6c85d..cd961aad52a 100644 --- a/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino +++ b/libraries/ESP32/examples/RMT/RMTCallback/RMTCallback.ino @@ -64,4 +64,4 @@ void loop() { Serial.printf("GPIO 4: %08x 5: %08x 10: %08x\n", mp1.val(), mp2.val(), mp3.val()); delay(500); -} \ No newline at end of file +} diff --git a/libraries/README.md b/libraries/README.md index 5edeebba424..23a4d376e18 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -69,9 +69,6 @@ arduino-esp32 includes libraries for Arduino compatibility along with some objec ### Preferences Flash keystore using ESP32 NVS -### ESP RainMaker - End-to-end platform by Espressif that enables Makers to realize their IoT ideas faster - ### SD Secure Digital card filesystem using SPI access diff --git a/libraries/RainMaker/README.md b/libraries/RainMaker/README.md deleted file mode 100644 index 03f5e4c520a..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, wifi 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 initialisation. -``` -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 addTempratureParam(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); -``` -* **Paramter** -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 paramter 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 posession 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 6c5bded09ac..00000000000 --- a/libraries/RainMaker/examples/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# ESP RainMaker Examples - -While building any examples for ESP RainMaker, take care of the following: -1. Change partition scheme in Arduino IDE to RainMaker (Tools -> Partition Scheme -> RainMaker). -2. Once ESP RainMaker gets started, compulsorily call `WiFi.beginProvision()` which is responsible for user-node mapping. -3. Use appropriate provisioning scheme as per the board. - - ESP32 Board: BLE Provisioning - - ESP32S2 Board: SoftAP Provisioning -4. Set debug level to Info (Tools -> Core Debug Level -> Info). This is recommended, but not mandatory. - diff --git a/libraries/RainMaker/examples/RMakerCustom/README.md b/libraries/RainMaker/examples/RMakerCustom/README.md deleted file mode 100644 index 42c998d49c4..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 Initialised. -[ 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 55012e413c6..00000000000 --- a/libraries/RainMaker/examples/RMakerCustom/RMakerCustom.ino +++ /dev/null @@ -1,126 +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 -static int gpio_0 = 0; -//GPIO for virtual device -static int gpio_dimmer = 16; -/* Variable for reading pin status*/ -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("Dimmer", "custom.device.dimmer", &gpio_dimmer); - -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); - printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); -#endif - break; - } -} - -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"); - - //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_PARAMS); - //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.start(); - - WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_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"); - 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/RMakerSonoffDualR3/RMakerSonoffDualR3.ino b/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino deleted file mode 100644 index 37eda40134b..00000000000 --- a/libraries/RainMaker/examples/RMakerSonoffDualR3/RMakerSonoffDualR3.ino +++ /dev/null @@ -1,193 +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("Switch_ch1", &gpio_relay1); -static Switch my_switch2("Switch_ch2", &gpio_relay2); - -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); - printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - 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; - } -} - -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"); - - //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_PARAMS); - //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(); - - //Service Name - for(int i=0; i<17; i=i+8) { - chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i; - } - - Serial.printf("\nChip ID: %d Service Name: %s\n", chipId, service_name); - - Serial.printf("\nStarting ESP-RainMaker\n"); - RMaker.start(); - - WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_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"); - 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"); - 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/RMakerSwitch/README.md b/libraries/RainMaker/examples/RMakerSwitch/README.md deleted file mode 100644 index 55b5ab1ed41..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 Initialised. -[ 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 e486bd200fb..00000000000 --- a/libraries/RainMaker/examples/RMakerSwitch/RMakerSwitch.ino +++ /dev/null @@ -1,111 +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 true -const char *service_name = "PROV_1234"; -const char *pop = "abcd1234"; - -//GPIO for push button -static int gpio_0 = 0; -//GPIO for virtual device -static int gpio_switch = 16; -/* 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("Switch", &gpio_switch); - -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); - printQR(service_name, pop, "ble"); -#else - Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop); - printQR(service_name, pop, "softap"); -#endif - break; - } -} - -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"); - - //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_PARAMS); - //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.start(); - - WiFi.onEvent(sysProvEvent); -#if CONFIG_IDF_TARGET_ESP32 - WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name); -#else - WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_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"); - 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/library.properties b/libraries/RainMaker/library.properties deleted file mode 100644 index b144328fef2..00000000000 --- a/libraries/RainMaker/library.properties +++ /dev/null @@ -1,8 +0,0 @@ -name=ESP RainMaker -version=2.0.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/RMaker.cpp b/libraries/RainMaker/src/RMaker.cpp deleted file mode 100644 index 2fda954c1ea..00000000000 --- a/libraries/RainMaker/src/RMaker.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include "sdkconfig.h" -#ifdef CONFIG_ESP_RMAKER_WORK_QUEUE_TASK_STACK -#include "RMaker.h" -#include -#include -bool wifiLowLevelInit(bool persistent); -static esp_err_t err; - -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 Initialised."); - 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:"); - } - } -} - -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); - 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_config.server_cert = cert; - err = esp_rmaker_ota_enable(&ota_config, type); - if(err != ESP_OK) { - log_e("OTA enable failed"); - } - return err; -} - -RMakerClass RMaker; -#endif diff --git a/libraries/RainMaker/src/RMaker.h b/libraries/RainMaker/src/RMaker.h deleted file mode 100644 index dbfbe5c49f5..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 start(); - esp_err_t stop(); -}; - -extern RMakerClass RMaker; -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerDevice.cpp b/libraries/RainMaker/src/RMakerDevice.cpp deleted file mode 100644 index dd1a3ba4ea4..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.cpp +++ /dev/null @@ -1,209 +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); - -void (*write_cb)(Device*, Param*, param_val_t, void*, write_ctx_t*); -void (*read_cb)(Device*, Param*, void*, read_ctx_t*); -Device device; -Param param; - -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.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - - write_cb(&device, ¶m, val, 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.setDeviceHandle(dev_handle); - param.setParamHandle(par_handle); - - read_cb(&device, ¶m, priv_data, ctx); - return ESP_OK; -} - -esp_err_t Device::deleteDevice() -{ - err = esp_rmaker_device_delete(getDeviceHandle()); - if(err != ESP_OK) { - log_e("Device deletion error"); - return err; - } - return ESP_OK; -} - -void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb) -{ - write_cb = writeCb; - read_cb = readCb; - err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback); - if(err != ESP_OK) { - log_e("Callback register error"); - } -} - -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 attriute 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("Adding custom parameter error"); - 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::addTempratureParam(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("Assigning primary param error"); - } - 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 paramter 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 paramter 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 paramter 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 paramter 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 f813359a25a..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.h +++ /dev/null @@ -1,167 +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 -{ - private: - const device_handle_t *device_handle; - - public: - Device() - { - device_handle = NULL; - } - Device(const char *dev_name, const char *dev_type = NULL, void *priv_data = NULL) - { - device_handle = esp_rmaker_device_create(dev_name, dev_type, priv_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; - } - - 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); - - 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 addTempratureParam(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) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_switch_device_create(dev_name, priv_data, 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) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_lightbulb_device_create(dev_name, priv_data, 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) - { - esp_rmaker_device_t *dev_handle = esp_rmaker_temp_sensor_device_create(dev_name, priv_data, temp); - setDeviceHandle(dev_handle); - if(dev_handle == NULL){ - log_e("Temperature Sensor device not created"); - } - } -}; -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerNode.cpp b/libraries/RainMaker/src/RMakerNode.cpp deleted file mode 100644 index 5cae9e8dea9..00000000000 --- a/libraries/RainMaker/src/RMakerNode.cpp +++ /dev/null @@ -1,42 +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 \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerNode.h b/libraries/RainMaker/src/RMakerNode.h deleted file mode 100644 index d169870f591..00000000000 --- a/libraries/RainMaker/src/RMakerNode.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 "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 \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerParam.cpp b/libraries/RainMaker/src/RMakerParam.cpp deleted file mode 100644 index 50a994c7590..00000000000 --- a/libraries/RainMaker/src/RMakerParam.cpp +++ /dev/null @@ -1,33 +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; -} -#endif diff --git a/libraries/RainMaker/src/RMakerParam.h b/libraries/RainMaker/src/RMakerParam.h deleted file mode 100644 index d1b4ea6d9d6..00000000000 --- a/libraries/RainMaker/src/RMakerParam.h +++ /dev/null @@ -1,51 +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); -}; -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerQR.h b/libraries/RainMaker/src/RMakerQR.h deleted file mode 100644 index 7b666557fcd..00000000000 --- a/libraries/RainMaker/src/RMakerQR.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 - -#define PROV_QR_VERSION "v1" -#define QRCODE_BASE_URL "https://rainmaker.espressif.com/qrcode.html" - -static 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]; - snprintf(payload, sizeof(payload), "{\"ver\":\"%s\",\"name\":\"%s\"" \ - ",\"pop\":\"%s\",\"transport\":\"%s\"}", - PROV_QR_VERSION, name, pop, transport); - Serial.printf("Scan this QR code from the ESP RainMaker phone app.\n"); - qrcode_display(payload); - 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 \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerType.cpp b/libraries/RainMaker/src/RMakerType.cpp deleted file mode 100644 index d94337cec4c..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); -} -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerType.h b/libraries/RainMaker/src/RMakerType.h deleted file mode 100644 index 003bd32a523..00000000000 --- a/libraries/RainMaker/src/RMakerType.h +++ /dev/null @@ -1,36 +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); -#endif \ No newline at end of file diff --git a/libraries/RainMaker/src/RMakerUtils.h b/libraries/RainMaker/src/RMakerUtils.h deleted file mode 100644 index 710b0e9a8a4..00000000000 --- a/libraries/RainMaker/src/RMakerUtils.h +++ /dev/null @@ -1,29 +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 - -static void RMakerFactoryReset(int seconds) -{ - esp_rmaker_factory_reset(0, seconds); -} - -static void RMakerWiFiReset(int seconds) -{ - esp_rmaker_wifi_reset(0, seconds); -} -#endif \ No newline at end of file diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index f9ecbfb057f..2b40185e7ae 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -352,7 +352,7 @@ size_t UpdateClass::writeStream(Stream &data) { bytesToRead = remaining(); } - /* + /* Init read&timeout counters and try to read, if read failed, increase counter, wait 100ms and try to read again. If counter > 300 (30 sec), give up/abort */ @@ -377,6 +377,8 @@ size_t UpdateClass::writeStream(Stream &data) { if((_bufferLen == remaining() || _bufferLen == SPI_FLASH_SEC_SIZE) && !_writeBuffer()) return written; written += toRead; + + delay(1); // Fix solo WDT } return written; } diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_console.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_console.h deleted file mode 100644 index 70c02ffeae0..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_console.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 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 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** Initialize console - * - * Initializes serial console and adds basic commands. - * - * @return ESP_OK on success. - * @return error in case of failures. - */ -esp_err_t esp_rmaker_console_init(void); - -/* Reference for adding custom console commands: -#include - -static int command_console_handler(int argc, char *argv[]) -{ - // Command code here -} - -static void register_console_command() -{ - const esp_console_cmd_t cmd = { - .command = "", - .help = "", - .func = &command_console_handler, - }; - ESP_ERROR_CHECK(esp_console_cmd_register(&cmd)); -} -*/ - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h deleted file mode 100644 index f9d96be4ee6..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_core.h +++ /dev/null @@ -1,893 +0,0 @@ -// Copyright 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 -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -#define ESP_RMAKER_CONFIG_VERSION "2020-03-20" - -/* Maximum length of the alert message that can be passed to esp_rmaker_raise_alert() */ -#define ESP_RMAKER_MAX_ALERT_LEN 100 - -/** @cond **/ -/** ESP RainMaker Event Base */ -ESP_EVENT_DECLARE_BASE(RMAKER_EVENT); -/** @endcond **/ - -/** ESP RainMaker Events */ -typedef enum { - /** RainMaker Core Initialisation Done */ - RMAKER_EVENT_INIT_DONE = 1, - /** Self Claiming Started */ - RMAKER_EVENT_CLAIM_STARTED, - /** Self Claiming was Successful */ - RMAKER_EVENT_CLAIM_SUCCESSFUL, - /** Self Claiming Failed */ - RMAKER_EVENT_CLAIM_FAILED, - /** Node side communication for User-Node mapping done. - * Actual mapping state will be managed by the ESP RainMaker cloud based on the user side communication. - * Associated data is the NULL terminated user id. - */ - RMAKER_EVENT_USER_NODE_MAPPING_DONE, - /** Local control started. Associated data is the NULL terminated Service Name */ - RMAKER_EVENT_LOCAL_CTRL_STARTED, - /* User reset request successfully sent to ESP RainMaker Cloud */ - RMAKER_EVENT_USER_NODE_MAPPING_RESET, -} esp_rmaker_event_t; - -/** ESP RainMaker Node information */ -typedef struct { - /** Name of the Node */ - char *name; - /** Type of the Node */ - char *type; - /** Firmware Version (Optional). If not set, PROJECT_VER is used as default (recommended)*/ - char *fw_version; - /** Model (Optional). If not set, PROJECT_NAME is used as default (recommended)*/ - char *model; -} esp_rmaker_node_info_t; - -/** ESP RainMaker Configuration */ -typedef struct { - /** Enable Time Sync - * Setting this true will enable SNTP and fetch the current time before - * attempting to connect to the ESP RainMaker service - */ - bool enable_time_sync; -} esp_rmaker_config_t; - -/** ESP RainMaker Parameter Value type */ -typedef enum { - /** Invalid */ - RMAKER_VAL_TYPE_INVALID = 0, - /** Boolean */ - RMAKER_VAL_TYPE_BOOLEAN, - /** Integer. Mapped to a 32 bit signed integer */ - RMAKER_VAL_TYPE_INTEGER, - /** Floating point number */ - RMAKER_VAL_TYPE_FLOAT, - /** NULL terminated string */ - RMAKER_VAL_TYPE_STRING, - /** NULL terminated JSON Object string Eg. {"name":"value"} */ - RMAKER_VAL_TYPE_OBJECT, - /** NULL terminated JSON Array string Eg. [1,2,3] */ - RMAKER_VAL_TYPE_ARRAY, -} esp_rmaker_val_type_t; - -/** ESP RainMaker Value */ -typedef union { - /** Boolean */ - bool b; - /** Integer */ - int i; - /** Float */ - float f; - /** NULL terminated string */ - char *s; -} esp_rmaker_val_t; - -/** ESP RainMaker Parameter Value */ -typedef struct { - /** Type of Value */ - esp_rmaker_val_type_t type; - /** Actual value. Depends on the type */ - esp_rmaker_val_t val; -} esp_rmaker_param_val_t; - -/** Param property flags */ -typedef enum { - PROP_FLAG_WRITE = (1 << 0), - PROP_FLAG_READ = (1 << 1), - PROP_FLAG_TIME_SERIES = (1 << 2), - PROP_FLAG_PERSIST = (1 << 3) -} esp_param_property_flags_t; - -/** System Service Reboot Flag */ -#define SYSTEM_SERV_FLAG_REBOOT (1 << 0) - -/** System Service Factory Reset Flag */ -#define SYSTEM_SERV_FLAG_FACTORY_RESET (1 << 1) - -/** System Service Wi-Fi Reset Flag */ -#define SYSTEM_SERV_FLAG_WIFI_RESET (1 << 2) - -/** System Service All Flags */ -#define SYSTEM_SERV_FLAGS_ALL (SYSTEM_SERV_FLAG_REBOOT | SYSTEM_SERV_FLAG_FACTORY_RESET | SYSTEM_SERV_FLAG_WIFI_RESET) - -/** Generic ESP RainMaker handle */ -typedef size_t esp_rmaker_handle_t; - -/** ESP RainMaker Node Handle */ -typedef esp_rmaker_handle_t esp_rmaker_node_t; - -/** ESP RainMaker Device Handle */ -typedef esp_rmaker_handle_t esp_rmaker_device_t; - -/** ESP RainMaker Parameter Handle */ -typedef esp_rmaker_handle_t esp_rmaker_param_t; - -/** Parameter read/write request source */ -typedef enum { - /** Request triggered in the init sequence i.e. when a value is found - * in persistent memory for parameters with PROP_FLAG_PERSIST. - */ - ESP_RMAKER_REQ_SRC_INIT, - /** Request received from cloud */ - ESP_RMAKER_REQ_SRC_CLOUD, - /** Request received when a schedule has triggered */ - ESP_RMAKER_REQ_SRC_SCHEDULE, - /** Request received from a local controller */ - ESP_RMAKER_REQ_SRC_LOCAL, - /** This will always be the last value. Any value equal to or - * greater than this should be considered invalid. - */ - ESP_RMAKER_REQ_SRC_MAX, -} esp_rmaker_req_src_t; - -/** Write request Context */ -typedef struct { - /** Source of request */ - esp_rmaker_req_src_t src; -} esp_rmaker_write_ctx_t; - -/** Read request context */ -typedef struct { - /** Source of request */ - esp_rmaker_req_src_t src; -} esp_rmaker_read_ctx_t; - -/** System service configuration */ -typedef struct { - /** Logical OR of system service flags (SYSTEM_SERV_FLAG_REBOOT, - * SYSTEM_SERV_FLAG_FACTORY_RESET, SYSTEM_SERV_FLAG_WIFI_RESET) as required - * or SYSTEM_SERV_FLAGS_ALL. - */ - uint16_t flags; - /** Time in seconds after which the device should reboot. - * Value of zero would trigger an immediate reboot if a write is received for - * the Reboot parameter. - * Recommended value: 2 - */ - int8_t reboot_seconds; - /** Time in seconds after which the device should reset (Wi-Fi or factory). - * Value of zero would trigger an immediate action if a write is received for - * the Wi-Fi reset or Factory reset parameter. - * Recommended value: 2 - */ - int8_t reset_seconds; - /** Time in seconds after which the device should reboot after it has been reset. - * Value of zero would mean that there won't be any reboot after the reset. - * Recommended value: 2 - */ - int8_t reset_reboot_seconds; -} esp_rmaker_system_serv_config_t; - -/** Callback for parameter value write requests. - * - * The callback should call the esp_rmaker_param_update_and_report() API if the new value is to be set - * and reported back. - * - * @param[in] device Device handle. - * @param[in] param Parameter handle. - * @param[in] param Pointer to \ref esp_rmaker_param_val_t. Use appropriate elements as per the value type. - * @param[in] priv_data Pointer to the private data paassed while creating the device. - * @param[in] ctx Context associated with the request. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -typedef esp_err_t (*esp_rmaker_device_write_cb_t)(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param, - const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx); - -/** Callback for parameter value changes - * - * The callback should call the esp_rmaker_param_update_and_report() API if the new value is to be set - * and reported back. - * - * @note Currently, the read callback never gets invoked as the communication between clients (mobile phones, CLI, etc.) - * and node is asynchronous. So, the read request does not reach the node. This callback will however be used in future. - * - * @param[in] device Device handle. - * @param[in] param Parameter handle. - * @param[in] priv_data Pointer to the private data passed while creating the device. - * @param[in] ctx Context associated with the request. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -typedef esp_err_t (*esp_rmaker_device_read_cb_t)(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param, - void *priv_data, esp_rmaker_read_ctx_t *ctx); - -/** Convert device callback source to string - * - * Device read/write callback can be via different sources. This is a helper API - * to give the source in string format for printing. - * - * Example Usage: - * @code{c} - * static esp_err_t write_cb(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param, - * const esp_rmaker_param_val_t val, void *priv_data, esp_rmaker_write_ctx_t *ctx) -{ - if (ctx) { - ESP_LOGI(TAG, "Received write request via : %s", esp_rmaker_device_cb_src_to_str(ctx->src)); - } - * @endcode - * - * @param[in] src The src field as received in the callback context. - * - * @return NULL terminated source string on success - * @return NULL on failure - */ -const char *esp_rmaker_device_cb_src_to_str(esp_rmaker_req_src_t src); - -/** - * Initialise a Boolean value - * - * @param[in] bval Initialising value. - * - * @return Value structure. - */ -esp_rmaker_param_val_t esp_rmaker_bool(bool bval); - -/** - * Initialise an Integer value - * - * @param[in] ival Initialising value. - * - * @return Value structure. - */ -esp_rmaker_param_val_t esp_rmaker_int(int ival); - -/** - * Initialise a Float value - * - * @param[in] fval Initialising value. - * - * @return Value structure. - */ -esp_rmaker_param_val_t esp_rmaker_float(float fval); - -/** - * Initialise a String value - * - * @param[in] sval Initialising value. - * - * @return Value structure. - */ -esp_rmaker_param_val_t esp_rmaker_str(const char *sval); - -/** - * Initialise a json object value - * - * @note the object will not be validated internally. it is the application's - * responsibility to ensure that the object is a valid json object. - * eg. esp_rmaker_obj("{\"name\":\"value\"}"); - * - * param[in] val initialising value - * - * return value structure - */ -esp_rmaker_param_val_t esp_rmaker_obj(const char *val); - -/** - * Initialise a json array value - * - * @note the array will not be validated internally. it is the application's - * responsibility to ensure that the array is a valid json array. - * eg. esp_rmaker_array("[1,2,3]"); - * - * param[in] val initialising value - * - * return value structure - */ -esp_rmaker_param_val_t esp_rmaker_array(const char *val); - - -/** Initialize ESP RainMaker Node - * - * This initializes the ESP RainMaker agent and creates the node. - * The model and firmware version for the node are set internally as per - * the project name and version. These can be overridden (but not recommended) using the - * esp_rmaker_node_add_fw_version() and esp_rmaker_node_add_model() APIs. - * - * @note This should be the first call before using any other ESP RainMaker API. - * - * @param[in] config Configuration to be used by the ESP RainMaker. - * @param[in] name Name of the node. - * @param[in] type Type of the node. - * - * @return Node handle on success. - * @return NULL in case of failure. - */ -esp_rmaker_node_t *esp_rmaker_node_init(const esp_rmaker_config_t *config, const char *name, const char *type); - -/** Start ESP RainMaker Agent - * - * This call starts the actual ESP RainMaker thread. This should preferably be called after a - * successful Wi-Fi connection in order to avoid unnecessary failures. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_start(void); - -/** Stop ESP RainMaker Agent - * - * This call stops the ESP RainMaker Agent instance started earlier by esp_rmaker_start(). - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_stop(void); - -/** Deinitialize ESP RainMaker Node - * - * This API deinitializes the ESP RainMaker agent and the node created using esp_rmaker_node_init(). - * - * @note This should be called after rainmaker has stopped. - * - * @param[in] node Node Handle returned by esp_rmaker_node_init(). - * - * @retur ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_node_deinit(const esp_rmaker_node_t *node); - -/** Get a handle to the Node - * - * This API returns handle to a node created using esp_rmaker_node_init(). - * - * @return Node handle on success. - * @return NULL in case of failure. - */ -const esp_rmaker_node_t *esp_rmaker_get_node(void); - -/** Get Node Id - * - * Returns pointer to the NULL terminated Node ID string. - * - * @return Pointer to a NULL terminated Node ID string. - */ -char *esp_rmaker_get_node_id(void); - -/** Get Node Info - * - * Returns pointer to the node info as configured during initialisation. - * - * @param node Node handle. - * - * @return Pointer to the node info on success. - * @return NULL in case of failure. - */ -esp_rmaker_node_info_t *esp_rmaker_node_get_info(const esp_rmaker_node_t *node); - -/** Add Node attribute - * - * Adds a new attribute as the metadata for the node. For the sake of simplicity, - * only string values are allowed. - * - * @param node Node handle. - * @param[in] attr_name Name of the attribute. - * @param[in] val Value for the attribute. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_node_add_attribute(const esp_rmaker_node_t *node, const char *attr_name, const char *val); - -/** Add FW version for a node (Not recommended) - * - * FW version is set internally to the project version. This API can be used to - * override that version. - * - * @param node Node handle. - * @param[in] fw_version New firmware version. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_node_add_fw_version(const esp_rmaker_node_t *node, const char *fw_version); - -/** Add model for a node (Not recommended) - * - * Model is set internally to the project name. This API can be used to - * override that name. - * - * @param node Node handle. - * @param[in] model New model string. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_node_add_model(const esp_rmaker_node_t *node, const char *model); - -/** - * Create a Device - * - * This API will create a virtual "Device". - * This could be something like a Switch, Lightbulb, etc. - * - * @note The device created needs to be added to a node using esp_rmaker_node_add_device(). - * - * @param[in] dev_name The unique device name. - * @param[in] type Optional device type. Can be kept NULL. - * @param[in] priv_data (Optional) Private data associated with the device. This will be passed to callbacks. - * It should stay allocated throughout the lifetime of the device. - * - * @return Device handle on success. - * @return NULL in case of any error. - */ -esp_rmaker_device_t *esp_rmaker_device_create(const char *dev_name, const char *type, void *priv_data); - -/** - * Create a Service - * - * This API will create a "Service". It is exactly same like a device in terms of structure and so, all - * APIs for device are also valid for a service. - * A service could be something like OTA, diagnostics, etc. - * - * @note Name of a service should not clash with name of a device. - * @note The service created needs to be added to a node using esp_rmaker_node_add_device(). - * - * @param[in] serv_name The unique service name. - * @param[in] type Optional service type. Can be kept NULL. - * @param[in] priv_data (Optional) Private data associated with the service. This will be passed to callbacks. - * It should stay allocated throughout the lifetime of the device. - * - * @return Device handle on success. - * @return NULL in case of any error. - */ -esp_rmaker_device_t *esp_rmaker_service_create(const char *serv_name, const char *type, void *priv_data); - -/** - * Delete a Device/Service - * - * This API will delete a device created using esp_rmaker_device_create(). - * - * @note The device should first be removed from the node using esp_rmaker_node_remove_device() before deleting. - * - * @param[in] device Device handle. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_device_delete(const esp_rmaker_device_t *device); - -/** - * Add callbacks for a device/service - * - * Add read/write callbacks for a device that will be invoked as per requests received from the cloud (or other paths - * as may be added in future). - * - * @param[in] device Device handle. - * @param[in] write_cb Write callback. - * @param[in] read_cb Read callback. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_device_add_cb(const esp_rmaker_device_t *device, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb); - -/** - * Add a device to a node - * - * @param[in] node Node handle. - * @param[in] device Device handle. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_node_add_device(const esp_rmaker_node_t *node, const esp_rmaker_device_t *device); - -/** - * Remove a device from a node - * - * @param[in] node Node handle. - * @param[in] device Device handle. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_node_remove_device(const esp_rmaker_node_t *node, const esp_rmaker_device_t *device); - -/** Get device by name - * - * Get handle for a device based on the name. - * - * @param[in] node Node handle. - * @param[in] device_name Device name to search. - * - * @return Device handle on success. - * @return NULL in case of failure. - */ -esp_rmaker_device_t *esp_rmaker_node_get_device_by_name(const esp_rmaker_node_t *node, const char *device_name); - -/** Add a Device attribute - * - * @note Device attributes are reported only once after a boot-up as part of the node - * configuration. - * Eg. Serial Number - * - * @param[in] device Device handle. - * @param[in] attr_name Name of the attribute. - * @param[in] val Value of the attribute. - * - * @return ESP_OK if the attribute was added successfully. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_device_add_attribute(const esp_rmaker_device_t *device, const char *attr_name, const char *val); - -/** Add a Device subtype - * - * This can be something like esp.subtype.rgb-light for a device of type esp.device.lightbulb. - * This would primarily be used by the phone apps to render different icons for the same device type. - * - * @param[in] device Device handle. - * @param[in] subtype String describing the sub type. - * - * @return ESP_OK if the subtype was added successfully. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_device_add_subtype(const esp_rmaker_device_t *device, const char *subtype); - -/** Get device name from handle - * - * @param[in] device Device handle. - * - * @return NULL terminated device name string on success. - * @return NULL in case of failure. - */ -char *esp_rmaker_device_get_name(const esp_rmaker_device_t *device); - -/** Get device type from handle - * - * @param[in] device Device handle. - * - * @return NULL terminated device type string on success. - * @return NULL in case of failure, or if the type wasn't provided while creating the device. - */ -char *esp_rmaker_device_get_type(const esp_rmaker_device_t *device); - -/** - * Add a parameter to a device/service - * - * @param[in] device Device handle. - * @param[in] param Parameter handle. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_device_add_param(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param); - - -/** Get parameter by type - * - * Get handle for a parameter based on the type. - * - * @note If there are multiple parameters with the same type, this will return the first one. The API - * esp_rmaker_device_get_param_by_name() can be used to get a specific parameter, because the parameter - * names in a device are unique. - * - * @param[in] device Device handle. - * @param[in] param_type Parameter type to search. - * - * @return Parameter handle on success. - * @return NULL in case of failure. - */ -esp_rmaker_param_t *esp_rmaker_device_get_param_by_type(const esp_rmaker_device_t *device, const char *param_type); - -/** Get parameter by name - * - * Get handle for a parameter based on the name. - * - * @param[in] device Device handle. - * @param[in] param_name Parameter name to search. - * - * @return Parameter handle on success. - * @return NULL in case of failure. - */ -esp_rmaker_param_t *esp_rmaker_device_get_param_by_name(const esp_rmaker_device_t *device, const char *param_name); - -/** Assign a primary parameter - * - * Assign a parameter (already added using esp_rmaker_device_add_param()) as a primary parameter, - * which can be used by clients (phone apps specifically) to give prominence to it. - * - * @param[in] device Device handle. - * @param[in] param Parameter handle. - * - * @return ESP_OK if the parameter was assigned as the primary successfully. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_device_assign_primary_param(const esp_rmaker_device_t *device, const esp_rmaker_param_t *param); - -/** - * Create a Parameter - * - * Parameter can be something like Temperature, Outlet state, Lightbulb brightness, etc. - * - * Any changes should be reported using the esp_rmaker_param_update_and_report() API. - * Any remote changes will be reported to the application via the device callback, if registered. - * - * @note The parameter created needs to be added to a device using esp_rmaker_device_add_param(). - * Parameter name should be unique in a given device. - * - * @param[in] param_name Name of the parameter. - a* @param[in] type Optional parameter type. Can be kept NULL. - * @param[in] val Value of the parameter. This also specifies the type that will be assigned - * to this parameter. You can use esp_rmaker_bool(), esp_rmaker_int(), esp_rmaker_float() - * or esp_rmaker_str() functions as the argument here. Eg, esp_rmaker_bool(true). - * @param[in] properties Properties of the parameter, which will be a logical OR of flags in - * \ref esp_param_property_flags_t. - * - * @return Parameter handle on success. - * @return NULL in case of failure. - */ -esp_rmaker_param_t *esp_rmaker_param_create(const char *param_name, const char *type, - esp_rmaker_param_val_t val, uint8_t properties); - -/** - * Add a UI Type to a parameter - * - * This will be used by the Phone apps (or other clients) to render appropriate UI for the given - * parameter. Please refer the RainMaker documetation for supported UI Types. - * - * @param[in] param Parameter handle. - * @param[in] ui_type String describing the UI Type. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_param_add_ui_type(const esp_rmaker_param_t *param, const char *ui_type); - -/** - * Add bounds for an integer/float parameter - * - * This can be used to add bounds (min/max values) for a given integer parameter. Eg. brightness - * will have bounds as 0 and 100 if it is a percentage. - * Eg. esp_rmaker_param_add_bounds(brightness_param, esp_rmaker_int(0), esp_rmaker_int(100), esp_rmaker_int(5)); - * - * @note The RainMaker core does not check the bounds. It is upto the application to handle it. - * - * @param[in] param Parameter handle. - * @param[in] min Minimum allowed value. - * @param[in] max Maximum allowed value. - * @param[in] step Minimum stepping (set to 0 if no specific value is desired). - * - * @return ESP_OK on success. - * return error in case of failure. - */ -esp_err_t esp_rmaker_param_add_bounds(const esp_rmaker_param_t *param, - esp_rmaker_param_val_t min, esp_rmaker_param_val_t max, esp_rmaker_param_val_t step); - -/** - * Add a list of valid strings for a string parameter - * - * This can be used to add a list of valid strings for a given string parameter. - * - * Eg. - * static const char *valid_strs[] = {"None","Yes","No","Can't Say"}; - * esp_rmaker_param_add_valid_str_list(param, valid_strs, 4); - * - * @note The RainMaker core does not check the values. It is upto the application to handle it. - * - * @param[in] param Parameter handle. - * @param[in] strs Pointer to an array of strings. Note that this memory should stay allocated - * throughout the lifetime of this parameter. - * @param[in] count Number of strings in the above array. - * - * @return ESP_OK on success. - * return error in case of failure. - */ -esp_err_t esp_rmaker_param_add_valid_str_list(const esp_rmaker_param_t *param, const char *strs[], uint8_t count); - -/** Add max count for an array parameter - * - * This can be used to put a limit on the maximum number of elements in an array. - * - * @note The RainMaker core does not check the values. It is upto the application to handle it. - * - * @param[in] param Parameter handle. - * @param[in] count Max number of elements allowed in the array. - * - * @return ESP_OK on success. - * return error in case of failure. - */ -esp_err_t esp_rmaker_param_add_array_max_count(const esp_rmaker_param_t *param, int count); - - -/* Update a parameter - * - * This will just update the value of a parameter with esp rainmaker core, without actually reporting - * it. This can be used when multiple parameters need to be reported together. - * Eg. If x parameters are to be reported, this API can be used for the first x -1 parameters - * and the last one can be updated using esp_rmaker_param_update_and_report(). - * This will report all parameters which were updated prior to this call. - * - * Sample: - * - * esp_rmaker_param_update(param1, esp_rmaker_float(10.2)); - * esp_rmaker_param_update(param2, esp_rmaker_int(55)); - * esp_rmaker_param_update(param3, esp_rmaker_int(95)); - * esp_rmaker_param_update_and_report(param1, esp_rmaker_bool(true)); - * - * @param[in] param Parameter handle. - * @param[in] val New value of the parameter. - * - * @return ESP_OK if the parameter was updated successfully. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_param_update(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); - -/** Update and report a parameter - * - * Calling this API will update the parameter and report it to ESP RainMaker cloud. - * This should be used whenever there is any local change. - * - * @param[in] param Parameter handle. - * @param[in] val New value of the parameter. - * - * @return ESP_OK if the parameter was updated successfully. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_param_update_and_report(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); - -/** Update and notify a parameter - * - * Calling this API will update the parameter and report it to ESP RainMaker cloud similar to - * esp_rmaker_param_update_and_report(). However, additionally, it will also trigger a notification - * on the phone apps (if enabled). - * - * @note This should be used only when some local change requires explicit notification even when the - * phone app is in background, not otherwise. - * Eg. Alarm got triggered, temperature exceeded some threshold, etc. - * - * Alternatively, the esp_rmaker_raise_alert() API can also be used to trigger notification - * on the phone apps with pre-formatted text. - * - * @param[in] param Parameter handle. - * @param[in] val New value of the parameter. - * - * @return ESP_OK if the parameter was updated successfully. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_param_update_and_notify(const esp_rmaker_param_t *param, esp_rmaker_param_val_t val); - -/** Trigger an alert on the phone app - * - * This API will trigger a notification alert on the phone apps (if enabled) using the formatted text - * provided. Note that this does not send a notification directly to the phone, but reports the alert - * to the ESP RainMaker cloud which then uses the Notification framework to send notifications to the - * phone apps. The value does not get stored anywhere, nor is it linked to any node parameters. - * - * @note This should be used only if some event requires explicitly alerting the user even when the - * phone app is in background, not otherwise. - * Eg. "Motion Detected", "Fire alarm triggered" - * - * @param[in] alert_str NULL terminated pre-formatted alert string. - * Maximum length can be ESP_RMAKER_MAX_ALERT_LEN, excluding NULL character. - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_raise_alert(const char *alert_str); - -/** Get parameter name from handle - * - * @param[in] param Parameter handle. - * - * @return NULL terminated parameter name string on success. - * @return NULL in case of failure. - */ -char *esp_rmaker_param_get_name(const esp_rmaker_param_t *param); - -/** Get parameter type from handle - * - * @param[in] param Parameter handle. - * - * @return NULL terminated parameter type string on success. - * @return NULL in case of failure, or if the type wasn't provided while creating the parameter. - */ -char *esp_rmaker_param_get_type(const esp_rmaker_param_t *param); - -/** Get parameter value - * - * This gives the parameter value that is stored in the RainMaker core. - * - * @note This does not call any explicit functions to read value from hardware/driver. - * - * @param[in] param Parameter handle - * - * @return Pointer to parameter value on success. - * @return NULL in case of failure. - */ -esp_rmaker_param_val_t *esp_rmaker_param_get_val(esp_rmaker_param_t *param); - -/** Report the node details to the cloud - * - * This API reports node details i.e. the node configuration and values of all the parameters to the ESP RainMaker cloud. - * Eg. If a new device is created (with some parameters and attributes), then this API should be called after that - * to send the node details to the cloud again and the changes to be reflected in the clients (like phone apps). - * - * @note Please use this API only if you need to create or delete devices after esp_rmaker_start() has already - * been called, for use cases like bridges or hubs. - * - * @return ESP_OK if the node details are successfully queued to be published. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_report_node_details(void); - -/** Enable Timezone Service - * - * This enables the ESP RainMaker standard timezone service which can be used to set - * timezone, either in POSIX or location string format. Please refer the specifications - * for additional details. - * - * @return ESP_OK on success - * @return error on failure - */ -esp_err_t esp_rmaker_timezone_service_enable(void); - -/** Enable System Service - * - * This enables the ESP RainMaker standard system service which can be - * used for operations like reboot, factory reset and Wi-Fi reset. - * - * Please refer the specifications for additional details. - * - * @param[in] config Configuration for the system service. - * - * @return ESP_OK on success - * @return error on failure - */ -esp_err_t esp_rmaker_system_service_enable(esp_rmaker_system_serv_config_t *config); - -/** - * Check if local_ctrl service has started - * - * @return true if service has started - * @return false if the service has not started - */ -bool esp_rmaker_local_ctrl_service_started(void); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h deleted file mode 100644 index 1cc6cd5156e..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_mqtt.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 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 -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -esp_rmaker_mqtt_conn_params_t *esp_rmaker_mqtt_get_conn_params(void); - -/** Initialize ESP RainMaker MQTT - * - * @param[in] config The MQTT configuration data - * - * @return ESP_OK on success. - * @return error in case of any error. - */ -esp_err_t esp_rmaker_mqtt_init(esp_rmaker_mqtt_conn_params_t *conn_params); - -/** MQTT Connect - * - * Starts the connection attempts to the MQTT broker as per the configuration - * provided during initializing. - * This should ideally be called after successful network connection. - * - * @return ESP_OK on success. - * @return error in case of any error. - */ -esp_err_t esp_rmaker_mqtt_connect(void); - -/** MQTT Disconnect - * - * Disconnects from the MQTT broker. - * - * @return ESP_OK on success. - * @return error in case of any error. - */ -esp_err_t esp_rmaker_mqtt_disconnect(void); - -/** Publish MQTT Message - * - * @param[in] topic The MQTT topic on which the message should be published. - * @param[in] data Data to be published - * @param[in] data_len Length of the data - * @param[in] qos Quality of Service for the Publish. Can be 0, 1 or 2. Also depends on what the MQTT broker supports. - * - * @return ESP_OK on success. - * @return error in case of any error. - */ -esp_err_t esp_rmaker_mqtt_publish(const char *topic, void *data, size_t data_len, uint8_t qos, int *msg_id); - -/** Subscribe to MQTT topic - * - * @param[in] topic The topic to be subscribed to. - * @param[in] cb The callback to be invoked when a message is received on the given topic. - * @param[in] priv_data Optional private data to be passed to the callback - * @param[in] qos Quality of Service for the Subscription. Can be 0, 1 or 2. Also depends on what the MQTT broker supports. - * - * @return ESP_OK on success. - * @return error in case of any error. - */ -esp_err_t esp_rmaker_mqtt_subscribe(const char *topic, esp_rmaker_mqtt_subscribe_cb_t cb, uint8_t qos, void *priv_data); - -/** Unsubscribe from MQTT topic - * - * @param[in] topic Topic from which to unsubscribe. - * - * @return ESP_OK on success. - * @return error in case of any error. - */ -esp_err_t esp_rmaker_mqtt_unsubscribe(const char *topic); -esp_err_t esp_rmaker_mqtt_setup(esp_rmaker_mqtt_config_t mqtt_config); -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h deleted file mode 100644 index e66b95705bc..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_ota.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 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 -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** Default ESP RainMaker OTA Server Certificate */ -extern const char *ESP_RMAKER_OTA_DEFAULT_SERVER_CERT; - -/** OTA Status to be reported to ESP RainMaker Cloud */ -typedef enum { - /** OTA is in Progress. This can be reported multiple times as the OTA progresses. */ - OTA_STATUS_IN_PROGRESS = 1, - /** OTA Succeeded. This should be reported only once, at the end of OTA. */ - OTA_STATUS_SUCCESS, - /** OTA Failed. This should be reported only once, at the end of OTA. */ - OTA_STATUS_FAILED, - /** OTA was delayed by the application */ - OTA_STATUS_DELAYED, -} ota_status_t; - -/** OTA Workflow type */ -typedef enum { - /** OTA will be performed using services and parameters. */ - OTA_USING_PARAMS = 1, - /** OTA will be performed using pre-defined MQTT topics. */ - OTA_USING_TOPICS -} esp_rmaker_ota_type_t; - -/** The OTA Handle to be used by the OTA callback */ -typedef void *esp_rmaker_ota_handle_t; - -/** OTA Data */ -typedef struct { - /** The OTA URL received from ESP RainMaker Cloud */ - char *url; - /** Size of the OTA File. Can be 0 if the file size isn't received from - * the ESP RainMaker Cloud */ - int filesize; - /** The server certificate passed in esp_rmaker_enable_ota() */ - const char *server_cert; - /** The private data passed in esp_rmaker_enable_ota() */ - char *priv; -} esp_rmaker_ota_data_t; - -/** Function prototype for OTA Callback - * - * This function will be invoked by the ESP RainMaker core whenever an OTA is available. - * The esp_rmaker_report_ota_status() API should be used to indicate the progress and - * success/fail status. - * - * @param[in] handle An OTA handle assigned by the ESP RainMaker Core - * @param[in] ota_data The data to be used for the OTA - * - * @return ESP_OK if the OTA was successful - * @return ESP_FAIL if the OTA failed. - */ -typedef esp_err_t (*esp_rmaker_ota_cb_t) (esp_rmaker_ota_handle_t handle, - esp_rmaker_ota_data_t *ota_data); - -/** Function Prototype for Post OTA Diagnostics - * - * If the Application rollback feature is enabled, this callback will be invoked - * as soon as you call esp_rmaker_ota_enable(), if it is the first - * boot after an OTA. You may perform some application specific diagnostics and - * report the status which will decide whether to roll back or not. - * - * @return true if diagnostics are successful, meaning that the new firmware is fine. - * @return false if diagnostics fail and a roolback to previous firmware is required. - */ -typedef bool (*esp_rmaker_post_ota_diag_t)(void); - -/** ESP RainMaker OTA Configuration */ -typedef struct { - /** OTA Callback. - * The callback to be invoked when an OTA Job is available. - * If kept NULL, the internal default callback will be used (Recommended). - */ - esp_rmaker_ota_cb_t ota_cb; - /** OTA Diagnostics Callback. - * A post OTA diagnostic handler to be invoked if app rollback feature is enabled. - * If kept NULL, the new firmware will be assumed to be fine, - * and no rollback will be performed. - */ - esp_rmaker_post_ota_diag_t ota_diag; - /** Server Certificate. - * The certificate to be passed to the OTA callback for server authentication. - * This is mandatory, unless you have disabled it in ESP HTTPS OTA config option. - * If you are using the ESP RainMaker OTA Service, you can just set this to - * `ESP_RMAKER_OTA_DEFAULT_SERVER_CERT`. - */ - const char *server_cert; - /** Private Data. - * Optional private data to be passed to the OTA callback. - */ - void *priv; -} esp_rmaker_ota_config_t; - -/** Enable OTA - * - * Calling this API enables OTA as per the ESP RainMaker specification. - * Please check the various ESP RainMaker configuration options to - * use the different variants of OTA. Refer the documentation for - * additional details. - * - * @param[in] ota_config Pointer to an OTA configuration structure - * @param[in] type The OTA workflow type - * - * @return ESP_OK on success - * @return error on failure - */ -esp_err_t esp_rmaker_ota_enable(esp_rmaker_ota_config_t *ota_config, esp_rmaker_ota_type_t type); - -/** Report OTA Status - * - * This API must be called from the OTA Callback to indicate the status of the OTA. The OTA_STATUS_IN_PROGRESS - * can be reported multiple times with appropriate additional information. The final success/failure should - * be reported only once, at the end. - * - * This can be ignored if you are using the default internal OTA callback. - * - * @param[in] ota_handle The OTA handle received by the callback - * @param[in] status Status to be reported - * @param[in] additional_info NULL terminated string indicating additional information for the status - * - * @return ESP_OK on success - * @return error on failure - */ -esp_err_t esp_rmaker_ota_report_status(esp_rmaker_ota_handle_t ota_handle, ota_status_t status, char *additional_info); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h deleted file mode 100644 index 383c0949188..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_schedule.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 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 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** Enable Schedules - * - * This API enables the scheduling service for the node. For more information, - * check [here](https://rainmaker.espressif.com/docs/scheduling.html) - * - * It is recommended to set the timezone while using schedules. Check [here](https://rainmaker.espressif.com/docs/time-service.html#time-zone) for more information on timezones - * - * @note This API should be called after esp_rmaker_node_init() but before esp_rmaker_start(). - * - * @return ESP_OK on success. - * @return error in case of failure. - */ -esp_err_t esp_rmaker_schedule_enable(void); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_devices.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_devices.h deleted file mode 100644 index db9480672ba..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_devices.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 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 -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** Create a standard Switch device - * - * This creates a Switch device with the mandatory parameters and also assigns - * the primary parameter. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] dev_name The unique device name - * @param[in] priv_data (Optional) Private data associated with the device. This should stay - * allocated throughout the lifetime of the device - * #@param[in] power Default value of the mandatory parameter "power" - * - * @return Device handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_device_t *esp_rmaker_switch_device_create(const char *dev_name, - void *priv_data, bool power); - -/** Create a standard Lightbulb device - * - * This creates a Lightbulb device with the mandatory parameters and also assigns - * the primary parameter. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] dev_name The unique device name - * @param[in] priv_data (Optional) Private data associated with the device. This should stay - * allocated throughout the lifetime of the device - * @param[in] power Default value of the mandatory parameter "power" - * - * @return Device handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_device_t *esp_rmaker_lightbulb_device_create(const char *dev_name, - void *priv_data, bool power); - -/** Create a standard Fan device - * - * This creates a Fan device with the mandatory parameters and also assigns - * the primary parameter. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] dev_name The unique device name - * @param[in] priv_data (Optional) Private data associated with the device. This should stay - * allocated throughout the lifetime of the device - * @param[in] power Default value of the mandatory parameter "power" - * - * @return Device handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_device_t *esp_rmaker_fan_device_create(const char *dev_name, - void *priv_data, bool power); - -/** Create a standard Temperature Sensor device - * - * This creates a Temperature Sensor device with the mandatory parameters and also assigns - * the primary parameter. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] dev_name The unique device name - * @param[in] priv_data (Optional) Private data associated with the device. This should stay - * allocated throughout the lifetime of the device - * @param[in] temperature Default value of the mandatory parameter "temperature" - * - * @return Device handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_device_t *esp_rmaker_temp_sensor_device_create(const char *dev_name, - void *priv_data, float temperature); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h deleted file mode 100644 index 6cde69a2935..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_params.h +++ /dev/null @@ -1,335 +0,0 @@ -// Copyright 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 -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Suggested default names for the parameters. - * These will also be used by default if you use any standard device helper APIs. - * - * @note These names are not mandatory. You can use the ESP RainMaker Core APIs - * to create your own parameters with custom names, if required. - */ - -#define ESP_RMAKER_DEF_NAME_PARAM "Name" -#define ESP_RMAKER_DEF_POWER_NAME "Power" -#define ESP_RMAKER_DEF_BRIGHTNESS_NAME "Brightness" -#define ESP_RMAKER_DEF_HUE_NAME "Hue" -#define ESP_RMAKER_DEF_SATURATION_NAME "Saturation" -#define ESP_RMAKER_DEF_INTENSITY_NAME "Intensity" -#define ESP_RMAKER_DEF_CCT_NAME "CCT" -#define ESP_RMAKER_DEF_DIRECTION_NAME "Direction" -#define ESP_RMAKER_DEF_SPEED_NAME "Speed" -#define ESP_RMAKER_DEF_TEMPERATURE_NAME "Temperature" -#define ESP_RMAKER_DEF_OTA_STATUS_NAME "Status" -#define ESP_RMAKER_DEF_OTA_INFO_NAME "Info" -#define ESP_RMAKER_DEF_OTA_URL_NAME "URL" -#define ESP_RMAKER_DEF_TIMEZONE_NAME "TZ" -#define ESP_RMAKER_DEF_TIMEZONE_POSIX_NAME "TZ-POSIX" -#define ESP_RMAKER_DEF_SCHEDULE_NAME "Schedules" -#define ESP_RMAKER_DEF_REBOOT_NAME "Reboot" -#define ESP_RMAKER_DEF_FACTORY_RESET_NAME "Factory-Reset" -#define ESP_RMAKER_DEF_WIFI_RESET_NAME "Wi-Fi-Reset" -#define ESP_RMAKER_DEF_LOCAL_CONTROL_POP "POP" -#define ESP_RMAKER_DEF_LOCAL_CONTROL_TYPE "Type" - -/** - * Create standard name param - * - * This will create the standard name parameter. - * This should be added to all devices for which you want a user customisable name. - * The value should be same as the device name. - * - * All standard device creation APIs will add this internally. - * No application registered callback will be called for this parameter, - * and changes will be managed internally. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_name_param_create(const char *param_name, const char *val); - -/** - * Create standard Power param - * - * This will create the standard power parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_power_param_create(const char *param_name, bool val); - -/** - * Create standard Brightness param - * - * This will create the standard brightness parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_brightness_param_create(const char *param_name, int val); - -/** - * Create standard Hue param - * - * This will create the standard hue parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_hue_param_create(const char *param_name, int val); - -/** - * Create standard Saturation param - * - * This will create the standard saturation parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_saturation_param_create(const char *param_name, int val); - -/** - * Create standard Intensity param - * - * This will create the standard intensity parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_intensity_param_create(const char *param_name, int val); - -/** - * Create standard CCT param - * - * This will create the standard cct parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_cct_param_create(const char *param_name, int val); - -/** - * Create standard Direction param - * - * This will create the standard direction parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_direction_param_create(const char *param_name, int val); - -/** - * Create standard Speed param - * - * This will create the standard speed parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_speed_param_create(const char *param_name, int val); - -/** - * Create standard Temperature param - * - * This will create the standard temperature parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_temperature_param_create(const char *param_name, float val); - -/** - * Create standard OTA Status param - * - * This will create the standard ota status parameter. Default value - * is set internally. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_ota_status_param_create(const char *param_name); - -/** - * Create standard OTA Info param - * - * This will create the standard ota info parameter. Default value - * is set internally. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_ota_info_param_create(const char *param_name); - -/** - * Create standard OTA URL param - * - * This will create the standard ota url parameter. Default value - * is set internally. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_ota_url_param_create(const char *param_name); - -/** - * Create standard Timezone param - * - * This will create the standard timezone parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter (Eg. "Asia/Shanghai"). Can be kept NULL. - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_timezone_param_create(const char *param_name, const char *val); - -/** - * Create standard POSIX Timezone param - * - * This will create the standard posix timezone parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter (Eg. "CST-8"). Can be kept NULL. - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_timezone_posix_param_create(const char *param_name, const char *val); - -/** - * Create standard Schedules param - * - * This will create the standard schedules parameter. Default value - * is set internally. - * - * @param[in] param_name Name of the parameter - * @param[in] max_schedules Maximum number of schedules allowed - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_schedules_param_create(const char *param_name, int max_schedules); - -/** - * Create standard Reboot param - * - * This will create the standard reboot parameter. - * Set value to true (via write param) for the action to trigger. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_reboot_param_create(const char *param_name); - -/** - * Create standard Factory Reset param - * - * This will create the standard factory reset parameter. - * Set value to true (via write param) for the action to trigger. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_factory_reset_param_create(const char *param_name); - -/** - * Create standard Wi-Fi Reset param - * - * This will create the standard Wi-Fi Reset parameter. - * Set value to true (via write param) for the action to trigger. - * - * @param[in] param_name Name of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_wifi_reset_param_create(const char *param_name); - -/** - * Create standard Local Control POP param - * - * This will create the standard Local Control POP parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter (Eg. "abcd1234"). Can be kept NULL. - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_local_control_pop_param_create(const char *param_name, const char *val); - -/** - * Create standard Local Control Type param - * - * This will create the standard Local Control security type parameter. - * - * @param[in] param_name Name of the parameter - * @param[in] val Default Value of the parameter - * - * @return Parameter handle on success. - * @return NULL in case of failures. - */ -esp_rmaker_param_t *esp_rmaker_local_control_type_param_create(const char *param_name, int val); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h deleted file mode 100644 index 7dc6dfbad80..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_services.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 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 -#include -#include -#include - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** Create a standard OTA service - * - * This creates an OTA service with the mandatory parameters. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] serv_name The unique service name - * @param[in] priv_data (Optional) Private data associated with the service. This should stay - * allocated throughout the lifetime of the service. - * - * @return service_handle on success. - * @return NULL in case of any error. - */ -esp_rmaker_device_t *esp_rmaker_ota_service_create(const char *serv_name, void *priv_data); - -/** Create a standard OTA service - * - * This creates an OTA service with the mandatory parameters. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] serv_name The unique service name - * @param[in] timezone Default value of timezone string (Eg. "Asia/Shanghai"). Can be kept NULL. - * @param[in] timezone_posix Default value of posix timezone string (Eg. "CST-8"). Can be kept NULL. - * @param[in] priv_data (Optional) Private data associated with the service. This should stay - * allocated throughout the lifetime of the service. - * - * @return service_handle on success. - * @return NULL in case of any error. - */ -esp_rmaker_device_t *esp_rmaker_time_service_create(const char *serv_name, const char *timezone, - const char *timezone_posix, void *priv_data); - -/** Create a standard Schedule service - * - * This creates a Schedule service with the mandatory parameters. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] serv_name The unique service name - * @param[in] write_cb Write callback. - * @param[in] read_cb Read callback. - * @param[in] max_schedules Maximum number of schedules supported. - * @param[in] priv_data (Optional) Private data associated with the service. This should stay - * allocated throughout the lifetime of the service. - * - * @return service_handle on success. - * @return NULL in case of any error. - */ -esp_rmaker_device_t *esp_rmaker_create_schedule_service(const char *serv_name, esp_rmaker_device_write_cb_t write_cb, esp_rmaker_device_read_cb_t read_cb, int max_schedules, void *priv_data); - -/** Create a standard System service - * - * This creates an empty System service. Appropriate parameters should be added by the caller. - * - * @param[in] serv_name The unique service name - * @param[in] priv_data (Optional) Private data associated with the service. This should stay - * allocated throughout the lifetime of the service. - * - * @return service_handle on success. - * @return NULL in case of any error. - */ - -esp_rmaker_device_t *esp_rmaker_create_system_service(const char *serv_name, void *priv_data); - -/** Create a standard Local Control service - * - * This creates a Local Control service with the mandatory parameters. The default parameter names will be used. - * Refer \ref esp_rmaker_standard_params.h for default names. - * - * @param[in] serv_name The unique service name - * @param[in] pop Proof of possession - * @param[in] sec_type Security type - * @param[in] priv_data (Optional) Private data associated with the service. This should stay - * allocated throughout the lifetime of the service. - * - * @return service_handle on success. - * @return NULL in case of any error. - */ -esp_rmaker_device_t *esp_rmaker_create_local_control_service(const char *serv_name, const char *pop, int sec_type, void *priv_data); - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h deleted file mode 100644 index 11eecebcb1c..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_standard_types.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 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 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/********** STANDARD UI TYPES **********/ - -#define ESP_RMAKER_UI_TOGGLE "esp.ui.toggle" -#define ESP_RMAKER_UI_SLIDER "esp.ui.slider" -#define ESP_RMAKER_UI_DROPDOWN "esp.ui.dropdown" -#define ESP_RMAKER_UI_TEXT "esp.ui.text" -#define ESP_RMAKER_UI_HUE_SLIDER "esp.ui.hue-slider" - -/********** STANDARD PARAM TYPES **********/ - -#define ESP_RMAKER_PARAM_NAME "esp.param.name" -#define ESP_RMAKER_PARAM_POWER "esp.param.power" -#define ESP_RMAKER_PARAM_BRIGHTNESS "esp.param.brightness" -#define ESP_RMAKER_PARAM_HUE "esp.param.hue" -#define ESP_RMAKER_PARAM_SATURATION "esp.param.saturation" -#define ESP_RMAKER_PARAM_INTENSITY "esp.param.intensity" -#define ESP_RMAKER_PARAM_CCT "esp.param.cct" -#define ESP_RMAKER_PARAM_SPEED "esp.param.speed" -#define ESP_RMAKER_PARAM_DIRECTION "esp.param.direction" -#define ESP_RMAKER_PARAM_TEMPERATURE "esp.param.temperature" -#define ESP_RMAKER_PARAM_OTA_STATUS "esp.param.ota_status" -#define ESP_RMAKER_PARAM_OTA_INFO "esp.param.ota_info" -#define ESP_RMAKER_PARAM_OTA_URL "esp.param.ota_url" -#define ESP_RMAKER_PARAM_TIMEZONE "esp.param.tz" -#define ESP_RMAKER_PARAM_TIMEZONE_POSIX "esp.param.tz_posix" -#define ESP_RMAKER_PARAM_SCHEDULES "esp.param.schedules" -#define ESP_RMAKER_PARAM_REBOOT "esp.param.reboot" -#define ESP_RMAKER_PARAM_FACTORY_RESET "esp.param.factory-reset" -#define ESP_RMAKER_PARAM_WIFI_RESET "esp.param.wifi-reset" -#define ESP_RMAKER_PARAM_LOCAL_CONTROL_POP "esp.param.local_control_pop" -#define ESP_RMAKER_PARAM_LOCAL_CONTROL_TYPE "esp.param.local_control_type" - - -/********** STANDARD DEVICE TYPES **********/ - -#define ESP_RMAKER_DEVICE_SWITCH "esp.device.switch" -#define ESP_RMAKER_DEVICE_LIGHTBULB "esp.device.lightbulb" -#define ESP_RMAKER_DEVICE_FAN "esp.device.fan" -#define ESP_RMAKER_DEVICE_TEMP_SENSOR "esp.device.temperature-sensor" - - -/********** STANDARD SERVICE TYPES **********/ -#define ESP_RMAKER_SERVICE_OTA "esp.service.ota" -#define ESP_RMAKER_SERVICE_TIME "esp.service.time" -#define ESP_RMAKER_SERVICE_SCHEDULE "esp.service.schedule" -#define ESP_RMAKER_SERVICE_SYSTEM "esp.service.system" -#define ESP_RMAKER_SERVICE_LOCAL_CONTROL "esp.service.local_control" - -#ifdef __cplusplus -} -#endif diff --git a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h b/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h deleted file mode 100644 index 77a153b02f2..00000000000 --- a/tools/sdk/esp32/include/esp_rainmaker/include/esp_rmaker_user_mapping.h +++ /dev/null @@ -1,83 +0,0 @@ -// Copyright 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 - -#ifdef __cplusplus -extern "C" -{ -#endif - -/** User-Node Mapping states */ -typedef enum { - /** Mapping does not exist or is not initialized */ - ESP_RMAKER_USER_MAPPING_RESET = 0, - /** Mapping has started */ - ESP_RMAKER_USER_MAPPING_STARTED, - /** Mapping is done */ - ESP_RMAKER_USER_MAPPING_DONE, -} esp_rmaker_user_mapping_state_t; - -/** - * Get User-Node mapping state - * - * This returns the current user-node mapping state. - * - * @return user mapping state - */ -esp_rmaker_user_mapping_state_t esp_rmaker_user_node_mapping_get_state(void); - -/** - * Create User Mapping Endpoint - * - * This will create a custom provisioning endpoint for user-node mapping. - * This should be called after wifi_prov_mgr_init() but before - * wifi_prov_mgr_start_provisioning() - * - * @return ESP_OK on success - * @return error on failure - */ -esp_err_t esp_rmaker_user_mapping_endpoint_create(void); - -/** - * Register User Mapping Endpoint - * - * This will register the callback for the custom provisioning endpoint - * for user-node mapping which was created with esp_rmaker_user_mapping_endpoint_create(). - * This should be called immediately after wifi_prov_mgr_start_provisioning(). - * - * @return ESP_OK on success - * @return error on failure - */ -esp_err_t esp_rmaker_user_mapping_endpoint_register(void); - -/** Add User-Node mapping - * - * This call will start the user-node mapping workflow on the node. - * This is automatically called if you have used esp_rmaker_user_mapping_endpoint_register(). - * Use this API only if you want to trigger the user-node mapping after the Wi-Fi provisioning - * has already been done. - * - * @param[in] user_id The User identifier received from the client (Phone app/CLI) - * @param[in] secret_key The Secret key received from the client (Phone app/CLI) - * - * @return ESP_OK if the workflow was successfully triggered. This does not guarantee success - * of the actual mapping. The mapping status needs to be checked separately by the clients. - * @return error on failure. - */ -esp_err_t esp_rmaker_start_user_node_mapping(char *user_id, char *secret_key); - -#ifdef __cplusplus -} -#endif