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/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5d2027ff7e3..e593d80dd50 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,6 +3,7 @@ name: Unit Test Results on: workflow_run: workflows: [Run tests in hardware] + branches-ignore: [master] types: - completed @@ -11,6 +12,9 @@ jobs: unit-test-results: name: Unit Test Results runs-on: ubuntu-latest + if: | + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion != 'skipped' steps: - name: Download and Extract Artifacts env: diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b47fd9129d..23e6647cc7f 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(IDF_TARGET MATCHES "esp32" AND CONFIG_ESP_RMAKER_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/boards.txt b/boards.txt index 2a1fbf7022d..fe5f3b853e0 100755 --- a/boards.txt +++ b/boards.txt @@ -13017,4 +13017,4 @@ deneyapkart1A.menu.DebugLevel.debug.build.code_debug=4 deneyapkart1A.menu.DebugLevel.verbose=Verbose deneyapkart1A.menu.DebugLevel.verbose.build.code_debug=5 -############################################################## \ No newline at end of file +############################################################## 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/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index b69c58d358c..7a10fe161a1 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -37,7 +37,7 @@ void serialEvent(void) {} #ifndef RX1 #if CONFIG_IDF_TARGET_ESP32 #define RX1 9 -#elif CONFIG_IDF_TARGET_ESP32S2 +#elif CONFIG_IDF_TARGET_ESP32S2 #define RX1 18 #elif CONFIG_IDF_TARGET_ESP32C3 #define RX1 18 @@ -86,6 +86,8 @@ void serialEvent2(void) {} #if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SERIAL) #if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC HardwareSerial Serial0(0); +#elif ARDUINO_HW_CDC_ON_BOOT +HardwareSerial Serial0(0); #else HardwareSerial Serial(0); #endif @@ -100,6 +102,8 @@ void serialEventRun(void) { #if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC if(Serial0.available()) serialEvent(); +#elif ARDUINO_HW_CDC_ON_BOOT + if(Serial0.available()) serialEvent(); #else if(Serial.available()) serialEvent(); #endif diff --git a/cores/esp32/HardwareSerial.h b/cores/esp32/HardwareSerial.h index 03542b519cd..7a25b64e37f 100644 --- a/cores/esp32/HardwareSerial.h +++ b/cores/esp32/HardwareSerial.h @@ -156,10 +156,10 @@ extern void serialEventRun(void) __attribute__((weak)); #define ARDUINO_USB_CDC_ON_BOOT 0 #endif #if ARDUINO_USB_CDC_ON_BOOT //Serial used for USB CDC -#if !ARDUINO_USB_MODE #include "USB.h" #include "USBCDC.h" -#endif +extern HardwareSerial Serial0; +#elif ARDUINO_HW_CDC_ON_BOOT extern HardwareSerial Serial0; #else extern HardwareSerial Serial; diff --git a/cores/esp32/USBCDC.cpp b/cores/esp32/USBCDC.cpp index f9623ce5d1b..a48a7548094 100644 --- a/cores/esp32/USBCDC.cpp +++ b/cores/esp32/USBCDC.cpp @@ -114,11 +114,14 @@ void USBCDC::onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback } size_t USBCDC::setRxBufferSize(size_t rx_queue_len){ - if(rx_queue){ - if(!rx_queue_len){ + size_t currentQueueSize = rx_queue ? + uxQueueSpacesAvailable(rx_queue) + uxQueueMessagesWaiting(rx_queue) : 0; + + if (rx_queue && (!rx_queue_len || rx_queue_len != currentQueueSize)) { vQueueDelete(rx_queue); rx_queue = NULL; - } + } + if(!rx_queue_len || rx_queue_len == currentQueueSize){ return 0; } rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t)); @@ -133,7 +136,8 @@ void USBCDC::begin(unsigned long baud) if(tx_lock == NULL) { tx_lock = xSemaphoreCreateMutex(); } - setRxBufferSize(256);//default if not preset + // if rx_queue was set before begin(), keep it + if (!rx_queue) setRxBufferSize(256); //default if not preset devices[itf] = this; } @@ -144,6 +148,7 @@ void USBCDC::end() setRxBufferSize(0); if(tx_lock != NULL) { vSemaphoreDelete(tx_lock); + tx_lock = NULL; } } @@ -246,14 +251,27 @@ void USBCDC::_onLineCoding(uint32_t _bit_rate, uint8_t _stop_bits, uint8_t _pari void USBCDC::_onRX(){ uint8_t buf[CONFIG_TINYUSB_CDC_RX_BUFSIZE+1]; uint32_t count = tud_cdc_n_read(itf, buf, CONFIG_TINYUSB_CDC_RX_BUFSIZE); + + if(rx_queue == NULL) { + return; + } + if (uxQueueSpacesAvailable(rx_queue) < count) { + //this VTaskDelay gives, to Arduino's task, time to the CPU do its processing + //without it, data may be lost when the number of bytes received is higher than CDC buffer size + vTaskDelay(10); + } for(uint32_t i=0; i extern "C" { #include "lwip/ip_addr.h" 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 e7c77efbad5..d7e0e8fbd29 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -67,9 +67,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 6740f5db58e..00000000000 --- a/libraries/RainMaker/src/RMaker.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#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; diff --git a/libraries/RainMaker/src/RMaker.h b/libraries/RainMaker/src/RMaker.h deleted file mode 100644 index aea700e932f..00000000000 --- a/libraries/RainMaker/src/RMaker.h +++ /dev/null @@ -1,40 +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 "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; diff --git a/libraries/RainMaker/src/RMakerDevice.cpp b/libraries/RainMaker/src/RMakerDevice.cpp deleted file mode 100644 index ed9f6501abd..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.cpp +++ /dev/null @@ -1,206 +0,0 @@ -#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; -} diff --git a/libraries/RainMaker/src/RMakerDevice.h b/libraries/RainMaker/src/RMakerDevice.h deleted file mode 100644 index 3c57b4245fe..00000000000 --- a/libraries/RainMaker/src/RMakerDevice.h +++ /dev/null @@ -1,164 +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 "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"); - } - } -}; diff --git a/libraries/RainMaker/src/RMakerNode.cpp b/libraries/RainMaker/src/RMakerNode.cpp deleted file mode 100644 index 6d5dce3213b..00000000000 --- a/libraries/RainMaker/src/RMakerNode.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#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; -} diff --git a/libraries/RainMaker/src/RMakerNode.h b/libraries/RainMaker/src/RMakerNode.h deleted file mode 100644 index 81cc0e89616..00000000000 --- a/libraries/RainMaker/src/RMakerNode.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 "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); -}; diff --git a/libraries/RainMaker/src/RMakerParam.cpp b/libraries/RainMaker/src/RMakerParam.cpp deleted file mode 100644 index b1196aae955..00000000000 --- a/libraries/RainMaker/src/RMakerParam.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#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; -} diff --git a/libraries/RainMaker/src/RMakerParam.h b/libraries/RainMaker/src/RMakerParam.h deleted file mode 100644 index f0fce9d4cf8..00000000000 --- a/libraries/RainMaker/src/RMakerParam.h +++ /dev/null @@ -1,48 +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 "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); -}; diff --git a/libraries/RainMaker/src/RMakerQR.h b/libraries/RainMaker/src/RMakerQR.h deleted file mode 100644 index 5e0a87021de..00000000000 --- a/libraries/RainMaker/src/RMakerQR.h +++ /dev/null @@ -1,34 +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 "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); -} diff --git a/libraries/RainMaker/src/RMakerType.cpp b/libraries/RainMaker/src/RMakerType.cpp deleted file mode 100644 index 022c8afdb35..00000000000 --- a/libraries/RainMaker/src/RMakerType.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#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); -} diff --git a/libraries/RainMaker/src/RMakerType.h b/libraries/RainMaker/src/RMakerType.h deleted file mode 100644 index 60a01475826..00000000000 --- a/libraries/RainMaker/src/RMakerType.h +++ /dev/null @@ -1,33 +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 "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); diff --git a/libraries/RainMaker/src/RMakerUtils.h b/libraries/RainMaker/src/RMakerUtils.h deleted file mode 100644 index 405e725a333..00000000000 --- a/libraries/RainMaker/src/RMakerUtils.h +++ /dev/null @@ -1,26 +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 "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); -} 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/esp32c3/ld/esp32c3.rom.ld b/tools/sdk/esp32c3/ld/esp32c3.rom.ld index db1a6ac02c9..471fc1c1a9f 100644 --- a/tools/sdk/esp32c3/ld/esp32c3.rom.ld +++ b/tools/sdk/esp32c3/ld/esp32c3.rom.ld @@ -1067,6 +1067,7 @@ r_lld_con_tx_prog = 0x40001140; r_lld_conn_dynamic_pti_process = 0x40001144; r_lld_continue_scan_rx_isr_end_process = 0x40001148; r_lld_ext_scan_dynamic_pti_process = 0x4000114c; +r_lld_ext_adv_dynamic_aux_pti_process = 0x40001b44; r_lld_hw_cca_end_isr = 0x40001150; r_lld_hw_cca_evt_handler = 0x40001154; r_lld_hw_cca_isr = 0x40001158; @@ -1896,7 +1897,7 @@ rom_read_sar2_code = 0x40001aa4; rom_get_sar2_vol = 0x40001aa8; rom_get_pll_vol = 0x40001aac; rom_get_phy_target_power = 0x40001ab0; -/* rom_temp_to_power = 0x40001ab4; */ +rom_temp_to_power = 0x40001ab4; rom_phy_track_pll_cap = 0x40001ab8; rom_phy_pwdet_always_en = 0x40001abc; rom_phy_pwdet_onetime_en = 0x40001ac0; diff --git a/variants/adafruit_feather_esp32_v2/pins_arduino.h b/variants/adafruit_feather_esp32_v2/pins_arduino.h index f984baf5aa2..97a09dba233 100644 --- a/variants/adafruit_feather_esp32_v2/pins_arduino.h +++ b/variants/adafruit_feather_esp32_v2/pins_arduino.h @@ -42,20 +42,19 @@ static const uint8_t A9 = 33; static const uint8_t A10 = 27; static const uint8_t A11 = 12; static const uint8_t A12 = 13; +static const uint8_t A13 = 35; // vbat measure -static const uint8_t BATT_MONITOR = 35; -static const uint8_t A13 = 35; +#define BATT_MONITOR 35 // internal switch -static const uint8_t BUTTON = 38; +#define BUTTON = 38; // Neopixel -static const uint8_t NEOPIXEL_PIN = 0; -static const uint8_t PIN_NEOPIXEL = 0; +#define PIN_NEOPIXEL 0 // Neopixel & I2C power -static const uint8_t NEOPIXEL_I2C_POWER = 2; +#define NEOPIXEL_I2C_POWER 2 static const uint8_t T0 = 4; static const uint8_t T1 = 0; diff --git a/variants/adafruit_feather_esp32s2/variant.cpp b/variants/adafruit_feather_esp32s2/variant.cpp index 97e26fb9c60..069f735161d 100644 --- a/variants/adafruit_feather_esp32s2/variant.cpp +++ b/variants/adafruit_feather_esp32s2/variant.cpp @@ -36,10 +36,11 @@ void initVariant(void) pinMode(NEOPIXEL_POWER, OUTPUT); digitalWrite(NEOPIXEL_POWER, HIGH); - // This board has a power control pin, and we must set it to output and low - // in order to enable the I2C port. + // turn on the I2C power by setting pin to opposite of 'rest state' + pinMode(PIN_I2C_POWER, INPUT); + delay(1); + bool polarity = digitalRead(PIN_I2C_POWER); pinMode(PIN_I2C_POWER, OUTPUT); - digitalWrite(PIN_I2C_POWER, LOW); + digitalWrite(PIN_I2C_POWER, !polarity); } - } diff --git a/variants/adafruit_qtpy_esp32c3/pins_arduino.h b/variants/adafruit_qtpy_esp32c3/pins_arduino.h index c0f1aefc8ce..6c93bfd5820 100644 --- a/variants/adafruit_qtpy_esp32c3/pins_arduino.h +++ b/variants/adafruit_qtpy_esp32c3/pins_arduino.h @@ -11,8 +11,8 @@ #define digitalPinToInterrupt(p) (((p)