Unverified Commit e7d3a2fb authored by Me No Dev's avatar Me No Dev Committed by GitHub

Merge branch 'master' into release/v2.x

parents 93903fc3 bef8a75e
......@@ -1012,6 +1012,9 @@ esp32wrover.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32wrover.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
esp32wrover.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS)
esp32wrover.menu.PartitionScheme.fatflash.build.partitions=ffat
esp32wrover.menu.PartitionScheme.rainmaker=RainMaker
esp32wrover.menu.PartitionScheme.rainmaker.build.partitions=rainmaker
esp32wrover.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728
esp32wrover.menu.FlashMode.qio=QIO
esp32wrover.menu.FlashMode.qio.build.flash_mode=dio
......@@ -1238,6 +1241,9 @@ esp32s3box.menu.PartitionScheme.fatflash.upload.maximum_size=2097152
esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB=16M Flash (3MB APP/9.9MB FATFS)
esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB.build.partitions=app3M_fat9M_16MB
esp32s3box.menu.PartitionScheme.app3M_fat9M_16MB.upload.maximum_size=3145728
esp32s3box.menu.PartitionScheme.rainmaker=RainMaker
esp32s3box.menu.PartitionScheme.rainmaker.build.partitions=rainmaker
esp32s3box.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728
esp32s3box.menu.DebugLevel.none=None
esp32s3box.menu.DebugLevel.none.build.code_debug=0
......@@ -1686,6 +1692,9 @@ esp32wroverkit.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
esp32wroverkit.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
esp32wroverkit.menu.PartitionScheme.fatflash=16M Flash (2MB APP/12.5MB FATFS)
esp32wroverkit.menu.PartitionScheme.fatflash.build.partitions=ffat
esp32wroverkit.menu.PartitionScheme.rainmaker=RainMaker
esp32wroverkit.menu.PartitionScheme.rainmaker.build.partitions=rainmaker
esp32wroverkit.menu.PartitionScheme.rainmaker.upload.maximum_size=3145728
esp32wroverkit.menu.FlashMode.qio=QIO
esp32wroverkit.menu.FlashMode.qio.build.flash_mode=dio
esp32wroverkit.menu.FlashMode.qio.build.boot=qio
......@@ -12109,6 +12118,198 @@ m5stack-coreink.menu.EraseFlash.all.upload.erase_cmd=-e
##############################################################
stamp-s3.name=STAMP-S3
stamp-s3.vid.0=0x303a
stamp-s3.pid.0=0x1001
stamp-s3.bootloader.tool=esptool_py
stamp-s3.bootloader.tool.default=esptool_py
stamp-s3.upload.tool=esptool_py
stamp-s3.upload.tool.default=esptool_py
stamp-s3.upload.tool.network=esp_ota
stamp-s3.upload.maximum_size=1310720
stamp-s3.upload.maximum_data_size=327680
stamp-s3.upload.flags=
stamp-s3.upload.extra_flags=
stamp-s3.upload.use_1200bps_touch=false
stamp-s3.upload.wait_for_upload_port=false
stamp-s3.serial.disableDTR=false
stamp-s3.serial.disableRTS=false
stamp-s3.build.tarch=xtensa
stamp-s3.build.bootloader_addr=0x0
stamp-s3.build.target=esp32s3
stamp-s3.build.mcu=esp32s3
stamp-s3.build.core=esp32
stamp-s3.build.variant=m5stack_stamp_s3
stamp-s3.build.board=STAMP_S3
stamp-s3.build.usb_mode=1
stamp-s3.build.cdc_on_boot=0
stamp-s3.build.msc_on_boot=0
stamp-s3.build.dfu_on_boot=0
stamp-s3.build.f_cpu=240000000L
stamp-s3.build.flash_size=4MB
stamp-s3.build.flash_freq=80m
stamp-s3.build.flash_mode=dio
stamp-s3.build.boot=qio
stamp-s3.build.boot_freq=80m
stamp-s3.build.partitions=default
stamp-s3.build.defines=
stamp-s3.build.loop_core=
stamp-s3.build.event_core=
stamp-s3.build.psram_type=qspi
stamp-s3.build.memory_type={build.boot}_{build.psram_type}
stamp-s3.menu.JTAGAdapter.default=Disabled
stamp-s3.menu.JTAGAdapter.default.build.copy_jtag_files=0
stamp-s3.menu.JTAGAdapter.builtin=Integrated USB JTAG
stamp-s3.menu.JTAGAdapter.builtin.build.openocdscript=esp32s3-builtin.cfg
stamp-s3.menu.JTAGAdapter.builtin.build.copy_jtag_files=1
stamp-s3.menu.JTAGAdapter.external=FTDI Adapter
stamp-s3.menu.JTAGAdapter.external.build.openocdscript=esp32s3-ftdi.cfg
stamp-s3.menu.JTAGAdapter.external.build.copy_jtag_files=1
stamp-s3.menu.JTAGAdapter.bridge=ESP USB Bridge
stamp-s3.menu.JTAGAdapter.bridge.build.openocdscript=esp32s3-bridge.cfg
stamp-s3.menu.JTAGAdapter.bridge.build.copy_jtag_files=1
stamp-s3.menu.PSRAM.disabled=Disabled
stamp-s3.menu.PSRAM.disabled.build.defines=
stamp-s3.menu.PSRAM.disabled.build.psram_type=qspi
stamp-s3.menu.PSRAM.enabled=QSPI PSRAM
stamp-s3.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM
stamp-s3.menu.PSRAM.enabled.build.psram_type=qspi
stamp-s3.menu.PSRAM.opi=OPI PSRAM
stamp-s3.menu.PSRAM.opi.build.defines=-DBOARD_HAS_PSRAM
stamp-s3.menu.PSRAM.opi.build.psram_type=opi
stamp-s3.menu.FlashMode.qio=QIO 80MHz
stamp-s3.menu.FlashMode.qio.build.flash_mode=dio
stamp-s3.menu.FlashMode.qio.build.boot=qio
stamp-s3.menu.FlashMode.qio.build.boot_freq=80m
stamp-s3.menu.FlashMode.qio.build.flash_freq=80m
stamp-s3.menu.FlashMode.qio120=QIO 120MHz
stamp-s3.menu.FlashMode.qio120.build.flash_mode=dio
stamp-s3.menu.FlashMode.qio120.build.boot=qio
stamp-s3.menu.FlashMode.qio120.build.boot_freq=120m
stamp-s3.menu.FlashMode.qio120.build.flash_freq=80m
stamp-s3.menu.FlashMode.dio=DIO 80MHz
stamp-s3.menu.FlashMode.dio.build.flash_mode=dio
stamp-s3.menu.FlashMode.dio.build.boot=dio
stamp-s3.menu.FlashMode.dio.build.boot_freq=80m
stamp-s3.menu.FlashMode.dio.build.flash_freq=80m
stamp-s3.menu.FlashMode.opi=OPI 80MHz
stamp-s3.menu.FlashMode.opi.build.flash_mode=dout
stamp-s3.menu.FlashMode.opi.build.boot=opi
stamp-s3.menu.FlashMode.opi.build.boot_freq=80m
stamp-s3.menu.FlashMode.opi.build.flash_freq=80m
stamp-s3.menu.FlashSize.4M=4MB (32Mb)
stamp-s3.menu.FlashSize.4M.build.flash_size=4MB
stamp-s3.menu.FlashSize.8M=8MB (64Mb)
stamp-s3.menu.FlashSize.8M.build.flash_size=8MB
stamp-s3.menu.FlashSize.8M.build.partitions=default_8MB
stamp-s3.menu.FlashSize.16M=16MB (128Mb)
stamp-s3.menu.FlashSize.16M.build.flash_size=16MB
#stamp-s3.menu.FlashSize.32M=32MB (256Mb)
#stamp-s3.menu.FlashSize.32M.build.flash_size=32MB
stamp-s3.menu.LoopCore.1=Core 1
stamp-s3.menu.LoopCore.1.build.loop_core=-DARDUINO_RUNNING_CORE=1
stamp-s3.menu.LoopCore.0=Core 0
stamp-s3.menu.LoopCore.0.build.loop_core=-DARDUINO_RUNNING_CORE=0
stamp-s3.menu.EventsCore.1=Core 1
stamp-s3.menu.EventsCore.1.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=1
stamp-s3.menu.EventsCore.0=Core 0
stamp-s3.menu.EventsCore.0.build.event_core=-DARDUINO_EVENT_RUNNING_CORE=0
stamp-s3.menu.USBMode.hwcdc=Hardware CDC and JTAG
stamp-s3.menu.USBMode.hwcdc.build.usb_mode=1
stamp-s3.menu.USBMode.default=USB-OTG (TinyUSB)
stamp-s3.menu.USBMode.default.build.usb_mode=0
stamp-s3.menu.CDCOnBoot.default=Disabled
stamp-s3.menu.CDCOnBoot.default.build.cdc_on_boot=0
stamp-s3.menu.CDCOnBoot.cdc=Enabled
stamp-s3.menu.CDCOnBoot.cdc.build.cdc_on_boot=1
stamp-s3.menu.MSCOnBoot.default=Disabled
stamp-s3.menu.MSCOnBoot.default.build.msc_on_boot=0
stamp-s3.menu.MSCOnBoot.msc=Enabled (Requires USB-OTG Mode)
stamp-s3.menu.MSCOnBoot.msc.build.msc_on_boot=1
stamp-s3.menu.DFUOnBoot.default=Disabled
stamp-s3.menu.DFUOnBoot.default.build.dfu_on_boot=0
stamp-s3.menu.DFUOnBoot.dfu=Enabled (Requires USB-OTG Mode)
stamp-s3.menu.DFUOnBoot.dfu.build.dfu_on_boot=1
stamp-s3.menu.UploadMode.default=UART0 / Hardware CDC
stamp-s3.menu.UploadMode.default.upload.use_1200bps_touch=false
stamp-s3.menu.UploadMode.default.upload.wait_for_upload_port=false
stamp-s3.menu.UploadMode.cdc=USB-OTG CDC (TinyUSB)
stamp-s3.menu.UploadMode.cdc.upload.use_1200bps_touch=true
stamp-s3.menu.UploadMode.cdc.upload.wait_for_upload_port=true
stamp-s3.menu.PartitionScheme.default=Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS)
stamp-s3.menu.PartitionScheme.default.build.partitions=default
stamp-s3.menu.PartitionScheme.defaultffat=Default 4MB with ffat (1.2MB APP/1.5MB FATFS)
stamp-s3.menu.PartitionScheme.defaultffat.build.partitions=default_ffat
stamp-s3.menu.PartitionScheme.default_8MB=8M with spiffs (3MB APP/1.5MB SPIFFS)
stamp-s3.menu.PartitionScheme.default_8MB.build.partitions=default_8MB
stamp-s3.menu.PartitionScheme.default_8MB.upload.maximum_size=3342336
stamp-s3.menu.CPUFreq.240=240MHz (WiFi)
stamp-s3.menu.CPUFreq.240.build.f_cpu=240000000L
stamp-s3.menu.CPUFreq.160=160MHz (WiFi)
stamp-s3.menu.CPUFreq.160.build.f_cpu=160000000L
stamp-s3.menu.CPUFreq.80=80MHz (WiFi)
stamp-s3.menu.CPUFreq.80.build.f_cpu=80000000L
stamp-s3.menu.CPUFreq.40=40MHz
stamp-s3.menu.CPUFreq.40.build.f_cpu=40000000L
stamp-s3.menu.CPUFreq.20=20MHz
stamp-s3.menu.CPUFreq.20.build.f_cpu=20000000L
stamp-s3.menu.CPUFreq.10=10MHz
stamp-s3.menu.CPUFreq.10.build.f_cpu=10000000L
stamp-s3.menu.UploadSpeed.921600=921600
stamp-s3.menu.UploadSpeed.921600.upload.speed=921600
stamp-s3.menu.UploadSpeed.115200=115200
stamp-s3.menu.UploadSpeed.115200.upload.speed=115200
stamp-s3.menu.UploadSpeed.256000.windows=256000
stamp-s3.menu.UploadSpeed.256000.upload.speed=256000
stamp-s3.menu.UploadSpeed.230400.windows.upload.speed=256000
stamp-s3.menu.UploadSpeed.230400=230400
stamp-s3.menu.UploadSpeed.230400.upload.speed=230400
stamp-s3.menu.UploadSpeed.460800.linux=460800
stamp-s3.menu.UploadSpeed.460800.macosx=460800
stamp-s3.menu.UploadSpeed.460800.upload.speed=460800
stamp-s3.menu.UploadSpeed.512000.windows=512000
stamp-s3.menu.UploadSpeed.512000.upload.speed=512000
stamp-s3.menu.DebugLevel.none=None
stamp-s3.menu.DebugLevel.none.build.code_debug=0
stamp-s3.menu.DebugLevel.error=Error
stamp-s3.menu.DebugLevel.error.build.code_debug=1
stamp-s3.menu.DebugLevel.warn=Warn
stamp-s3.menu.DebugLevel.warn.build.code_debug=2
stamp-s3.menu.DebugLevel.info=Info
stamp-s3.menu.DebugLevel.info.build.code_debug=3
stamp-s3.menu.DebugLevel.debug=Debug
stamp-s3.menu.DebugLevel.debug.build.code_debug=4
stamp-s3.menu.DebugLevel.verbose=Verbose
stamp-s3.menu.DebugLevel.verbose.build.code_debug=5
stamp-s3.menu.EraseFlash.none=Disabled
stamp-s3.menu.EraseFlash.none.upload.erase_cmd=
stamp-s3.menu.EraseFlash.all=Enabled
stamp-s3.menu.EraseFlash.all.upload.erase_cmd=-e
##############################################################
odroid_esp32.name=ODROID ESP32
odroid_esp32.bootloader.tool=esptool_py
......
......@@ -269,17 +269,25 @@ const char * EspClass::getChipModel(void)
uint32_t pkg_ver = chip_ver & 0x7;
switch (pkg_ver) {
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ6 :
return "ESP32-D0WDQ6";
if (getChipRevision() == 3)
return "ESP32-D0WDQ6-V3";
else
return "ESP32-D0WDQ6";
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDQ5 :
return "ESP32-D0WDQ5";
if (getChipRevision() == 3)
return "ESP32-D0WD-V3";
else
return "ESP32-D0WD";
case EFUSE_RD_CHIP_VER_PKG_ESP32D2WDQ5 :
return "ESP32-D2WDQ5";
return "ESP32-D2WD";
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD2 :
return "ESP32-PICO-D2";
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOD4 :
return "ESP32-PICO-D4";
case EFUSE_RD_CHIP_VER_PKG_ESP32PICOV302 :
return "ESP32-PICO-V3-02";
case EFUSE_RD_CHIP_VER_PKG_ESP32D0WDR2V3 :
return "ESP32-D0WDR2-V3";
default:
return "Unknown";
}
......
......@@ -25,6 +25,34 @@ extern "C" {
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#ifdef __cplusplus
enum SerialConfig {
SERIAL_5N1 = 0x8000010,
SERIAL_6N1 = 0x8000014,
SERIAL_7N1 = 0x8000018,
SERIAL_8N1 = 0x800001c,
SERIAL_5N2 = 0x8000030,
SERIAL_6N2 = 0x8000034,
SERIAL_7N2 = 0x8000038,
SERIAL_8N2 = 0x800003c,
SERIAL_5E1 = 0x8000012,
SERIAL_6E1 = 0x8000016,
SERIAL_7E1 = 0x800001a,
SERIAL_8E1 = 0x800001e,
SERIAL_5E2 = 0x8000032,
SERIAL_6E2 = 0x8000036,
SERIAL_7E2 = 0x800003a,
SERIAL_8E2 = 0x800003e,
SERIAL_5O1 = 0x8000013,
SERIAL_6O1 = 0x8000017,
SERIAL_7O1 = 0x800001b,
SERIAL_8O1 = 0x800001f,
SERIAL_5O2 = 0x8000033,
SERIAL_6O2 = 0x8000037,
SERIAL_7O2 = 0x800003b,
SERIAL_8O2 = 0x800003f
};
#else
#define SERIAL_5N1 0x8000010
#define SERIAL_6N1 0x8000014
#define SERIAL_7N1 0x8000018
......@@ -49,6 +77,7 @@ extern "C" {
#define SERIAL_6O2 0x8000037
#define SERIAL_7O2 0x800003b
#define SERIAL_8O2 0x800003f
#endif // __cplusplus
// These are Hardware Flow Contol possible usage
// equivalent to UDF enum uart_hw_flowcontrol_t from
......
......@@ -13,13 +13,13 @@ Examples
ESP-NOW Master
**************
.. literalinclude:: ../../../libraries/ESP32/examples/ESPNow/Basic/Master/Master.ino
.. literalinclude:: ../../../libraries/ESP32/examples/ESPNow/ESPNow_Basic_Master/ESPNow_Basic_Master.ino
:language: arduino
ESP-NOW Slave
*************
.. literalinclude:: ../../../libraries/ESP32/examples/ESPNow/Basic/Slave/Slave.ino
.. literalinclude:: ../../../libraries/ESP32/examples/ESPNow/ESPNow_Basic_Slave/ESPNow_Basic_Slave.ino
:language: arduino
Resources
......
......@@ -578,7 +578,7 @@ Copy a series of bytes stored against a given key in the currently open namespac
- the number of bytes to be written to the buffer pointed to by ``buf``
**Returns**
* if successful, the number of bytes equal to ``len`` is written to buffer ``buf``, and the method returns ``1``.
* if successful, the number of bytes equal to ``len`` is written to buffer ``buf``, and the method returns ``len``.
* if the method fails, nothing is written to the buffer and the method returns ``0``.
**Notes**
......@@ -698,4 +698,4 @@ Get the number of free entries available in the key table of the currently open
* A message providing the reason for a failed call is sent to the arduino-esp32 ``log_e`` facility.
.. --- EOF ----
\ No newline at end of file
.. --- EOF ----
......@@ -139,6 +139,26 @@ This function will return
1. `ESP_OK` : On success
2. Error in case of failure
RMaker.enableSystemService
**************************
This API enables the System service for the node. It should be called after `RMaker.initNode()` and before `RMaker.start()`.
For more information, check `here <https://rainmaker.espressif.com/docs/sys-service.html>`__.
.. code-block:: arduino
esp_err_t enableSystemService(uint16_t flags, int8_t reboot_seconds, int8_t reset_seconds, int8_t reset_reboot_seconds)
* ``flags`` : 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.
* ``reboot_seconds`` Time in seconds after which the device should reboot. Recommended value: 2
* ``reset_seconds`` Time in seconds after which the device should reset(Wi-Fi or Factory). Recommended value: 2
* ``reset_reboot_seconds`` Time in seconds after which the device should reboot after it has been reset. Zero as a value would mean there won't be any reboot after the reset. Recommended value: 2
This function will return
1. `ESP_OK` : On success
2. Error in case of failure
RMaker.setTimeZone
******************
......
......@@ -562,8 +562,8 @@ static esp_err_t stream_handler(httpd_req_t *req)
httpd_resp_set_hdr(req, "X-Framerate", "60");
#if CONFIG_LED_ILLUMINATOR_ENABLED
enable_led(true);
isStreaming = true;
enable_led(true);
#endif
while (true)
......
......@@ -619,7 +619,21 @@ int HTTPClient::sendRequest(const char * type, uint8_t * payload, size_t size)
// send Payload if needed
if(payload && size > 0) {
if(_client->write(&payload[0], size) != size) {
size_t sent_bytes = 0;
while(sent_bytes < size){
size_t sent = _client->write(&payload[sent_bytes], size - sent_bytes);
if (sent == 0){
log_w("Failed to send chunk! Lets wait a bit");
delay(100);
sent = _client->write(&payload[sent_bytes], size - sent_bytes);
if (sent == 0){
log_e("Failed to send chunk!");
break;
}
}
sent_bytes += sent;
}
if(sent_bytes != size){
return returnError(HTTPC_ERROR_SEND_PAYLOAD_FAILED);
}
}
......
......@@ -106,7 +106,9 @@ void loop() {
// value is used to put the LED on. If the LED is on with HIGH, that value should be passed
// httpUpdate.setLedPin(LED_BUILTIN, HIGH);
t_httpUpdate_return ret = httpUpdate.update(client, "https://server/file.bin");
t_httpUpdate_return ret = httpUpdate.update(client, "https://server/file.bin", "", [](HTTPClient *client) {
client->setAuthorization("test", "password");
});
// Or:
//t_httpUpdate_return ret = httpUpdate.update(client, "server", 443, "/file.bin");
......
......@@ -48,46 +48,46 @@ HTTPUpdate::~HTTPUpdate(void)
{
}
HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const String& currentVersion)
HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const String& currentVersion, HTTPUpdateRequestCB requestCB)
{
HTTPClient http;
if(!http.begin(client, url))
{
return HTTP_UPDATE_FAILED;
}
return handleUpdate(http, currentVersion, false);
return handleUpdate(http, currentVersion, false, requestCB);
}
HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& currentVersion)
HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& currentVersion, HTTPUpdateRequestCB requestCB)
{
return handleUpdate(httpClient, currentVersion, true);
return handleUpdate(httpClient, currentVersion, true, requestCB);
}
HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion)
HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion, HTTPUpdateRequestCB requestCB)
{
HTTPClient http;
if(!http.begin(client, url))
{
return HTTP_UPDATE_FAILED;
}
return handleUpdate(http, currentVersion, true);
return handleUpdate(http, currentVersion, true, requestCB);
}
HTTPUpdateResult HTTPUpdate::update(HTTPClient& httpClient,
const String& currentVersion)
const String& currentVersion, HTTPUpdateRequestCB requestCB)
{
return handleUpdate(httpClient, currentVersion, false);
return handleUpdate(httpClient, currentVersion, false, requestCB);
}
HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& host, uint16_t port, const String& uri,
const String& currentVersion)
const String& currentVersion, HTTPUpdateRequestCB requestCB)
{
HTTPClient http;
if(!http.begin(client, host, port, uri))
{
return HTTP_UPDATE_FAILED;
}
return handleUpdate(http, currentVersion, false);
return handleUpdate(http, currentVersion, false, requestCB);
}
/**
......@@ -180,7 +180,7 @@ String getSketchSHA256() {
* @param currentVersion const char *
* @return HTTPUpdateResult
*/
HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs)
HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs, HTTPUpdateRequestCB requestCB)
{
HTTPUpdateResult ret = HTTP_UPDATE_FAILED;
......@@ -216,6 +216,9 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
if(currentVersion && currentVersion[0] != 0x00) {
http.addHeader("x-ESP32-version", currentVersion);
}
if (requestCB) {
requestCB(&http);
}
const char * headerkeys[] = { "x-MD5" };
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
......
......@@ -53,6 +53,7 @@ enum HTTPUpdateResult {
typedef HTTPUpdateResult t_httpUpdate_return; // backward compatibility
using HTTPUpdateStartCB = std::function<void()>;
using HTTPUpdateRequestCB = std::function<void(HTTPClient*)>;
using HTTPUpdateEndCB = std::function<void()>;
using HTTPUpdateErrorCB = std::function<void(int)>;
using HTTPUpdateProgressCB = std::function<void(int, int)>;
......@@ -84,17 +85,18 @@ public:
_ledOn = ledOn;
}
t_httpUpdate_return update(WiFiClient& client, const String& url, const String& currentVersion = "");
t_httpUpdate_return update(WiFiClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return update(WiFiClient& client, const String& host, uint16_t port, const String& uri = "/",
const String& currentVersion = "");
const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = "");
t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return update(HTTPClient& httpClient,
const String& currentVersion = "");
const String& currentVersion = "",
HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String &currentVersion = "");
t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
// Notification callbacks
void onStart(HTTPUpdateStartCB cbOnStart) { _cbStart = cbOnStart; }
......@@ -106,7 +108,7 @@ public:
String getLastErrorString(void);
protected:
t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false);
t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false, HTTPUpdateRequestCB requestCB = NULL);
bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH);
// Set the error and potentially use a CB to notify the application
......
......@@ -22,27 +22,27 @@ 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);
static Device *my_device = NULL;
void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#endif
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
}
}
......@@ -51,8 +51,8 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
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);
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);
......@@ -71,22 +71,25 @@ void setup()
Node my_node;
my_node = RMaker.initNode("ESP RainMaker Node");
my_device = new Device("Dimmer", "custom.device.dimmer", &gpio_dimmer);
if (!my_device) {
return;
}
//Create custom dimmer device
my_device.addNameParam();
my_device.addPowerParam(DEFAULT_POWER_MODE);
my_device.assignPrimaryParam(my_device.getParamByName(ESP_RMAKER_DEF_POWER_NAME));
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->addParam(level_param);
my_device.addCb(write_callback);
my_device->addCb(write_callback);
//Add custom dimmer device to the node
my_node.addDevice(my_device);
my_node.addDevice(*my_device);
//This is optional
RMaker.enableOTA(OTA_USING_TOPICS);
......@@ -112,29 +115,33 @@ void setup()
void loop()
{
if(digitalRead(gpio_0) == LOW) { //Push button pressed
if (digitalRead(gpio_0) == LOW) { //Push button pressed
// Key debounce handling
delay(100);
int startTime = millis();
while(digitalRead(gpio_0) == LOW) delay(50);
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);
// 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);
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);
}
// Toggle device state
dimmer_state = !dimmer_state;
Serial.printf("Toggle State to %s.\n", dimmer_state ? "true" : "false");
if (my_device) {
my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, dimmer_state);
}
(dimmer_state == false) ? digitalWrite(gpio_dimmer, LOW) : digitalWrite(gpio_dimmer, HIGH);
}
}
delay(100);
}
......@@ -39,27 +39,27 @@ bool power_state = true;
// The framework provides some standard device types like switch, lightbulb, fan, temperature sensor.
// But, you can also define custom devices using the 'Device' base class object, as shown here
static Device my_device("Air Cooler", "my.device.air-cooler", NULL);
static Device *my_device = NULL;
void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
#endif
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
}
}
......@@ -68,13 +68,13 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
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);
if (strcmp(param_name, "Power") == 0) {
Serial.printf("Received value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name);
power_state = val.val.b;
(power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH);
param->updateAndReport(val);
} else if (strcmp(param_name, "Swing") == 0) {
Serial.printf("\nReceived value = %s for %s - %s\n", val.val.b? "true" : "false", device_name, param_name);
Serial.printf("\nReceived value = %s for %s - %s\n", val.val.b ? "true" : "false", device_name, param_name);
bool swing = val.val.b;
(swing == false) ? digitalWrite(gpio_swing, LOW) : digitalWrite(gpio_swing, HIGH);
param->updateAndReport(val);
......@@ -84,7 +84,7 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
analogWrite(gpio_speed, speed);
param->updateAndReport(val);
} else if (strcmp(param_name, "Mode") == 0) {
const char* mode = val.val.s;
const char *mode = val.val.s;
if (strcmp(mode, "Auto") == 0) {
digitalWrite(gpio_mode_auto, HIGH);
digitalWrite(gpio_mode_heat, LOW);
......@@ -112,41 +112,50 @@ void setup()
pinMode(gpio_swing, OUTPUT);
digitalWrite(gpio_swing, DEFAULT_SWING);
pinMode(gpio_mode_auto, OUTPUT);
if (strcmp(DEFAULT_MODE, "Auto") == 0) digitalWrite(gpio_mode_auto, HIGH);
if (strcmp(DEFAULT_MODE, "Auto") == 0) {
digitalWrite(gpio_mode_auto, HIGH);
}
pinMode(gpio_mode_cool, OUTPUT);
if (strcmp(DEFAULT_MODE, "Cool") == 0) digitalWrite(gpio_mode_auto, HIGH);
if (strcmp(DEFAULT_MODE, "Cool") == 0) {
digitalWrite(gpio_mode_auto, HIGH);
}
pinMode(gpio_mode_heat, OUTPUT);
if (strcmp(DEFAULT_MODE, "Heat") == 0) digitalWrite(gpio_mode_auto, HIGH);
if (strcmp(DEFAULT_MODE, "Heat") == 0) {
digitalWrite(gpio_mode_auto, HIGH);
}
pinMode(gpio_speed, OUTPUT);
analogWrite(gpio_speed, DEFAULT_SPEED);
Node my_node;
my_node = RMaker.initNode("ESP RainMaker Node");
my_device = new Device("Air Cooler", "my.device.air-cooler", NULL);
if (!my_device) {
return;
}
//Create custom air cooler device
my_device.addNameParam();
my_device.addPowerParam(DEFAULT_POWER_MODE);
my_device.assignPrimaryParam(my_device.getParamByName(ESP_RMAKER_DEF_POWER_NAME));
my_device->addNameParam();
my_device->addPowerParam(DEFAULT_POWER_MODE);
my_device->assignPrimaryParam(my_device->getParamByName(ESP_RMAKER_DEF_POWER_NAME));
Param swing("Swing", ESP_RMAKER_PARAM_TOGGLE, value(DEFAULT_SWING), PROP_FLAG_READ | PROP_FLAG_WRITE);
swing.addUIType(ESP_RMAKER_UI_TOGGLE);
my_device.addParam(swing);
my_device->addParam(swing);
Param speed("Speed", ESP_RMAKER_PARAM_RANGE, value(DEFAULT_SPEED), PROP_FLAG_READ | PROP_FLAG_WRITE);
speed.addUIType(ESP_RMAKER_UI_SLIDER);
speed.addBounds(value(0), value(255), value(1));
my_device.addParam(speed);
my_device->addParam(speed);
static const char* modes[] = { "Auto", "Cool", "Heat" };
static const char *modes[] = { "Auto", "Cool", "Heat" };
Param mode_param("Mode", ESP_RMAKER_PARAM_MODE, value("Auto"), PROP_FLAG_READ | PROP_FLAG_WRITE);
mode_param.addValidStrList(modes, 3);
mode_param.addUIType(ESP_RMAKER_UI_DROPDOWN);
my_device.addParam(mode_param);
my_device->addParam(mode_param);
my_device.addCb(write_callback);
my_device->addCb(write_callback);
//Add custom Air Cooler device to the node
my_node.addDevice(my_device);
my_node.addDevice(*my_device);
//This is optional
// RMaker.enableOTA(OTA_USING_TOPICS);
......@@ -172,29 +181,33 @@ void setup()
void loop()
{
if(digitalRead(gpio_reset) == LOW) { //Push button pressed
if (digitalRead(gpio_reset) == LOW) { //Push button pressed
// Key debounce handling
delay(100);
int startTime = millis();
while(digitalRead(gpio_reset) == LOW) delay(50);
while (digitalRead(gpio_reset) == LOW) {
delay(50);
}
int press_duration = millis() - startTime;
if (press_duration > 10000) {
// If key pressed for more than 10secs, reset all
Serial.printf("Reset to factory.\n");
RMakerFactoryReset(2);
// If key pressed for more than 10secs, reset all
Serial.printf("Reset to factory.\n");
RMakerFactoryReset(2);
} else if (press_duration > 3000) {
Serial.printf("Reset Wi-Fi.\n");
// If key pressed for more than 3secs, but less than 10, reset Wi-Fi
RMakerWiFiReset(2);
Serial.printf("Reset Wi-Fi.\n");
// If key pressed for more than 3secs, but less than 10, reset Wi-Fi
RMakerWiFiReset(2);
} else {
// Toggle device state
power_state = !power_state;
Serial.printf("Toggle power state to %s.\n", power_state ? "true" : "false");
my_device.updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, power_state);
(power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH);
}
// Toggle device state
power_state = !power_state;
Serial.printf("Toggle power state to %s.\n", power_state ? "true" : "false");
if (my_device) {
my_device->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, power_state);
}
(power_state == false) ? digitalWrite(gpio_power, LOW) : digitalWrite(gpio_power, HIGH);
}
}
delay(100);
}
......@@ -31,32 +31,32 @@ 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;
static Switch my_switch2;
static Switch *my_switch1 = NULL;
static Switch *my_switch2 = NULL;
void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
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");
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");
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;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
break;
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
Serial.printf("\nConnected to Wi-Fi!\n");
digitalWrite(gpio_led, true);
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
}
}
......@@ -67,34 +67,35 @@ void write_callback(Device *device, Param *param, const param_val_t val, void *p
const char *device_name = device->getDeviceName();
const char *param_name = param->getParamName();
if(strcmp(device_name, "Switch_ch1") == 0) {
if (strcmp(device_name, "Switch_ch1") == 0) {
Serial.printf("Lightbulb = %s\n", val.val.b? "true" : "false");
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);
}
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) {
} else if (strcmp(device_name, "Switch_ch2") == 0) {
Serial.printf("Switch value = %s\n", val.val.b? "true" : "false");
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);
}
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<LightSwitch*>(arg);
void ARDUINO_ISR_ATTR isr(void *arg)
{
LightSwitch *s = static_cast<LightSwitch *>(arg);
s->pressed = true;
}
......@@ -125,16 +126,19 @@ void setup()
my_node = RMaker.initNode("Sonoff Dual R3");
//Initialize switch device
my_switch1 = Switch("Switch_ch1", &gpio_relay1);
my_switch2 = Switch("Switch_ch2", &gpio_relay2);
my_switch1 = new Switch("Switch_ch1", &gpio_relay1);
my_switch2 = new Switch("Switch_ch2", &gpio_relay2);
if (!my_switch1 || !my_switch2) {
return;
}
//Standard switch device
my_switch1.addCb(write_callback);
my_switch2.addCb(write_callback);
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);
my_node.addDevice(*my_switch1);
my_node.addDevice(*my_switch2);
//This is optional
RMaker.enableOTA(OTA_USING_TOPICS);
......@@ -147,8 +151,8 @@ void setup()
RMaker.enableScenes();
//Service Name
for(int i=0; i<17; i=i+8) {
chipId |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
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);
......@@ -173,7 +177,9 @@ void loop()
// 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);
if (my_switch1) {
my_switch1->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch1);
}
(switch_state_ch1 == false) ? digitalWrite(gpio_relay1, LOW) : digitalWrite(gpio_relay1, HIGH);
} else if (switch_ch2.pressed) {
Serial.printf("Switch 2 has been changed\n");
......@@ -181,27 +187,31 @@ void loop()
// 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);
if (my_switch2) {
my_switch2->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME, switch_state_ch2);
}
(switch_state_ch2 == false) ? digitalWrite(gpio_relay2, LOW) : digitalWrite(gpio_relay2, HIGH);
}
// Read GPIO0 (external button to reset device
if(digitalRead(gpio_reset) == LOW) { //Push button pressed
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);
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);
// 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);
Serial.printf("Reset Wi-Fi.\n");
// If key pressed for more than 3secs, but less than 10, reset Wi-Fi
RMakerWiFiReset(2);
}
}
delay(100);
......
//This example demonstrates the ESP RainMaker with a standard Switch device.
// This example demonstrates the ESP RainMaker with a standard Switch device.
#include "RMaker.h"
#include "WiFi.h"
#include "WiFiProv.h"
......@@ -7,12 +7,12 @@
const char *service_name = "PROV_1234";
const char *pop = "abcd1234";
//GPIO for push button
// GPIO for push button
#if CONFIG_IDF_TARGET_ESP32C3
static int gpio_0 = 9;
static int gpio_switch = 7;
#else
//GPIO for virtual device
// GPIO for virtual device
static int gpio_0 = 0;
static int gpio_switch = 16;
#endif
......@@ -20,40 +20,46 @@ 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;
// The framework provides some standard device types like switch, lightbulb,
// fan, temperaturesensor.
static Switch *my_switch = NULL;
void sysProvEvent(arduino_event_t *sys_event)
{
switch (sys_event->event_id) {
case ARDUINO_EVENT_PROV_START:
case ARDUINO_EVENT_PROV_START:
#if CONFIG_IDF_TARGET_ESP32S2
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n", service_name, pop);
printQR(service_name, pop, "softap");
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on SoftAP\n",
service_name, pop);
printQR(service_name, pop, "softap");
#else
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n", service_name, pop);
printQR(service_name, pop, "ble");
Serial.printf("\nProvisioning Started with name \"%s\" and PoP \"%s\" on BLE\n",
service_name, pop);
printQR(service_name, pop, "ble");
#endif
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
break;
case ARDUINO_EVENT_PROV_INIT:
wifi_prov_mgr_disable_auto_stop(10000);
break;
case ARDUINO_EVENT_PROV_CRED_SUCCESS:
wifi_prov_mgr_stop_provisioning();
break;
default:;
}
}
void write_callback(Device *device, Param *param, const param_val_t val, void *priv_data, write_ctx_t *ctx)
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);
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);
(switch_state == false) ? digitalWrite(gpio_switch, LOW)
: digitalWrite(gpio_switch, HIGH);
param->updateAndReport(val);
}
}
......@@ -68,62 +74,76 @@ void setup()
Node my_node;
my_node = RMaker.initNode("ESP RainMaker Node");
//Initialize switch device
my_switch = Switch("Switch", &gpio_switch);
//Standard switch device
my_switch.addCb(write_callback);
// Initialize switch device
my_switch = new Switch("Switch", &gpio_switch);
if (!my_switch) {
return;
}
// Standard switch device
my_switch->addCb(write_callback);
//Add switch device to the node
my_node.addDevice(my_switch);
// Add switch device to the node
my_node.addDevice(*my_switch);
//This is optional
// This is optional
RMaker.enableOTA(OTA_USING_TOPICS);
//If you want to enable scheduling, set time zone for your region using setTimeZone().
//The list of available values are provided here https://rainmaker.espressif.com/docs/time-service.html
// RMaker.setTimeZone("Asia/Shanghai");
// Alternatively, enable the Timezone service and let the phone apps set the appropriate timezone
// If you want to enable scheduling, set time zone for your region using
// setTimeZone(). The list of available values are provided here
// https://rainmaker.espressif.com/docs/time-service.html
// RMaker.setTimeZone("Asia/Shanghai");
// Alternatively, enable the Timezone service and let the phone apps set the
// appropriate timezone
RMaker.enableTZService();
RMaker.enableSchedule();
RMaker.enableScenes();
RMaker.enableSystemService(SYSTEM_SERV_FLAGS_ALL, 2, 2, 2);
RMaker.start();
WiFi.onEvent(sysProvEvent);
#if CONFIG_IDF_TARGET_ESP32S2
WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE, WIFI_PROV_SECURITY_1, pop, service_name);
WiFiProv.beginProvision(WIFI_PROV_SCHEME_SOFTAP, WIFI_PROV_SCHEME_HANDLER_NONE,
WIFI_PROV_SECURITY_1, pop, service_name);
#else
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM, WIFI_PROV_SECURITY_1, pop, service_name);
WiFiProv.beginProvision(WIFI_PROV_SCHEME_BLE, WIFI_PROV_SCHEME_HANDLER_FREE_BTDM,
WIFI_PROV_SECURITY_1, pop, service_name);
#endif
}
void loop()
{
if(digitalRead(gpio_0) == LOW) { //Push button pressed
if (digitalRead(gpio_0) == LOW) { // Push button pressed
// Key debounce handling
delay(100);
int startTime = millis();
while(digitalRead(gpio_0) == LOW) delay(50);
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);
// 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);
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);
}
// Toggle device state
switch_state = !switch_state;
Serial.printf("Toggle State to %s.\n", switch_state ? "true" : "false");
if (my_switch) {
my_switch->updateAndReportParam(ESP_RMAKER_DEF_POWER_NAME,
switch_state);
}
(switch_state == false) ? digitalWrite(gpio_switch, LOW)
: digitalWrite(gpio_switch, HIGH);
}
}
delay(100);
}
......@@ -155,5 +155,18 @@ esp_err_t RMakerClass::enableScenes()
}
return err;
}
esp_err_t RMakerClass::enableSystemService(uint16_t flags, int8_t reboot_seconds, int8_t reset_seconds, int8_t reset_reboot_seconds)
{
esp_rmaker_system_serv_config_t config = {
.flags = flags,
.reboot_seconds = reboot_seconds,
.reset_seconds = reset_seconds,
.reset_reboot_seconds = reset_reboot_seconds
};
err = esp_rmaker_system_service_enable(&config);
return err;
}
RMakerClass RMaker;
#endif
......@@ -36,6 +36,7 @@ class RMakerClass
esp_err_t enableTZService();
esp_err_t enableOTA(ota_type_t type, const char *cert = ESP_RMAKER_OTA_DEFAULT_SERVER_CERT);
esp_err_t enableScenes();
esp_err_t enableSystemService(uint16_t flags, int8_t reboot_seconds = 2, int8_t reset_seconds = 2, int8_t reset_reboot_seconds = 2);
esp_err_t start();
esp_err_t stop();
};
......
......@@ -33,7 +33,7 @@ esp_err_t Device::deleteDevice()
{
err = esp_rmaker_device_delete(getDeviceHandle());
if(err != ESP_OK) {
log_e("Device deletion error");
log_e("Failed to delete device");
return err;
}
return ESP_OK;
......@@ -45,7 +45,7 @@ void Device::addCb(deviceWriteCb writeCb, deviceReadCb readCb)
read_cb = readCb;
err = esp_rmaker_device_add_cb(getDeviceHandle(), write_callback, read_callback);
if(err != ESP_OK) {
log_e("Callback register error");
log_e("Failed to register callback");
}
}
......@@ -64,7 +64,7 @@ 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");
log_e("Failed to add custom parameter");
return err;
}
return ESP_OK;
......@@ -140,7 +140,7 @@ 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");
log_e("Failed to assign primary parameter");
}
return err;
}
......@@ -157,7 +157,7 @@ esp_err_t Device::updateAndReportParam(const char *param_name, bool my_val)
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");
log_e("Update parameter failed");
return err;
}else {
log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val ? "true" : "false");
......@@ -171,7 +171,7 @@ esp_err_t Device::updateAndReportParam(const char *param_name, int my_val)
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");
log_e("Update parameter failed");
return err;
}else {
log_i("Device : %s, Param Name : %s, Val : %d", getDeviceName(), param_name, my_val);
......@@ -185,7 +185,7 @@ esp_err_t Device::updateAndReportParam(const char *param_name, float my_val)
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");
log_e("Update parameter failed");
return err;
}else {
log_i("Device : %s, Param Name : %s, Val : %f", getDeviceName(), param_name, my_val);
......@@ -199,7 +199,7 @@ esp_err_t Device::updateAndReportParam(const char *param_name, const char *my_va
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");
log_e("Update parameter failed");
return err;
}else {
log_i("Device : %s, Param Name : %s, Val : %s", getDeviceName(), param_name, my_val);
......
......@@ -45,7 +45,7 @@ https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protoc
5. before initiating the first SSL connection, call
my_client.setCACertBundle(rootca_crt_bundle_start);
To use this feature in Android IDE:
To use this feature in Arduino IDE:
If the Arduino IDE added support for embedding files in the meantime, then follow the instructions above.
If not, you have three choices:
1. convert your project to PlatformIO
......
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#include "soc/soc_caps.h"
#define USB_VID 0x303a
#define USB_PID 0x1001
#define EXTERNAL_NUM_INTERRUPTS 23
#define NUM_DIGITAL_PINS 46
#define NUM_ANALOG_INPUTS 15
#define analogInputToDigitalPin(p) \
(((p) < 20) ? (analogChannelToDigitalPin(p)) : -1)
#define digitalPinToInterrupt(p) (((p) < 48) ? (p) : -1)
#define digitalPinHasPWM(p) (p < 46)
static const uint8_t TX = 43;
static const uint8_t RX = 44;
static const uint8_t TXD2 = 1;
static const uint8_t RXD2 = 2;
static const uint8_t SDA = 13;
static const uint8_t SCL = 15;
static const uint8_t G0 = 0;
static const uint8_t G1 = 1;
static const uint8_t G2 = 2;
static const uint8_t G3 = 3;
static const uint8_t G4 = 4;
static const uint8_t G5 = 5;
static const uint8_t G6 = 6;
static const uint8_t G7 = 7;
static const uint8_t G8 = 8;
static const uint8_t G9 = 9;
static const uint8_t G10 = 10;
static const uint8_t G11 = 11;
static const uint8_t G12 = 12;
static const uint8_t G13 = 13;
static const uint8_t G14 = 14;
static const uint8_t G15 = 15;
static const uint8_t G39 = 39;
static const uint8_t G40 = 40;
static const uint8_t G41 = 41;
static const uint8_t G42 = 42;
static const uint8_t G43 = 43;
static const uint8_t G44 = 44;
static const uint8_t G46 = 46;
static const uint8_t ADC1 = 7;
static const uint8_t ADC2 = 8;
#endif /* Pins_Arduino_h */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment