diff --git a/.travis.yml b/.travis.yml index a76e910..58d8ed8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ python: env: - PLATFORMIO_PROJECT_DIR=examples/arduino-blink - PLATFORMIO_PROJECT_DIR=examples/arduino-wifiscan + - PLATFORMIO_PROJECT_DIR=examples/espidf-aws-iot - PLATFORMIO_PROJECT_DIR=examples/espidf-ble-adv - PLATFORMIO_PROJECT_DIR=examples/espidf-coap-server - PLATFORMIO_PROJECT_DIR=examples/espidf-exceptions diff --git a/appveyor.yml b/appveyor.yml index 54477b0..ca01cfe 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,6 +4,7 @@ environment: matrix: - PLATFORMIO_PROJECT_DIR: "examples/arduino-blink" - PLATFORMIO_PROJECT_DIR: "examples/arduino-wifiscan" + - PLATFORMIO_PROJECT_DIR: "examples/espidf-aws-iot" - PLATFORMIO_PROJECT_DIR: "examples/espidf-ble-adv" - PLATFORMIO_PROJECT_DIR: "examples/espidf-coap-server" - PLATFORMIO_PROJECT_DIR: "examples/espidf-exceptions" diff --git a/boards/alksesp32.json b/boards/alksesp32.json new file mode 100644 index 0000000..a2df27c --- /dev/null +++ b/boards/alksesp32.json @@ -0,0 +1,43 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_ALKS", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "alksesp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino" + ], + "name": "ALKS ESP32", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "protocol": "esptool", + "protocols": [ + "esptool", + "olimex-arm-usb-tiny-h", + "olimex-arm-usb-ocd-h", + "olimex-arm-usb-ocd", + "olimex-jtag-tiny", + "minimodule" + ], + "require_upload_port": true, + "speed": 115200 + }, + "url": "https://github.com/RoboticsBrno/ArduinoLearningKitStarter.git", + "vendor": "RoboticsBrno" +} \ No newline at end of file diff --git a/boards/esp-wrover-kit.json b/boards/esp-wrover-kit.json index cdd88c7..258aff1 100644 --- a/boards/esp-wrover-kit.json +++ b/boards/esp-wrover-kit.json @@ -1,7 +1,7 @@ { "build": { "core": "esp32", - "extra_flags": "-DARDUINO_ESP32_DEV", + "extra_flags": "-DARDUINO_ESP32_DEV -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue", "f_cpu": "240000000L", "f_flash": "40000000L", "flash_mode": "dio", diff --git a/boards/lolin32.json b/boards/lolin32.json index f39bef7..4a0cc51 100644 --- a/boards/lolin32.json +++ b/boards/lolin32.json @@ -39,6 +39,6 @@ "require_upload_port": true, "speed": 921600 }, - "url": "https://wemos.cc", + "url": "https://wiki.wemos.cc/products:lolin32:lolin32", "vendor": "WEMOS" } diff --git a/boards/lolin_d32.json b/boards/lolin_d32.json new file mode 100644 index 0000000..a71ac9c --- /dev/null +++ b/boards/lolin_d32.json @@ -0,0 +1,44 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_LOLIN_D32", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "d32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "WEMOS LOLIN D32", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "protocol": "esptool", + "protocols": [ + "esptool", + "olimex-arm-usb-tiny-h", + "olimex-arm-usb-ocd-h", + "olimex-arm-usb-ocd", + "olimex-jtag-tiny", + "minimodule" + ], + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://wiki.wemos.cc/products:d32:d32", + "vendor": "WEMOS" +} diff --git a/boards/lolin_d32_pro.json b/boards/lolin_d32_pro.json new file mode 100644 index 0000000..1fa88e2 --- /dev/null +++ b/boards/lolin_d32_pro.json @@ -0,0 +1,44 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_LOLIN_D32_PRO", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "d32_pro" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "WEMOS LOLIN D32 PRO", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "protocol": "esptool", + "protocols": [ + "esptool", + "olimex-arm-usb-tiny-h", + "olimex-arm-usb-ocd-h", + "olimex-arm-usb-ocd", + "olimex-jtag-tiny", + "minimodule" + ], + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://wiki.wemos.cc/products:d32:d32_pro", + "vendor": "WEMOS" +} diff --git a/boards/m5stack-fire.json b/boards/m5stack-fire.json new file mode 100644 index 0000000..c2953d2 --- /dev/null +++ b/boards/m5stack-fire.json @@ -0,0 +1,36 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_M5STACK_FIRE", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "m5stack_fire" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "frameworks": [ + "arduino", + "espidf" + ], + "name": "M5Stack FIRE", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "protocol": "esptool", + "protocols": [ + "esptool" + ], + "require_upload_port": true, + "speed": 921600 + }, + "url": "http://www.m5stack.com", + "vendor": "M5Stack" +} diff --git a/boards/ttgo-lora32-v1.json b/boards/ttgo-lora32-v1.json new file mode 100644 index 0000000..a776012 --- /dev/null +++ b/boards/ttgo-lora32-v1.json @@ -0,0 +1,44 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_TTGO_LoRa32_V1", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "ttgo-lora32-v1" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "TTGO LoRa32-OLED V1", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "protocol": "esptool", + "protocols": [ + "esptool", + "olimex-arm-usb-tiny-h", + "olimex-arm-usb-ocd-h", + "olimex-arm-usb-ocd", + "olimex-jtag-tiny", + "minimodule" + ], + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://www.google.com.ua/search?q=TTGO+LoRa32-OLED+V1", + "vendor": "TTGO" +} diff --git a/boards/xinabox_cw02.json b/boards/xinabox_cw02.json new file mode 100644 index 0000000..435b4f5 --- /dev/null +++ b/boards/xinabox_cw02.json @@ -0,0 +1,44 @@ +{ + "build": { + "core": "esp32", + "extra_flags": "-DARDUINO_ESP32_DEV", + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "ldscript": "esp32_out.ld", + "mcu": "esp32", + "variant": "xinabox" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "XinaBox CW02", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "protocol": "esptool", + "protocols": [ + "esptool", + "olimex-arm-usb-tiny-h", + "olimex-arm-usb-ocd-h", + "olimex-arm-usb-ocd", + "olimex-jtag-tiny", + "minimodule" + ], + "require_upload_port": true, + "speed": 921600 + }, + "url": "https://xinabox.cc/products/cw02", + "vendor": "XinaBox" +} diff --git a/builder/frameworks/_embedtxt_files.py b/builder/frameworks/_embedtxt_files.py new file mode 100644 index 0000000..5d64c56 --- /dev/null +++ b/builder/frameworks/_embedtxt_files.py @@ -0,0 +1,102 @@ +# Copyright 2014-present PlatformIO +# +# 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. + +from os import SEEK_CUR, SEEK_END +from os.path import basename, isfile, join + +from SCons.Script import Builder + +from platformio.util import cd + +Import("env") + + +# +# TXT files helpers +# + + +def prepare_files(files): + if not files: + return + + for f in files: + with open(env.subst(f), "rb+") as fp: + fp.seek(-1, SEEK_END) + if fp.read(1) != '\0': + fp.seek(0, SEEK_CUR) + fp.write('\0') + + +def extract_files(cppdefines): + for define in cppdefines: + if "COMPONENT_EMBED_TXTFILES" not in define: + continue + + if not isinstance(define, tuple): + print("Warning! COMPONENT_EMBED_TXTFILES macro cannot be empty!") + return [] + + with cd(env.subst("$PROJECT_DIR")): + value = define[1] + if not isinstance(value, str): + print("Warning! COMPONENT_EMBED_TXTFILES macro must contain " + "a list of files separated by ':'") + return [] + + result = [] + for f in value.split(':'): + if not isfile(f): + print("Warning! Could not find file %s" % f) + continue + result.append(join("$PROJECT_DIR", f)) + + return result + + +def remove_config_define(cppdefines): + for define in cppdefines: + if "COMPONENT_EMBED_TXTFILES" in define: + env.ProcessUnFlags("-D%s" % "=".join(str(d) for d in define)) + return + + +def embed_files(files): + for f in files: + filename = basename(f) + ".txt.o" + file_target = env.TxtToBin(join("$BUILD_DIR", filename), f) + env.Depends("$PIOMAINPROG", file_target) + env.Append(PIOBUILDFILES=[env.File(join("$BUILD_DIR", filename))]) + + +env.Append( + BUILDERS=dict( + TxtToBin=Builder( + action=env.VerboseAction(" ".join([ + "xtensa-esp32-elf-objcopy", + "--input-target", "binary", + "--output-target", "elf32-xtensa-le", + "--binary-architecture", "xtensa", + "--rename-section", ".data=.rodata.embedded", + "$SOURCE", "$TARGET" + ]), "Converting $TARGET"), + suffix=".txt.o")) +) + +flags = env.get("CPPDEFINES") +if "COMPONENT_EMBED_TXTFILES" in env.Flatten(flags): + files = extract_files(flags) + prepare_files(files) + embed_files(files) + remove_config_define(flags) diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py index 713bc8a..13d29e3 100644 --- a/builder/frameworks/arduino.py +++ b/builder/frameworks/arduino.py @@ -11,6 +11,7 @@ # 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. + """ Arduino @@ -25,6 +26,10 @@ from os.path import join from SCons.Script import DefaultEnvironment, SConscript +env = DefaultEnvironment() + +SConscript("_embedtxt_files.py", exports="env") + SConscript( join(DefaultEnvironment().PioPlatform().get_package_dir( "framework-arduinoespressif32"), "tools", "platformio-build.py")) diff --git a/builder/frameworks/espidf.py b/builder/frameworks/espidf.py index 937eb7e..2979b3f 100644 --- a/builder/frameworks/espidf.py +++ b/builder/frameworks/espidf.py @@ -32,6 +32,8 @@ from SCons.Script import DefaultEnvironment env = DefaultEnvironment() platform = env.PioPlatform() +env.SConscript("_embedtxt_files.py", exports="env") + FRAMEWORK_DIR = platform.get_package_dir("framework-espidf") assert FRAMEWORK_DIR and isdir(FRAMEWORK_DIR) @@ -341,7 +343,7 @@ else: is_new = False with open(join(env.subst("$PROJECTSRC_DIR"), "sdkconfig.h")) as fp: for l in fp.readlines(): - if "CONFIG_ADC_CAL_LUT_ENABLE" in l: + if "CONFIG_AWS_IOT_SDK" in l: is_new = True break @@ -453,6 +455,13 @@ libs.append(env.BuildLibrary( src_filter="+<*> - -" )) +libs.append(env.BuildLibrary( + join("$BUILD_DIR", "aws_iot"), + join(FRAMEWORK_DIR, "components", "aws_iot"), + src_filter="-<*> + +" +)) + + envsafe = env.Clone() envsafe.Prepend( CPPDEFINES=[ diff --git a/examples/arduino-wifiscan/platformio.ini b/examples/arduino-wifiscan/platformio.ini index c10fb3f..32cbdd8 100644 --- a/examples/arduino-wifiscan/platformio.ini +++ b/examples/arduino-wifiscan/platformio.ini @@ -13,10 +13,10 @@ framework = arduino board = esp32dev monitor_speed = 115200 -[env:nano32] +[env:esp wrover kit] platform = espressif32 framework = arduino -board = nano32 +board = esp-wrover-kit monitor_speed = 115200 [env:espea32] diff --git a/examples/espidf-aws-iot/.gitignore b/examples/espidf-aws-iot/.gitignore new file mode 100644 index 0000000..5402c18 --- /dev/null +++ b/examples/espidf-aws-iot/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/espidf-aws-iot/.travis.yml b/examples/espidf-aws-iot/.travis.yml new file mode 100644 index 0000000..2c4ff5c --- /dev/null +++ b/examples/espidf-aws-iot/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/page/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/page/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/page/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/espidf-aws-iot/README.rst b/examples/espidf-aws-iot/README.rst new file mode 100644 index 0000000..d8417bd --- /dev/null +++ b/examples/espidf-aws-iot/README.rst @@ -0,0 +1,32 @@ +.. Copyright 2014-present PlatformIO + 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. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO Core `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-espressif32/examples/espidf-aws-iot + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/espidf-aws-iot/lib/readme.txt b/examples/espidf-aws-iot/lib/readme.txt new file mode 100644 index 0000000..6581e73 --- /dev/null +++ b/examples/espidf-aws-iot/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organised `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/page/projectconf.html#lib-install + diff --git a/examples/espidf-aws-iot/platformio.ini b/examples/espidf-aws-iot/platformio.ini new file mode 100644 index 0000000..ec18ab7 --- /dev/null +++ b/examples/espidf-aws-iot/platformio.ini @@ -0,0 +1,18 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter, extra scripting +; Upload options: custom port, speed and extra flags +; Library options: dependencies, extra library storages +; +; Please visit documentation for the other options and examples +; http://docs.platformio.org/page/projectconf.html + +[env:esp32dev] +platform = espressif32 +framework = espidf +board = esp32dev +monitor_speed = 115200 +build_flags = + -DCOMPONENT_EMBED_TXTFILES=src/private.pem.key:src/certificate.pem.crt:src/aws-root-ca.pem + -DCONFIG_WIFI_SSID=\"ESP_AP\" + -DCONFIG_WIFI_PASSWORD=\"MYPASS\" diff --git a/examples/espidf-aws-iot/src/aws-root-ca.pem b/examples/espidf-aws-iot/src/aws-root-ca.pem new file mode 100644 index 0000000..b9514c5 --- /dev/null +++ b/examples/espidf-aws-iot/src/aws-root-ca.pem @@ -0,0 +1,28 @@ +-----BEGIN CERTIFICATE----- +MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB +yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL +ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp +U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW +ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0 +aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL +MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW +ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln +biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp +U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y +aXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1 +nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKzj/i5Vbex +t0uz/o9+B1fs70PbZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIz +SdhDY2pSS9KP6HBRTdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQG +BO+QueQA5N06tRn/Arr0PO7gi+s3i+z016zy9vA9r911kTMZHRxAy3QkGSGT2RT+ +rCpSx4/VBEnkjWNHiDxpg8v+R70rfk/Fla4OndTRQ8Bnc+MUCH7lP59zuDMKz10/ +NIeWiu5T6CUVAgMBAAGjgbIwga8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8E +BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAH +BgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVy +aXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFH/TZafC3ey78DAJ80M5+gKv +MzEzMA0GCSqGSIb3DQEBBQUAA4IBAQCTJEowX2LP2BqYLz3q3JktvXf2pXkiOOzE +p6B4Eq1iDkVwZMXnl2YtmAl+X6/WzChl8gGqCBpH3vn5fJJaCGkgDdk+bW48DW7Y +5gaRQBi5+MHt39tBquCWIMnNZBU4gcmU7qKEKQsTb47bDN0lAtukixlE0kF6BWlK +WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ +4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N +hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq +-----END CERTIFICATE----- \ No newline at end of file diff --git a/examples/espidf-aws-iot/src/certificate.pem.crt b/examples/espidf-aws-iot/src/certificate.pem.crt new file mode 100644 index 0000000..d831f6f --- /dev/null +++ b/examples/espidf-aws-iot/src/certificate.pem.crt @@ -0,0 +1,3 @@ +-----BEGIN CERTIFICATE----- +DUMMY CONTENT +-----END CERTIFICATE----- \ No newline at end of file diff --git a/examples/espidf-aws-iot/src/private.pem.key b/examples/espidf-aws-iot/src/private.pem.key new file mode 100644 index 0000000..d831f6f --- /dev/null +++ b/examples/espidf-aws-iot/src/private.pem.key @@ -0,0 +1,3 @@ +-----BEGIN CERTIFICATE----- +DUMMY CONTENT +-----END CERTIFICATE----- \ No newline at end of file diff --git a/examples/espidf-aws-iot/src/sdkconfig.h b/examples/espidf-aws-iot/src/sdkconfig.h new file mode 100644 index 0000000..aacab29 --- /dev/null +++ b/examples/espidf-aws-iot/src/sdkconfig.h @@ -0,0 +1,234 @@ +/* + * + * Automatically generated file; DO NOT EDIT. + * Espressif IoT Development Framework Configuration + * + */ +#define CONFIG_GATTC_ENABLE 1 +#define CONFIG_ESP32_PHY_MAX_TX_POWER 20 +#define CONFIG_TRACEMEM_RESERVE_DRAM 0x0 +#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16 +#define CONFIG_BLE_SMP_ENABLE 1 +#define CONFIG_TCP_RECVMBOX_SIZE 6 +#define CONFIG_FATFS_CODEPAGE_437 1 +#define CONFIG_LWIP_ETHARP_TRUST_IP_MAC 1 +#define CONFIG_TCP_WND_DEFAULT 5744 +#define CONFIG_SPIFFS_USE_MAGIC_LENGTH 1 +#define CONFIG_IPC_TASK_STACK_SIZE 1024 +#define CONFIG_FATFS_PER_FILE_CACHE 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ "40m" +#define CONFIG_MBEDTLS_KEY_EXCHANGE_RSA 1 +#define CONFIG_UDP_RECVMBOX_SIZE 6 +#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0 +#define CONFIG_MBEDTLS_AES_C 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP521R1_ENABLED 1 +#define CONFIG_MBEDTLS_GCM_C 1 +#define CONFIG_ESPTOOLPY_FLASHSIZE "2MB" +#define CONFIG_HEAP_POISONING_DISABLED 1 +#define CONFIG_SPIFFS_CACHE_WR 1 +#define CONFIG_BROWNOUT_DET_LVL_SEL_0 1 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER 1 +#define CONFIG_SPIFFS_CACHE 1 +#define CONFIG_INT_WDT 1 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1 1 +#define CONFIG_MBEDTLS_ECDSA_C 1 +#define CONFIG_ESPTOOLPY_FLASHFREQ_40M 1 +#define CONFIG_LOG_BOOTLOADER_LEVEL_INFO 1 +#define CONFIG_ESPTOOLPY_FLASHSIZE_2MB 1 +#define CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE 0 +#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1 +#define CONFIG_MBEDTLS_ECDH_C 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ELLIPTIC_CURVE 1 +#define CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM 10 +#define CONFIG_MBEDTLS_SSL_ALPN 1 +#define CONFIG_MBEDTLS_PEM_WRITE_C 1 +#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1 +#define CONFIG_BT_RESERVE_DRAM 0x10000 +#define CONFIG_FATFS_FS_LOCK 0 +#define CONFIG_IP_LOST_TIMER_INTERVAL 120 +#define CONFIG_SPIFFS_META_LENGTH 4 +#define CONFIG_ESP32_PANIC_PRINT_REBOOT 1 +#define CONFIG_MBEDTLS_ECP_DP_BP384R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP256K1_ENABLED 1 +#define CONFIG_CONSOLE_UART_BAUDRATE 115200 +#define CONFIG_LWIP_MAX_SOCKETS 10 +#define CONFIG_LWIP_NETIF_LOOPBACK 1 +#define CONFIG_EMAC_TASK_PRIORITY 20 +#define CONFIG_TIMER_TASK_STACK_DEPTH 2048 +#define CONFIG_TCP_MSS 1436 +#define CONFIG_MBEDTLS_ECP_DP_CURVE25519_ENABLED 1 +#define CONFIG_FATFS_CODEPAGE 437 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_160 1 +#define CONFIG_ULP_COPROC_RESERVE_MEM 0 +#define CONFIG_LWIP_MAX_UDP_PCBS 16 +#define CONFIG_ESPTOOLPY_BAUD 115200 +#define CONFIG_INT_WDT_CHECK_CPU1 1 +#define CONFIG_ADC_CAL_LUT_ENABLE 1 +#define CONFIG_FLASHMODE_DIO 1 +#define CONFIG_ESPTOOLPY_AFTER_RESET 1 +#define CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED 1 +#define CONFIG_LWIP_DHCPS_MAX_STATION_NUM 8 +#define CONFIG_TOOLPREFIX "xtensa-esp32-elf-" +#define CONFIG_MBEDTLS_ECP_C 1 +#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1024 +#define CONFIG_MBEDTLS_RC4_DISABLED 1 +#define CONFIG_CONSOLE_UART_NUM 0 +#define CONFIG_ESP32_APPTRACE_LOCK_ENABLE 1 +#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1 +#define CONFIG_ESPTOOLPY_BAUD_115200B 1 +#define CONFIG_TCP_OVERSIZE_MSS 1 +#define CONFIG_FOUR_UNIVERSAL_MAC_ADDRESS 1 +#define CONFIG_CONSOLE_UART_DEFAULT 1 +#define CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN 16384 +#define CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS 4 +#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1 +#define CONFIG_TIMER_TASK_STACK_SIZE 3584 +#define CONFIG_ESP32_ENABLE_COREDUMP_TO_NONE 1 +#define CONFIG_MBEDTLS_X509_CRL_PARSE_C 1 +#define CONFIG_LWIP_DHCPS_LEASE_UNIT 60 +#define CONFIG_SPIFFS_USE_MAGIC 1 +#define CONFIG_TCPIP_TASK_STACK_SIZE 2048 +#define CONFIG_BLUEDROID_PINNED_TO_CORE_0 1 +#define CONFIG_TASK_WDT 1 +#define CONFIG_MAIN_TASK_STACK_SIZE 3584 +#define CONFIG_SPIFFS_PAGE_CHECK 1 +#define CONFIG_LWIP_MAX_ACTIVE_TCP 16 +#define CONFIG_TASK_WDT_TIMEOUT_S 5 +#define CONFIG_INT_WDT_TIMEOUT_MS 300 +#define CONFIG_ESPTOOLPY_FLASHMODE "dio" +#define CONFIG_BTC_TASK_STACK_SIZE 3072 +#define CONFIG_BLUEDROID_ENABLED 1 +#define CONFIG_NEWLIB_STDIN_LINE_ENDING_CR 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA 1 +#define CONFIG_ESPTOOLPY_BEFORE "default_reset" +#define CONFIG_FATFS_LFN_HEAP 1 +#define CONFIG_LOG_DEFAULT_LEVEL 3 +#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1 +#define CONFIG_TIMER_QUEUE_LENGTH 10 +#define CONFIG_MAKE_WARN_UNDEFINED_VARIABLES 1 +#define CONFIG_FATFS_TIMEOUT_MS 10000 +#define CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM 32 +#define CONFIG_MBEDTLS_CCM_C 1 +#define CONFIG_ESP32_PHY_MAX_WIFI_TX_POWER 20 +#define CONFIG_ESP32_RTC_CLK_CAL_CYCLES 1024 +#define CONFIG_ESP32_WIFI_TX_BA_WIN 6 +#define CONFIG_ESP32_WIFI_NVS_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP224R1_ENABLED 1 +#define CONFIG_LIBSODIUM_USE_MBEDTLS_SHA 1 +#define CONFIG_DMA_RX_BUF_NUM 10 +#define CONFIG_MBEDTLS_ECP_DP_SECP384R1_ENABLED 1 +#define CONFIG_TCP_SYNMAXRTX 6 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA 1 +#define CONFIG_PYTHON "python" +#define CONFIG_MBEDTLS_ECP_NIST_OPTIM 1 +#define CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1 1 +#define CONFIG_ESPTOOLPY_COMPRESSED 1 +#define CONFIG_PARTITION_TABLE_FILENAME "partitions_singleapp.csv" +#define CONFIG_TCP_SND_BUF_DEFAULT 5744 +#define CONFIG_LWIP_DHCP_MAX_NTP_SERVERS 1 +#define CONFIG_TCP_MSL 60000 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_1 1 +#define CONFIG_LWIP_SO_REUSE_RXTOALL 1 +#define CONFIG_PARTITION_TABLE_SINGLE_APP 1 +#define CONFIG_ESP32_WIFI_RX_BA_WIN 6 +#define CONFIG_MBEDTLS_X509_CSR_PARSE_C 1 +#define CONFIG_SPIFFS_USE_MTIME 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA 1 +#define CONFIG_LWIP_DHCP_DOES_ARP_CHECK 1 +#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE 2048 +#define CONFIG_BOOTLOADER_VDDSDIO_BOOST_1_9V 1 +#define CONFIG_ESP32_DEEP_SLEEP_WAKEUP_DELAY 2000 +#define CONFIG_BROWNOUT_DET_LVL 0 +#define CONFIG_MBEDTLS_PEM_PARSE_C 1 +#define CONFIG_SPIFFS_GC_MAX_RUNS 10 +#define CONFIG_ESP32_APPTRACE_DEST_NONE 1 +#define CONFIG_PARTITION_TABLE_CUSTOM_APP_BIN_OFFSET 0x10000 +#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA 1 +#define CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM 32 +#define CONFIG_MBEDTLS_ECP_DP_BP256R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP224K1_ENABLED 1 +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU1 1 +#define CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ 160 +#define CONFIG_MBEDTLS_HARDWARE_AES 1 +#define CONFIG_FREERTOS_HZ 100 +#define CONFIG_LOG_COLORS 1 +#define CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE 1 +#define CONFIG_STACK_CHECK_NONE 1 +#define CONFIG_ADC_CAL_EFUSE_TP_ENABLE 1 +#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1 +#define CONFIG_BROWNOUT_DET 1 +#define CONFIG_ESP32_XTAL_FREQ 40 +#define CONFIG_MONITOR_BAUD_115200B 1 +#define CONFIG_LOG_BOOTLOADER_LEVEL 3 +#define CONFIG_MBEDTLS_TLS_ENABLED 1 +#define CONFIG_LWIP_MAX_RAW_PCBS 16 +#define CONFIG_SMP_ENABLE 1 +#define CONFIG_MBEDTLS_SSL_SESSION_TICKETS 1 +#define CONFIG_SPIFFS_MAX_PARTITIONS 3 +#define CONFIG_BTDM_CONTROLLER_PINNED_TO_CORE_0 1 +#define CONFIG_MBEDTLS_SSL_RENEGOTIATION 1 +#define CONFIG_ESPTOOLPY_BEFORE_RESET 1 +#define CONFIG_ESPTOOLPY_BAUD_OTHER_VAL 115200 +#define CONFIG_SPIFFS_OBJ_NAME_LEN 32 +#define CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT 5 +#define CONFIG_TCPIP_RECVMBOX_SIZE 32 +#define CONFIG_TCP_MAXRTX 12 +#define CONFIG_ESPTOOLPY_AFTER "hard_reset" +#define CONFIG_LWIP_SO_REUSE 1 +#define CONFIG_ESP32_XTAL_FREQ_40 1 +#define CONFIG_DMA_TX_BUF_NUM 10 +#define CONFIG_LWIP_MAX_LISTENING_TCP 16 +#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1 +#define CONFIG_WL_SECTOR_SIZE 4096 +#define CONFIG_ESP32_DEBUG_OCDAWARE 1 +#define CONFIG_TIMER_TASK_PRIORITY 1 +#define CONFIG_MBEDTLS_TLS_CLIENT 1 +#define CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI 1 +#define CONFIG_BT_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED 1 +#define CONFIG_MONITOR_BAUD 115200 +#define CONFIG_FREERTOS_CORETIMER_0 1 +#define CONFIG_PARTITION_TABLE_CUSTOM_FILENAME "partitions.csv" +#define CONFIG_MBEDTLS_HAVE_TIME 1 +#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1 +#define CONFIG_TCP_QUEUE_OOSEQ 1 +#define CONFIG_GATTS_ENABLE 1 +#define CONFIG_ADC_CAL_EFUSE_VREF_ENABLE 1 +#define CONFIG_MBEDTLS_TLS_SERVER 1 +#define CONFIG_MBEDTLS_TLS_SERVER_AND_CLIENT 1 +#define CONFIG_FREERTOS_ISR_STACKSIZE 1536 +#define CONFIG_OPENSSL_ASSERT_DO_NOTHING 1 +#define CONFIG_WL_SECTOR_SIZE_4096 1 +#define CONFIG_OPTIMIZATION_LEVEL_DEBUG 1 +#define CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP192R1_ENABLED 1 +#define CONFIG_MBEDTLS_ECP_DP_BP512R1_ENABLED 1 +#define CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA 1 +#define CONFIG_SYSTEM_EVENT_QUEUE_SIZE 32 +#define CONFIG_FATFS_MAX_LFN 255 +#define CONFIG_BT_ACL_CONNECTIONS 4 +#define CONFIG_ESP32_WIFI_TX_BUFFER_TYPE 1 +#define CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED 1 +#define CONFIG_LWIP_LOOPBACK_MAX_PBUFS 8 +#define CONFIG_APP_OFFSET 0x10000 +#define CONFIG_MEMMAP_SMP 1 +#define CONFIG_SPI_FLASH_ROM_DRIVER_PATCH 1 +#define CONFIG_MBEDTLS_ECP_DP_SECP192K1_ENABLED 1 +#define CONFIG_TASK_WDT_CHECK_IDLE_TASK_CPU0 1 +#define CONFIG_ESP32_PTHREAD_TASK_STACK_SIZE_DEFAULT 3072 +#define CONFIG_MONITOR_BAUD_OTHER_VAL 115200 +#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1 +#define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" +#define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 +#define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" diff --git a/examples/espidf-aws-iot/src/subscribe_publish_sample.c b/examples/espidf-aws-iot/src/subscribe_publish_sample.c new file mode 100644 index 0000000..ba36bb2 --- /dev/null +++ b/examples/espidf-aws-iot/src/subscribe_publish_sample.c @@ -0,0 +1,337 @@ +/* + * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Additions Copyright 2016 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. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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. + */ +/** + * @file subscribe_publish_sample.c + * @brief simple MQTT publish and subscribe on the same topic + * + * This example takes the parameters from the build configuration and establishes a connection to the AWS IoT MQTT Platform. + * It subscribes and publishes to the same topic - "test_topic/esp32" + * + * Some setup is required. See example README for details. + * + */ +#include +#include +#include +#include +#include +#include + +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/event_groups.h" +#include "esp_system.h" +#include "esp_wifi.h" +#include "esp_event_loop.h" +#include "esp_log.h" +#include "esp_vfs_fat.h" +#include "driver/sdmmc_host.h" + +#include "nvs.h" +#include "nvs_flash.h" + +#include "aws_iot_config.h" +#include "aws_iot_log.h" +#include "aws_iot_version.h" +#include "aws_iot_mqtt_client_interface.h" + +static const char *TAG = "subpub"; + +/* The examples use simple WiFi configuration that you can set via + 'make menuconfig'. + + If you'd rather not, just change the below entries to strings with + the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid" +*/ +#define EXAMPLE_WIFI_SSID CONFIG_WIFI_SSID +#define EXAMPLE_WIFI_PASS CONFIG_WIFI_PASSWORD + +/* FreeRTOS event group to signal when we are connected & ready to make a request */ +static EventGroupHandle_t wifi_event_group; + +/* The event group allows multiple bits for each event, + but we only care about one event - are we connected + to the AP with an IP? */ +const int CONNECTED_BIT = BIT0; + + +/* CA Root certificate, device ("Thing") certificate and device + * ("Thing") key. + + Example can be configured one of two ways: + + "Embedded Certs" are loaded from files in "certs/" and embedded into the app binary. + + "Filesystem Certs" are loaded from the filesystem (SD card, etc.) + + See example README for more details. +*/ +#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS) + +extern const uint8_t aws_root_ca_pem_start[] asm("_binary_src_aws_root_ca_pem_start"); +extern const uint8_t aws_root_ca_pem_end[] asm("_binary_src_aws_root_ca_pem_end"); +extern const uint8_t certificate_pem_crt_start[] asm("_binary_src_certificate_pem_crt_start"); +extern const uint8_t certificate_pem_crt_end[] asm("_binary_src_certificate_pem_crt_end"); +extern const uint8_t private_pem_key_start[] asm("_binary_src_private_pem_key_start"); +extern const uint8_t private_pem_key_end[] asm("_binary_src_private_pem_key_end"); + +#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS) + +static const char * DEVICE_CERTIFICATE_PATH = CONFIG_EXAMPLE_CERTIFICATE_PATH; +static const char * DEVICE_PRIVATE_KEY_PATH = CONFIG_EXAMPLE_PRIVATE_KEY_PATH; +static const char * ROOT_CA_PATH = CONFIG_EXAMPLE_ROOT_CA_PATH; + +#else +#error "Invalid method for loading certs" +#endif + +/** + * @brief Default MQTT HOST URL is pulled from the aws_iot_config.h + */ +char HostAddress[255] = AWS_IOT_MQTT_HOST; + +/** + * @brief Default MQTT port is pulled from the aws_iot_config.h + */ +uint32_t port = AWS_IOT_MQTT_PORT; + + +static esp_err_t event_handler(void *ctx, system_event_t *event) +{ + switch(event->event_id) { + case SYSTEM_EVENT_STA_START: + esp_wifi_connect(); + break; + case SYSTEM_EVENT_STA_GOT_IP: + xEventGroupSetBits(wifi_event_group, CONNECTED_BIT); + break; + case SYSTEM_EVENT_STA_DISCONNECTED: + /* This is a workaround as ESP32 WiFi libs don't currently + auto-reassociate. */ + esp_wifi_connect(); + xEventGroupClearBits(wifi_event_group, CONNECTED_BIT); + break; + default: + break; + } + return ESP_OK; +} + +void iot_subscribe_callback_handler(AWS_IoT_Client *pClient, char *topicName, uint16_t topicNameLen, + IoT_Publish_Message_Params *params, void *pData) { + ESP_LOGI(TAG, "Subscribe callback"); + ESP_LOGI(TAG, "%.*s\t%.*s", topicNameLen, topicName, (int) params->payloadLen, (char *)params->payload); +} + +void disconnectCallbackHandler(AWS_IoT_Client *pClient, void *data) { + ESP_LOGW(TAG, "MQTT Disconnect"); + IoT_Error_t rc = FAILURE; + + if(NULL == pClient) { + return; + } + + if(aws_iot_is_autoreconnect_enabled(pClient)) { + ESP_LOGI(TAG, "Auto Reconnect is enabled, Reconnecting attempt will start now"); + } else { + ESP_LOGW(TAG, "Auto Reconnect not enabled. Starting manual reconnect..."); + rc = aws_iot_mqtt_attempt_reconnect(pClient); + if(NETWORK_RECONNECTED == rc) { + ESP_LOGW(TAG, "Manual Reconnect Successful"); + } else { + ESP_LOGW(TAG, "Manual Reconnect Failed - %d", rc); + } + } +} + +void aws_iot_task(void *param) { + char cPayload[100]; + + int32_t i = 0; + + IoT_Error_t rc = FAILURE; + + AWS_IoT_Client client; + IoT_Client_Init_Params mqttInitParams = iotClientInitParamsDefault; + IoT_Client_Connect_Params connectParams = iotClientConnectParamsDefault; + + IoT_Publish_Message_Params paramsQOS0; + IoT_Publish_Message_Params paramsQOS1; + + ESP_LOGI(TAG, "AWS IoT SDK Version %d.%d.%d-%s", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_TAG); + + mqttInitParams.enableAutoReconnect = false; // We enable this later below + mqttInitParams.pHostURL = HostAddress; + mqttInitParams.port = port; + +#if defined(CONFIG_EXAMPLE_EMBEDDED_CERTS) + mqttInitParams.pRootCALocation = (const char *)aws_root_ca_pem_start; + mqttInitParams.pDeviceCertLocation = (const char *)certificate_pem_crt_start; + mqttInitParams.pDevicePrivateKeyLocation = (const char *)private_pem_key_start; + +#elif defined(CONFIG_EXAMPLE_FILESYSTEM_CERTS) + mqttInitParams.pRootCALocation = ROOT_CA_PATH; + mqttInitParams.pDeviceCertLocation = DEVICE_CERTIFICATE_PATH; + mqttInitParams.pDevicePrivateKeyLocation = DEVICE_PRIVATE_KEY_PATH; +#endif + + mqttInitParams.mqttCommandTimeout_ms = 20000; + mqttInitParams.tlsHandshakeTimeout_ms = 5000; + mqttInitParams.isSSLHostnameVerify = true; + mqttInitParams.disconnectHandler = disconnectCallbackHandler; + mqttInitParams.disconnectHandlerData = NULL; + +#ifdef CONFIG_EXAMPLE_SDCARD_CERTS + ESP_LOGI(TAG, "Mounting SD card..."); + sdmmc_host_t host = SDMMC_HOST_DEFAULT(); + sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); + esp_vfs_fat_sdmmc_mount_config_t mount_config = { + .format_if_mount_failed = false, + .max_files = 3, + }; + sdmmc_card_t* card; + esp_err_t ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card); + if (ret != ESP_OK) { + ESP_LOGE(TAG, "Failed to mount SD card VFAT filesystem."); + abort(); + } +#endif + + rc = aws_iot_mqtt_init(&client, &mqttInitParams); + if(SUCCESS != rc) { + ESP_LOGE(TAG, "aws_iot_mqtt_init returned error : %d ", rc); + abort(); + } + + /* Wait for WiFI to show as connected */ + xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, + false, true, portMAX_DELAY); + + connectParams.keepAliveIntervalInSec = 10; + connectParams.isCleanSession = true; + connectParams.MQTTVersion = MQTT_3_1_1; + /* Client ID is set in the menuconfig of the example */ + connectParams.pClientID = CONFIG_AWS_EXAMPLE_CLIENT_ID; + connectParams.clientIDLen = (uint16_t) strlen(CONFIG_AWS_EXAMPLE_CLIENT_ID); + connectParams.isWillMsgPresent = false; + + ESP_LOGI(TAG, "Connecting to AWS..."); + do { + rc = aws_iot_mqtt_connect(&client, &connectParams); + if(SUCCESS != rc) { + ESP_LOGE(TAG, "Error(%d) connecting to %s:%d", rc, mqttInitParams.pHostURL, mqttInitParams.port); + vTaskDelay(1000 / portTICK_RATE_MS); + } + } while(SUCCESS != rc); + + /* + * Enable Auto Reconnect functionality. Minimum and Maximum time of Exponential backoff are set in aws_iot_config.h + * #AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL + * #AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL + */ + rc = aws_iot_mqtt_autoreconnect_set_status(&client, true); + if(SUCCESS != rc) { + ESP_LOGE(TAG, "Unable to set Auto Reconnect to true - %d", rc); + abort(); + } + + const char *TOPIC = "test_topic/esp32"; + const int TOPIC_LEN = strlen(TOPIC); + + ESP_LOGI(TAG, "Subscribing..."); + rc = aws_iot_mqtt_subscribe(&client, TOPIC, TOPIC_LEN, QOS0, iot_subscribe_callback_handler, NULL); + if(SUCCESS != rc) { + ESP_LOGE(TAG, "Error subscribing : %d ", rc); + abort(); + } + + sprintf(cPayload, "%s : %d ", "hello from SDK", i); + + paramsQOS0.qos = QOS0; + paramsQOS0.payload = (void *) cPayload; + paramsQOS0.isRetained = 0; + + paramsQOS1.qos = QOS1; + paramsQOS1.payload = (void *) cPayload; + paramsQOS1.isRetained = 0; + + while((NETWORK_ATTEMPTING_RECONNECT == rc || NETWORK_RECONNECTED == rc || SUCCESS == rc)) { + + //Max time the yield function will wait for read messages + rc = aws_iot_mqtt_yield(&client, 100); + if(NETWORK_ATTEMPTING_RECONNECT == rc) { + // If the client is attempting to reconnect we will skip the rest of the loop. + continue; + } + + ESP_LOGI(TAG, "-->sleep"); + vTaskDelay(1000 / portTICK_RATE_MS); + sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS0)", i++); + paramsQOS0.payloadLen = strlen(cPayload); + rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS0); + + sprintf(cPayload, "%s : %d ", "hello from ESP32 (QOS1)", i++); + paramsQOS1.payloadLen = strlen(cPayload); + rc = aws_iot_mqtt_publish(&client, TOPIC, TOPIC_LEN, ¶msQOS1); + if (rc == MQTT_REQUEST_TIMEOUT_ERROR) { + ESP_LOGW(TAG, "QOS1 publish ack not received."); + rc = SUCCESS; + } + } + + ESP_LOGE(TAG, "An error occurred in the main loop."); + abort(); +} + +static void initialise_wifi(void) +{ + tcpip_adapter_init(); + wifi_event_group = xEventGroupCreate(); + ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + ESP_ERROR_CHECK( esp_wifi_init(&cfg) ); + ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) ); + wifi_config_t wifi_config = { + .sta = { + .ssid = EXAMPLE_WIFI_SSID, + .password = EXAMPLE_WIFI_PASS, + }, + }; + ESP_LOGI(TAG, "Setting WiFi configuration SSID %s...", wifi_config.sta.ssid); + ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) ); + ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &wifi_config) ); + ESP_ERROR_CHECK( esp_wifi_start() ); +} + + +void app_main() +{ + // Initialize NVS. + esp_err_t err = nvs_flash_init(); + if (err == ESP_ERR_NVS_NO_FREE_PAGES) { + ESP_ERROR_CHECK(nvs_flash_erase()); + err = nvs_flash_init(); + } + ESP_ERROR_CHECK( err ); + + initialise_wifi(); +#ifdef CONFIG_MBEDTLS_DEBUG + const size_t stack_size = 36*1024; +#else + const size_t stack_size = 36*1024; +#endif + xTaskCreatePinnedToCore(&aws_iot_task, "aws_iot_task", stack_size, NULL, 5, NULL, 1); +} diff --git a/examples/espidf-ble-adv/platformio.ini b/examples/espidf-ble-adv/platformio.ini index f569580..370f2b4 100644 --- a/examples/espidf-ble-adv/platformio.ini +++ b/examples/espidf-ble-adv/platformio.ini @@ -14,10 +14,10 @@ board = nano32 build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" monitor_speed = 115200 -[env:espea32] +[env:esp wrover kit] platform = espressif32 framework = espidf -board = espea32 +board = esp-wrover-kit build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" monitor_speed = 115200 diff --git a/examples/espidf-ble-adv/src/sdkconfig.h b/examples/espidf-ble-adv/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-ble-adv/src/sdkconfig.h +++ b/examples/espidf-ble-adv/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/examples/espidf-coap-server/platformio.ini b/examples/espidf-coap-server/platformio.ini index f569580..370f2b4 100644 --- a/examples/espidf-coap-server/platformio.ini +++ b/examples/espidf-coap-server/platformio.ini @@ -14,10 +14,10 @@ board = nano32 build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" monitor_speed = 115200 -[env:espea32] +[env:esp wrover kit] platform = espressif32 framework = espidf -board = espea32 +board = esp-wrover-kit build_flags = -DCONFIG_WIFI_SSID=\"ESP_AP\" -DCONFIG_WIFI_PASSWORD=\"MYPASS\" monitor_speed = 115200 diff --git a/examples/espidf-coap-server/src/sdkconfig.h b/examples/espidf-coap-server/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-coap-server/src/sdkconfig.h +++ b/examples/espidf-coap-server/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/examples/espidf-exceptions/platformio.ini b/examples/espidf-exceptions/platformio.ini index 151a124..2094ef0 100644 --- a/examples/espidf-exceptions/platformio.ini +++ b/examples/espidf-exceptions/platformio.ini @@ -14,10 +14,10 @@ board = esp32dev build_flags = -DPIO_FRAMEWORK_ESP_IDF_ENABLE_EXCEPTIONS monitor_speed = 115200 -[env:quantum] +[env:esp wrover kit] platform = espressif32 framework = espidf -board = quantum +board = esp-wrover-kit build_flags = -DPIO_FRAMEWORK_ESP_IDF_ENABLE_EXCEPTIONS monitor_speed = 115200 diff --git a/examples/espidf-exceptions/src/sdkconfig.h b/examples/espidf-exceptions/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-exceptions/src/sdkconfig.h +++ b/examples/espidf-exceptions/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/examples/espidf-hello-world/platformio.ini b/examples/espidf-hello-world/platformio.ini index d5db57d..0df3abc 100644 --- a/examples/espidf-hello-world/platformio.ini +++ b/examples/espidf-hello-world/platformio.ini @@ -13,10 +13,10 @@ framework = espidf board = esp32dev monitor_speed = 115200 -[env:quantum] +[env:esp wrover kit] platform = espressif32 framework = espidf -board = quantum +board = esp-wrover-kit monitor_speed = 115200 [env:lolin 32] diff --git a/examples/espidf-hello-world/src/sdkconfig.h b/examples/espidf-hello-world/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-hello-world/src/sdkconfig.h +++ b/examples/espidf-hello-world/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/examples/espidf-http-request/src/sdkconfig.h b/examples/espidf-http-request/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-http-request/src/sdkconfig.h +++ b/examples/espidf-http-request/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/examples/espidf-peripherals-uart/src/sdkconfig.h b/examples/espidf-peripherals-uart/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-peripherals-uart/src/sdkconfig.h +++ b/examples/espidf-peripherals-uart/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/examples/espidf-storage-sdcard/src/sdkconfig.h b/examples/espidf-storage-sdcard/src/sdkconfig.h index 67391da..83ee3fc 100644 --- a/examples/espidf-storage-sdcard/src/sdkconfig.h +++ b/examples/espidf-storage-sdcard/src/sdkconfig.h @@ -221,3 +221,14 @@ #define CONFIG_ESPTOOLPY_PORT "/dev/ttyUSB0" #define CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ABORTS 1 #define CONFIG_BLUEDROID_PINNED_TO_CORE 0 +#define CONFIG_AWS_IOT_MQTT_PORT 8883 +#define CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 +#define CONFIG_AWS_IOT_MQTT_RX_BUF_LEN 512 +#define CONFIG_AWS_IOT_MQTT_TX_BUF_LEN 512 +#define CONFIG_EXAMPLE_EMBEDDED_CERTS 1 +#define CONFIG_AWS_IOT_SDK 1 +#define CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 +#define CONFIG_AWS_EXAMPLE_CLIENT_ID "myesp32" +#define CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 +#define CONFIG_AWS_IOT_MQTT_HOST "" + diff --git a/platform.json b/platform.json index 0b82702..1b3fa05 100644 --- a/platform.json +++ b/platform.json @@ -12,7 +12,7 @@ "type": "git", "url": "https://github.com/platformio/platform-espressif32.git" }, - "version": "1.1.2", + "version": "1.2.0", "packageRepositories": [ "https://dl.bintray.com/platformio/dl-packages/manifest.json", "http://dl.platformio.org/packages/manifest.json", @@ -45,12 +45,12 @@ "framework-arduinoespressif32": { "type": "framework", "optional": true, - "version": "~1.6.0" + "version": "~1.10000.0" }, "framework-espidf": { "type": "framework", "optional": true, - "version": "~2.301.0" + "version": "~2.302.0" }, "framework-simba": { "type": "framework", @@ -64,7 +64,7 @@ }, "tool-esptoolpy": { "type": "uploader", - "version": "~1.20410.0" + "version": "~1.20500.0" }, "tool-espotapy": { "type": "uploader", diff --git a/platform.py b/platform.py index 37483c7..1df8e76 100644 --- a/platform.py +++ b/platform.py @@ -81,7 +81,6 @@ class Espressif32Platform(PlatformBase): "end", "target extended-remote $DEBUG_PORT", "$INIT_BREAK", - "mon reset halt", "$LOAD_CMD", "pio_reset_halt_target" ],