├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── README.md ├── azure-pipelines.yml ├── build_all ├── PrintTestsLst.cmd ├── README_builder.ps1 ├── README_template.md ├── Tests_Huzzah.lst ├── Tests_M0WiFi.lst ├── Tests_Thingdev.lst ├── base-libraries │ ├── AzureIoTHub │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── keywords.txt │ │ ├── library.properties │ │ └── src │ │ │ ├── AzureIoTHub.h │ │ │ └── scripts │ │ │ └── automate_board_config.py │ ├── AzureIoTProtocol_HTTP │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── keywords.txt │ │ ├── library.properties │ │ └── src │ │ │ └── AzureIoTProtocol_HTTP.h │ ├── AzureIoTProtocol_MQTT │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── keywords.txt │ │ ├── library.properties │ │ └── src │ │ │ └── AzureIoTProtocol_MQTT.h │ ├── AzureIoTSocket_WiFi │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── keywords.txt │ │ ├── library.properties │ │ └── src │ │ │ └── AzureIoTSocket_WiFi.h │ └── AzureIoTUtility │ │ ├── .travis.yml │ │ ├── README.md │ │ ├── keywords.txt │ │ ├── library.properties │ │ └── src │ │ ├── AzureIoTUtility.h │ │ ├── esp32 │ │ ├── azcpgmspace.cpp │ │ ├── azcpgmspace.h │ │ ├── sample_init.cpp │ │ └── sample_init.h │ │ ├── esp8266 │ │ ├── azcpgmspace.cpp │ │ ├── azcpgmspace.h │ │ ├── sample_init.cpp │ │ └── sample_init.h │ │ └── samd │ │ ├── NTPClientAz.cpp │ │ ├── NTPClientAz.h │ │ ├── sample_init.cpp │ │ ├── sample_init.h │ │ ├── stdio.cpp │ │ └── time.cpp ├── build.cmd ├── build_prep.cmd ├── bump_version.ps1 ├── download_blob.cmd ├── edit_huzzah.ps1 ├── edit_sample.ps1 ├── ensure_delete_directory.cmd ├── ensure_tagged_git_repo.cmd ├── execute.ps1 ├── fix_format_strings.ps1 ├── get_sample.cmd ├── make_sdk.cmd ├── make_sdk.py ├── make_sdk_cmds_dict.py └── set_build_vars.cmd ├── devdoc ├── img_src │ └── tlsio_arduino.vsdx ├── platform_arduino_requirements.md ├── threadapi_arduino_requirements.md └── tlsio_arduino_requirements.md ├── jenkins ├── ubuntu1604_c.sh └── windows_c.cmd ├── pal ├── AzureIoTSocket_WiFi │ └── socketio_esp32wifi.cpp ├── azure_c_shared_utility │ └── xlogging.h ├── inc │ ├── sslClient_arduino.h │ └── tlsio_arduino.h ├── samples │ ├── esp32 │ │ └── iothub_ll_telemetry_sample │ │ │ ├── iot_configs.h │ │ │ ├── iothub_ll_telemetry_sample.ino │ │ │ ├── platform.local.txt │ │ │ └── sample_init.h │ └── esp8266 │ │ └── iothub_ll_telemetry_sample │ │ ├── iot_configs.h │ │ ├── iothub_ll_telemetry_sample.ino │ │ ├── platform.local.txt │ │ └── sample_init.h └── src │ ├── platform_arduino.c │ ├── sslClient_arduino.cpp │ ├── threadapi_arduino.c │ ├── tlsio_arduino.c │ └── xlogging_dump_bytes.c └── sdk_tests ├── CMakeLists.txt ├── platformarduino_ut ├── CMakeLists.txt ├── main.c └── platformarduino_ut.c └── tlsioarduino_ut ├── CMakeLists.txt ├── main.c └── tlsioarduino_ut.c /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "pal/mbedtls"] 2 | path = pal/mbedtls 3 | url = https://github.com/ARMmbed/mbedtls 4 | [submodule "sdk"] 5 | path = sdk 6 | url = https://github.com/Azure/azure-iot-sdk-c 7 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | cmake_minimum_required(VERSION 2.8.11) 5 | 6 | project(azure_external_unit_tests) 7 | 8 | # Set up the C SDK options to build as little as possible 9 | option(skip_samples "set skip_samples to ON to skip building samples (default is OFF)[if possible, they are always build]" ON) 10 | option(compileOption_C "passes a string to the command line of the C compiler" OFF) 11 | option(compileOption_CXX "passes a string to the command line of the C++ compiler" OFF) 12 | option(no_logging "disable logging" OFF) 13 | option(run_e2e_tests "set run_e2e_tests to ON to run e2e tests (default is OFF)" OFF) 14 | option(run_unittests "set run_unittests to ON to run unittests (default is OFF)" OFF) 15 | option(use_cppunittest "set use_cppunittest to ON to build CppUnitTest tests on Windows (default is ON)" ON) 16 | 17 | # include the sdk for its header files and libs 18 | set(run_unittests OFF) 19 | include("sdk/c-utility/configs/azure_iot_external_pal_unit_test_setup.cmake") 20 | 21 | # Configure this external repo 22 | # Currently this CMakeLists.txt file is only used for unit tests 23 | # EXTERNAL_PAL_REPO_DIR contains this top-level CMakeLists.txt 24 | set(EXTERNAL_PAL_REPO_DIR ${CMAKE_CURRENT_LIST_DIR}) 25 | include_directories(${SHARED_UTIL_PAL_INC_FOLDER}) 26 | 27 | 28 | set(run_unittests ON) 29 | add_subdirectory(sdk_tests) 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # azure-iot-pal-arduino 2 | 3 | > ### Stop! Before you proceed: 4 | > 5 | > _This Arduino Library is deprecated._ 6 | > 7 | > _It is kept here for **reference only** and should not be used for any new development._ 8 | > 9 | > _If you’re looking for an Arduino Library you should use the new version: [aka.ms/arduino](https://aka.ms/arduino)_ 10 | > 11 | >_You can find more information about it in this [IoT Tech Community blog post](https://techcommunity.microsoft.com/t5/internet-of-things-blog/arduino-library-for-azure-iot/ba-p/3034455)._ 12 | > 13 | 14 | This repository contains all of the Arduino-specific source files for the Azure IoT Arduino 15 | libraries. 16 | 17 | #### Published libraries 18 | The published Azure IoT Arduino libraries are here: 19 | * [AzureIoTHub Arduino **published library**](https://github.com/Azure/azure-iot-arduino) 20 | * [AzureIoTProtocol_MQTT Arduino **published library**](https://github.com/Azure/azure-iot-arduino-protocol-mqtt) 21 | * [AzureIoTProtocol_HTTP Arduino **published library**](https://github.com/Azure/azure-iot-arduino-protocol-http) 22 | * [AzureIoTUtility Arduino **published library**](https://github.com/Azure/azure-iot-arduino-utility) 23 | * [AzureIoTSocket_WiFi **published library**](https://github.com/Azure/azure-iot-arduino-socket-esp32-wifi) 24 | 25 | Contributions should _not_ be made to these locations, as they are auto-generated. 26 | 27 | #### Arduino-specific library sources 28 | 29 | Arduino-specific sources for the Azure IoT Arduino libraries are kept in this repository: 30 | * [AzureIoTHub **Arduino sources**](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTHub) 31 | * [AzureIoTProtocol_MQTT **Arduino sources**](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTProtocol_MQTT) 32 | * [AzureIoTProtocol_HTTP **Arduino sources**](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTProtocol_HTTP) 33 | * [AzureIoTUtility **Arduino sources**](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTUtility) 34 | * [AzureIoTSocket_WiFi **Arduino sources**](https://github.com/Azure/azure-iot-pal-arduino/tree/master/pal/AzureIoTSocket_WiFi) 35 | 36 | Arduino-specific contributions should be made to these locations. 37 | 38 | #### Non-Arduino-specific Azure IoT sources 39 | 40 | The non-Arduino-specific portions of the Azure IoT C SDK are found here: 41 | * [AzureIoTHub **sources**](https://github.com/Azure/azure-iot-sdk-c) 42 | * [AzureIoTProtocol_MQTT **sources**](https://github.com/Azure/azure-umqtt-c) 43 | * [AzureIoTProtocol_HTTP **sources**](https://github.com/Azure/azure-c-shared-utility) 44 | * [AzureIoTUtility **sources**](https://github.com/Azure/azure-c-shared-utility) 45 | 46 | Contributions which are not Arduino-specific should be made to these locations. 47 | 48 | #### Azure IoT Arduino Library README.md sources 49 | 50 | The README.txt files for the Arduino libraries are auto-generated during the release 51 | process from a template file using a script. 52 | Contributions to the README.md files for any of the four Azure IoT Arduino libraries should be made by 53 | modifying one or both of 54 | 55 | * [README_builder.ps1](https://github.com/Azure/azure-iot-pal-arduino/blob/master/build_all/README_builder.ps1) 56 | * [README_template.md](https://github.com/Azure/azure-iot-pal-arduino/blob/master/build_all/README_template.md) 57 | 58 | 59 | ### Contributing 60 | 61 | This project welcomes contributions and suggestions. Most contributions require you to agree to a 62 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us 63 | the rights to use your contribution. For details, visit https://cla.microsoft.com. 64 | 65 | When you submit a pull request, a CLA-bot will automatically determine whether you need to provide 66 | a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions 67 | provided by the bot. You will only need to do this once across all repos using our CLA. 68 | 69 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 70 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or 71 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 72 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Starter pipeline 2 | # Start with a minimal pipeline that you can customize to build and deploy your code. 3 | # Add steps that build, run tests, deploy, and more: 4 | # https://aka.ms/yaml 5 | 6 | trigger: 7 | - master 8 | 9 | pool: 10 | vmImage: ubuntu-latest 11 | 12 | steps: 13 | - script: echo Hello, world! 14 | displayName: 'Run a one-line script' 15 | 16 | - script: | 17 | echo Add other tasks to build, test, and deploy your project. 18 | echo See https://aka.ms/yaml 19 | displayName: 'Run a multi-line script' 20 | -------------------------------------------------------------------------------- /build_all/PrintTestsLst.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @echo off 5 | setlocal EnableDelayedExpansion 6 | 7 | REM =============================================================================================================== 8 | REM == This batch shows how to parser the tests.lst. It will call "ExecuteTest" for each test in the list, the test 9 | REM == name will be in projectName, and each parameter in the list will set as a local variable. It is necessary to 10 | REM == use '!' besides '%' in these variables to avoid batch expansion problem. 11 | REM =============================================================================================================== 12 | 13 | call :ParserTestLst 14 | goto :eof 15 | 16 | 17 | REM Parser tests.lst 18 | :ParserTestLst 19 | set buildlog=tests.lst 20 | set testName=false 21 | set projectName= 22 | 23 | for /F "tokens=*" %%F in (%buildlog%) do ( 24 | if /i "%%F"=="" ( 25 | REM ignore empty line. 26 | ) else ( 27 | set command=%%F 28 | if /i "!command:~0,1!"=="#" ( 29 | echo Comment=!command:~1! 30 | ) else ( if /i "!command:~0,1!"=="[" ( 31 | call :ExecuteTest 32 | set projectName=!command:~1,-1! 33 | if /i "!projectName!"=="End" goto :eof 34 | ) else ( 35 | for /f "tokens=1 delims==" %%A in ("!command!") do set key=%%A 36 | call set value=%%command:!key!=%% 37 | set value=!value:~1! 38 | set !key!=!value! 39 | ) ) ) 40 | ) 41 | ) 42 | goto :eof 43 | 44 | 45 | REM Execute each test in the Tests.lst 46 | :ExecuteTest 47 | if not "!projectName!"=="" ( 48 | echo. 49 | echo Execute !projectName! 50 | echo RelativePath=!RelativePath! 51 | echo RelativeWorkingDir=!RelativeWorkingDir! 52 | echo MaxAllowedDurationSeconds=!MaxAllowedDurationSeconds! 53 | echo Categories=!Categories! 54 | echo Hardware=!Hardware! 55 | echo CPUParameters=!CPUParameters! 56 | echo Build=!Build! 57 | echo Installation=!Installation! 58 | echo Execution=!Execution! 59 | ) 60 | goto :eof -------------------------------------------------------------------------------- /build_all/README_builder.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/azure-iot-pal-arduino/a9849e7f23ce998357ab888a3d268c6c87de1606/build_all/README_builder.ps1 -------------------------------------------------------------------------------- /build_all/README_template.md: -------------------------------------------------------------------------------- 1 | This project has adopted the 2 | [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 3 | For more information see the 4 | [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact 5 | [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 6 | 7 | {{title}} 8 | 9 | ## Contributors 10 | 11 | ### **Pull request caution!** 12 | All of the files in these Arduino library directories are auto-generated 13 | by the Azure IoT C SDK release process, so pull requests cannot be 14 | accepted in this repo. 15 | Your Arduino-specific contributions will be welcomed with open arms in these locations: 16 | * [AzureIoTHub Arduino-specific sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTHub) 17 | * [AzureIoTProtocol_HTTP sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTProtocol_HTTP) 18 | * [AzureIoTProtocol_MQTT Arduino-specific sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTProtocol_MQTT) 19 | * [AzureIoTUtility Arduino-specific sources](https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all/base-libraries/AzureIoTUtility) 20 | 21 | Contributions for code that is not Arduino-specific can be made to the 22 | [Azuure IoT C SDK](https://github.com/azure/azure-iot-sdk-c) 23 | 24 | ## Currently supported hardware 25 | - Atmel SAMD Based boards 26 | - Adafruit [Feather M0](https://www.adafruit.com/products/3010) 27 | - ESP8266 based boards with [esp8266/arduino](https://github.com/esp8266/arduino) 28 | - SparkFun [Thing](https://www.sparkfun.com/products/13711) 29 | - Adafruit [Feather Huzzah](https://www.adafruit.com/products/2821) 30 | 31 | ## Prerequisites 32 | 33 | You should have the following ready before beginning with any board: 34 | - [Setup your IoT hub](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md) 35 | - [Provision your device and get its credentials](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md#create-new-device-in-the-iot-hub-device-identity-registry) 36 | - [Arduino IDE 1.6.12](https://www.arduino.cc/en/Main/Software) 37 | - Install the [`AzureIoTHub`](https://github.com/Azure/azure-iot-arduino) library via the Arduino IDE Library Manager 38 | - Install the [`AzureIoTUtility`](https://github.com/Azure/azure-iot-arduino-utility) library via the Arduino IDE Library Manager 39 | - Install the [`AzureIoTProtocol_{{protocol_uc}}`](https://github.com/Azure/azure-iot-arduino-protocol-{{protocol_lc}}) library via the Arduino IDE Library Manager 40 | 41 | 42 | ## Simple Sample Instructions 43 | 44 | ### ESP8266 45 | ##### Sparkfun Thing, Adafruit Feather Huzzah, or generic ESP8266 board 46 | 47 | 1. Install esp8266 board support into your Arduino IDE. 48 | * Start Arduino and open Preferences window. 49 | * Enter `http://arduino.esp8266.com/stable/package_esp8266com_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. 50 | * Open Boards Manager from Tools > Board menu and install esp8266 platform 2.2.0 or later 51 | * Select your ESP8266 board from Tools > Board menu after installation 52 | 53 | 2. Open the `simplesample_{{protocol_lc}}` example from the Arduino IDE File->AzureIoTHub->ESP8266->Examples menu. 54 | 4. Update Wifi SSID/Password and IoT Hub Connection string in iot_configs.h 55 | * Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. 56 | 6. Access the [SparkFun Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-thingdev-getstartedkit/) tutorial to learn more about Microsoft Sparkfun Dev Kit. 57 | 7. Access the [Huzzah Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-huzzah-getstartedkit/) tutorial to learn more about Microsoft Huzzah Dev Kit. 58 | 59 | 60 | ### Adafruit Feather M0 61 | 1. Install Feather M0 board support into your Arduino IDE. 62 | * Start Arduino and open Preferences window. 63 | * Enter `https://adafruit.github.io/arduino-board-index/package_adafruit_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. 64 | * Open Boards Manager from Tools > Board menu and install `Arduino SAMD Boards` and `Adafruit SAMD Boards` 1.0.7 or later. 65 | * Select your `Adafruit Feather M0` from Tools > Board menu after installation 66 | 2. Install the `WiFi101` library from the Arduino IDE Library Manager. 67 | 3. Install the `RTCZero` library from the Arduino IDE Library Manager. 68 | 5. Open the `simplesample_{{protocol_lc}}` example from the Arduino IDE File->AzureIoTHub->M0->Examples menu. 69 | 4. Update Wifi SSID/Password and IoT Hub Connection string in iot_configs.h 70 | * Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. 71 | 9. Access the [Feather M0 WiFi Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-m0wifi-getstartedkit/) tutorial to learn more about Microsoft Feather M0 WiFi Dev Kit. 72 | 73 | ## License 74 | 75 | See [LICENSE](LICENSE) file. 76 | 77 | [azure-certifiedforiot]: http://azure.com/certifiedforiot 78 | [Microsoft-Azure-Certified-Badge]: images/Microsoft-Azure-Certified-150x150.png (Microsoft Azure Certified) 79 | -------------------------------------------------------------------------------- /build_all/Tests_Huzzah.lst: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | [huzzah_remote_monitoring] 5 | Target=remote_monitoring.ino 6 | SourcePath=!kits_root!\iot-hub-c-huzzah-getstartedkit\remote_monitoring 7 | RelativeWorkingDir=\huzzah_remote_monitoring 8 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-huzzah-getstartedkit 9 | MaxAllowedDurationSeconds=100 10 | LogLines=300 11 | MinimumHeap=6400 12 | Categories=IoTHub 13 | Hardware=Adafruit_Huzzah 14 | SerialPort=COM4 15 | CPUParameters=-fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 16 | Build=Enable 17 | Execution=Enable 18 | 19 | [huzzah_device_twin] 20 | Target=device_twin.ino 21 | SourcePath=!kits_root!\iot-hub-c-huzzah-getstartedkit\device_twin 22 | RelativeWorkingDir=\device_twin 23 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-huzzah-getstartedkit 24 | MaxAllowedDurationSeconds=100 25 | LogLines=300 26 | MinimumHeap=6400 27 | Categories=IoTHub 28 | Hardware=Adafruit_Huzzah 29 | SerialPort=COM4 30 | CPUParameters=-fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 31 | Build=Enable 32 | Execution=Disable 33 | 34 | [huzzah_command_center] 35 | Target=command_center.ino 36 | SourcePath=!kits_root!\iot-hub-c-huzzah-getstartedkit\command_center 37 | RelativeWorkingDir=\huzzah_command_center 38 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-huzzah-getstartedkit 39 | MaxAllowedDurationSeconds=100 40 | LogLines=300 41 | MinimumHeap=6400 42 | Categories=IoTHub 43 | Hardware=Adafruit_Huzzah 44 | SerialPort=COM4 45 | CPUParameters=-fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 46 | Build=Enable 47 | Execution=Disable 48 | 49 | [huzzah_simplesample_http] 50 | Target=simplesample_http.ino 51 | SourcePath=!kits_root!\iot-hub-c-huzzah-getstartedkit\simplesample_http 52 | RelativeWorkingDir=\huzzah_simplesample_http 53 | CloneURL="" 54 | MaxAllowedDurationSeconds=100 55 | LogLines=300 56 | MinimumHeap=6400 57 | Categories=IoTHub 58 | Hardware=Adafruit_Huzzah 59 | SerialPort=COM4 60 | CPUParameters=-fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 61 | Build=Enable 62 | Execution=Disable 63 | 64 | [huzzah_simplesample_mqtt] 65 | Target=simplesample_mqtt.ino 66 | SourcePath=!kits_root!\iot-hub-c-huzzah-getstartedkit\simplesample_mqtt 67 | RelativeWorkingDir=\huzzah_simplesample_mqtt 68 | CloneURL="" 69 | MaxAllowedDurationSeconds=100 70 | LogLines=300 71 | MinimumHeap=6400 72 | Categories=IoTHub 73 | Hardware=Adafruit_Huzzah 74 | SerialPort=COM4 75 | CPUParameters=-fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 76 | Build=Enable 77 | Execution=Disable 78 | 79 | [End] -------------------------------------------------------------------------------- /build_all/Tests_M0WiFi.lst: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | [m0wifi_remote_monitoring] 5 | Target=remote_monitoring.ino 6 | SourcePath=!kits_root!\iot-hub-c-m0wifi-getstartedkit\remote_monitoring 7 | RelativeWorkingDir=\m0wifi_remote_monitoring 8 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-m0wifi-getstartedkit 9 | MaxAllowedDurationSeconds=100 10 | LogLines=300 11 | MinimumHeap=7000 12 | Categories=IoTHub 13 | Hardware=Adafruit_FeatherM0 14 | SerialPort=COM9 15 | CPUParameters=-fqbn=adafruit:samd:adafruit_feather_m0 -ide-version=10805 16 | Build=Enable 17 | Execution=Disable 18 | 19 | [m0wifi_command_center] 20 | Target=command_center.ino 21 | SourcePath=!kits_root!\iot-hub-c-m0wifi-getstartedkit\command_center 22 | RelativeWorkingDir=\m0wifi_command_center 23 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-m0wifi-getstartedkit 24 | MaxAllowedDurationSeconds=100 25 | LogLines=300 26 | MinimumHeap=7000 27 | Categories=IoTHub 28 | Hardware=Adafruit_FeatherM0 29 | SerialPort=COM9 30 | CPUParameters=-fqbn=adafruit:samd:adafruit_feather_m0 -ide-version=10805 31 | Build=Enable 32 | Execution=Disable 33 | 34 | [m0wifi_simplesample_http] 35 | Target=simplesample_http.ino 36 | SourcePath=!kits_root!\iot-hub-c-m0wifi-getstartedkit\simplesample_http 37 | RelativeWorkingDir=\m0wifi_simplesample_http 38 | CloneURL="" 39 | MaxAllowedDurationSeconds=100 40 | LogLines=300 41 | MinimumHeap=7000 42 | Categories=IoTHub 43 | Hardware=Adafruit_FeatherM0 44 | SerialPort=COM9 45 | CPUParameters=-fqbn=adafruit:samd:adafruit_feather_m0 -ide-version=10805 46 | Build=Disable 47 | Execution=Disable 48 | 49 | [m0wifi_simplesample_mqtt] 50 | Target=simplesample_mqtt.ino 51 | SourcePath=!kits_root!\iot-hub-c-m0wifi-getstartedkit\simplesample_mqtt 52 | RelativeWorkingDir=\m0wifi_simplesample_mqtt 53 | CloneURL="" 54 | MaxAllowedDurationSeconds=100 55 | LogLines=300 56 | MinimumHeap=7000 57 | Categories=IoTHub 58 | Hardware=Adafruit_FeatherM0 59 | SerialPort=COM9 60 | CPUParameters=-fqbn=adafruit:samd:adafruit_feather_m0 -ide-version=10805 61 | Build=Disable 62 | Execution=Disable 63 | 64 | [End] -------------------------------------------------------------------------------- /build_all/Tests_Thingdev.lst: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | [thingdev_remote_monitoring] 5 | Target=remote_monitoring.ino 6 | SourcePath=!kits_root!\iot-hub-c-thingdev-getstartedkit\remote_monitoring 7 | RelativeWorkingDir=\thingdev_remote_monitoring 8 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-thingdev-getstartedkit.git 9 | MaxAllowedDurationSeconds=100 10 | LogLines=300 11 | MinimumHeap=7000 12 | Categories=IoTHub 13 | Hardware=SparkFun_ESP8266_Thing 14 | SerialPort=COM6 15 | CPUParameters=-fqbn=esp8266:esp8266:thingdev:CpuFrequency=80,FlashSize=512K0,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 -ide-version=10805 16 | Build=Enable 17 | Execution=Enable 18 | 19 | [thingdev_command_center] 20 | Target=command_center.ino 21 | SourcePath=!kits_root!\iot-hub-c-thingdev-getstartedkit\command_center 22 | RelativeWorkingDir=\thingdev_command_center 23 | CloneURL=https://github.com/Azure-Samples/iot-hub-c-thingdev-getstartedkit.git 24 | MaxAllowedDurationSeconds=100 25 | LogLines=300 26 | MinimumHeap=7000 27 | Categories=IoTHub 28 | Hardware=SparkFun_ESP8266_Thing 29 | SerialPort=COM6 30 | CPUParameters=-fqbn=esp8266:esp8266:thingdev:CpuFrequency=80,FlashSize=512K0,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 -ide-version=10805 31 | Build=Enable 32 | Execution=Disable 33 | 34 | [thingdev_simplesample_http] 35 | Target=simplesample_http.ino 36 | SourcePath=!kits_root!\iot-hub-c-thingdev-getstartedkit\simplesample_http 37 | RelativeWorkingDir=\thingdev_simplesample_http 38 | CloneURL="" 39 | MaxAllowedDurationSeconds=100 40 | LogLines=300 41 | MinimumHeap=7000 42 | Categories=IoTHub 43 | Hardware=SparkFun_ESP8266_Thing 44 | SerialPort=COM6 45 | CPUParameters=-fqbn=esp8266:esp8266:thingdev:CpuFrequency=80,FlashSize=512K0,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 -ide-version=10805 46 | Build=Enable 47 | Execution=Disable 48 | 49 | [thingdev_simplesample_mqtt] 50 | Target=simplesample_mqtt.ino 51 | SourcePath=!kits_root!\iot-hub-c-thingdev-getstartedkit\simplesample_mqtt 52 | RelativeWorkingDir=\thingdev_simplesample_mqtt 53 | CloneURL="" 54 | MaxAllowedDurationSeconds=100 55 | LogLines=300 56 | MinimumHeap=7000 57 | Categories=IoTHub 58 | Hardware=SparkFun_ESP8266_Thing 59 | SerialPort=COM6 60 | CPUParameters=-fqbn=esp8266:esp8266:thingdev:CpuFrequency=80,FlashSize=512K0,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,UploadSpeed=115200 -ide-version=10805 61 | Build=Enable 62 | Execution=Disable 63 | 64 | [End] -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTHub/.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | language: generic 5 | env: 6 | global: 7 | - IDE_VERSION=1.8.10 8 | matrix: 9 | - BOARD="esp8266:esp8266:huzzah:FlashSize=4M3M,CpuFrequency=80" 10 | - BOARD="esp8266:esp8266:thing" 11 | - BOARD="esp32:esp32:huzzah" 12 | before_install: 13 | - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 14 | - sleep 3 15 | - export DISPLAY=:1.0 16 | - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz 17 | - tar xf arduino-$IDE_VERSION-linux64.tar.xz 18 | - mv arduino-$IDE_VERSION $HOME/arduino-ide 19 | - export PATH=$PATH:$HOME/arduino-ide 20 | - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then 21 | arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --install-boards esp8266:esp8266; 22 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 23 | arduino --install-library NTPClient; 24 | fi 25 | - if [[ "$BOARD" =~ "esp32:esp32:" ]]; then 26 | arduino --pref "boardsmanager.additional.urls=https://dl.espressif.com/dl/package_esp32_index.json" --install-boards esp32:esp32; 27 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 28 | arduino --install-library NTPClient; 29 | fi 30 | 31 | - findAndReplace() { sed -i'' -e"s|$1|$2|g" "$3"; } 32 | - buildExampleSketch() { 33 | EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino; 34 | 35 | arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH; 36 | } 37 | install: 38 | - arduino --install-library "AzureIoTUtility" 39 | - arduino --install-library "AzureIoTSocket_WiFi" 40 | - arduino --install-library "AzureIoTProtocol_MQTT" 41 | - arduino --install-library "AzureIoTProtocol_HTTP" 42 | - ln -s $PWD $HOME/Arduino/libraries/. 43 | script: 44 | - buildExampleSketch telemetry_sample.c 45 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTHub/README.md: -------------------------------------------------------------------------------- 1 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 2 | 3 | #### Azure IoT Hub Library source files 4 | 5 | 6 | # AzureIoTHub - Azure IoT Hub library for Arduino 7 | 8 | This is the location of the Arduino-specific source files for the 9 | 10 | [AzureIoTHub Arduino published library](https://github.com/Azure/azure-iot-arduino). 11 | 12 | This library is a port of the [Microsoft Azure IoT device SDK for C](https://github.com/Azure/azure-iot-sdk-c) to Arduino. It allows you to use several Arduino compatible boards with Azure IoT Hub. Please submit any contribution directly to [azure-iot-sdks](https://github.com/Azure/azure-iot-sdks). 13 | 14 | Currently supported hardware: 15 | 16 | - ESP8266 based boards with [esp8266/arduino](https://github.com/esp8266/arduino) 17 | 18 | - SparkFun [Thing](https://www.sparkfun.com/products/13711) 19 | 20 | - Adafruit [Feather Huzzah](https://www.adafruit.com/products/2821) 21 | 22 | - ESP32 based boards with [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32) 23 | 24 | - Adafruit [HUZZAH32](https://www.adafruit.com/product/3405) 25 | 26 | ## Prerequisites 27 | 28 | You should have the following ready before beginning with any board: 29 | 30 | - [Setup your IoT hub](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md) 31 | 32 | - [Provision your device and get its credentials](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md#create-new-device-in-the-iot-hub-device-identity-registry) 33 | 34 | - [Arduino IDE](https://www.arduino.cc/en/Main/Software) 35 | 36 | - Install the Azure IoT C SDK libraries by one of two options: 37 | 1. Generate the Libraries by executing the [`make_sdk.py`](https://github.com/Azure/azure-iot-pal-arduino/blob/master/build_all/make_sdk.py) script within the `build_all` folder, E.x.: `python3 make_sdk.py -o ` 38 | - Note: this is also currently the ONLY way to build the `AzureIoTSocket_WiFi` library for using the esp32. 39 | 40 | 2. Install the following libraries through the Arduino IDE Library Manager: 41 | - `AzureIoTHub`, `AzureIoTUtility`, `AzureIoTProtocol_MQTT`, `AzureIoTProtocol_HTTP` 42 | 43 | # Simple Sample Instructions 44 | 45 | ## ESP8266 46 | 47 | ##### Sparkfun Thing, Adafruit Feather Huzzah, or generic ESP8266 board 48 | 49 | 1. Install esp8266 board support into your Arduino IDE. 50 | 51 | - Start Arduino and open Preferences window. 52 | 53 | - Enter `http://arduino.esp8266.com/stable/package_esp8266com_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. 54 | 55 | - Open Boards Manager from Tools > Board menu and install esp8266 platform 2.5.2 or later 56 | 57 | - Select your ESP8266 board from Tools > Board menu after installation 58 | 59 | 2. Open the `iothub_ll_telemetry_sample` example from the Arduino IDE File->Examples->AzureIoTHub menu. 60 | 61 | 3. Update Wifi SSID/Password in `iot_configs.h` 62 | 63 | - Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. 64 | 65 | 4. Update IoT Hub Connection string in `iot_configs.h` 66 | 67 | 5. Configure board library using the automation script and `python3`. If you choose this method you can skip step 6. 68 | - Clone or download this repo: `git clone https://github.com/Azure/azure-iot-pal-arduino.git` , navigate to the downloaded sub-folder: `cd azure-iot-pal-arduino/build_all/base-libraries/AzureIoTHub/src/scripts` , and check that the script `automate_board_config.py` exists in this location. If this folder or script cannot be located, download the script [directly](https://raw.githubusercontent.com/Azure/azure-iot-pal-arduino/master/build_all/base-libraries/AzureIoTHub/src/scripts/automate_board_config.py). 69 | - Run the script E.x.: `python3 automate_board_config.py` and select appropriate options. 70 | - Note: if you update or reinstall your board library in Arduino you will need to run this script again. 71 | 72 | 6. Navigate to where your esp8266 board package is located, typically in `C:\Users\\AppData\Local\Arduino15\packages` on Windows and `~/.arduino15/packages/` on Linux 73 | 74 | - Locate the board's `Arduino.h` (`hardware/esp8266//cores/esp8266/` and comment out the line containing `#define round(x)`, around line 137. 75 | 76 | - Two folders up from the `Arduino.h` step above, in the same folder as the board's `platform.txt`, paste the [`platform.local.txt`](https://github.com/Azure/azure-iot-arduino/blob/master/examples/iothub_ll_telemetry_sample/esp8266/platform.local.txt) file from the `esp8266` folder in the sample into it. 77 | 78 | - Note1: It is necessary to add `-DDONT_USE_UPLOADTOBLOB` and `-DUSE_BALTIMORE_CERT` to `build.extra_flags=` in a `platform.txt` in order to run the sample, however, you can define them in your own `platform.txt` or a `platform.local.txt` of your own creation. 79 | 80 | - Note2: If your device is not intended to connect to the global portal.azure.com, please change the CERT define to the appropriate cert define as laid out in [`certs.c`](https://github.com/Azure/azure-iot-sdk-c/blob/master/certs/certs.c) 81 | 82 | - Note3: Due to RAM limits, you must select just one CERT define. 83 | 84 | 7. Run the sample. 85 | 86 | 8. Access the [SparkFun Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-thingdev-getstartedkit/) tutorial to learn more about Microsoft Sparkfun Dev Kit. 87 | 88 | 9. Access the [Huzzah Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-huzzah-getstartedkit/) tutorial to learn more about Microsoft Huzzah Dev Kit. 89 | 90 | ## ESP32 91 | 92 | ##### Sparkfun ESP32 Thing, Adafruit ESP32 Feather, or generic ESP32 board 93 | 94 | 1. Install esp32 board support into your Arduino IDE. 95 | 96 | - Start Arduino and open Preferences window. 97 | 98 | - Enter `https://dl.espressif.com/dl/package_esp32_index.json` into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. 99 | 100 | - Open Boards Manager from Tools > Board menu and install esp32 platform 1.0.2 or later 101 | 102 | - Select your ESP32 board from Tools > Board menu after installation 103 | 104 | 2. Open the `iothub_ll_telemetry_sample` example from the Arduino IDE File->Examples->AzureIoTHub menu. 105 | 106 | 3. Update Wifi SSID/Password in `iot_configs.h` 107 | 108 | - Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. 109 | 110 | 4. Update IoT Hub Connection string in `iot_configs.h` 111 | 112 | 5. Configure board library using the automation script and `python3`. If you choose this method you can skip step 6. 113 | - Clone or download this repo: `git clone https://github.com/Azure/azure-iot-pal-arduino.git` , navigate to the downloaded sub-folder: `cd azure-iot-pal-arduino/build_all/base-libraries/AzureIoTHub/src/scripts` , and check that the script `automate_board_config.py` exists in this location. If this folder or script cannot be located, download the script [directly](https://raw.githubusercontent.com/Azure/azure-iot-pal-arduino/master/build_all/base-libraries/AzureIoTHub/src/scripts/automate_board_config.py). 114 | - Run the script E.x.: `python3 automate_board_config.py` and select appropriate options. 115 | - Note: if you update or reinstall your board library in Arduino you will need to run this script again. 116 | 117 | 6. Navigate to where your esp32 board package is located, typically in `C:\Users\\AppData\Local\Arduino15\packages` on Windows and `~/.arduino15/packages/` on Linux 118 | 119 | - Navigate deeper in to `hardware/esp8266//` where the `platform.txt` file lives. 120 | 121 | - Copy the [`platform.local.txt`](https://github.com/Azure/azure-iot-arduino/blob/master/examples/iothub_ll_telemetry_sample/esp32/platform.local.txt) file from the `esp32` folder in the sample into the same folder as the `platform.txt`. 122 | 123 | - Alternatively, or for later versions of the Board Package, add the define `-DDONT_USE_UPLOADTOBLOB` to `build.extra_flags=` in `platform.txt` or a `platform.local.txt` that you create. 124 | 125 | 7. Run the sample. 126 | 127 | 8. Access the [SparkFun Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-thingdev-getstartedkit/) tutorial to learn more about Microsoft Sparkfun Dev Kit. 128 | 129 | 9. Access the [Huzzah Get Started](https://azure.microsoft.com/en-us/documentation/samples/iot-hub-c-huzzah-getstartedkit/) tutorial to learn more about Microsoft Huzzah Dev Kit. 130 | 131 | ## License 132 | 133 | See [LICENSE](LICENSE) file. 134 | 135 | 136 | [azure-certifiedforiot]: http://azure.com/certifiedforiot 137 | 138 | [Microsoft-Azure-Certified-Badge]: images/Microsoft-Azure-Certified-150x150.png (Microsoft Azure Certified) 139 | 140 | Complete information for contributing to the Azure IoT Arduino libraries 141 | 142 | can be found [here](https://github.com/Azure/azure-iot-pal-arduino). 143 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTHub/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For AzureIoTHub 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | AzureIoTHubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | setEpochTime KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTHub/library.properties: -------------------------------------------------------------------------------- 1 | name=AzureIoTHub 2 | version=1.6.0 3 | author=Microsoft 4 | maintainer=Microsoft 5 | sentence=Azure IoT library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing. 6 | paragraph=Arduino port of the Azure IoT C device SDK. It allows you to use your Arduino with the Azure IoT Hub. See readme.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information. 7 | category=Communication 8 | url=https://github.com/Azure/azure-iot-arduino 9 | architectures=esp8266,esp32 10 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTHub/src/AzureIoTHub.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef AZUREIOTHUB_H 5 | #define AZUREIOTHUB_H 6 | 7 | #include "AzureIoTUtility.h" 8 | 9 | #include "serializer.h" 10 | 11 | #include "iothub.h" 12 | #include "iothub_client_ll.h" 13 | #include "iothub_device_client_ll.h" 14 | #include "iothub_client_options.h" 15 | #include "iothub_message.h" 16 | #include "certs/certs.h" 17 | 18 | #define AzureIoTHubVersion "1.6.0" 19 | #endif 20 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTHub/src/scripts/automate_board_config.py: -------------------------------------------------------------------------------- 1 | from pathlib import Path 2 | import os 3 | import sys 4 | import getopt 5 | import fileinput 6 | from shutil import copyfile 7 | 8 | ESP8266_PACKAGE_PATH = Path("packages/esp8266/hardware/esp8266/") 9 | ESP32_PACKAGE_PATH = Path("packages/esp32/hardware/esp32/") 10 | ARDUINO_PACKAGES_PATH = None # Determined by user opts or platform 11 | 12 | 13 | def update_line_file( 14 | file_path, str_line_to_update, str_append, comment_only=False, 15 | comment_str=None): 16 | ''' 17 | Updates a line on a file with a replacement (preserving the original line) 18 | or comments it out 19 | 20 | :param file_path: The path to the file 21 | :type file_path: str 22 | :param str_to_update: The string which will be replaced 23 | :type str_line_to_update str: 24 | :param str_append: The string which replace the line of str_to_update 25 | :type str_append str: 26 | :param comment_only: Determines whether to replace or only comment out a 27 | line 28 | :type comment_only boolean: 29 | :param comment_str: Str to use for a comment if commenting 30 | :type comment_str str: 31 | :raises: :class:`FileNotFound`: File couldn't be opened 32 | 33 | :returns: whether the string was replaced in the file or it was commented 34 | out 35 | :rtype: boolean 36 | ''' 37 | file_modified = False 38 | for line in fileinput.input(file_path, inplace=True): 39 | if line.startswith(str_line_to_update): 40 | if comment_only: 41 | line = f"{comment_str} {line}" 42 | file_modified = True 43 | else: 44 | line = line.rstrip() 45 | line = f"{line}{str_append}\n" 46 | file_modified = True 47 | sys.stdout.write(line) 48 | return file_modified 49 | 50 | 51 | def confirm_overwrite(file_path): 52 | ''' 53 | Confirms whether to overwrite changes otherwise exits program 54 | 55 | :param file_path: The path to the file 56 | :type file_path: str 57 | ''' 58 | prompt = f"There is already a backup file at" \ 59 | f" {file_path}; proceeding will" \ 60 | f" overwrite this file. Do you wish to proceed?" \ 61 | f" Input Y or N:" \ 62 | f" " 63 | while True: 64 | response = input(prompt) 65 | response = response.lower() 66 | if response == 'n': 67 | print("No changes made... exiting") 68 | sys.exit() 69 | elif response == 'y': 70 | print("Backup will be overwritten") 71 | break 72 | else: 73 | print("Ensure your response is a Y or N") 74 | 75 | 76 | def usage(): 77 | ''' 78 | Prints script's opt usage 79 | ''' 80 | print( 81 | "automate_board_config.py usage:\n" 82 | " -h or --help: Print usage text\n" 83 | " -p or --packages_path: Set custom path for Arduino packages path") 84 | sys.exit() 85 | 86 | 87 | def parse_opts(): 88 | ''' 89 | Prints script's command line options 90 | ''' 91 | options, _ = getopt.gnu_getopt( 92 | sys.argv[1:], 93 | 'hp:', 94 | ['help', 'packages_path']) 95 | 96 | for opt, arg in options: 97 | if opt in ('-h', '--help'): 98 | usage() 99 | elif opt in ('-p', '--packages_path'): 100 | global ARDUINO_PACKAGES_PATH 101 | ARDUINO_PACKAGES_PATH = Path(arg) 102 | 103 | 104 | def main(): 105 | parse_opts() 106 | disclaimer_prompt = \ 107 | "This script will attempt to automatically update" \ 108 | " your ESP8266 and/or ESP32 board files to work with Azure IoT Hub" \ 109 | " for the repo https://github.com/Azure/azure-iot-arduino" \ 110 | "\nPlease refer to the license agreement there." \ 111 | "\nThis script will update all installed versions of board" \ 112 | " libraries for ESP8266 and/or ESP32." \ 113 | "\nDo you wish to proceed? Please answer Y or N:" \ 114 | " " 115 | 116 | while True: 117 | response = input(disclaimer_prompt) 118 | response = response.lower() 119 | if response == 'n': 120 | print("No changes made... exiting") 121 | sys.exit() 122 | elif response == 'y': 123 | print("Proceeding") 124 | break 125 | else: 126 | print("Ensure your response is a Y or N") 127 | 128 | board_prompt = \ 129 | "Would you like to update your ESP8266 or ESP32 board files?\n" \ 130 | "For ESP8266 please respond: 8266\n" \ 131 | "For ESP32 please respond: 32\n" \ 132 | "Which board files would you like to update:" \ 133 | " " 134 | 135 | board_to_update = "" 136 | PACKAGE_PATH = "" 137 | while True: 138 | response = input(board_prompt) 139 | response = response.lower() 140 | if response == '8266': 141 | board_to_update = '8266' 142 | PACKAGE_PATH = ESP8266_PACKAGE_PATH 143 | break 144 | elif response == '32': 145 | board_to_update = '32' 146 | PACKAGE_PATH = ESP32_PACKAGE_PATH 147 | break 148 | else: 149 | print("Ensure your response is either 8226 or 32") 150 | 151 | global ARDUINO_PACKAGES_PATH 152 | if ARDUINO_PACKAGES_PATH is None: 153 | if sys.platform == "darwin": 154 | ARDUINO_PACKAGES_PATH = Path(Path.home() / "Library/Arduino15") 155 | elif sys.platform == "linux": 156 | ARDUINO_PACKAGES_PATH = Path(Path.home() / ".arduino15") 157 | elif sys.platform == "win32": 158 | ARDUINO_PACKAGES_PATH = Path( 159 | Path.home() / "AppData/Local/Arduino15") 160 | else: 161 | print(f"Error: no valid board path condition for platform:" 162 | f" {sys.platform}") 163 | sys.exit() 164 | 165 | print(f"Arduino path for platform {sys.platform} is:" 166 | f" {ARDUINO_PACKAGES_PATH}") 167 | 168 | # Check for and change other versions if they exist 169 | BOARD_PATH = Path(ARDUINO_PACKAGES_PATH / PACKAGE_PATH) 170 | try: 171 | versions = [] 172 | with os.scandir(BOARD_PATH) as entries: 173 | for version in entries: 174 | # avoid files and hidden files 175 | if version.is_dir and not version.name.startswith('.'): 176 | versions.append( 177 | Path(BOARD_PATH / version)) 178 | if len(versions) == 0: 179 | raise FileNotFoundError 180 | except FileNotFoundError: 181 | print( 182 | f'Error: Board files for ESP{board_to_update} not found!\n' 183 | f'Directory searched was: {BOARD_PATH}\n' 184 | f'Please ensure that the board library exists at the location' 185 | f', or check command line parameters to specify a' 186 | f' custom Arduino packages path') 187 | sys.exit(1) 188 | 189 | for path in versions: 190 | if PACKAGE_PATH == ESP8266_PACKAGE_PATH: 191 | # 8266 has specific files which 32 aren't required to change 192 | arduino_header_backup = Path(path / "cores/esp8266/Arduino.h.orig") 193 | if arduino_header_backup.exists(): 194 | confirm_overwrite(arduino_header_backup) 195 | arduino_header_file = Path(path / "cores/esp8266/Arduino.h") 196 | if arduino_header_file.exists(): 197 | print(f"Updating: {arduino_header_file}") 198 | copyfile( 199 | arduino_header_file, 200 | Path(path / "cores/esp8266/Arduino.h.orig")) 201 | print( 202 | f"Backup created:" 203 | f" {Path(path / 'cores/esp8266/Arduino.h.orig')}") 204 | get_update = update_line_file( 205 | arduino_header_file, "#define round(x)", 206 | str_append=None, comment_only=True, 207 | comment_str="//") 208 | print(f"Updated: {get_update} for {arduino_header_file}") 209 | else: 210 | print(f"Could not find {arduino_header_file}") 211 | sys.exit(1) 212 | 213 | platform_txt_backup = Path(path / "platform.txt.orig") 214 | if platform_txt_backup.exists(): 215 | confirm_overwrite(platform_txt_backup) 216 | platform_txt_file = Path(path / "platform.txt") 217 | if platform_txt_file.exists(): 218 | print(f"Updating: {platform_txt_file}") 219 | copyfile(platform_txt_file, Path(path / "platform.txt.orig")) 220 | print(f"Backup created: {Path(path / 'platform.txt.orig')}") 221 | append_str = "" 222 | if PACKAGE_PATH == ESP8266_PACKAGE_PATH: 223 | # Ensure to include spaces for flags 224 | append_str = " -DDONT_USE_UPLOADTOBLOB" \ 225 | " -DUSE_BALTIMORE_CERT" 226 | elif PACKAGE_PATH == ESP32_PACKAGE_PATH: 227 | append_str = " -DDONT_USE_UPLOADTOBLOB" 228 | get_update = update_line_file( 229 | platform_txt_file, "build.extra_flags=", 230 | str_append=append_str) 231 | print(f"Updated: {get_update} for {platform_txt_file}") 232 | else: 233 | print(f"Could not find {platform_txt_file}") 234 | sys.exit(1) 235 | 236 | 237 | main() 238 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_HTTP/.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | language: generic 5 | env: 6 | global: 7 | - IDE_VERSION=1.8.10 8 | matrix: 9 | - BOARD="esp8266:esp8266:huzzah:FlashSize=4M3M,CpuFrequency=80" 10 | - BOARD="esp8266:esp8266:thing" 11 | - BOARD="esp32:esp32:huzzah" 12 | before_install: 13 | - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 14 | - sleep 3 15 | - export DISPLAY=:1.0 16 | - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz 17 | - tar xf arduino-$IDE_VERSION-linux64.tar.xz 18 | - mv arduino-$IDE_VERSION $HOME/arduino-ide 19 | - export PATH=$PATH:$HOME/arduino-ide 20 | - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then 21 | arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --install-boards esp8266:esp8266; 22 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 23 | arduino --install-library NTPClient; 24 | arduino --install-library NTPClient; 25 | fi 26 | - if [[ "$BOARD" =~ "esp32:esp32:" ]]; then 27 | arduino --pref "boardsmanager.additional.urls=https://dl.espressif.com/dl/package_esp32_index.json" --install-boards esp32:esp32; 28 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 29 | arduino --install-library NTPClient; 30 | fi 31 | 32 | - findAndReplace() { sed -i'' -e"s|$1|$2|g" "$3"; } 33 | - buildExampleSketch() { 34 | EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino; 35 | 36 | arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH; 37 | } 38 | install: 39 | - arduino --install-library "AzureIoTUtility" 40 | - arduino --install-library "AzureIoTSocket_WiFi" 41 | - arduino --install-library "AzureIoTProtocol_HTTP" 42 | - ln -s $PWD $HOME/Arduino/libraries/. 43 | script: 44 | - buildExampleSketch telemetry_sample.c 45 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_HTTP/README.md: -------------------------------------------------------------------------------- 1 | #### Azure IoT Protocol HTTP Library source files 2 | 3 | This is the location of the Arduino-specific source files for the 4 | [AzureIoTProtocol_HTTP Arduino published library](https://github.com/Azure/azure-iot-arduino-protocol-http). 5 | 6 | Complete information for contributing to the Azure IoT Arduino libraries 7 | can be found [here](https://github.com/Azure/azure-iot-pal-arduino). 8 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_HTTP/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For AzreuoIoTProtocol_HTTP 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | AzureIoTHubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | setEpochTime KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_HTTP/library.properties: -------------------------------------------------------------------------------- 1 | name=AzureIoTProtocol_HTTP 2 | version=1.6.0 3 | author=Microsoft 4 | maintainer=Microsoft 5 | sentence=Azure HTTP protocol library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing. 6 | paragraph=Microsoft compact implementation of the HTTP protocol for small devices like Arduino. It allows you to use your Arduino with the Azure IoT Hub using HTTP as the transport protocol. See readme.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information. 7 | category=Communication 8 | url=https://github.com/Azure/azure-iot-arduino-protocol-http 9 | architectures=esp8266,esp32 10 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_HTTP/src/AzureIoTProtocol_HTTP.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef AZUREIOTPROTOCOLHTTP_H 5 | #define AZUREIOTPROTOCOLHTTP_H 6 | 7 | #define AzureIoTProtocolHTTPVersion "1.6.0" 8 | 9 | #endif //AZUREIOTPROTOCOLHTTP_H 10 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_MQTT/.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | language: generic 5 | env: 6 | global: 7 | - IDE_VERSION=1.8.10 8 | matrix: 9 | - BOARD="esp8266:esp8266:huzzah:FlashSize=4M3M,CpuFrequency=80" 10 | - BOARD="esp8266:esp8266:thing" 11 | - BOARD="esp32:esp32:huzzah" 12 | before_install: 13 | - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 14 | - sleep 3 15 | - export DISPLAY=:1.0 16 | - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz 17 | - tar xf arduino-$IDE_VERSION-linux64.tar.xz 18 | - mv arduino-$IDE_VERSION $HOME/arduino-ide 19 | - export PATH=$PATH:$HOME/arduino-ide 20 | - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then 21 | arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --install-boards esp8266:esp8266; 22 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 23 | arduino --install-library NTPClient; 24 | arduino --install-library NTPClient; 25 | fi 26 | - if [[ "$BOARD" =~ "esp32:esp32:" ]]; then 27 | arduino --pref "boardsmanager.additional.urls=https://dl.espressif.com/dl/package_esp32_index.json" --install-boards esp32:esp32; 28 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 29 | arduino --install-library NTPClient; 30 | fi 31 | 32 | - findAndReplace() { sed -i'' -e"s|$1|$2|g" "$3"; } 33 | - buildExampleSketch() { 34 | EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino; 35 | 36 | arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH; 37 | } 38 | install: 39 | - arduino --install-library "AzureIoTUtility" 40 | - arduino --install-library "AzureIoTSocket_WiFi" 41 | - arduino --install-library "AzureIoTProtocol_MQTT" 42 | - ln -s $PWD $HOME/Arduino/libraries/. 43 | script: 44 | - buildExampleSketch telemetry_sample.c 45 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_MQTT/README.md: -------------------------------------------------------------------------------- 1 | #### Azure IoT Protocol MQTT Library source files 2 | 3 | This is the location of the Arduino-specific source files for the 4 | [AzureIoTProtocol_MQTT Arduino published library](https://github.com/Azure/azure-iot-arduino-protocol-mqtt). 5 | 6 | Complete information for contributing to the Azure IoT Arduino libraries 7 | can be found [here](https://github.com/Azure/azure-iot-pal-arduino). 8 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_MQTT/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For AzureIoTProtocol_MQTT 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | AzureIoTHubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | setEpochTime KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_MQTT/library.properties: -------------------------------------------------------------------------------- 1 | name=AzureIoTProtocol_MQTT 2 | version=1.6.0 3 | author=Microsoft 4 | maintainer=Microsoft 5 | sentence=Azure MQTT protocol library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing. 6 | paragraph=Microsoft compact implementation of the MQTT protocol for small devices like Arduino. It allows you to use your Arduino with the Azure IoT Hub using MQTT as the transport protocol. See readme.md for more details. 7 | category=Communication 8 | url=https://github.com/Azure/azure-iot-arduino-protocol-mqtt 9 | architectures=samd,esp8266,esp32 10 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTProtocol_MQTT/src/AzureIoTProtocol_MQTT.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef AZUREIOTPROTOCOLMQTT_H 5 | #define AZUREIOTPROTOCOLMQTT_H 6 | 7 | #include "azure_umqtt_c/mqtt_client.h" 8 | 9 | #define AzureIoTProtocolMQTTVersion "1.6.0" 10 | 11 | #endif //AZUREIOTPROTOCOLMQTT_H 12 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTSocket_WiFi/.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | language: generic 5 | env: 6 | global: 7 | - IDE_VERSION=1.8.10 8 | matrix: 9 | - BOARD="esp8266:esp8266:huzzah:FlashSize=4M3M,CpuFrequency=80" 10 | - BOARD="esp8266:esp8266:thing" 11 | - BOARD="esp32:esp32:huzzah" 12 | before_install: 13 | - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 14 | - sleep 3 15 | - export DISPLAY=:1.0 16 | - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz 17 | - tar xf arduino-$IDE_VERSION-linux64.tar.xz 18 | - mv arduino-$IDE_VERSION $HOME/arduino-ide 19 | - export PATH=$PATH:$HOME/arduino-ide 20 | - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then 21 | arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --install-boards esp8266:esp8266; 22 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 23 | arduino --install-library NTPClient; 24 | arduino --install-library NTPClient; 25 | fi 26 | - if [[ "$BOARD" =~ "esp32:esp32:" ]]; then 27 | arduino --pref "boardsmanager.additional.urls=https://dl.espressif.com/dl/package_esp32_index.json" --install-boards esp32:esp32; 28 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 29 | arduino --install-library NTPClient; 30 | fi 31 | 32 | - findAndReplace() { sed -i'' -e"s|$1|$2|g" "$3"; } 33 | - buildExampleSketch() { 34 | EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino; 35 | 36 | arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH; 37 | } 38 | install: 39 | - arduino --install-library "AzureIoTUtility" 40 | - arduino --install-library "AzureIoTSocket_WiFi" 41 | - arduino --install-library "AzureIoTProtocol_MQTT" 42 | - arduino --install-library "AzureIoTProtocol_HTTP" 43 | - ln -s $PWD $HOME/Arduino/libraries/. 44 | script: 45 | - buildExampleSketch telemetry_sample.c 46 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTSocket_WiFi/README.md: -------------------------------------------------------------------------------- 1 | #### Azure IoT Utility 2 | 3 | This is the location of the Arduino-specific source files for the 4 | [AzureIoTUtility Wi-Fi adapter Arduino published library](https://github.com/Azure/azure-iot-arduino-socket-esp32-wifi). 5 | 6 | Complete information for contributing to the Azure IoT Arduino libraries 7 | can be found [here](https://github.com/Azure/azure-iot-pal-arduino). -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTSocket_WiFi/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For WiFi 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | #AzureIoTHubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | #begin KEYWORD2 16 | #setEpochTime KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTSocket_WiFi/library.properties: -------------------------------------------------------------------------------- 1 | name=AzureIoTSocket_WiFi 2 | version=1.0.2 3 | author=Microsoft 4 | maintainer=Microsoft 5 | sentence=Azure IoT network adapter layer for use with Wi-Fi such as ESP32 6 | paragraph=Microsoft Wi-Fi adaptation layer for connection to an IoT hub. Together with AzureIoTHub, it allows you to use your Arduino with the Azure IoT Hub. See readme.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information. 7 | category=Communication 8 | url=https://github.com/Azure/azure-iot-arduino-socket-esp32-wifi 9 | architectures=samd,esp32 10 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTSocket_WiFi/src/AzureIoTSocket_WiFi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef AZUREIOTSOCKETWIFI_H 5 | #define AZUREIOTSOCKETWIFI_H 6 | 7 | #define AzureIoTSocketWiFiVersion "1.0.2" 8 | 9 | #ifdef ARDUINO_ARCH_ESP8266 10 | #include 11 | #elif ARDUINO_ARCH_ESP32 12 | #include 13 | #elif WIO_TERMINAL 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #endif //AZUREIOTSOCKETWIFI_H 20 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | language: generic 5 | env: 6 | global: 7 | - IDE_VERSION=1.8.10 8 | matrix: 9 | - BOARD="esp8266:esp8266:huzzah:FlashSize=4M3M,CpuFrequency=80" 10 | - BOARD="esp8266:esp8266:thing" 11 | - BOARD="esp32:esp32:huzzah" 12 | before_install: 13 | - /sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16 14 | - sleep 3 15 | - export DISPLAY=:1.0 16 | - wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz 17 | - tar xf arduino-$IDE_VERSION-linux64.tar.xz 18 | - mv arduino-$IDE_VERSION $HOME/arduino-ide 19 | - export PATH=$PATH:$HOME/arduino-ide 20 | - if [[ "$BOARD" =~ "esp8266:esp8266:" ]]; then 21 | arduino --pref "boardsmanager.additional.urls=http://arduino.esp8266.com/stable/package_esp8266com_index.json" --install-boards esp8266:esp8266; 22 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 23 | arduino --install-library NTPClient; 24 | fi 25 | - if [[ "$BOARD" =~ "esp32:esp32:" ]]; then 26 | arduino --pref "boardsmanager.additional.urls=https://dl.espressif.com/dl/package_esp32_index.json" --install-boards esp32:esp32; 27 | arduino --pref "boardsmanager.additional.urls=" --save-prefs; 28 | arduino --install-library NTPClient; 29 | fi 30 | 31 | - findAndReplace() { sed -i'' -e"s|$1|$2|g" "$3"; } 32 | - buildExampleSketch() { 33 | EXAMPLE_SKETCH=$PWD/examples/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino; 34 | 35 | arduino --verbose-build --verify --board $BOARD $EXAMPLE_SKETCH; 36 | } 37 | install: 38 | - arduino --install-library "AzureIoTUtility" 39 | - arduino --install-library "AzureIoTSocket_WiFi" 40 | - arduino --install-library "AzureIoTProtocol_MQTT" 41 | - arduino --install-library "AzureIoTProtocol_HTTP" 42 | - ln -s $PWD $HOME/Arduino/libraries/. 43 | script: 44 | - buildExampleSketch telemetry_sample.c 45 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/README.md: -------------------------------------------------------------------------------- 1 | #### Azure IoT Utility 2 | 3 | This is the location of the Arduino-specific source files for the 4 | [AzureIoTUtility Arduino published library](https://github.com/Azure/azure-iot-arduino-utility). 5 | 6 | Complete information for contributing to the Azure IoT Arduino libraries 7 | can be found [here](https://github.com/Azure/azure-iot-pal-arduino). -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For AzureIoTUtility 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | AzureIoTHubClient KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | setEpochTime KEYWORD2 17 | 18 | ####################################### 19 | # Constants (LITERAL1) 20 | ####################################### 21 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/library.properties: -------------------------------------------------------------------------------- 1 | name=AzureIoTUtility 2 | version=1.6.0 3 | author=Microsoft 4 | maintainer=Microsoft 5 | sentence=Azure C shared utility library for Arduino. For the Arduino MKR1000 or Zero and WiFi Shield 101, Adafruit Huzzah and Feather M0, or SparkFun Thing. 6 | paragraph=Microsoft port of the Azure C Shared Utility. Together with AzureIoTHub, it allows you to use your Arduino with the Azure IoT Hub. See readme.md for more details. Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See LICENSE file in the project root for full license information. 7 | category=Communication 8 | url=https://github.com/Azure/azure-iot-arduino-utility 9 | architectures=esp8266,esp32 10 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/AzureIoTUtility.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef AZUREIOTUTILITY_H 5 | #define AZUREIOTUTILITY_H 6 | 7 | #include "azure_c_shared_utility/platform.h" 8 | #include "azure_c_shared_utility/lock.h" 9 | #include "azure_c_shared_utility/threadapi.h" 10 | #include "azure_c_shared_utility/crt_abstractions.h" 11 | #include "azure_c_shared_utility/shared_util_options.h" 12 | #include "azure_c_shared_utility/tlsio.h" 13 | #include "azure_c_shared_utility/xlogging.h" 14 | 15 | #define AzureIoTUtilityVersion "1.6.0" 16 | 17 | #endif //AZUREIOTUTILITY_H 18 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp32/azcpgmspace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifdef ARDUINO_ARCH_ESP32 5 | #include "azcpgmspace.h" 6 | #include 7 | 8 | char* az_c_strncpy_P(char* dest, PGM_P src, size_t size) { 9 | return strncpy_P(dest, src, size); 10 | } 11 | 12 | size_t az_c_strlen_P(PGM_P s) { 13 | return strlen_P(s); 14 | } 15 | 16 | #endif // ARDUINO_ARCH_ESP32 17 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp32/azcpgmspace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file azcpgmspace.h 5 | * @brief Function prototypes for pgmspace functions that need extern-ing to C 6 | * 7 | * @details These fucntions are just wrappers around existing ones in pgmspace.h that 8 | * are not defined in a way to make them linkable from c libs. 9 | */ 10 | #ifdef ARDUINO_ARCH_ESP32 11 | #ifndef AZCPGMSPACE_H 12 | #define AZCPGMSPACE_H 13 | 14 | #include 15 | #include "azure_c_shared_utility/crt_abstractions.h" 16 | 17 | #ifdef __cplusplus 18 | #include 19 | extern "C" { 20 | #else 21 | #include 22 | #endif 23 | 24 | extern char* az_c_strncpy_P(char* dest, PGM_P src, size_t size); 25 | extern size_t az_c_strlen_P(PGM_P s); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif // _AZCPGMSPACE_H 32 | 33 | #endif // ARDUINO_ARCH_ESP32 34 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp32/sample_init.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifdef ARDUINO_ARCH_ESP32 5 | 6 | #include 7 | #include 8 | #include "AzureIoTSocket_WiFi.h" 9 | #include 10 | #include 11 | #include 12 | 13 | // Times before 2010 (1970 + 40 years) are invalid 14 | #define MIN_EPOCH (40 * 365 * 24 * 3600) 15 | 16 | 17 | static void initSerial() { 18 | // Start serial and initialize stdout 19 | Serial.begin(1000000); 20 | Serial.setDebugOutput(true); 21 | } 22 | 23 | static void initWifi(const char* ssid, const char* pass) { 24 | // Attempt to connect to Wifi network: 25 | Serial.print("\r\n\r\nAttempting to connect to SSID: "); 26 | Serial.println(ssid); 27 | 28 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 29 | WiFi.begin(ssid, pass); 30 | while (WiFi.status() != WL_CONNECTED) { 31 | delay(500); 32 | Serial.print("."); 33 | } 34 | 35 | Serial.println("\r\nConnected to wifi"); 36 | } 37 | 38 | static void initTime() 39 | { 40 | time_t epochTime; 41 | 42 | configTime(0, 0, "pool.ntp.org", "time.nist.gov"); 43 | 44 | while (true) { 45 | epochTime = time(NULL); 46 | 47 | if (epochTime < MIN_EPOCH) { 48 | Serial.println("Fetching NTP epoch time failed! Waiting 2 seconds to retry."); 49 | delay(2000); 50 | } else { 51 | Serial.print("Fetched NTP epoch time is: "); 52 | Serial.println(epochTime); 53 | break; 54 | } 55 | } 56 | } 57 | 58 | void esp32_sample_init(const char* ssid, const char* password) 59 | { 60 | initSerial(); 61 | initWifi(ssid, password); 62 | initTime(); 63 | } 64 | 65 | #endif // ARDUINO_ARCH_ESP32 66 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp32/sample_init.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SAMPLE_INIT_H 5 | #define SAMPLE_INIT_H 6 | 7 | #define sample_init esp32_sample_init 8 | 9 | void esp32_sample_init(const char* ssid, const char* password); 10 | 11 | #endif // SAMPLE_INIT_H 12 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp8266/azcpgmspace.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #if defined(ARDUINO_ARCH_ESP8266) 5 | #include "azcpgmspace.h" 6 | #include 7 | 8 | char* az_c_strncpy_P(char* dest, PGM_P src, size_t size) { 9 | return strncpy_P(dest, src, size); 10 | } 11 | 12 | size_t az_c_strlen_P(PGM_P s) { 13 | return strlen_P(s); 14 | } 15 | 16 | #endif // ARDUINO_ARCH_ESP8266 17 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp8266/azcpgmspace.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file azcpgmspace.h 5 | * @brief Function prototypes for pgmspace functions that need extern-ing to C 6 | * 7 | * @details These fucntions are just wrappers around existing ones in pgmspace.h that 8 | * are not defined in a way to make them linkable from c libs. 9 | */ 10 | #if defined(ARDUINO_ARCH_ESP8266) 11 | #ifndef AZCPGMSPACE_H 12 | #define AZCPGMSPACE_H 13 | 14 | #include 15 | #include "azure_c_shared_utility/crt_abstractions.h" 16 | 17 | #ifdef __cplusplus 18 | #include 19 | extern "C" { 20 | #else 21 | #include 22 | #endif 23 | 24 | extern char* az_c_strncpy_P(char* dest, PGM_P src, size_t size); 25 | extern size_t az_c_strlen_P(PGM_P s); 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif // _AZCPGMSPACE_H 32 | 33 | #endif // #if defined(ARDUINO_ARCH_ESP8266) 34 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp8266/sample_init.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifdef ARDUINO_ARCH_ESP8266 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "user_interface.h" 11 | #include "Esp.h" 12 | 13 | // Times before 2010 (1970 + 40 years) are invalid 14 | #define MIN_EPOCH (40 * 365 * 24 * 3600) 15 | 16 | static void initSerial() { 17 | // Start serial and initialize stdout 18 | Serial.begin(115200); 19 | Serial.setDebugOutput(true); 20 | } 21 | 22 | static void initWifi(const char* ssid, const char* pass) { 23 | // Attempt to connect to Wifi network: 24 | Serial.print("\r\n\r\nAttempting to connect to SSID: "); 25 | Serial.println(ssid); 26 | 27 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 28 | WiFi.mode(WIFI_STA); 29 | WiFi.begin(ssid, pass); 30 | while (WiFi.status() != WL_CONNECTED) { 31 | delay(500); 32 | Serial.print("."); 33 | } 34 | 35 | Serial.println("\r\nConnected to wifi"); 36 | } 37 | 38 | static void initTime() { 39 | time_t epochTime; 40 | 41 | configTime(0, 0, "pool.ntp.org", "time.nist.gov"); 42 | 43 | while (true) { 44 | epochTime = time(NULL); 45 | 46 | if (epochTime < MIN_EPOCH) { 47 | Serial.println("Fetching NTP epoch time failed! Waiting 2 seconds to retry."); 48 | delay(2000); 49 | } else { 50 | Serial.print("Fetched NTP epoch time is: "); 51 | Serial.println(epochTime); 52 | break; 53 | } 54 | } 55 | } 56 | 57 | void esp8266_sample_init(const char* ssid, const char* password) 58 | { 59 | initSerial(); 60 | initWifi(ssid, password); 61 | initTime(); 62 | /* Uncomment wdt_disable() and comment out next line when gdb debugging. 63 | Note: use of system_get_free_heap_size() function may also help in tracking available memory. */ 64 | //wdt_disable(); 65 | wdt_enable(5000); 66 | } 67 | 68 | #endif // ARDUINO_ARCH_ESP8266 69 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/esp8266/sample_init.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SAMPLE_INIT_H 5 | #define SAMPLE_INIT_H 6 | 7 | #define sample_init esp8266_sample_init 8 | 9 | void esp8266_sample_init(const char* ssid, const char* password); 10 | 11 | #endif // SAMPLE_INIT_H 12 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/samd/NTPClientAz.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Arduino. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #if defined(ARDUINO_ARCH_SAMD) 5 | #include "NTPClientAz.h" 6 | 7 | #define LOCAL_UDP_PORT 2390 8 | 9 | NTPClientAz::NTPClientAz() : 10 | _udp() 11 | { 12 | } 13 | 14 | int NTPClientAz::begin() 15 | { 16 | return _udp.begin(LOCAL_UDP_PORT); 17 | } 18 | 19 | uint32_t NTPClientAz::getEpochTime(const char* host, int port, unsigned long timeout) 20 | { 21 | if (host == NULL || port < 1) { 22 | return (uint32_t)-1; 23 | } 24 | 25 | prepareRequest(); 26 | sendRequest(host, port); 27 | 28 | if (!receiveResponse(timeout)) { 29 | return (uint32_t)-1; 30 | } 31 | 32 | return parseResponse(); 33 | } 34 | 35 | void NTPClientAz::end() 36 | { 37 | _udp.stop(); 38 | } 39 | 40 | void NTPClientAz::prepareRequest() 41 | { 42 | memset(_buffer, 0, NTP_PACKET_SIZE); 43 | 44 | // Initialize values needed to form NTP request 45 | _buffer[0] = 0b11100011; // LI, Version, Mode 46 | _buffer[1] = 0; // Stratum, or type of clock 47 | _buffer[2] = 6; // Polling Interval 48 | _buffer[3] = 0xEC; // Peer Clock Precision 49 | 50 | // 8 bytes of zero for Root Delay & Root Dispersion 51 | 52 | _buffer[12] = 49; 53 | _buffer[13] = 0x4E; 54 | _buffer[14] = 49; 55 | _buffer[15] = 52; 56 | } 57 | 58 | void NTPClientAz::sendRequest(const char* host, int port) 59 | { 60 | _udp.beginPacket(host, port); 61 | 62 | #if WIO_TERMINAL 63 | _udp.write((const uint8_t*)_buffer, NTP_PACKET_SIZE); 64 | #else 65 | _udp.write(_buffer, NTP_PACKET_SIZE); 66 | #endif 67 | 68 | _udp.endPacket(); 69 | } 70 | 71 | int NTPClientAz::receiveResponse(unsigned long timeout) 72 | { 73 | long start = millis(); 74 | int size = 0; 75 | 76 | while(size == 0 && (millis() - start) < timeout) { 77 | size = _udp.parsePacket(); 78 | } 79 | 80 | if (size != NTP_PACKET_SIZE) { 81 | return 0; 82 | } 83 | 84 | _udp.read(_buffer, NTP_PACKET_SIZE); 85 | 86 | return 1; 87 | } 88 | 89 | uint32_t NTPClientAz::parseResponse() 90 | { 91 | uint16_t high = word(_buffer[40], _buffer[41]); 92 | uint16_t low = word(_buffer[42], _buffer[43]); 93 | uint32_t ntpTime = high << 16 | low; // since 1900 94 | uint32_t epoch = ntpTime - 2208988800UL; // since 1970 95 | 96 | return epoch; 97 | } 98 | #endif 99 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/samd/NTPClientAz.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Arduino. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #if defined(ARDUINO_ARCH_SAMD) 5 | 6 | #ifndef NTPCLIENT_AZ_H 7 | #define NTPCLIENT_AZ_H 8 | 9 | #if WIO_TERMINAL 10 | #include 11 | #else 12 | #include 13 | #endif 14 | 15 | #include 16 | 17 | #define NTP_PACKET_SIZE 48 18 | #define NTP_PORT 123 19 | 20 | #define DEFAULT_NTP_TIMEOUT 10000 21 | 22 | class NTPClientAz 23 | { 24 | public: 25 | NTPClientAz(); 26 | int begin(); 27 | uint32_t getEpochTime(const char* host, int port = NTP_PORT, unsigned long timeout = DEFAULT_NTP_TIMEOUT); 28 | void end(); 29 | 30 | private: 31 | void prepareRequest(); 32 | void sendRequest(const char* host, int port); 33 | int receiveResponse(unsigned long timeout); 34 | uint32_t parseResponse(); 35 | 36 | char _buffer[NTP_PACKET_SIZE]; 37 | WiFiUDP _udp; 38 | }; 39 | 40 | #endif // NTPCLIENT_AZ_H 41 | 42 | #endif // ARDUINO_ARCH_SAMD 43 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/samd/sample_init.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifdef ARDUINO_ARCH_SAMD 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #if WIO_TERMINAL 14 | #include 15 | #include "WiFiClientSecure.h" 16 | static WiFiClientSecure sslClient; // for Wio Terminal variant of SAMD 17 | #else 18 | #include 19 | static WiFiSSLClient sslClient; 20 | #endif 21 | 22 | #include 23 | #include "NTPClientAz.h" 24 | 25 | #ifdef ARDUINO_SAMD_FEATHER_M0 26 | 27 | // Optional LIPO battery monitoring 28 | #define VBAT_ENABLED 1 29 | #define VBAT_PIN A7 30 | 31 | #define WINC_CS 8 32 | #define WINC_IRQ 7 33 | #define WINC_RST 4 34 | #define WINC_EN 2 35 | 36 | #endif // ARDUINO_SAMD_FEATHER_M0 37 | 38 | static void initWifi(const char* ssid, const char* pass) 39 | { 40 | #ifdef ARDUINO_SAMD_FEATHER_M0 41 | //Configure pins for Adafruit ATWINC1500 Feather 42 | Serial.println(F("WINC1500 on FeatherM0 detected.")); 43 | Serial.println(F("Setting pins for WiFi101 library (WINC1500 on FeatherM0)")); 44 | WiFi.setPins(WINC_CS, WINC_IRQ, WINC_RST, WINC_EN); 45 | // for the Adafruit WINC1500 we need to enable the chip 46 | pinMode(WINC_EN, OUTPUT); 47 | digitalWrite(WINC_EN, HIGH); 48 | Serial.println(F("Enabled WINC1500 interface for FeatherM0")); 49 | #endif 50 | 51 | // Attempt to connect to Wifi network: 52 | int status = WL_IDLE_STATUS; 53 | Serial.print("Attempting to connect to WPA SSID: "); 54 | Serial.println(ssid); 55 | 56 | // Connect to WPA/WPA2 network. Change this line if using open or WEP network: 57 | while ( status != WL_CONNECTED) 58 | { 59 | // Connect to WPA/WPA2 network: 60 | status = WiFi.begin(ssid, pass); 61 | Serial.print(" WiFi status: "); 62 | Serial.println(status); 63 | // wait 2 seconds to try again 64 | delay(2000); 65 | } 66 | 67 | Serial.println("\r\nConnected to wifi"); 68 | } 69 | 70 | static void initTime() { 71 | WiFiUDP _udp; 72 | 73 | time_t epochTime = (time_t)-1; 74 | 75 | NTPClientAz ntpClient; 76 | Serial.println("Fetching NTP epoch time"); 77 | ntpClient.begin(); 78 | 79 | while (true) { 80 | epochTime = ntpClient.getEpochTime("0.pool.ntp.org"); 81 | 82 | if (epochTime == (time_t)-1) { 83 | Serial.println("Fetching NTP epoch time failed! Waiting 2 seconds to retry."); 84 | delay(2000); 85 | } else { 86 | Serial.print("Fetched NTP epoch time is: "); 87 | 88 | #if WIO_TERMINAL 89 | char buff[32]; 90 | sprintf(buff, "%.f", difftime(epochTime, (time_t) 0)); 91 | Serial.println(buff); 92 | #else 93 | Serial.println(epochTime); 94 | #endif 95 | 96 | break; 97 | } 98 | } 99 | 100 | ntpClient.end(); 101 | 102 | struct timeval tv; 103 | tv.tv_sec = epochTime; 104 | tv.tv_usec = 0; 105 | 106 | settimeofday(&tv, NULL); 107 | } 108 | 109 | void m0_sample_init(const char* ssid, const char* password) 110 | { 111 | // The Feather M0 loses it's COMn connection with every reset. 112 | // This 10 s delay allows you to reselect the COM port and open the serial monitor window. 113 | delay(10000); 114 | Serial.begin(115200); 115 | initWifi(ssid, password); 116 | initTime(); 117 | } 118 | 119 | #endif // ARDUINO_ARCH_SAMD 120 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/samd/sample_init.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SAMPLE_INIT_H 5 | #define SAMPLE_INIT_H 6 | 7 | #define sample_init m0_sample_init 8 | 9 | void m0_sample_init(const char* ssid, const char* password); 10 | 11 | #endif // SAMPLE_INIT_H 12 | -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/samd/stdio.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #if defined(ARDUINO_ARCH_SAMD) 5 | #include 6 | 7 | #include "Arduino.h" 8 | 9 | // these are needed by the serializer, so force link 10 | asm(".global _printf_float"); 11 | asm(".global _scanf_float"); 12 | 13 | extern "C" { 14 | size_t _write(int handle, const unsigned char *buf, size_t bufSize) 15 | { 16 | /* Check for the command to flush all handles */ 17 | if (handle == -1) { 18 | return 0; 19 | } 20 | 21 | /* Check for stdout and stderr (only necessary if FILE descriptors are enabled.) */ 22 | if (handle != 1 && handle != 2) { 23 | return -1; 24 | } 25 | 26 | size_t nChars = 0; 27 | for (; bufSize > 0; --bufSize, ++buf, ++nChars) { 28 | Serial.write(*buf); 29 | } 30 | return nChars; 31 | } 32 | } 33 | #endif -------------------------------------------------------------------------------- /build_all/base-libraries/AzureIoTUtility/src/samd/time.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #if defined(ARDUINO_ARCH_SAMD) && !defined(WIO_TERMINAL) 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | RTCZero rtc; 11 | 12 | extern "C" { 13 | int _gettimeofday(struct timeval* tp, void* /*tzvp*/) 14 | { 15 | tp->tv_sec = rtc.getEpoch(); 16 | tp->tv_usec = 0; 17 | 18 | return 0; 19 | } 20 | 21 | int settimeofday(const struct timeval* tp, const struct timezone* /*tzp*/) 22 | { 23 | rtc.begin(); 24 | rtc.setEpoch(tp->tv_sec); 25 | 26 | return 0; 27 | } 28 | } 29 | #endif -------------------------------------------------------------------------------- /build_all/build.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @setlocal EnableExtensions EnableDelayedExpansion 5 | @echo off 6 | 7 | call set_build_vars.cmd %* 8 | if !ERRORLEVEL! NEQ 0 ( 9 | echo Failed to set build vars 10 | exit /b 1 11 | ) 12 | 13 | rem ----------------------------------------------------------------------------- 14 | rem -- Execute all tests 15 | rem ----------------------------------------------------------------------------- 16 | 17 | call :ExecuteAllTests 18 | 19 | set finalResult=0 20 | 21 | if %build_test%==ON ( 22 | echo. 23 | echo. 24 | echo Build results: 25 | 26 | for /F "tokens=2* delims=.=" %%A in ('set __errolevel_build.') do ( 27 | @echo Build %%A %%B 28 | if "%%B"=="FAILED" ( 29 | set finalResult=1 30 | ) 31 | ) 32 | ) 33 | 34 | if %run_test%==ON ( 35 | echo. 36 | echo. 37 | echo Execution results: 38 | 39 | for /F "tokens=2* delims=.=" %%A in ('set __errolevel_run.') do ( 40 | @echo Run %%A %%B 41 | if "%%B"=="FAILED" ( 42 | set finalResult=1 43 | ) 44 | ) 45 | ) 46 | 47 | echo. 48 | if !finalResult!==0 ( 49 | echo TEST SUCCEED 50 | ) else ( 51 | echo TEST FAILED 52 | ) 53 | 54 | exit /b !finalResult! 55 | 56 | 57 | rem ----------------------------------------------------------------------------- 58 | rem -- subroutines 59 | rem ----------------------------------------------------------------------------- 60 | 61 | :usage 62 | echo build.cmd [options] 63 | echo options: 64 | echo -b, --build-only only build the project (default) 65 | echo -r, --run-only only run the test 66 | echo -e2e, --run-e2e-tests run end-to-end test 67 | echo -t, --tests determine the file with the test list 68 | goto :eof 69 | 70 | 71 | rem ----------------------------------------------------------------------------- 72 | rem -- helper subroutines 73 | rem ----------------------------------------------------------------------------- 74 | 75 | REM Parser tests.lst 76 | :ExecuteAllTests 77 | set testName=false 78 | set projectName= 79 | set SourcePath="******* SourcePath not set ********" 80 | 81 | for /F "tokens=*" %%F in (%tests_list_file%) do ( 82 | if /i "%%F"=="" ( 83 | REM ignore empty line. 84 | ) else ( 85 | set command=%%F 86 | if /i "!command:~0,1!"=="#" ( 87 | echo Comment=!command:~1! 88 | ) else ( if /i "!command:~0,1!"=="[" ( 89 | if %build_test%==ON ( 90 | call :BuildTest 91 | ) 92 | if %run_test%==ON ( 93 | call :RunTest 94 | ) 95 | set projectName=!command:~1,-1! 96 | if /i "!projectName!"=="End" goto :eof 97 | ) else ( 98 | for /f "tokens=1 delims==" %%A in ("!command!") do set key=%%A 99 | call set value=%%command:!key!=%% 100 | set value=!value:~1! 101 | set !key!=!value! 102 | ) ) ) 103 | ) 104 | ) 105 | goto :eof 106 | 107 | 108 | REM Build each test in the Tests.lst 109 | :BuildTest 110 | if not "!projectName!"=="" ( 111 | echo. 112 | echo Build !projectName! 113 | echo test_root=%test_root% 114 | echo work_root=%work_root% 115 | echo Target=!Target! 116 | echo RelativePath=!RelativePath! 117 | echo RelativeWorkingDir=!RelativeWorkingDir! 118 | echo SerialPort=!SerialPort! 119 | echo MaxAllowedDurationSeconds=!MaxAllowedDurationSeconds! 120 | echo CloneURL=!CloneURL! 121 | echo Categories=!Categories! 122 | echo Hardware=!Hardware! 123 | echo CPUParameters=!CPUParameters! 124 | echo Build=!Build! 125 | 126 | if "!Build!"=="Disable" ( 127 | set __errolevel_build.!projectName!=DISABLED 128 | echo ** Build for !projectName! is disable. ** 129 | goto :eof 130 | ) 131 | 132 | mkdir %built_binaries_root%!RelativeWorkingDir! 133 | 134 | rem Step 1, build dump preferences: 135 | rem Ex: arduino-builder 136 | rem -dump-prefs 137 | rem -logger=machine 138 | rem -hardware "C:\Program Files (x86)\Arduino\hardware" 139 | rem -hardware "C:\Users\iottestuser\AppData\Local\Arduino15\packages" 140 | rem -hardware "C:\Users\iottestuser\Documents\Arduino\hardware" 141 | rem -tools "C:\Program Files (x86)\Arduino\tools-builder" 142 | rem -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" 143 | rem -tools "C:\Users\iottestuser\AppData\Local\Arduino15\packages" 144 | rem -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" 145 | rem -libraries "C:\Users\iottestuser\Documents\Arduino\libraries" 146 | rem -fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,UploadSpeed=115200,FlashSize=4M3M 147 | rem -ide-version=10609 148 | rem -build-path "C:\Users\iottestuser\AppData\Local\Temp\build505ec6e3f4000475ae6da076f93e5ffe.tmp" 149 | rem -warnings=none 150 | rem -prefs=build.warn_data_percentage=75 151 | rem -verbose 152 | rem "F:\Azure\IoT\SDKs\iot-hub-c-huzzah-getstartedkit-master\remote_monitoring\remote_monitoring.ino" 153 | rem 154 | rem Step 2, compile the project: 155 | rem Ex: arduino-builder 156 | rem -compile 157 | rem -logger=machine 158 | rem -hardware "C:\Program Files (x86)\Arduino\hardware" 159 | rem -hardware "C:\Users\iottestuser\AppData\Local\Arduino15\packages" 160 | rem -hardware "C:\Users\iottestuser\Documents\Arduino\hardware" 161 | rem -tools "C:\Program Files (x86)\Arduino\tools-builder" 162 | rem -tools "C:\Program Files (x86)\Arduino\hardware\tools\avr" 163 | rem -tools "C:\Users\iottestuser\AppData\Local\Arduino15\packages" 164 | rem -built-in-libraries "C:\Program Files (x86)\Arduino\libraries" 165 | rem -libraries "C:\Users\iottestuser\Documents\Arduino\libraries" 166 | rem -fqbn=esp8266:esp8266:huzzah:CpuFrequency=80,UploadSpeed=115200,FlashSize=4M3M 167 | rem -ide-version=10609 168 | rem -build-path "C:\Users\iottestuser\AppData\Local\Temp\build505ec6e3f4000475ae6da076f93e5ffe.tmp" 169 | rem -warnings=none 170 | rem -prefs=build.warn_data_percentage=75 171 | rem -verbose 172 | rem "F:\Azure\IoT\SDKs\iot-hub-c-huzzah-getstartedkit-master\remote_monitoring\remote_monitoring.ino" 173 | 174 | set compiler_name=%compiler_path%\arduino-builder.exe 175 | 176 | set hardware_parameters=-hardware "%compiler_hardware_path%" -hardware "%compiler_packages_path%" 177 | set tools_parameters=-tools "%compiler_tools_builder_path%" -tools "%compiler_tools_processor_path%" -tools "%compiler_packages_path%" 178 | set libraries_parameters=-built-in-libraries "%compiler_libraries_path%" -libraries "%user_libraries_path%" 179 | set parameters=-logger=machine !hardware_parameters! !tools_parameters! !libraries_parameters! !CPUParameters! -build-path "%built_binaries_root%!RelativeWorkingDir!" -warnings=none -prefs=build.warn_data_percentage=75 -verbose !SourcePath!\!Target! 180 | 181 | echo Dump Arduino preferences: 182 | echo !compiler_name! -dump-prefs !parameters! 183 | call !compiler_name! -dump-prefs !parameters! 184 | 185 | echo. 186 | echo Building: !RelativePath! 187 | echo. Compiler: !compiler_name! 188 | echo. -compile !parameters! 189 | call !compiler_name! -compile !parameters! 190 | 191 | if "!errorlevel!"=="0" ( 192 | set __errolevel_build.!projectName!=SUCCEED 193 | ) else ( 194 | set __errolevel_build.!projectName!=FAILED 195 | ) 196 | ) 197 | set SourcePath="******* SourcePath not set ********" 198 | goto :eof 199 | 200 | 201 | REM Run each test in the Tests.lst 202 | :RunTest 203 | if not "!projectName!"=="" ( 204 | echo. 205 | echo Run !projectName! 206 | echo Target=!Target! 207 | echo RelativeWorkingDir=!RelativeWorkingDir! 208 | echo LogLines=!LogLines! 209 | echo MinimumHeap=!MinimumHeap! 210 | echo Execution=!Execution! 211 | 212 | if "!Execution!"=="Disable" ( 213 | set __errolevel_run.!projectName!=DISABLED 214 | echo ** Execution for !projectName! is disable. ** 215 | goto :eof 216 | ) 217 | 218 | call powershell.exe -NoProfile -NonInteractive -ExecutionPolicy unrestricted -Command .\execute.ps1 -binaryPath:%built_binaries_root%!RelativeWorkingDir!\!Target!.bin -serialPort:!SerialPort! -esptool:%compiler_packages_path%\esp8266\tools\esptool\%esptool_version%\esptool.exe -logLines:!LogLines! -minimumHeap:!MinimumHeap! 219 | 220 | if "!errorlevel!"=="0" ( 221 | set __errolevel_run.!projectName!=SUCCEED 222 | ) else ( 223 | set __errolevel_run.!projectName!=FAILED 224 | ) 225 | 226 | ) 227 | goto :eof 228 | -------------------------------------------------------------------------------- /build_all/build_prep.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @setlocal EnableExtensions EnableDelayedExpansion 5 | @echo off 6 | 7 | call set_build_vars.cmd 8 | if !ERRORLEVEL! NEQ 0 ( 9 | echo Failed to set build vars 10 | exit /b 1 11 | ) 12 | 13 | rem ----------------------------------------------------------------------------- 14 | rem -- ensure environment variables for sample editing 15 | rem ----------------------------------------------------------------------------- 16 | call :ensure_environment ARDUINO_WIFI_SSID 17 | call :ensure_environment ARDUINO_WIFI_PASSWORD 18 | call :ensure_environment ARDUINO_HOST_NAME 19 | call :ensure_environment ARDUINO_HUZZAH_ID 20 | call :ensure_environment ARDUINO_M0_ID 21 | call :ensure_environment ARDUINO_SPARK_ID 22 | call :ensure_environment ARDUINO_HUZZAH_KEY 23 | call :ensure_environment ARDUINO_M0_KEY 24 | call :ensure_environment ARDUINO_SPARK_KEY 25 | if !environment_ok! EQU "bad" ( 26 | exit /b 1 27 | ) 28 | 29 | rem ----------------------------------------------------------------------------- 30 | rem -- download arduino packages 31 | rem ----------------------------------------------------------------------------- 32 | rem ----------------------------------------------------------------------------- 33 | rem -- download arduino compiler 34 | rem ----------------------------------------------------------------------------- 35 | rem // The packages and compiler are no longer maintained in the cloud, and 36 | rem // instead are just kept on the Arduino release machine. See the Arduino 37 | rem // release instructions for more info. 38 | 39 | rem ----------------------------------------------------------------------------- 40 | rem -- create test directories 41 | rem ----------------------------------------------------------------------------- 42 | call ensure_delete_directory.cmd %work_root% 43 | if !ERRORLEVEL! NEQ 0 ( 44 | exit /b 1 45 | ) 46 | mkdir %work_root% 47 | rem -- keep mkdir quiet when work_root == kits_root 48 | mkdir %kits_root% >nul 2>&1 49 | 50 | rem // Download all of the samples from the kits, and modify them for release testing 51 | pushd %kits_root% 52 | call %scripts_path%\get_sample.cmd %kits_root% iot-hub-c-huzzah-getstartedkit || exit /b 1 53 | call %scripts_path%\get_sample.cmd %kits_root% iot-hub-c-m0wifi-getstartedkit || exit /b 1 54 | call %scripts_path%\get_sample.cmd %kits_root% iot-hub-c-thingdev-getstartedkit || exit /b 1 55 | popd 56 | 57 | rem ----------------------------------------------------------------------------- 58 | rem -- build the Azure Arduino libraries in the user_libraries_path 59 | rem -- wipe the user_libraries_path and re-create it 60 | rem ----------------------------------------------------------------------------- 61 | call ensure_delete_directory.cmd %user_libraries_path% 62 | if !ERRORLEVEL! NEQ 0 ( 63 | echo Failed to delete directory: %user_libraries_path% 64 | exit /b 1 65 | ) 66 | call make_sdk.cmd %user_libraries_path% 67 | if !ERRORLEVEL! NEQ 0 ( 68 | echo Failed to make sdk in %user_libraries_path% 69 | exit /b 1 70 | ) 71 | 72 | rem ----------------------------------------------------------------------------- 73 | rem -- Fix source files that contain '%zu' or '%zd', which Arduino can't do 74 | rem ----------------------------------------------------------------------------- 75 | PowerShell.exe -ExecutionPolicy Bypass -Command "& './fix_format_strings.ps1 ' '%user_libraries_path%'" 76 | if !ERRORLEVEL! NEQ 0 ( 77 | echo Failed to fix format strings 78 | exit /b 1 79 | ) else ( 80 | echo Format strings fixed 81 | ) 82 | 83 | rem ----------------------------------------------------------------------------- 84 | rem -- Generate the README.md files for the Arduino libraries 85 | rem ----------------------------------------------------------------------------- 86 | PowerShell.exe -ExecutionPolicy Bypass -Command "& './README_builder.ps1 ' '%user_libraries_path%'" 87 | if !ERRORLEVEL! NEQ 0 ( 88 | echo Failed to generate readmes 89 | exit /b 1 90 | ) else ( 91 | echo Generated readmes 92 | ) 93 | 94 | rem ----------------------------------------------------------------------------- 95 | rem -- Copy the samples from the kits into the Arduino libraries 96 | rem ----------------------------------------------------------------------------- 97 | xcopy %kits_root%\iot-hub-c-huzzah-getstartedkit\simplesample_http %user_libraries_path%\AzureIoTHub\examples\esp8266\simplesample_http /I 98 | xcopy %kits_root%\iot-hub-c-huzzah-getstartedkit\simplesample_mqtt %user_libraries_path%\AzureIoTProtocol_MQTT\examples\esp8266\simplesample_mqtt /I 99 | xcopy %kits_root%\iot-hub-c-huzzah-getstartedkit\simplesample_http %user_libraries_path%\AzureIoTProtocol_HTTP\examples\esp8266\simplesample_http /I 100 | xcopy %kits_root%\iot-hub-c-huzzah-getstartedkit\simplesample_http %user_libraries_path%\AzureIoTUtility\examples\esp8266\simplesample_http /I 101 | xcopy %kits_root%\iot-hub-c-m0wifi-getstartedkit\simplesample_http %user_libraries_path%\AzureIoTHub\examples\samd\simplesample_http /I 102 | xcopy %kits_root%\iot-hub-c-m0wifi-getstartedkit\simplesample_mqtt %user_libraries_path%\AzureIoTProtocol_MQTT\examples\samd\simplesample_mqtt /I 103 | xcopy %kits_root%\iot-hub-c-m0wifi-getstartedkit\simplesample_http %user_libraries_path%\AzureIoTProtocol_HTTP\examples\samd\simplesample_http /I 104 | xcopy %kits_root%\iot-hub-c-m0wifi-getstartedkit\simplesample_http %user_libraries_path%\AzureIoTUtility\examples\samd\simplesample_http /I 105 | 106 | rem ----------------------------------------------------------------------------- 107 | rem -- download arduino libraries into user_libraries_path 108 | rem ----------------------------------------------------------------------------- 109 | mkdir %user_libraries_path% 110 | pushd %user_libraries_path% 111 | git clone https://github.com/adafruit/Adafruit_Sensor 112 | git clone https://github.com/adafruit/Adafruit_DHT_Unified 113 | git clone https://github.com/adafruit/DHT-sensor-library 114 | git clone https://github.com/adafruit/Adafruit_BME280_Library 115 | git clone https://github.com/arduino-libraries/WiFi101 116 | git clone https://github.com/arduino-libraries/RTCZero 117 | 118 | rem ----------------------------------------------------------------------------- 119 | rem -- convert the Azure Arduino libraries in the user_libraries_path into 120 | rem -- their respective git repos. This is equivalent to a clone followed 121 | rem -- by updating the library contents, but avoids putting robocopy warnings 122 | rem -- into the output. 123 | rem ----------------------------------------------------------------------------- 124 | 125 | rem -- clone the Azure arduino libraries into temp directories 126 | git clone https://github.com/Azure/azure-iot-arduino AzureIoTHub_temp 127 | git clone https://github.com/Azure/azure-iot-arduino-protocol-mqtt AzureIoTProtocol_MQTT_temp 128 | git clone https://github.com/Azure/azure-iot-arduino-protocol-http AzureIoTProtocol_HTTP_temp 129 | git clone https://github.com/Azure/azure-iot-arduino-utility AzureIoTUtility_temp 130 | 131 | rem -- turn the built libraries into proper git repos by giving them their .git folders 132 | call :relocate_git_folders AzureIoTHub 133 | if !ERRORLEVEL! NEQ 0 ( 134 | popd 135 | exit /b 1 136 | ) 137 | call :relocate_git_folders AzureIoTProtocol_MQTT 138 | if !ERRORLEVEL! NEQ 0 ( 139 | popd 140 | exit /b 1 141 | ) 142 | call :relocate_git_folders AzureIoTProtocol_HTTP 143 | if !ERRORLEVEL! NEQ 0 ( 144 | popd 145 | exit /b 1 146 | ) 147 | call :relocate_git_folders AzureIoTUtility 148 | if !ERRORLEVEL! NEQ 0 ( 149 | popd 150 | exit /b 1 151 | ) 152 | popd 153 | 154 | 155 | 156 | exit /b 0 157 | 158 | rem ----------------------------------------------------------------------------- 159 | rem -- Put the .git folders from the temp repos into the actual Arduino 160 | rem -- library folders and delete the temp repo. The clone is not done in 161 | rem -- this routine because moving the file too soon after the clone can 162 | rem -- provoke access denied errors. 163 | rem 164 | rem -- Also bump the versions in the new libraries 165 | rem ----------------------------------------------------------------------------- 166 | :relocate_git_folders 167 | attrib -h %1_temp\.git 168 | move %1_temp\.git %1\.git 169 | attrib +h %1\.git 170 | pushd !scripts_path! 171 | PowerShell.exe -ExecutionPolicy Bypass -Command "& './bump_version.ps1 ' -oldDir '%user_libraries_path%\%1_temp' -newDir '%user_libraries_path%\%1'" 172 | if !ERRORLEVEL! NEQ 0 ( 173 | echo Failed to bump version in %1 174 | popd 175 | exit /b 1 176 | ) else ( 177 | echo Bumped version in %1 178 | ) 179 | popd 180 | rd /s /q %1_temp 181 | exit /b 0 182 | 183 | rem -- Make sure this variable is defined 184 | :ensure_environment 185 | if "!%1!"=="" ( 186 | echo Error: %1 is not defined 187 | set environment_ok="bad" 188 | ) 189 | exit /b 190 | 191 | -------------------------------------------------------------------------------- /build_all/bump_version.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param([string]$oldDir, [string]$newDir) 5 | 6 | $ErrorActionPreference = "Stop" 7 | 8 | try { 9 | Set-Variable oldLibraryProperties "$oldDir\library.properties" 10 | Set-Variable newLibraryProperties "$newDir\library.properties" 11 | # The newDir directory name is the library name 12 | Set-Variable libraryName $newDir.split("\")[-1] 13 | 14 | Get-Content $oldLibraryProperties | Foreach-Object{ 15 | $var = $_.Split('=') 16 | New-Variable -Name $var[0] -Value $var[1] 17 | } 18 | 19 | # Increment the 3rd part of the version 20 | echo "Found old version: $version" 21 | $newVersion = ($version).Split(".") 22 | $newVersion[2] = [int]$newVersion[2] + 1 23 | $newVersion = $newVersion -join "." 24 | echo "New version: $newVersion" 25 | 26 | # ------------------------------------------------------- 27 | # Update the library.properties file 28 | # ------------------------------------------------------- 29 | Get-Content $newLibraryProperties | 30 | % { $_ -creplace "version.+", "version=$newVersion" } -OutVariable newLibraryPropertiesContent | Out-Null 31 | 32 | $newLibraryPropertiesContent | Set-Content $newLibraryProperties 33 | 34 | # ------------------------------------------------------- 35 | # Update the library header file 36 | # ------------------------------------------------------- 37 | Set-Variable libraryHeaderFile "$newDir\src\$libraryName.h" 38 | Set-Variable versionDefine ("#define " + $libraryName.replace('_','') + "Version `"$newVersion`"") 39 | 40 | Get-Content $libraryHeaderFile | 41 | % { $_ -creplace "#define AzureIoT.+", $versionDefine } -OutVariable newLibraryHeaderContent | Out-Null 42 | 43 | $newLibraryHeaderContent | Set-Content $libraryHeaderFile 44 | 45 | # ------------------------------------------------------- 46 | # Commit changes to git and set a tag 47 | # ------------------------------------------------------- 48 | Push-Location -Path $newDir 49 | git add . 50 | git commit -m "Sync Arduino libraries with latest Azure IoT SDK $newVersion" 51 | git tag v$newVersion -m "Add tag v$newVersion" 52 | $gitResult = $LastExitCode 53 | if ($gitResult -ne 0) { 54 | throw gitResult 55 | } 56 | Pop-Location 57 | } 58 | 59 | catch { 60 | echo "Failed to bump version for $newLibraryProperties $PSItem" 61 | exit 1 62 | } 63 | -------------------------------------------------------------------------------- /build_all/download_blob.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @setlocal EnableExtensions EnableDelayedExpansion 5 | @echo off 6 | 7 | if %AZURE_CONTAINER_SASTOKEN%=="" ( 8 | echo Fatal: Container SAS token has not been set. 9 | echo. 10 | goto :usage 11 | ) 12 | if "%AZURE_CONTAINER_URL%"=="" ( 13 | echo Fatal: Container URL has not been set. 14 | echo. 15 | goto :usage 16 | ) 17 | 18 | :args_loop 19 | if "%1" equ "" goto args_done 20 | if "%1" equ "-directory" goto arg_directory 21 | if "%1" equ "-zip_file_name" goto arg_zip_file_name 22 | if "%1" equ "-file" goto arg_zip_file_name 23 | if "%1" equ "-check_path" goto arg_check_path 24 | if "%1" equ "-check" goto arg_check_path 25 | echo Fatal: Unknown paramenter %1. 26 | echo. 27 | goto :usage 28 | 29 | :arg_directory 30 | shift 31 | set directory=%1 32 | goto args_continue 33 | 34 | :arg_zip_file_name 35 | shift 36 | set zip_file_name=%1 37 | goto args_continue 38 | 39 | :arg_check_path 40 | shift 41 | set check_path=%1 42 | goto args_continue 43 | 44 | :args_continue 45 | shift 46 | goto args_loop 47 | 48 | :usage 49 | @echo Download test artifacts from an Azure Storage Account. The artifact must be a single zip file stored in a Blobs container. This is a simple way to store and retrieve files that you need to execute tests in the cloud that, for some reason, you cannot make it public. For example, one test that needs a dll that belongs to a third part. 50 | @echo. 51 | @echo To use this script, you must: 52 | @echo. 53 | @echo 1) Have an Azure Storage Account (https://azure.microsoft.com/en-us/documentation/articles/storage-create-storage-account/) 54 | @echo 2) Create a Container to store your artifacts, for example 'myproductcontainer'. 55 | @echo 3) Compress the files and directories, for example 'contosodlls.zip'. 56 | @echo 4) Using Microsoft Azure Storage Explorer (http://storageexplorer.com/), generate a SasToken (Shared Access Signature) for the Container, copy the 'URL' and the 'Query string'. 57 | @echo 5) Set container environment variables: 58 | @echo a. AZURE_CONTAINER_SASTOKEN="Query string". Use the Query string generated in the step 4 with double quotes to avoid issues with special characters on it. 59 | @echo "!!!! Important !!!! If the sas token contains percent signs, they must be doubled up in the SET command or they will be stripped out 60 | @echo b. AZURE_CONTAINER_URL="URL". Got from Microsoft Azure Storage Explorer, it must be something like https://contoso.blob.core.windows.net/myproductcontainer 61 | @echo 6) For each zip file, call download_blob.cmd with the parameters 62 | @echo a. -file "file name without extension". Required parameter with zip file name 63 | @echo b. -directory "directory path". Destination directory, if not provided, it will use the current directory. 64 | @echo c. -check "file or directory path". File or directory to check, if it exists, do not download and unzip the file. If not provided, this script will download and unzip anyway. 65 | 66 | exit /b 1 67 | 68 | :args_done 69 | 70 | if "%zip_file_name%"=="" ( 71 | echo Fatal: Required parameter -file missed. 72 | echo. 73 | goto :usage 74 | ) 75 | 76 | if "%directory%"=="" set directory=%CD% 77 | 78 | set sasToken=!AZURE_CONTAINER_SASTOKEN:%%3A=:! 79 | set sasToken=!sasToken:%"=! 80 | 81 | set containerUrl=!AZURE_CONTAINER_URL:%"=! 82 | if "%containerUrl:~-1%"=="/" (set containerUrl=%containerUrl:~0,-1%) 83 | 84 | mkdir %directory% > nul 2>&1 85 | 86 | set compiler_fullZipName=%directory%\%zip_file_name%.zip 87 | 88 | if "%check_path%"=="" goto :download 89 | 90 | if exist %directory%\%check_path% ( 91 | echo ***do not download %zip_file_name% because %check_path% already exist.*** 92 | exit /b 0 93 | ) 94 | 95 | :download 96 | if exist %compiler_fullZipName% ( 97 | echo ***do not download %zip_file_name% because it already exist, only unzip it.*** 98 | ) else ( 99 | echo Downloading %containerUrl%/%zip_file_name%.zip to %compiler_fullZipName% 100 | powershell.exe -nologo -noprofile -command "& { try { iwr '%containerUrl%/%zip_file_name%.zip%sasToken%' -OutFile '%compiler_fullZipName%'; } catch { echo $_; Exit 1; } }" 101 | if !ERRORLEVEL! NEQ 0 ( 102 | echo Failed to download %compiler_fullZipName% 103 | exit /b 1 104 | ) else ( 105 | echo Downloaded %compiler_fullZipName% 106 | ) 107 | ) 108 | 109 | echo Uncompressing %compiler_fullZipName% to %directory% 110 | powershell.exe -nologo -noprofile -command "& { try { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('%compiler_fullZipName%', '%directory%'); } catch { Exit 1; } }" 111 | if !ERRORLEVEL! NEQ 0 ( 112 | echo Failed to unzip %compiler_fullZipName% 113 | exit /b 1 114 | ) else ( 115 | echo Unzipped %compiler_fullZipName% 116 | echo Deleting %compiler_fullZipName% 117 | del %compiler_fullZipName% 118 | ) 119 | -------------------------------------------------------------------------------- /build_all/edit_huzzah.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param([string]$file) 5 | 6 | $ErrorActionPreference = "Stop" 7 | 8 | try { 9 | $target = "void remote_monitoring_run\(void\)\r\n" 10 | 11 | $memcheck = @" 12 | // This function drops heap info into the output where execute.ps1 can check for too much heap consumption 13 | #include 14 | static void do_memcheck() 15 | { 16 | size_t current_heap_size = umm_free_heap_size(); 17 | LogInfo("Heap:%d", current_heap_size); 18 | return; 19 | } 20 | 21 | 22 | void remote_monitoring_run(void) 23 | 24 | "@ 25 | 26 | $while_loop = "while\s*\(1\)\r\n\s*\{" 27 | 28 | $while_loop_2 = @" 29 | while(1) 30 | { 31 | do_memcheck(); 32 | "@ 33 | 34 | 35 | # Edit the sample iot_configs.h to have proper WiFi and subscription info 36 | Get-Content $file | Out-String | 37 | % { $_ -replace $while_loop, $while_loop_2 } | 38 | % { $_ -creplace $target, $memcheck } -OutVariable content | Out-Null 39 | 40 | $content | Set-Content $file 41 | 42 | } 43 | 44 | catch { 45 | echo "Failure editing huzzah file" 46 | exit 1 47 | } 48 | 49 | -------------------------------------------------------------------------------- /build_all/edit_sample.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/azure-iot-pal-arduino/a9849e7f23ce998357ab888a3d268c6c87de1606/build_all/edit_sample.ps1 -------------------------------------------------------------------------------- /build_all/ensure_delete_directory.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @setlocal EnableExtensions EnableDelayedExpansion 5 | @echo off 6 | 7 | rmdir %1 /s /q > nul 2>&1 || @rem 8 | if !ERRORLEVEL! NEQ 0 ( 9 | if !ERRORLEVEL! NEQ 2 ( 10 | echo Failed to delete directory: %1 11 | exit /b 1 12 | ) 13 | ) 14 | exit /b 0 15 | -------------------------------------------------------------------------------- /build_all/ensure_tagged_git_repo.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @setlocal EnableExtensions EnableDelayedExpansion 5 | @echo off 6 | 7 | REM Ensure the existence of a git repo specified by %2, in a directory specified by 8 | REM %1 at a release tag specified by %3. The repo directory name is equal to the release tag name. 9 | REM Any sibling content will be assumed to be an old version, and will be deleted. 10 | 11 | set container=%1 12 | set repo=%2 13 | set tag_name=%3 14 | 15 | REM First just check for the existence of the tag-named directory. If it's there, 16 | REM assume everything is okay. 17 | 18 | if EXIST %container%\%tag_name% ( 19 | echo Tag name %tag_name% for %repo% is present 20 | exit /b 0 21 | ) 22 | 23 | REM Before cloning the repo, empty out the containing directory 24 | pushd %container% 25 | del *.* /S /Q >nul 2>&1 26 | REM Deleting all the empty subdirs that were left behind 27 | echo *********************** 28 | for /d %%p in (%container%\*) do rmdir /S /Q "%%p" 29 | 30 | REM Clone the repo into a temp directory (temp avoids problems if the process fails to do the checkout) 31 | echo Cloning %repo% into %container% as %tag_name% 32 | git clone %repo% temp 33 | if !ERRORLEVEL! NEQ 0 ( 34 | echo Failed to clone %repo% 35 | popd 36 | exit /b 1 37 | ) 38 | cd temp 39 | 40 | REM Checkout the requested tag 41 | echo Checking out the requested tag %tag_name% 42 | git -c advice.detachedHead=false checkout %tag_name% 43 | if !ERRORLEVEL! NEQ 0 ( 44 | echo Failed to checkout tag %tag_name% 45 | popd 46 | exit /b 1 47 | ) 48 | cd .. 49 | 50 | REM Rename the repo to be the tag name 51 | rename temp %tag_name% 52 | 53 | popd 54 | -------------------------------------------------------------------------------- /build_all/execute.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | <# 5 | This script uploads a binary on Arduino Huzzah (esp8266) and monitor its serial for some time, looking for issues. 6 | It will throw an exception if Arduino send Panic, Abort, reset, or Exception to the serial, or if it send a lower than the minimum heap size. 7 | #> 8 | 9 | param ( 10 | [Parameter(Mandatory=$true)] 11 | [ValidateNotNullOrEmpty()] 12 | [string] $binaryPath, 13 | 14 | [Parameter(Mandatory=$true)] 15 | [ValidateNotNullOrEmpty()] 16 | [string] $serialPort, 17 | 18 | [Parameter(Mandatory=$true)] 19 | [ValidateNotNullOrEmpty()] 20 | [string] $esptool, 21 | 22 | [Parameter(Mandatory=$false)] 23 | [ValidateNotNullOrEmpty()] 24 | [int] $logLines=300, 25 | 26 | [Parameter(Mandatory=$false)] 27 | [ValidateNotNullOrEmpty()] 28 | [int] $maxFailed=10, 29 | 30 | [Parameter(Mandatory=$false)] 31 | [ValidateNotNullOrEmpty()] 32 | [int] $minimumHeap=22000, 33 | 34 | [Parameter(Mandatory=$false)] 35 | [ValidateSet("75", "110", "300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200")] 36 | [string] $serialBW="115200" 37 | ) 38 | 39 | $installcmd = "$esptool -vv -cd nodemcu -cb $serialBW -cp $serialPort -ca 0x00000 -cf $binaryPath" 40 | 41 | Write-Output "" 42 | Write-Output "Upload the binaries to the hardware with command:" 43 | Write-Output $installcmd 44 | Write-Output "" 45 | 46 | Invoke-Expression $installcmd 47 | 48 | Write-Output "" 49 | Write-Output "Monitor the hardware via USB/Serial:" 50 | Write-Output "" 51 | 52 | $port = New-Object System.IO.Ports.SerialPort $serialPort,$serialBW,None,8,one 53 | try 54 | { 55 | $port.Open() 56 | while($logLines--) 57 | { 58 | $result = $port.ReadLine() 59 | Write-Output $result 60 | if($result.ToLower().Contains("panic")) 61 | { 62 | throw("Arduino throw a panic") 63 | } 64 | if($result.ToLower().Contains("failed")) 65 | { 66 | if(($maxFailed--) -eq 0) 67 | { 68 | throw("Arduino ran with fail") 69 | } 70 | } 71 | if($result.ToLower().Contains("abort")) 72 | { 73 | $port.Close() 74 | throw("Arduino aborted") 75 | } 76 | if($result.ToLower().Contains("reset")) 77 | { 78 | $port.Close() 79 | throw("Arduino reseted") 80 | } 81 | if($result.ToLower().Contains("exception")) 82 | { 83 | $port.Close() 84 | throw("Arduino throw an exception") 85 | } 86 | $keyVal=$result.split(":") 87 | if(($keyVal[0].ToLower().Contains("heap")) -and ([convert]::ToInt32($keyVal[1]) -le $minimumHeap)) 88 | { 89 | $port.Close() 90 | throw("Out of memory") 91 | } 92 | } 93 | } 94 | catch 95 | { 96 | throw 97 | } 98 | finally 99 | { 100 | $port.Close() 101 | } 102 | -------------------------------------------------------------------------------- /build_all/fix_format_strings.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | # This script checks .c files for '%zu' and '%zd' in format strings and 5 | # replaces them with '%u', which the Arduino compilers can understand 6 | param( 7 | [Parameter(Position = 0)][string]$libsDir 8 | ) 9 | 10 | if ($libsDir -eq '') { 11 | echo "README_builder.ps1 needs a single positional target path parameter" 12 | exit 1 13 | } 14 | 15 | # The locations of .c files that need to be checked for 16 | $d1 = "$libsDir\AzureIoTHub\src\sdk" 17 | $d2 = "$libsDir\AzureIoTProtocol_HTTP\src\azure_uhttp_c" 18 | $d3 = "$libsDir\AzureIoTProtocol_MQTT\src\azure_umqtt_c" 19 | $d4 = "$libsDir\AzureIoTUtility\src\azure_c_shared_utility" 20 | 21 | function Fix-File 22 | { 23 | param([Parameter(Position = 0)][string]$target_file) 24 | echo $target_file 25 | # Edit the sample iot_configs.h to have proper WiFi and subscription info 26 | Get-Content $target_file | Out-String | 27 | % { $_ -creplace "%zu", "%u" } | 28 | % { $_ -creplace "%zd", "%u" } -OutVariable content | Out-Null 29 | 30 | $content | Set-Content $target_file 31 | 32 | } 33 | 34 | 35 | function Fix-Dir 36 | { 37 | param([Parameter(Position = 0)][string]$target_dir) 38 | echo "$target_dir" 39 | get-childitem $target_dir -recurse | where {$_.extension -eq ".c"} | % { 40 | Fix-File $_.FullName 41 | } 42 | } 43 | 44 | Fix-Dir $d1 45 | Fix-Dir $d2 46 | Fix-Dir $d3 47 | Fix-Dir $d4 48 | -------------------------------------------------------------------------------- /build_all/get_sample.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @echo off 5 | @setlocal EnableExtensions EnableDelayedExpansion 6 | 7 | REM This script is not designed to be used directly. It's a client of release_prep.cmd 8 | REM Parameter 1 is the workspace directory. Parameter 2 is the repo name. 9 | echo ... 10 | set repo_dir=%1\%2 11 | 12 | git clone https://github.com/Azure-Samples/%2.git %repo_dir% 13 | 14 | REM The particulars of the various devices and the SSID and password are environment variables 15 | if [%2]==[iot-hub-c-huzzah-getstartedkit] ( 16 | set dev_id=%ARDUINO_HUZZAH_ID% 17 | set dev_key=%ARDUINO_HUZZAH_KEY% 18 | set huzzah_file=%repo_dir%\remote_monitoring\remote_monitoring.c 19 | echo Editing !huzzah_file! to add heap check 20 | pushd !scripts_path! 21 | PowerShell.exe -ExecutionPolicy Bypass -Command "& './edit_huzzah.ps1 ' -file '!huzzah_file!'" 22 | popd 23 | if !ERRORLEVEL! NEQ 0 ( 24 | echo Failed to edit huzzah sample: !huzzah_file! 25 | exit /b 1 26 | ) 27 | ) else if [%2]==[iot-hub-c-m0wifi-getstartedkit] ( 28 | set dev_id=%ARDUINO_M0_ID% 29 | set dev_key=%ARDUINO_M0_KEY% 30 | ) else ( 31 | set dev_id=%ARDUINO_SPARK_ID% 32 | set dev_key=%ARDUINO_SPARK_KEY% 33 | ) 34 | 35 | echo Editing iot_configs.h for %2 36 | pushd !scripts_path! 37 | set iotconfigs=%repo_dir%\remote_monitoring\iot_configs.h 38 | PowerShell.exe -ExecutionPolicy Bypass -Command "& './edit_sample.ps1 ' -file '!iotconfigs!' -ssid '%ARDUINO_WIFI_SSID%' -password '%ARDUINO_WIFI_PASSWORD%' -hostname '!ARDUINO_HOST_NAME!' -id '!dev_id!' -key '!dev_key!'" 39 | set iotconfigs=%repo_dir%\device_twin\iot_configs.h 40 | PowerShell.exe -ExecutionPolicy Bypass -Command "& './edit_sample.ps1 ' -file '!iotconfigs!' -ssid '%ARDUINO_WIFI_SSID%' -password '%ARDUINO_WIFI_PASSWORD%' -hostname '!ARDUINO_HOST_NAME!' -id '!dev_id!' -key '!dev_key!'" 41 | popd 42 | -------------------------------------------------------------------------------- /build_all/make_sdk.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @echo off 5 | 6 | REM This script creates the SDK folder with the latest bits from the Azure SDK repository. 7 | REM It removes some files we do not need. 8 | 9 | if "%1" equ "" ( 10 | echo make_sdk.cmd requires a single output directory parameter 11 | exit /b 1 12 | ) 13 | 14 | set use_mbedtls="true" 15 | if "%2" equ "esp8266" ( 16 | echo building without mbedtls adapter 17 | set use_mbedtls="false" 18 | ) 19 | 20 | set Libraries_path=%1 21 | 22 | rem // The location of the Azure IoT SDK relative to this file 23 | set arduino_repo_root=%~dp0..\ 24 | rem // resolve to fully qualified path 25 | for %%i in ("%arduino_repo_root%") do set arduino_repo_root=%%~fi 26 | 27 | rem // The location of the Arduino PAL directory relative to this file 28 | set Arduino_pal_path=%arduino_repo_root%pal\ 29 | set AzureIoTSDKs_path=%arduino_repo_root%sdk\ 30 | 31 | set AzureIoTHub_path=%Libraries_path%\AzureIoTHub\ 32 | set AzureIoTProtocolHTTP_path=%Libraries_path%\AzureIoTProtocol_HTTP\ 33 | set AzureIoTProtocolMQTT_path=%Libraries_path%\AzureIoTProtocol_MQTT\ 34 | 35 | set AzureIoTUtility_path=%Libraries_path%\AzureIoTUtility\ 36 | set AzureIoTSocketWiFi_path=%Libraries_path%\AzureIoTSocket_WiFi\ 37 | set AzureIoTSocketEthernet_path=%Libraries_path%\AzureIoTSocket_Ethernet2\ 38 | 39 | set AzureUHTTP_path=%AzureIoTProtocolHTTP_path%src\azure_uhttp_c\ 40 | set AzureUMQTT_path=%AzureIoTProtocolMQTT_path%src\azure_umqtt_c\ 41 | 42 | set SharedUtility_path=%AzureIoTUtility_path%src\azure_c_shared_utility\ 43 | set Adapters_path=%AzureIoTUtility_path%src\adapters\ 44 | set Macro_Utils_path=%AzureIoTUtility_path%src\azure_c_shared_utility\azure_macro_utils\ 45 | set Hub_Macro_Utils_path=%AzureIoTHub_path%src\azure_macro_utils\ 46 | set Umock_c_path=%AzureIoTUtility_path%src\umock_c\ 47 | set MbedTLS_path=%Arduino_pal_path%mbedtls\ 48 | set sdk_path=%AzureIoTHub_path%src\ 49 | set internal_path=%AzureIoTHub_path%\src\internal\ 50 | 51 | mkdir %Libraries_path% 52 | pushd %Libraries_path% 53 | 54 | if exist "%AzureIoTHub_path%" rd /s /q %AzureIoTHub_path% 55 | 56 | robocopy %~dp0\base-libraries\AzureIoTHub %AzureIoTHub_path% -MIR 57 | robocopy %~dp0\base-libraries\AzureIoTUtility %AzureIoTUtility_path% -MIR 58 | robocopy %~dp0\base-libraries\AzureIoTProtocol_HTTP %AzureIoTProtocolHTTP_path% -MIR 59 | robocopy %~dp0\base-libraries\AzureIoTProtocol_MQTT %AzureIoTProtocolMQTT_path% -MIR 60 | robocopy %~dp0\base-libraries\AzureIoTSocket_WiFi %AzureIoTSocketWiFi_path% -MIR 61 | robocopy %~dp0\base-libraries\AzureIoTSocket_Ethernet2 %AzureIoTSocketEthernet_path% -MIR 62 | 63 | mkdir %sdk_path% 64 | mkdir %internal_path% 65 | 66 | cd /D %AzureIoTSDKs_path% 67 | rem echo Upstream HEAD @ > %sdk_path%metadata.txt 68 | rem git rev-parse HEAD >> %sdk_path%metadata.txt 69 | 70 | echo arduino_repo_root: %arduino_repo_root% 71 | 72 | copy %AzureIoTSDKs_path%LICENSE %AzureIoTHub_path%LICENSE 73 | 74 | copy %AzureIoTSDKs_path%iothub_client\src\ %sdk_path% 75 | copy %AzureIoTSDKs_path%iothub_client\inc\ %sdk_path% 76 | copy %AzureIoTSDKs_path%iothub_client\inc\internal %internal_path% 77 | copy %AzureIoTSDKs_path%serializer\src\ %sdk_path% 78 | copy %AzureIoTSDKs_path%serializer\inc\ %sdk_path% 79 | copy %AzureIoTSDKs_path%deps\parson\parson.* %sdk_path% 80 | 81 | mkdir %SharedUtility_path% 82 | mkdir %Adapters_path% 83 | mkdir %Umock_c_path% 84 | mkdir %Umock_c_path%aux_inc\ 85 | mkdir %Umock_c_path%azure_macro_utils\ 86 | mkdir %Macro_Utils_path% 87 | mkdir %Hub_Macro_Utils_path% 88 | mkdir %AzureIoTHub_path%examples\iothub_ll_telemetry_sample\ 89 | mkdir %AzureIoTHub_path%src\certs\ 90 | 91 | copy %Arduino_pal_path%samples\esp8266\* %AzureIoTHub_path%examples\iothub_ll_telemetry_sample 92 | copy %AzureIoTSDKs_path%c-utility\inc\azure_c_shared_utility %SharedUtility_path% 93 | copy %AzureIoTSDKs_path%c-utility\src\ %SharedUtility_path% 94 | copy /y %Arduino_pal_path%\azure_c_shared_utility\*.* %SharedUtility_path% 95 | copy %AzureIoTSDKs_path%deps\umock-c\inc\umock_c\ %Umock_c_path% 96 | copy %AzureIoTSDKs_path%deps\umock-c\inc\umock_c\aux_inc\ %Umock_c_path%aux_inc\ 97 | copy %AzureIoTSDKs_path%deps\umock-c\src\ %Umock_c_path% 98 | copy %AzureIoTSDKs_path%deps\azure-macro-utils-c\inc\azure_macro_utils\ %Hub_Macro_Utils_path% 99 | copy %AzureIoTSDKs_path%deps\azure-macro-utils-c\inc\azure_macro_utils\ %Macro_Utils_path% 100 | copy %AzureIoTSDKs_path%deps\azure-macro-utils-c\inc\azure_macro_utils\ %Umock_c_path%azure_macro_utils\ 101 | copy %AzureIoTSDKs_path%certs\ %AzureIoTHub_path%src\certs\ 102 | 103 | copy %AzureIoTSDKs_path%c-utility\pal\agenttime.c %Adapters_path% 104 | copy %AzureIoTSDKs_path%c-utility\pal\tickcounter.c %Adapters_path% 105 | copy %AzureIoTSDKs_path%deps\azure-macro-utils-c\inc\ %Azure_macro_utils_path% 106 | rem // Bring in the generic refcount_os.h 107 | copy %AzureIoTSDKs_path%c-utility\pal\generic\refcount_os.h %SharedUtility_path% 108 | rem // and tlsio_options.c 109 | copy %AzureIoTSDKs_path%c-utility\pal\tlsio_options.c %SharedUtility_path% 110 | 111 | rem // Copy the Arduino-specific files from the Arduino PAL path 112 | copy %Arduino_pal_path%inc\*.* %Adapters_path% 113 | copy %Arduino_pal_path%src\*.* %Adapters_path% 114 | 115 | if %use_mbedtls% equ "true" ( 116 | rem // Use the MbedTLS adaptor instead of the above 117 | copy %AzureIoTSDKs_path%c-utility\adapters\tlsio_mbedtls.c %Adapters_path% 118 | copy %AzureIoTSDKs_path%c-utility\inc\azure_c_shared_utility\tlsio_mbedtls.h %Adapters_path% 119 | ) 120 | 121 | 122 | mkdir %AzureUHTTP_path% 123 | copy %AzureIoTSDKs_path%c-utility\adapters\httpapi_compact.c %AzureUHTTP_path% 124 | 125 | mkdir %AzureUMQTT_path% 126 | copy %AzureIoTSDKs_path%umqtt\src %AzureUMQTT_path% 127 | mkdir %AzureIoTHub_path%src\azure_umqtt_c\ 128 | copy %AzureIoTSDKs_path%umqtt\inc\azure_umqtt_c %AzureIoTHub_path%src\azure_umqtt_c\ 129 | 130 | copy %Arduino_pal_path%AzureIoTSocket_WiFi\socketio_esp32wifi.cpp %AzureIoTSocketWiFi_path%src 131 | @echo %Arduino_pal_path%AzureIoTSocket_Ethernet\socketio_esp32ethernet2.cpp 132 | @echo %AzureIoTSocketEthernet_path%src 133 | copy %Arduino_pal_path%AzureIoTSocket_Ethernet\socketio_esp32ethernet2.cpp %AzureIoTSocketEthernet_path%src 134 | 135 | del %sdk_path%*amqp*.* 136 | del %sdk_path%iothubtransportmqtt_websockets.* 137 | del %sdk_path%blob.c 138 | del %internal_path%blob.h 139 | del %Adapters_path%tlsio_bearssl* 140 | 141 | del %SharedUtility_path%tlsio_cyclonessl*.* 142 | del %SharedUtility_path%tlsio_openssl.* 143 | del %SharedUtility_path%tlsio_bearssl.* 144 | del %SharedUtility_path%tlsio_schannel.* 145 | del %SharedUtility_path%tlsio_wolfssl.* 146 | del %SharedUtility_path%gbnetwork.* 147 | del %SharedUtility_path%dns_resolver* 148 | del %SharedUtility_path%logging_stacktrace* 149 | del %SharedUtility_path%wsio*.* 150 | del %SharedUtility_path%x509_*.* 151 | del %SharedUtility_path%etw*.* 152 | del %SharedUtility_path%http_proxy_io.c 153 | 154 | popd 155 | -------------------------------------------------------------------------------- /build_all/make_sdk.py: -------------------------------------------------------------------------------- 1 | import os 2 | import shutil 3 | from distutils import dir_util 4 | import sys 5 | import getopt 6 | import glob 7 | import make_sdk_cmds_dict as commands_dict 8 | 9 | def pattern_copy(pattern): # helper method 10 | # Get a list of all the files that match the pattern in specified directory 11 | fileList = glob.glob(pattern) 12 | for filePath in fileList: 13 | try: 14 | shutil.copy2(filePath) 15 | except: 16 | print("Error while copying file : ", filePath) 17 | 18 | 19 | def pattern_delete(pattern): # helper method 20 | # Get a list of all the files that match the pattern in specified directory 21 | fileList = glob.glob(pattern) 22 | # Iterate over the list of filepaths & remove each file. 23 | for filePath in fileList: 24 | try: 25 | os.remove(filePath) 26 | except: 27 | print("Error while deleting file : ", filePath) 28 | 29 | 30 | def pattern_delete_folder(pattern): # helper method 31 | # Get a list of all the file paths that match the pattern in specified directory 32 | fileList = glob.glob(pattern) 33 | # Iterate over the list of filepaths & remove each file. 34 | for filePath in fileList: 35 | try: 36 | shutil.rmtree(filePath) 37 | except: 38 | print("Error while deleting filepath : ", filePath) 39 | 40 | def line_prepender(filename, line): 41 | with open(filename, 'r+') as f: 42 | content = f.read() 43 | f.seek(0, 0) 44 | f.write(line.rstrip('\r\n') + '\n' + content) 45 | 46 | def line_appender(filename, line): 47 | with open(filename, 'a') as f: 48 | f.write(line.rstrip('\r\n') + '\n') 49 | 50 | def usage(): 51 | # Iterates through command dictionary to print out script's opt usage 52 | usage_txt = "make_sdk.py accepts the following arguments: \r\n" 53 | 54 | for commands in commands_dict.cmds: 55 | usage_txt += " - %s: " %commands + commands_dict.cmds[commands]['text'] + "\r\n" 56 | 57 | return usage_txt 58 | 59 | def parse_opts(): 60 | options, remainder = getopt.gnu_getopt(sys.argv[1:], 'ho:d:', ['output', 'help', 'device']) 61 | # print('OPTIONS :', options) 62 | for opt, arg in options: 63 | if opt in ('-h', '--help'): 64 | print(usage()) 65 | elif opt in ('-o', '--output'): 66 | commands_dict.output_path = arg 67 | 68 | 69 | def run(): 70 | # ---- set up paths for copying ---- 71 | output_path = os.path.abspath(commands_dict.output_path) 72 | arduino_repo_root = os.path.abspath('../') 73 | print(output_path) 74 | arduino_pal_path = arduino_repo_root + '/pal/' 75 | azure_iot_sdk_path = arduino_repo_root + '/sdk/' 76 | AzureIoTHub_path = output_path + '/AzureIoTHub/' 77 | AzureIoTProtocolHTTP_path = output_path + '/AzureIoTProtocol_HTTP/' 78 | AzureIoTProtocolMQTT_path = output_path + '/AzureIoTProtocol_MQTT/' 79 | AzureIoTUtility_path = output_path + '/AzureIoTUtility/' 80 | AzureIoTSocketWiFi_path = output_path + '/AzureIoTSocket_WiFi/' 81 | AzureUHTTP_path = AzureIoTProtocolHTTP_path + 'src/azure_uhttp_c/' 82 | AzureUMQTT_path = AzureIoTProtocolMQTT_path + 'src/azure_umqtt_c/' 83 | SharedUtility_path = AzureIoTUtility_path + 'src/azure_c_shared_utility/' 84 | Adapters_path = AzureIoTUtility_path + 'src/adapters/' 85 | Macro_Utils_path = AzureIoTUtility_path + 'src/azure_c_shared_utility/azure_macro_utils/' 86 | Hub_Macro_Utils_path = AzureIoTHub_path + 'src/azure_macro_utils/' 87 | Umock_c_path = AzureIoTUtility_path + 'src/umock_c/' 88 | sdk_path = AzureIoTHub_path + 'src/' 89 | internal_path = AzureIoTHub_path + 'src/internal/' 90 | 91 | # ---- clear out existing Arduino Azure libs ---- 92 | if (os.path.exists(output_path)): 93 | #clear it out 94 | pattern_delete_folder(output_path + '/Azure*') 95 | else: 96 | os.mkdir(output_path) 97 | 98 | # ---- copy pal library files (Arduino specific) ---- 99 | dir_util.copy_tree(arduino_repo_root + '/build_all/base-libraries/AzureIoTHub', AzureIoTHub_path) 100 | dir_util.copy_tree(arduino_repo_root + '/build_all/base-libraries/AzureIoTUtility', AzureIoTUtility_path) 101 | dir_util.copy_tree(arduino_repo_root + '/build_all/base-libraries/AzureIoTProtocol_HTTP', AzureIoTProtocolHTTP_path) 102 | dir_util.copy_tree(arduino_repo_root + '/build_all/base-libraries/AzureIoTProtocol_MQTT', AzureIoTProtocolMQTT_path) 103 | dir_util.copy_tree(arduino_repo_root + '/build_all/base-libraries/AzureIoTSocket_WiFi', AzureIoTSocketWiFi_path) 104 | 105 | # ---- copy sdk files + certs ---- 106 | dir_util.copy_tree(azure_iot_sdk_path + 'iothub_client/src/', sdk_path) 107 | dir_util.copy_tree(azure_iot_sdk_path + 'iothub_client/inc/', sdk_path) 108 | dir_util.copy_tree(azure_iot_sdk_path + 'iothub_client/inc/internal/', internal_path) 109 | dir_util.copy_tree(azure_iot_sdk_path + 'serializer/src/', sdk_path) 110 | dir_util.copy_tree(azure_iot_sdk_path + 'serializer/inc/', sdk_path) 111 | shutil.copy2(azure_iot_sdk_path + 'deps/parson/parson.h', sdk_path) 112 | shutil.copy2(azure_iot_sdk_path + 'deps/parson/parson.c', sdk_path) 113 | 114 | # ---- copy sdk certs --- 115 | dir_util.copy_tree(azure_iot_sdk_path + 'certs/', AzureIoTHub_path + 'src/certs/') 116 | 117 | # ---- make sub folders in new Arduino libs ---- 118 | os.mkdir(SharedUtility_path) 119 | os.mkdir(Adapters_path) 120 | os.mkdir(Umock_c_path) 121 | os.mkdir(Umock_c_path + 'aux_inc/') 122 | os.mkdir(Umock_c_path + 'azure_macro_utils/') 123 | os.mkdir(Macro_Utils_path) 124 | os.mkdir(Hub_Macro_Utils_path) 125 | os.mkdir(AzureIoTHub_path + 'examples/') 126 | 127 | # ---- copy sample ---- 128 | dir_util.copy_tree(arduino_pal_path + 'samples/', AzureIoTHub_path + 'examples/') 129 | 130 | # ---- copy dependencies ---- 131 | dir_util.copy_tree(azure_iot_sdk_path + 'c-utility/inc/azure_c_shared_utility/', SharedUtility_path) 132 | dir_util.copy_tree(azure_iot_sdk_path + 'c-utility/src/', SharedUtility_path) 133 | dir_util.copy_tree(arduino_pal_path + 'azure_c_shared_utility/', SharedUtility_path) 134 | shutil.copy2(azure_iot_sdk_path + 'c-utility/pal/generic/refcount_os.h', SharedUtility_path) 135 | shutil.copy2(azure_iot_sdk_path + 'c-utility/pal/tlsio_options.c', SharedUtility_path) 136 | dir_util.copy_tree(azure_iot_sdk_path + 'deps/umock-c/inc/umock_c/', Umock_c_path) 137 | dir_util.copy_tree(azure_iot_sdk_path + 'deps/umock-c/src/', Umock_c_path) 138 | dir_util.copy_tree(azure_iot_sdk_path + 'deps/azure-macro-utils-c/inc/azure_macro_utils/', Hub_Macro_Utils_path) 139 | dir_util.copy_tree(azure_iot_sdk_path + 'deps/azure-macro-utils-c/inc/azure_macro_utils/', Macro_Utils_path) 140 | dir_util.copy_tree(azure_iot_sdk_path + 'deps/azure-macro-utils-c/inc/azure_macro_utils/', Umock_c_path + 'azure_macro_utils/') 141 | 142 | 143 | # ---- copy adapters ---- 144 | shutil.copy2(azure_iot_sdk_path + 'c-utility/pal/agenttime.c', Adapters_path) 145 | shutil.copy2(azure_iot_sdk_path + 'c-utility/pal/tickcounter.c', Adapters_path) 146 | dir_util.copy_tree(arduino_pal_path + 'inc/', Adapters_path) 147 | dir_util.copy_tree(arduino_pal_path + 'src/', Adapters_path) 148 | 149 | shutil.copy2(azure_iot_sdk_path + 'c-utility/adapters/tlsio_mbedtls.c', Adapters_path) 150 | # add in define for ARDUINO_ARCH_ESP32 151 | line_prepender(Adapters_path + 'tlsio_mbedtls.c', "#ifdef ARDUINO_ARCH_ESP32") 152 | line_appender(Adapters_path + 'tlsio_mbedtls.c', "#endif //ARDUINO_ARCH_ESP32") 153 | 154 | shutil.copy2(azure_iot_sdk_path + 'c-utility/inc/azure_c_shared_utility/tlsio_mbedtls.h', Adapters_path) 155 | 156 | # ---- make protocol and socket layer libs ---- 157 | os.mkdir(AzureUHTTP_path) 158 | shutil.copy2(azure_iot_sdk_path + 'c-utility/adapters/httpapi_compact.c', AzureUHTTP_path) 159 | 160 | os.mkdir(AzureUMQTT_path) 161 | dir_util.copy_tree(azure_iot_sdk_path + 'umqtt/src/', AzureUMQTT_path) 162 | dir_util.copy_tree(azure_iot_sdk_path + 'umqtt/inc/', AzureIoTHub_path + 'src/') 163 | 164 | shutil.copy2(arduino_pal_path + 'AzureIoTSocket_WiFi/socketio_esp32wifi.cpp', AzureIoTSocketWiFi_path + 'src/') 165 | 166 | # ---- add license files ---- 167 | shutil.copy2(azure_iot_sdk_path + 'LICENSE', AzureIoTHub_path) 168 | shutil.copy2(azure_iot_sdk_path + 'LICENSE', AzureUMQTT_path) 169 | shutil.copy2(azure_iot_sdk_path + 'LICENSE', AzureUHTTP_path) 170 | shutil.copy2(azure_iot_sdk_path + 'LICENSE', AzureIoTSocketWiFi_path) 171 | shutil.copy2(azure_iot_sdk_path + 'LICENSE', AzureIoTUtility_path) 172 | 173 | # ---- clean out files not needed ---- 174 | os.remove(sdk_path + 'blob.c') 175 | os.remove(internal_path + 'blob.h') 176 | os.remove(SharedUtility_path + 'http_proxy_io.c') 177 | 178 | pattern_delete(sdk_path + '*amqp*.*') 179 | pattern_delete(sdk_path + 'iothubtransportmqtt_websockets.*') 180 | pattern_delete(Adapters_path + 'tlsio_bearssl*') 181 | pattern_delete(SharedUtility_path + 'tlsio_cyclonessl*.*') 182 | pattern_delete(SharedUtility_path + 'tlsio_openssl*.*') 183 | pattern_delete(SharedUtility_path + 'tlsio_bearssl*.*') 184 | pattern_delete(SharedUtility_path + 'tlsio_schannel*.*') 185 | pattern_delete(SharedUtility_path + 'tlsio_wolfssl*.*') 186 | pattern_delete(SharedUtility_path + 'gbnetwork.*') 187 | pattern_delete(SharedUtility_path + 'dns_resolver*') 188 | pattern_delete(SharedUtility_path + 'logging_stacktrace*') 189 | pattern_delete(SharedUtility_path + 'wsio*.*') 190 | pattern_delete(SharedUtility_path + 'x509_*.*') 191 | pattern_delete(SharedUtility_path + 'etw*.*') 192 | 193 | 194 | if __name__ == '__main__': 195 | parse_opts() 196 | run() 197 | -------------------------------------------------------------------------------- /build_all/make_sdk_cmds_dict.py: -------------------------------------------------------------------------------- 1 | output_path = '' 2 | 3 | cmds = { 4 | "help": {'short': 'h', 'text': "print help text"}, 5 | "output": {'short': 'o', 'text': "arg required: Sets the path used to save output folders and libraries."}, 6 | } 7 | -------------------------------------------------------------------------------- /build_all/set_build_vars.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | @echo off 5 | 6 | set scripts_path=%~dp0 7 | rem // remove trailing slash 8 | set scripts_path=%scripts_path:~0,-1% 9 | 10 | set jenkins_workspace=%scripts_path%\..\.. 11 | rem // resolve to fully qualified path 12 | for %%i in ("%jenkins_workspace%") do set jenkins_workspace=%%~fi 13 | 14 | set arduino_esp8266_version=2.4.0 15 | set adafruit_samd_version=1.0.21 16 | set arduino_samd_version=1.6.17 17 | set arduino_builder_version=1.8.5 18 | set esptool_version=0.4.13 19 | 20 | set work_root=%jenkins_workspace%\arduino_work 21 | set kits_root=%jenkins_workspace%\arduino_work 22 | set tools_root=%jenkins_workspace%\arduino_tools 23 | set tools_root=%jenkins_workspace%\arduino_tools 24 | set built_binaries_root=%jenkins_workspace%\arduino_work\bin 25 | 26 | set tests_list_file=tests.lst 27 | set compiler_path=%jenkins_workspace%\arduino_tools\arduino-%arduino_builder_version% 28 | 29 | set compiler_hardware_path=%compiler_path%\hardware 30 | set compiler_tools_builder_path=%compiler_path%\tools-builder 31 | set compiler_tools_processor_path=%compiler_path%\hardware\tools\avr 32 | 33 | set compiler_libraries_path=%compiler_path%\libraries 34 | set compiler_packages_path=%jenkins_workspace%\arduino_tools\packages 35 | 36 | rem ----------------------------------------------------------------------------- 37 | rem -- Libraries get built and used from c:\jenkins\workspace\arduino_work 38 | rem ----------------------------------------------------------------------------- 39 | set user_libraries_path=%work_root%\libraries 40 | 41 | 42 | rem ----------------------------------------------------------------------------- 43 | rem -- parse script arguments 44 | rem ----------------------------------------------------------------------------- 45 | set build_test=ON 46 | set run_test=OFF 47 | 48 | :args_loop 49 | if "%1" equ "" goto args_done 50 | if "%1" equ "-b" goto arg_build_only 51 | if "%1" equ "--build-only" goto arg_build_only 52 | if "%1" equ "-r" goto arg_run_only 53 | if "%1" equ "--run-only" goto arg_run_only 54 | if "%1" equ "-e2e" goto arg_run_e2e_tests 55 | if "%1" equ "--run-e2e-tests" goto arg_run_e2e_tests 56 | if "%1" equ "--tests" goto arg_test_tests 57 | if "%1" equ "-t" goto arg_test_tests 58 | call :usage && exit /b 1 59 | 60 | :arg_build_only 61 | set build_test=ON 62 | goto args_continue 63 | 64 | :arg_run_only 65 | set build_test=OFF 66 | set run_test=ON 67 | goto args_continue 68 | 69 | :arg_run_e2e_tests 70 | set build_test=ON 71 | set run_test=ON 72 | goto args_continue 73 | 74 | :arg_test_tests 75 | set tests_list_file=%2 76 | shift 77 | goto args_continue 78 | 79 | :args_continue 80 | shift 81 | goto args_loop 82 | 83 | :args_done 84 | 85 | echo. 86 | echo Setup environment for Arduino with the following parameters: 87 | echo. 88 | echo build_test = %build_test% 89 | echo run_test = %run_test% 90 | echo tests_list_file = %tests_list_file% 91 | echo. 92 | echo scripts_path = %scripts_path% 93 | echo jenkins_workspace = %jenkins_workspace% 94 | echo work_root = %work_root% 95 | echo kits_root = %kits_root% 96 | echo built_binaries_root = %built_binaries_root% 97 | echo. 98 | echo compiler_path = %compiler_path% 99 | echo compiler_hardware_path = %compiler_hardware_path% 100 | echo compiler_tools_builder_path = %compiler_tools_builder_path% 101 | echo compiler_tools_processor_path = %compiler_tools_processor_path% 102 | echo compiler_libraries_path = %compiler_libraries_path% 103 | echo compiler_packages_path = %compiler_packages_path% 104 | echo. 105 | echo user_libraries_path = %user_libraries_path% 106 | echo. 107 | echo arduino_esp8266_version = %arduino_esp8266_version% 108 | echo adafruit_samd_version = %adafruit_samd_version% 109 | echo arduino_samd_version = %arduino_samd_version% 110 | echo arduino_builder_version = %arduino_builder_version% 111 | echo esptool_version = %esptool_version% 112 | echo. 113 | echo. 114 | -------------------------------------------------------------------------------- /devdoc/img_src/tlsio_arduino.vsdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/azure-iot-pal-arduino/a9849e7f23ce998357ab888a3d268c6c87de1606/devdoc/img_src/tlsio_arduino.vsdx -------------------------------------------------------------------------------- /devdoc/platform_arduino_requirements.md: -------------------------------------------------------------------------------- 1 | platform_arduino 2 | ============= 3 | 4 | ## Overview 5 | 6 | platform_arduino implements a standard way for SDK to access dedicated Arduino interfaces. 7 | 8 | ## References 9 | 10 | 11 | ### Standard 12 | 13 | **SRS_PLATFORM_ARDUINO_21_001: [** The platform_arduino shall implement the interface provided in the `platfom.h`. 14 | ```c 15 | MOCKABLE_FUNCTION(, int, platform_init); 16 | MOCKABLE_FUNCTION(, void, platform_deinit); 17 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, platform_get_default_tlsio); 18 | MOCKABLE_FUNCTION(, STRING_HANDLE, platform_get_system_info); 19 | ``` 20 | **]** 21 | 22 | **SRS_PLATFORM_ARDUINO_21_002: [** The platform_arduino shall use the tlsio functions defined by the 'xio.h'. 23 | ```c 24 | typedef OPTIONHANDLER_HANDLE (*IO_RETRIEVEOPTIONS)(CONCRETE_IO_HANDLE concrete_io); 25 | typedef CONCRETE_IO_HANDLE(*IO_CREATE)(void* io_create_parameters); 26 | typedef void(*IO_DESTROY)(CONCRETE_IO_HANDLE concrete_io); 27 | typedef int(*IO_OPEN)(CONCRETE_IO_HANDLE concrete_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context); 28 | typedef int(*IO_CLOSE)(CONCRETE_IO_HANDLE concrete_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context); 29 | typedef int(*IO_SEND)(CONCRETE_IO_HANDLE concrete_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context); 30 | typedef void(*IO_DOWORK)(CONCRETE_IO_HANDLE concrete_io); 31 | typedef int(*IO_SETOPTION)(CONCRETE_IO_HANDLE concrete_io, const char* optionName, const void* value); 32 | 33 | typedef struct IO_INTERFACE_DESCRIPTION_TAG 34 | { 35 | IO_RETRIEVEOPTIONS concrete_io_retrieveoptions; 36 | IO_CREATE concrete_io_create; 37 | IO_DESTROY concrete_io_destroy; 38 | IO_OPEN concrete_io_open; 39 | IO_CLOSE concrete_io_close; 40 | IO_SEND concrete_io_send; 41 | IO_DOWORK concrete_io_dowork; 42 | IO_SETOPTION concrete_io_setoption; 43 | } IO_INTERFACE_DESCRIPTION; 44 | ``` 45 | **]** 46 | 47 | ### platform_init 48 | 49 | ```c 50 | int platform_init(void) 51 | ``` 52 | 53 | **SRS_PLATFORM_ARDUINO_21_003: [** The platform_init shall initialize the platform. **]** 54 | 55 | **SRS_PLATFORM_ARDUINO_21_004: [** The platform_init shall allocate any memory needed to control the platform. **]** 56 | 57 | 58 | ### platform_deinit 59 | 60 | ```c 61 | int platform_deinit(void) 62 | ``` 63 | 64 | **SRS_PLATFORM_ARDUINO_21_005: [** The platform_deinit shall deinitialize the platform. **]** 65 | 66 | **SRS_PLATFORM_ARDUINO_21_006: [** The platform_deinit shall free all allocate memory needed to control the platform. **]** 67 | 68 | 69 | ### platform_get_default_tlsio 70 | 71 | ```c 72 | const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void) 73 | ``` 74 | 75 | **SRS_PLATFORM_ARDUINO_21_007: [** The platform_get_default_tlsio shall return a set of tlsio functions provided by the Arduino tlsio implementation. **]** 76 | -------------------------------------------------------------------------------- /devdoc/threadapi_arduino_requirements.md: -------------------------------------------------------------------------------- 1 | threadapi_arduino 2 | ================= 3 | 4 | ## Overview 5 | 6 | threadapi_arduino implements a wrapper function for Arduino's delay function. Arduino do not support thread, so it returns error for the other ThreadAPI functions. 7 | 8 | ## References 9 | 10 | [Delay](https://www.arduino.cc/en/Reference/Delay) 11 | 12 | ### Exposed API 13 | 14 | **SRS_THREADAPI_ARDUINO_21_001: [** The threadapi_arduino shall implement the method sleep defined by the `threadapi.h`. 15 | ```c 16 | /** 17 | * @brief Sleeps the current thread for the given number of milliseconds. 18 | * 19 | * @param milliseconds The number of milliseconds to sleep. 20 | */ 21 | MOCKABLE_FUNCTION(, void, ThreadAPI_Sleep, unsigned int, milliseconds); 22 | ``` 23 | **]** 24 | 25 | 26 | ### ThreadAPI_Sleep 27 | 28 | ```c 29 | void ThreadAPI_Sleep(unsigned int milliseconds); 30 | ``` 31 | 32 | **SRS_THREADAPI_ARDUINO_21_002: [** The ThreadAPI_Sleep shall receive a time in milliseconds. **]** 33 | 34 | **SRS_THREADAPI_ARDUINO_21_003: [** The ThreadAPI_Sleep shall stop the thread for the specified time. **]** 35 | 36 | 37 | ### ThreadAPI_Create 38 | 39 | ```c 40 | THREADAPI_RESULT ThreadAPI_Create(THREAD_HANDLE* threadHandle, THREAD_START_FUNC func, void* arg); 41 | ``` 42 | 43 | **SRS_THREADAPI_ARDUINO_21_004: [** The Arduino do not support ThreadAPI_Create, it shall return THREADAPI_ERROR. **]** 44 | 45 | 46 | ### ThreadAPI_Join 47 | 48 | ```c 49 | THREADAPI_RESULT ThreadAPI_Join(THREAD_HANDLE threadHandle, int* res); 50 | ``` 51 | 52 | **SRS_THREADAPI_ARDUINO_21_005: [** The Arduino do not support ThreadAPI_Join, it shall return THREADAPI_ERROR. **]** 53 | 54 | 55 | ### ThreadAPI_Exit 56 | 57 | ```c 58 | void ThreadAPI_Exit(int res); 59 | ``` 60 | 61 | **SRS_THREADAPI_ARDUINO_21_006: [** The Arduino do not support ThreadAPI_Exit, it shall not do anything. **]** 62 | -------------------------------------------------------------------------------- /jenkins/ubuntu1604_c.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright (c) Microsoft. All rights reserved. 3 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 4 | 5 | build_root=$(cd "$(dirname "$0")/.." && pwd) 6 | cd $build_root/sdk/c-utility/build_all/linux 7 | 8 | # -- C -- 9 | ./build.sh --run-unittests --run_valgrind --build-root $build_root "$@" #-x 10 | [ $? -eq 0 ] || exit $? 11 | 12 | -------------------------------------------------------------------------------- /jenkins/windows_c.cmd: -------------------------------------------------------------------------------- 1 | @REM Copyright (c) Microsoft. All rights reserved. 2 | @REM Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | setlocal 5 | 6 | set build-root=%~dp0.. 7 | rem // resolve to fully qualified path 8 | for %%i in ("%build-root%") do set build-root=%%~fi 9 | 10 | echo %build-root% 11 | 12 | REM -- C -- 13 | cd %build-root%\sdk\c-utility\build_all\windows 14 | 15 | call build.cmd %* --build-root %build-root% --solution-name azure_external_unit_tests 16 | if errorlevel 1 goto :eof 17 | cd %build-root% -------------------------------------------------------------------------------- /pal/azure_c_shared_utility/xlogging.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // This is the Arduino-specific version of xlogging.h 5 | 6 | #ifndef XLOGGING_H 7 | #define XLOGGING_H 8 | 9 | #include "azure_c_shared_utility/agenttime.h" 10 | #include "azure_c_shared_utility/optimize_size.h" 11 | 12 | #if defined(ARDUINO_ARCH_ESP8266) 13 | #include "esp8266/azcpgmspace.h" 14 | #define STRINGS_C_SPRINTF_BUFFER_SIZE 512 15 | #endif 16 | 17 | #ifdef __cplusplus 18 | #include 19 | extern "C" { 20 | #else 21 | #include 22 | #endif /* __cplusplus */ 23 | 24 | typedef enum LOG_CATEGORY_TAG 25 | { 26 | AZ_LOG_ERROR, 27 | AZ_LOG_INFO, 28 | AZ_LOG_TRACE 29 | } LOG_CATEGORY; 30 | 31 | #if defined _MSC_VER 32 | #define FUNC_NAME __FUNCDNAME__ 33 | #else 34 | #define FUNC_NAME __func__ 35 | #endif 36 | 37 | typedef void(*LOGGER_LOG)(LOG_CATEGORY log_category, const char* file, const char* func, int line, unsigned int options, const char* format, ...); 38 | typedef void(*LOGGER_LOG_GETLASTERROR)(const char* file, const char* func, int line, const char* format, ...); 39 | 40 | #define LOG_NONE 0x00 41 | #define LOG_LINE 0x01 42 | 43 | /*no logging is useful when time and fprintf are mocked*/ 44 | #ifdef NO_LOGGING 45 | #define LOG(...) 46 | #define LogInfo(...) 47 | #define LogError(...) 48 | #define xlogging_get_log_function() NULL 49 | #define xlogging_set_log_function(...) 50 | #define LogErrorWinHTTPWithGetLastErrorAsString(...) 51 | #define UNUSED(x) (void)(x) 52 | #elif (defined MINIMAL_LOGERROR) 53 | #define LOG(...) 54 | #define LogInfo(...) 55 | #define LogError(...) printf("error %s: line %d\n",__FILE__,__LINE__); 56 | #define xlogging_get_log_function() NULL 57 | #define xlogging_set_log_function(...) 58 | #define LogErrorWinHTTPWithGetLastErrorAsString(...) 59 | #define UNUSED(x) (void)(x) 60 | 61 | #elif defined(ARDUINO_ARCH_ESP8266) 62 | /* 63 | The ESP8266 compiler doesn't do a good job compiling this code; it doesn't understand that the 'format' is 64 | a 'const char*' and moves it to RAM as a global variable, increasing the .bss size. So we create a 65 | specific LogInfo that explicitly pins the 'format' on the PROGMEM (flash) using a _localFORMAT variable 66 | with the macro PSTR. 67 | #define ICACHE_FLASH_ATTR __attribute__((section(".irom0.text"))) 68 | #define PROGMEM ICACHE_RODATA_ATTR 69 | #define PSTR(s) (__extension__({static const char __c[] PROGMEM = (s); &__c[0];})) 70 | const char* __localFORMAT = PSTR(FORMAT); 71 | On the other hand, vsprintf does not support the pinned 'format' and os_printf does not work with va_list, 72 | so we compacted the log in the macro LogInfo. 73 | */ 74 | #define LOG(log_category, log_options, FORMAT, ...) { \ 75 | const char* __localFORMAT = PSTR(FORMAT); \ 76 | os_printf(__localFORMAT, ##__VA_ARGS__); \ 77 | os_printf("\r\n"); \ 78 | } 79 | 80 | #define LogInfo(FORMAT, ...) { \ 81 | const char* __localFORMAT = PSTR(FORMAT); \ 82 | os_printf(__localFORMAT, ##__VA_ARGS__); \ 83 | os_printf("\r\n"); \ 84 | } 85 | #define LogError LogInfo 86 | 87 | #else /* !ARDUINO_ARCH_ESP8266 */ 88 | 89 | #if defined _MSC_VER 90 | #define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, __VA_ARGS__); } 91 | #else 92 | #define LOG(log_category, log_options, format, ...) { LOGGER_LOG l = xlogging_get_log_function(); if (l != NULL) l(log_category, __FILE__, FUNC_NAME, __LINE__, log_options, format, ##__VA_ARGS__); } 93 | #endif 94 | 95 | #if defined _MSC_VER 96 | #define LogInfo(FORMAT, ...) do{LOG(AZ_LOG_INFO, LOG_LINE, FORMAT, __VA_ARGS__); }while((void)0,0) 97 | #else 98 | #define LogInfo(FORMAT, ...) do{LOG(AZ_LOG_INFO, LOG_LINE, FORMAT, ##__VA_ARGS__); }while((void)0,0) 99 | #endif 100 | 101 | #if defined _MSC_VER 102 | 103 | extern void xlogging_set_log_function_GetLastError(LOGGER_LOG_GETLASTERROR log_function); 104 | extern LOGGER_LOG_GETLASTERROR xlogging_get_log_function_GetLastError(void); 105 | #define LogLastError(FORMAT, ...) do{ LOGGER_LOG_GETLASTERROR l = xlogging_get_log_function_GetLastError(); if(l!=NULL) l(__FILE__, FUNC_NAME, __LINE__, FORMAT, __VA_ARGS__); }while((void)0,0) 106 | 107 | #define LogError(FORMAT, ...) do{ LOG(AZ_LOG_ERROR, LOG_LINE, FORMAT, __VA_ARGS__); }while((void)0,0) 108 | #define TEMP_BUFFER_SIZE 1024 109 | #define MESSAGE_BUFFER_SIZE 260 110 | #define LogErrorWinHTTPWithGetLastErrorAsString(FORMAT, ...) do { \ 111 | DWORD errorMessageID = GetLastError(); \ 112 | char messageBuffer[MESSAGE_BUFFER_SIZE]; \ 113 | LogError(FORMAT, __VA_ARGS__); \ 114 | if (errorMessageID == 0) \ 115 | {\ 116 | LogError("GetLastError() returned 0. Make sure you are calling this right after the code that failed. "); \ 117 | } \ 118 | else\ 119 | {\ 120 | int size = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_IGNORE_INSERTS, \ 121 | GetModuleHandle("WinHttp"), errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), messageBuffer, MESSAGE_BUFFER_SIZE, NULL); \ 122 | if (size == 0)\ 123 | {\ 124 | size = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), messageBuffer, MESSAGE_BUFFER_SIZE, NULL); \ 125 | if (size == 0)\ 126 | {\ 127 | LogError("GetLastError Code: %d. ", errorMessageID); \ 128 | }\ 129 | else\ 130 | {\ 131 | LogError("GetLastError: %s.", messageBuffer); \ 132 | }\ 133 | }\ 134 | else\ 135 | {\ 136 | LogError("GetLastError: %s.", messageBuffer); \ 137 | }\ 138 | }\ 139 | } while((void)0,0) 140 | #else // _MSC_VER 141 | #define LogError(FORMAT, ...) do{ LOG(AZ_LOG_ERROR, LOG_LINE, FORMAT, ##__VA_ARGS__); }while((void)0,0) 142 | #endif // _MSC_VER 143 | 144 | extern void xlogging_set_log_function(LOGGER_LOG log_function); 145 | extern LOGGER_LOG xlogging_get_log_function(void); 146 | 147 | #endif /* ARDUINO_ARCH_ESP8266 */ 148 | 149 | 150 | /** 151 | * @brief Print the memory content byte pre byte in hexadecimal and as a char it the byte correspond to any printable ASCII chars. 152 | * 153 | * This function prints the 'size' bytes in the 'buf' to the log. It will print in portions of 16 bytes, 154 | * and will print the byte as a hexadecimal value, and, it is a printable, this function will print 155 | * the correspondent ASCII character. 156 | * Non printable characters will shows as a single '.'. 157 | * For this function, printable characters are all characters between ' ' (0x20) and '~' (0x7E). 158 | * 159 | * @param buf Pointer to the memory address with the buffer to print. 160 | * @param size Number of bytes to print. 161 | */ 162 | extern void xlogging_dump_bytes(const void* buf, size_t size); 163 | 164 | #ifdef __cplusplus 165 | } // extern "C" 166 | #endif /* __cplusplus */ 167 | 168 | #endif /* XLOGGING_H */ 169 | -------------------------------------------------------------------------------- /pal/inc/sslClient_arduino.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SSLCLIENT_ARDUINO_H 5 | #define SSLCLIENT_ARDUINO_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #include 11 | #else 12 | #include 13 | #include 14 | #endif /* __cplusplus */ 15 | 16 | #include "umock_c/umock_c_prod.h" 17 | 18 | MOCKABLE_FUNCTION(, void, sslClient_setTimeout, unsigned long, timeout); 19 | MOCKABLE_FUNCTION(, uint8_t, sslClient_connected); 20 | MOCKABLE_FUNCTION(, int, sslClient_connect, const char*, name, uint16_t, port); 21 | MOCKABLE_FUNCTION(, void, sslClient_stop); 22 | MOCKABLE_FUNCTION(, size_t, sslClient_write, const uint8_t*, buf, size_t, size); 23 | MOCKABLE_FUNCTION(, size_t, sslClient_print, const char*, str); 24 | MOCKABLE_FUNCTION(, int, sslClient_read, uint8_t*, buf, size_t, size); 25 | MOCKABLE_FUNCTION(, int, sslClient_available); 26 | 27 | MOCKABLE_FUNCTION(, uint8_t, sslClient_hostByName, const char*, hostName, uint32_t*, ipAddress); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif /* __cplusplus */ 32 | 33 | #endif /* SSLCLIENT_ARDUINO_H */ 34 | 35 | -------------------------------------------------------------------------------- /pal/inc/tlsio_arduino.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TLSIO_ARDUINO_H 5 | #define TLSIO_ARDUINO_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #else 11 | #include 12 | #endif /* __cplusplus */ 13 | 14 | #include "azure_c_shared_utility/xio.h" 15 | #include "umock_c/umock_c_prod.h" 16 | 17 | /** @brief Return the tlsio table of functions. 18 | * 19 | * @param void. 20 | * 21 | * @return The tlsio interface (IO_INTERFACE_DESCRIPTION). 22 | */ 23 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_arduino_get_interface_description); 24 | 25 | 26 | /** Expose tlsio state for test proposes. 27 | */ 28 | #define TLSIO_ARDUINO_STATE_VALUES \ 29 | TLSIO_ARDUINO_STATE_CLOSED, \ 30 | TLSIO_ARDUINO_STATE_OPENING, \ 31 | TLSIO_ARDUINO_STATE_OPEN, \ 32 | TLSIO_ARDUINO_STATE_CLOSING, \ 33 | TLSIO_ARDUINO_STATE_ERROR, \ 34 | TLSIO_ARDUINO_STATE_NULL 35 | MU_DEFINE_ENUM_WITHOUT_INVALID(TLSIO_ARDUINO_STATE, TLSIO_ARDUINO_STATE_VALUES); 36 | 37 | 38 | /** @brief Return the tlsio state for test proposes. 39 | * 40 | * @param Unique handle that identifies the tlsio instance. 41 | * 42 | * @return The tlsio state (TLSIO_ARDUINO_STATE). 43 | */ 44 | TLSIO_ARDUINO_STATE tlsio_arduino_get_state(CONCRETE_IO_HANDLE tlsio_handle); 45 | 46 | #ifdef __cplusplus 47 | } 48 | #endif /* __cplusplus */ 49 | 50 | #endif /* TLSIO_ARDUINO_H */ 51 | 52 | -------------------------------------------------------------------------------- /pal/samples/esp32/iothub_ll_telemetry_sample/iot_configs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOT_CONFIGS_H 5 | #define IOT_CONFIGS_H 6 | 7 | /** 8 | * WiFi setup 9 | */ 10 | #define IOT_CONFIG_WIFI_SSID "your-wifi-name" 11 | #define IOT_CONFIG_WIFI_PASSWORD "your-wifi-pwd" 12 | 13 | /** 14 | * IoT Hub Device Connection String setup 15 | * Find your Device Connection String by going to your Azure portal, creating (or navigating to) an IoT Hub, 16 | * navigating to IoT Devices tab on the left, and creating (or selecting an existing) IoT Device. 17 | * Then click on the named Device ID, and you will have able to copy the Primary or Secondary Device Connection String to this sample. 18 | */ 19 | #define DEVICE_CONNECTION_STRING "your-iothub-DEVICE-connection-string" 20 | 21 | // The protocol you wish to use should be uncommented 22 | // 23 | #define SAMPLE_MQTT 24 | //#define SAMPLE_HTTP 25 | 26 | #endif /* IOT_CONFIGS_H */ 27 | -------------------------------------------------------------------------------- /pal/samples/esp32/iothub_ll_telemetry_sample/iothub_ll_telemetry_sample.ino: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // CAVEAT: This sample is to demonstrate azure IoT client concepts only and is not a guide design principles or style 5 | // Checking of return codes and error values shall be omitted for brevity. Please practice sound engineering practices 6 | // when writing production code. 7 | 8 | // Note: PLEASE see https://github.com/Azure/azure-iot-arduino#simple-sample-instructions for detailed sample setup instructions. 9 | // Note2: To use this sample with the esp32, you MUST build the AzureIoTSocket_WiFi library by using the make_sdk.py, 10 | // found in https://github.com/Azure/azure-iot-pal-arduino/tree/master/build_all. 11 | // Command line example: python3 make_sdk.py -o 12 | #include 13 | #include 14 | #include 15 | 16 | #include "iot_configs.h" // You must set your wifi SSID, wifi PWD, and your IoTHub Device Connection String in iot_configs.h 17 | #include "sample_init.h" 18 | 19 | #ifdef is_esp_board 20 | #include "Esp.h" 21 | #endif 22 | 23 | #ifdef SAMPLE_MQTT 24 | #include "AzureIoTProtocol_MQTT.h" 25 | #include "iothubtransportmqtt.h" 26 | #endif // SAMPLE_MQTT 27 | #ifdef SAMPLE_HTTP 28 | #include "AzureIoTProtocol_HTTP.h" 29 | #include "iothubtransporthttp.h" 30 | #endif // SAMPLE_HTTP 31 | 32 | static const char ssid[] = IOT_CONFIG_WIFI_SSID; 33 | static const char pass[] = IOT_CONFIG_WIFI_PASSWORD; 34 | 35 | /* Define several constants/global variables */ 36 | static const char* connectionString = DEVICE_CONNECTION_STRING; 37 | static bool g_continueRunning = true; // defines whether or not the device maintains its IoT Hub connection after sending (think receiving messages from the cloud) 38 | static size_t g_message_count_send_confirmations = 0; 39 | static bool g_run_demo = true; 40 | 41 | IOTHUB_MESSAGE_HANDLE message_handle; 42 | size_t messages_sent = 0; 43 | #define MESSAGE_COUNT 5 // determines the number of times the device tries to send a message to the IoT Hub in the cloud. 44 | const char* telemetry_msg = "test_message"; 45 | const char* quit_msg = "quit"; 46 | const char* exit_msg = "exit"; 47 | 48 | IOTHUB_DEVICE_CLIENT_LL_HANDLE device_ll_handle; 49 | 50 | static int callbackCounter; 51 | int receiveContext = 0; 52 | 53 | /* -- receive_message_callback -- 54 | * Callback method which executes upon receipt of a message originating from the IoT Hub in the cloud. 55 | * Note: Modifying the contents of this method allows one to command the device from the cloud. 56 | */ 57 | static IOTHUBMESSAGE_DISPOSITION_RESULT receive_message_callback(IOTHUB_MESSAGE_HANDLE message, void* userContextCallback) 58 | { 59 | int* counter = (int*)userContextCallback; 60 | const unsigned char* buffer; 61 | size_t size; 62 | const char* messageId; 63 | 64 | // Message properties 65 | if ((messageId = IoTHubMessage_GetMessageId(message)) == NULL) 66 | { 67 | messageId = ""; 68 | } 69 | 70 | // Message content 71 | if (IoTHubMessage_GetByteArray(message, (const unsigned char**)&buffer, &size) != IOTHUB_MESSAGE_OK) 72 | { 73 | LogInfo("unable to retrieve the message data\r\n"); 74 | } 75 | else 76 | { 77 | LogInfo("Received Message [%d]\r\n Message ID: %s\r\n Data: <<<%.*s>>> & Size=%d\r\n", *counter, messageId, (int)size, buffer, (int)size); 78 | // If we receive the word 'quit' then we stop running 79 | if (size == (strlen(quit_msg) * sizeof(char)) && memcmp(buffer, quit_msg, size) == 0) 80 | { 81 | g_continueRunning = false; 82 | } 83 | } 84 | 85 | /* Some device specific action code goes here... */ 86 | (*counter)++; 87 | return IOTHUBMESSAGE_ACCEPTED; 88 | } 89 | 90 | 91 | /* -- send_confirm_callback -- 92 | * Callback method which executes upon confirmation that a message originating from this device has been received by the IoT Hub in the cloud. 93 | */ 94 | static void send_confirm_callback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) 95 | { 96 | (void)userContextCallback; 97 | // When a message is sent this callback will get envoked 98 | g_message_count_send_confirmations++; 99 | LogInfo("Confirmation callback received for message %lu with result %s\r\n", (unsigned long)g_message_count_send_confirmations, MU_ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result)); 100 | } 101 | 102 | /* -- connection_status_callback -- 103 | * Callback method which executes on receipt of a connection status message from the IoT Hub in the cloud. 104 | */ 105 | static void connection_status_callback(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason, void* user_context) 106 | { 107 | (void)reason; 108 | (void)user_context; 109 | // This sample DOES NOT take into consideration network outages. 110 | if (result == IOTHUB_CLIENT_CONNECTION_AUTHENTICATED) 111 | { 112 | LogInfo("The device client is connected to iothub\r\n"); 113 | } 114 | else 115 | { 116 | LogInfo("The device client has been disconnected\r\n"); 117 | } 118 | } 119 | 120 | /* -- reset_esp_helper -- 121 | * waits for call of exit_msg over Serial line to reset device 122 | */ 123 | static void reset_esp_helper() 124 | { 125 | #ifdef is_esp_board 126 | // Read from local serial 127 | if (Serial.available()){ 128 | String s1 = Serial.readStringUntil('\n');// s1 is String type variable. 129 | Serial.print("Received Data: "); 130 | Serial.println(s1);//display same received Data back in serial monitor. 131 | 132 | // Restart device upon receipt of 'exit' call. 133 | int e_start = s1.indexOf('e'); 134 | String ebit = (String) s1.substring(e_start, e_start+4); 135 | if(ebit == exit_msg) 136 | { 137 | ESP.restart(); 138 | } 139 | } 140 | #endif // is_esp_board 141 | } 142 | 143 | /* -- run_demo -- 144 | * Runs active task of sending telemetry to IoTHub 145 | * WARNING: only call this function once, as it includes steps to destroy handles and clean up at the end. 146 | */ 147 | static void run_demo() 148 | { 149 | int result = 0; 150 | 151 | // action phase of the program, sending messages to the IoT Hub in the cloud. 152 | do 153 | { 154 | if (messages_sent < MESSAGE_COUNT) 155 | { 156 | // Construct the iothub message from a string or a byte array 157 | message_handle = IoTHubMessage_CreateFromString(telemetry_msg); 158 | //message_handle = IoTHubMessage_CreateFromByteArray((const unsigned char*)msgText, strlen(msgText))); 159 | 160 | // Set Message property 161 | /*(void)IoTHubMessage_SetMessageId(message_handle, "MSG_ID"); 162 | (void)IoTHubMessage_SetCorrelationId(message_handle, "CORE_ID"); 163 | (void)IoTHubMessage_SetContentTypeSystemProperty(message_handle, "application%2fjson"); 164 | (void)IoTHubMessage_SetContentEncodingSystemProperty(message_handle, "utf-8");*/ 165 | 166 | // Add custom properties to message 167 | // (void)IoTHubMessage_SetProperty(message_handle, "property_key", "property_value"); 168 | 169 | LogInfo("Sending message %d to IoTHub\r\n", (int)(messages_sent + 1)); 170 | result = IoTHubDeviceClient_LL_SendEventAsync(device_ll_handle, message_handle, send_confirm_callback, NULL); 171 | // The message is copied to the sdk so the we can destroy it 172 | IoTHubMessage_Destroy(message_handle); 173 | 174 | messages_sent++; 175 | } 176 | else if (g_message_count_send_confirmations >= MESSAGE_COUNT) 177 | { 178 | // After all messages are all received stop running 179 | g_continueRunning = false; 180 | } 181 | 182 | IoTHubDeviceClient_LL_DoWork(device_ll_handle); 183 | ThreadAPI_Sleep(3); 184 | reset_esp_helper(); 185 | 186 | } while (g_continueRunning); 187 | 188 | // Clean up the iothub sdk handle 189 | IoTHubDeviceClient_LL_Destroy(device_ll_handle); 190 | // Free all the sdk subsystem 191 | IoTHub_Deinit(); 192 | 193 | LogInfo("done with sending"); 194 | return; 195 | } 196 | 197 | void setup() { 198 | 199 | // Select the Protocol to use with the connection 200 | #ifdef SAMPLE_MQTT 201 | IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = MQTT_Protocol; 202 | #endif // SAMPLE_MQTT 203 | #ifdef SAMPLE_HTTP 204 | IOTHUB_CLIENT_TRANSPORT_PROVIDER protocol = HTTP_Protocol; 205 | #endif // SAMPLE_HTTP 206 | 207 | sample_init(ssid, pass); 208 | 209 | // Used to initialize IoTHub SDK subsystem 210 | (void)IoTHub_Init(); 211 | // Create the iothub handle here 212 | device_ll_handle = IoTHubDeviceClient_LL_CreateFromConnectionString(connectionString, protocol); 213 | LogInfo("Creating IoTHub Device handle\r\n"); 214 | 215 | if (device_ll_handle == NULL) 216 | { 217 | LogInfo("Error AZ002: Failure creating Iothub device. Hint: Check you connection string.\r\n"); 218 | } 219 | else 220 | { 221 | // Set any option that are neccessary. 222 | // For available options please see the iothub_sdk_options.md documentation in the main C SDK 223 | // turn off diagnostic sampling 224 | int diag_off = 0; 225 | IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_DIAGNOSTIC_SAMPLING_PERCENTAGE, &diag_off); 226 | 227 | #ifndef SAMPLE_HTTP 228 | // Example sdk status tracing for troubleshooting 229 | bool traceOn = true; 230 | IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_LOG_TRACE, &traceOn); 231 | #endif // SAMPLE_HTTP 232 | 233 | // Setting the Trusted Certificate. 234 | IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_TRUSTED_CERT, certificates); 235 | 236 | #if defined SAMPLE_MQTT 237 | //Setting the auto URL Encoder (recommended for MQTT). Please use this option unless 238 | //you are URL Encoding inputs yourself. 239 | //ONLY valid for use with MQTT 240 | bool urlEncodeOn = true; 241 | IoTHubDeviceClient_LL_SetOption(device_ll_handle, OPTION_AUTO_URL_ENCODE_DECODE, &urlEncodeOn); 242 | /* Setting Message call back, so we can receive Commands. */ 243 | if (IoTHubClient_LL_SetMessageCallback(device_ll_handle, receive_message_callback, &receiveContext) != IOTHUB_CLIENT_OK) 244 | { 245 | LogInfo("ERROR: IoTHubClient_LL_SetMessageCallback..........FAILED!\r\n"); 246 | } 247 | #endif // SAMPLE_MQTT 248 | 249 | // Setting connection status callback to get indication of connection to iothub 250 | (void)IoTHubDeviceClient_LL_SetConnectionStatusCallback(device_ll_handle, connection_status_callback, NULL); 251 | 252 | } 253 | } 254 | 255 | void loop(void) 256 | { 257 | if (g_run_demo) 258 | { 259 | run_demo(); 260 | g_run_demo = false; 261 | } 262 | reset_esp_helper(); 263 | } 264 | -------------------------------------------------------------------------------- /pal/samples/esp32/iothub_ll_telemetry_sample/platform.local.txt: -------------------------------------------------------------------------------- 1 | name=ESP32 Arduino 2 | version=1.0.2 3 | 4 | 5 | 6 | tools.esptool_py.path={runtime.tools.esptool_py.path} 7 | tools.esptool_py.cmd=esptool 8 | tools.esptool_py.cmd.linux=esptool.py 9 | tools.esptool_py.cmd.windows=esptool.exe 10 | 11 | tools.esptool_py.network_cmd=python "{runtime.platform.path}/tools/espota.py" 12 | tools.esptool_py.network_cmd.windows="{runtime.platform.path}/tools/espota.exe" 13 | 14 | tools.gen_esp32part.cmd=python "{runtime.platform.path}/tools/gen_esp32part.py" 15 | tools.gen_esp32part.cmd.windows="{runtime.platform.path}/tools/gen_esp32part.exe" 16 | 17 | compiler.warning_flags=-w 18 | compiler.warning_flags.none=-w 19 | compiler.warning_flags.default= 20 | compiler.warning_flags.more=-Wall -Werror=all 21 | compiler.warning_flags.all=-Wall -Werror=all -Wextra 22 | 23 | compiler.path={runtime.tools.xtensa-esp32-elf-gcc.path}/bin/ 24 | compiler.sdk.path={runtime.platform.path}/tools/sdk 25 | compiler.cpreprocessor.flags=-DESP_PLATFORM -DMBEDTLS_CONFIG_FILE="mbedtls/esp_config.h" -DHAVE_CONFIG_H "-I{compiler.sdk.path}/include/config" "-I{compiler.sdk.path}/include/app_trace" "-I{compiler.sdk.path}/include/app_update" "-I{compiler.sdk.path}/include/asio" "-I{compiler.sdk.path}/include/bootloader_support" "-I{compiler.sdk.path}/include/bt" "-I{compiler.sdk.path}/include/coap" "-I{compiler.sdk.path}/include/console" "-I{compiler.sdk.path}/include/driver" "-I{compiler.sdk.path}/include/esp-tls" "-I{compiler.sdk.path}/include/esp32" "-I{compiler.sdk.path}/include/esp_adc_cal" "-I{compiler.sdk.path}/include/esp_event" "-I{compiler.sdk.path}/include/esp_http_client" "-I{compiler.sdk.path}/include/esp_http_server" "-I{compiler.sdk.path}/include/esp_https_ota" "-I{compiler.sdk.path}/include/esp_ringbuf" "-I{compiler.sdk.path}/include/ethernet" "-I{compiler.sdk.path}/include/expat" "-I{compiler.sdk.path}/include/fatfs" "-I{compiler.sdk.path}/include/freemodbus" "-I{compiler.sdk.path}/include/freertos" "-I{compiler.sdk.path}/include/heap" "-I{compiler.sdk.path}/include/idf_test" "-I{compiler.sdk.path}/include/jsmn" "-I{compiler.sdk.path}/include/json" "-I{compiler.sdk.path}/include/libsodium" "-I{compiler.sdk.path}/include/log" "-I{compiler.sdk.path}/include/lwip" "-I{compiler.sdk.path}/include/mbedtls" "-I{compiler.sdk.path}/include/mdns" "-I{compiler.sdk.path}/include/micro-ecc" "-I{compiler.sdk.path}/include/mqtt" "-I{compiler.sdk.path}/include/newlib" "-I{compiler.sdk.path}/include/nghttp" "-I{compiler.sdk.path}/include/nvs_flash" "-I{compiler.sdk.path}/include/openssl" "-I{compiler.sdk.path}/include/protobuf-c" "-I{compiler.sdk.path}/include/protocomm" "-I{compiler.sdk.path}/include/pthread" "-I{compiler.sdk.path}/include/sdmmc" "-I{compiler.sdk.path}/include/smartconfig_ack" "-I{compiler.sdk.path}/include/soc" "-I{compiler.sdk.path}/include/spi_flash" "-I{compiler.sdk.path}/include/spiffs" "-I{compiler.sdk.path}/include/tcp_transport" "-I{compiler.sdk.path}/include/tcpip_adapter" "-I{compiler.sdk.path}/include/ulp" "-I{compiler.sdk.path}/include/vfs" "-I{compiler.sdk.path}/include/wear_levelling" "-I{compiler.sdk.path}/include/wifi_provisioning" "-I{compiler.sdk.path}/include/wpa_supplicant" "-I{compiler.sdk.path}/include/xtensa-debug-module" "-I{compiler.sdk.path}/include/esp32-camera" "-I{compiler.sdk.path}/include/esp-face" "-I{compiler.sdk.path}/include/fb_gfx" 26 | 27 | compiler.c.cmd=xtensa-esp32-elf-gcc 28 | compiler.c.flags=-std=gnu99 -Os -g3 -fstack-protector -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib -Wpointer-arith {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -Wno-old-style-declaration -MMD -c 29 | 30 | compiler.cpp.cmd=xtensa-esp32-elf-g++ 31 | compiler.cpp.flags=-std=gnu++11 -fno-exceptions -Os -g3 -Wpointer-arith -fexceptions -fstack-protector -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -mlongcalls -nostdlib {compiler.warning_flags} -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-sign-compare -fno-rtti -MMD -c 32 | 33 | compiler.S.cmd=xtensa-esp32-elf-gcc 34 | compiler.S.flags=-c -g3 -x assembler-with-cpp -MMD -mlongcalls 35 | 36 | compiler.c.elf.cmd=xtensa-esp32-elf-gcc 37 | compiler.c.elf.flags=-nostdlib "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.spiram_incompatible_fns.ld -u ld_include_panic_highint_hdl -u call_user_start_cpu0 -Wl,--gc-sections -Wl,-static -Wl,--undefined=uxTopUsedPriority -u __cxa_guard_dummy -u __cxx_fatal_exception 38 | compiler.c.elf.libs=-lgcc -lopenssl -lbtdm_app -lfatfs -lwps -lcoexist -lwear_levelling -lesp_http_client -lprotobuf-c -lhal -lnewlib -ldriver -lbootloader_support -lpp -lfreemodbus -lmesh -lsmartconfig -ljsmn -lwpa -lethernet -lphy -lfrmn -lapp_trace -lfr_coefficients -lconsole -lulp -lwpa_supplicant -lfreertos -lbt -lmicro-ecc -lesp32-camera -lcxx -lxtensa-debug-module -ltcp_transport -lmdns -lvfs -lmtmn -lesp_ringbuf -lsoc -lcore -lfb_gfx -lsdmmc -llibsodium -lcoap -ltcpip_adapter -lprotocomm -lesp_event -limage_util -lc_nano -lesp-tls -lasio -lrtc -lspi_flash -lwpa2 -lwifi_provisioning -lesp32 -lface_recognition -lapp_update -lnghttp -lspiffs -lface_detection -lespnow -lnvs_flash -lesp_adc_cal -llog -ldl_lib -lsmartconfig_ack -lexpat -lfd_coefficients -lm -lmqtt -lc -lheap -lmbedtls -llwip -lnet80211 -lesp_http_server -lpthread -ljson -lesp_https_ota -lstdc++ 39 | 40 | compiler.as.cmd=xtensa-esp32-elf-as 41 | 42 | compiler.ar.cmd=xtensa-esp32-elf-ar 43 | compiler.ar.flags=cru 44 | 45 | compiler.size.cmd=xtensa-esp32-elf-size 46 | 47 | # This can be overriden in boards.txt 48 | build.flash_size=4MB 49 | build.flash_mode=dio 50 | build.boot=bootloader 51 | build.code_debug=0 52 | build.defines= 53 | build.extra_flags=-DESP32 -DDONT_USE_UPLOADTOBLOB -DUSE_BALTIMORE_CERT -DUSE_MBEDTLS 54 | #-DCORE_DEBUG_LEVEL={build.code_debug} {build.defines} 55 | 56 | # These can be overridden in platform.local.txt 57 | compiler.c.extra_flags= 58 | compiler.c.elf.extra_flags= 59 | compiler.S.extra_flags= 60 | compiler.cpp.extra_flags= 61 | compiler.ar.extra_flags= 62 | compiler.objcopy.eep.extra_flags= 63 | compiler.elf2hex.extra_flags= 64 | 65 | ## Compile c files 66 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" -DARDUINO_VARIANT="{build.variant}" {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 67 | 68 | ## Compile c++ files 69 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" -DARDUINO_VARIANT="{build.variant}" {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 70 | 71 | ## Compile S files 72 | recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" -DARDUINO_VARIANT="{build.variant}" {compiler.S.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 73 | 74 | ## Create archives 75 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" 76 | 77 | ## Combine gc-sections, archives, and objects 78 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group -Wl,-EL -o "{build.path}/{build.project_name}.elf" 79 | 80 | ## Create eeprom 81 | recipe.objcopy.eep.pattern={tools.gen_esp32part.cmd} -q "{runtime.platform.path}/tools/partitions/{build.partitions}.csv" "{build.path}/{build.project_name}.partitions.bin" 82 | 83 | ## Create hex 84 | recipe.objcopy.hex.pattern="{tools.esptool_py.path}/{tools.esptool_py.cmd}" --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf" 85 | recipe.objcopy.hex.pattern.linux=python "{tools.esptool_py.path}/{tools.esptool_py.cmd}" --chip esp32 elf2image --flash_mode "{build.flash_mode}" --flash_freq "{build.flash_freq}" --flash_size "{build.flash_size}" -o "{build.path}/{build.project_name}.bin" "{build.path}/{build.project_name}.elf" 86 | 87 | ## Save hex 88 | recipe.output.tmp_file={build.project_name}.bin 89 | recipe.output.save_file={build.project_name}.{build.variant}.bin 90 | 91 | ## Compute size 92 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" 93 | recipe.size.regex=^(?:\.iram0\.text|\.iram0\.vectors|\.dram0\.data|\.flash\.text|\.flash\.rodata|)\s+([0-9]+).* 94 | recipe.size.regex.data=^(?:\.dram0\.data|\.dram0\.bss|\.noinit)\s+([0-9]+).* 95 | 96 | # ------------------------------ 97 | 98 | tools.esptool_py.upload.protocol=esp32 99 | tools.esptool_py.upload.params.verbose= 100 | tools.esptool_py.upload.params.quiet= 101 | tools.esptool_py.upload.pattern="{path}/{cmd}" --chip esp32 --port "{serial.port}" --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size detect 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x1000 "{runtime.platform.path}/tools/sdk/bin/bootloader_{build.boot}_{build.flash_freq}.bin" 0x10000 "{build.path}/{build.project_name}.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 102 | tools.esptool_py.upload.pattern.linux=python "{path}/{cmd}" --chip esp32 --port "{serial.port}" --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size detect 0xe000 "{runtime.platform.path}/tools/partitions/boot_app0.bin" 0x1000 "{runtime.platform.path}/tools/sdk/bin/bootloader_{build.boot}_{build.flash_freq}.bin" 0x10000 "{build.path}/{build.project_name}.bin" 0x8000 "{build.path}/{build.project_name}.partitions.bin" 103 | tools.esptool_py.upload.network_pattern={network_cmd} -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin" 104 | -------------------------------------------------------------------------------- /pal/samples/esp32/iothub_ll_telemetry_sample/sample_init.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SAMPLE_INIT_H 5 | #define SAMPLE_INIT_H 6 | #if defined(ARDUINO_ARCH_ESP8266) 7 | #define sample_init esp8266_sample_init 8 | #define is_esp_board 9 | void esp8266_sample_init(const char* ssid, const char* password); 10 | #endif // ARDUINO_ARCH_ESP8266 11 | #if defined(ARDUINO_ARCH_ESP32) 12 | #define sample_init esp32_sample_init 13 | #define is_esp_board 14 | void esp32_sample_init(const char* ssid, const char* password); 15 | #endif // ARDUINO_ARCH_ESP32 16 | 17 | #endif // SAMPLE_INIT_H 18 | -------------------------------------------------------------------------------- /pal/samples/esp8266/iothub_ll_telemetry_sample/iot_configs.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOT_CONFIGS_H 5 | #define IOT_CONFIGS_H 6 | 7 | /** 8 | * WiFi setup 9 | */ 10 | #define IOT_CONFIG_WIFI_SSID "your-wifi-name" 11 | #define IOT_CONFIG_WIFI_PASSWORD "your-wifi-pwd" 12 | 13 | /** 14 | * IoT Hub Device Connection String setup 15 | * Find your Device Connection String by going to your Azure portal, creating (or navigating to) an IoT Hub, 16 | * navigating to IoT Devices tab on the left, and creating (or selecting an existing) IoT Device. 17 | * Then click on the named Device ID, and you will have able to copy the Primary or Secondary Device Connection String to this sample. 18 | */ 19 | #define DEVICE_CONNECTION_STRING "your-iothub-DEVICE-connection-string" 20 | 21 | // The protocol you wish to use should be uncommented 22 | // 23 | #define SAMPLE_MQTT 24 | //#define SAMPLE_HTTP 25 | 26 | #endif /* IOT_CONFIGS_H */ 27 | -------------------------------------------------------------------------------- /pal/samples/esp8266/iothub_ll_telemetry_sample/platform.local.txt: -------------------------------------------------------------------------------- 1 | 2 | # ESP8266 platform 3 | # ------------------------------ 4 | 5 | # For more info: 6 | # https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification 7 | 8 | name=ESP8266 Boards (2.5.2) 9 | version=2.5.2 10 | 11 | # These will be removed by the packager script when doing a JSON release 12 | 13 | runtime.tools.signing={runtime.platform.path}/tools/signing.py 14 | runtime.tools.elf2bin={runtime.platform.path}/tools/elf2bin.py 15 | runtime.tools.makecorever={runtime.platform.path}/tools/makecorever.py 16 | runtime.tools.eboot={runtime.platform.path}/bootloaders/eboot/eboot.elf 17 | 18 | compiler.warning_flags=-w 19 | compiler.warning_flags.none=-w 20 | compiler.warning_flags.default= 21 | compiler.warning_flags.more=-Wall 22 | compiler.warning_flags.all=-Wall -Wextra 23 | 24 | build.lwip_lib=-llwip_gcc 25 | build.lwip_include=lwip/include 26 | build.lwip_flags=-DLWIP_OPEN_SRC 27 | 28 | build.vtable_flags=-DVTABLES_IN_FLASH 29 | 30 | build.sslflags= 31 | 32 | build.exception_flags=-fno-exceptions 33 | build.stdcpp_lib=-lstdc++ 34 | 35 | build.float=-u _printf_float -u _scanf_float 36 | build.led= 37 | build.sdk=NONOSDK221 38 | 39 | compiler.path={runtime.tools.xtensa-lx106-elf-gcc.path}/bin/ 40 | compiler.sdk.path={runtime.platform.path}/tools/sdk 41 | 42 | compiler.libc.path={runtime.platform.path}/tools/sdk/libc/xtensa-lx106-elf 43 | compiler.cpreprocessor.flags=-D__ets__ -DICACHE_FLASH -U__STRICT_ANSI__ "-I{compiler.sdk.path}/include" "-I{compiler.sdk.path}/{build.lwip_include}" "-I{compiler.libc.path}/include" "-I{build.path}/core" 44 | 45 | compiler.c.cmd=xtensa-lx106-elf-gcc 46 | compiler.c.flags=-c {compiler.warning_flags} -Os -g -Wpointer-arith -Wno-implicit-function-declaration -Wl,-EL -fno-inline-functions -nostdlib -mlongcalls -mtext-section-literals -falign-functions=4 -MMD -std=gnu99 -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} 47 | 48 | compiler.S.cmd=xtensa-lx106-elf-gcc 49 | compiler.S.flags=-c -g -x assembler-with-cpp -MMD -mlongcalls 50 | 51 | compiler.c.elf.flags=-g {compiler.warning_flags} -Os -nostdlib -Wl,--no-check-sections -u app_entry {build.float} -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/lib/{build.sdk}" "-L{compiler.sdk.path}/ld" "-L{compiler.libc.path}/lib" "-T{build.flash_ld}" -Wl,--gc-sections -Wl,-wrap,system_restart_local -Wl,-wrap,spi_flash_read 52 | 53 | compiler.c.elf.cmd=xtensa-lx106-elf-gcc 54 | compiler.c.elf.libs=-lhal -lphy -lpp -lnet80211 {build.lwip_lib} -lwpa -lcrypto -lmain -lwps -lbearssl -laxtls -lespnow -lsmartconfig -lairkiss -lwpa2 {build.stdcpp_lib} -lm -lc -lgcc 55 | 56 | compiler.cpp.cmd=xtensa-lx106-elf-g++ 57 | compiler.cpp.flags=-c {compiler.warning_flags} -Os -g -mlongcalls -mtext-section-literals -fno-rtti -falign-functions=4 -std=c++11 -MMD -ffunction-sections -fdata-sections {build.exception_flags} {build.sslflags} 58 | 59 | compiler.as.cmd=xtensa-lx106-elf-as 60 | 61 | compiler.ar.cmd=xtensa-lx106-elf-ar 62 | compiler.ar.flags=cru 63 | 64 | compiler.elf2hex.cmd=esptool 65 | compiler.elf2hex.flags= 66 | 67 | compiler.size.cmd=xtensa-lx106-elf-size 68 | 69 | # This can be overriden in boards.txt 70 | build.extra_flags=-DESP8266 -DDONT_USE_UPLOADTOBLOB -DUSE_BALTIMORE_CERT 71 | # build.extra_flags=-DESP8266 72 | 73 | # These can be overridden in platform.local.txt 74 | compiler.c.extra_flags=-DDONT_USE_UPLOADTOBLOB -DUSE_BALTIMORE_CERT 75 | compiler.c.elf.extra_flags= 76 | compiler.S.extra_flags= 77 | compiler.cpp.extra_flags=-DDONT_USE_UPLOADTOBLOB -DUSE_BALTIMORE_CERT 78 | compiler.ar.extra_flags= 79 | compiler.objcopy.eep.extra_flags= 80 | compiler.elf2hex.extra_flags= 81 | 82 | ## generate file with git version number 83 | ## needs bash, git, and echo 84 | recipe.hooks.core.prebuild.1.pattern="{runtime.tools.python.path}/python" "{runtime.tools.signing}" --mode header --publickey "{build.source.path}/public.key" --out "{build.path}/core/Updater_Signing.h" 85 | 86 | 87 | ## Build the app.ld linker file 88 | recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -CC -E -P {build.vtable_flags} "{runtime.platform.path}/tools/sdk/ld/eagle.app.v6.common.ld.h" -o "{build.path}/local.eagle.app.v6.common.ld" 89 | 90 | ## Compile c files 91 | recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.c.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 92 | 93 | ## Compile c++ files 94 | recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpreprocessor.flags} {compiler.cpp.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.cpp.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 95 | 96 | ## Compile S files 97 | recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.flags} {compiler.S.flags} -D{build.sdk}=1 -DF_CPU={build.f_cpu} {build.lwip_flags} {build.debug_port} {build.debug_level} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} -DARDUINO_BOARD="{build.board}" {build.led} {build.flash_flags} {compiler.c.extra_flags} {build.extra_flags} {includes} "{source_file}" -o "{object_file}" 98 | 99 | ## Create archives 100 | recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}" 101 | 102 | ## Combine gc-sections, archives, and objects 103 | recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {build.exception_flags} -Wl,-Map "-Wl,{build.path}/{build.project_name}.map" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{archive_file_path}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" 104 | 105 | ## Create eeprom 106 | recipe.objcopy.eep.pattern= 107 | 108 | ## Create hex 109 | recipe.objcopy.hex.1.pattern="{runtime.tools.python.path}/python" "{runtime.tools.elf2bin}" --eboot "{runtime.tools.eboot}" --app "{build.path}/{build.project_name}.elf" --flash_mode {build.flash_mode} --flash_freq {build.flash_freq} --flash_size {build.flash_size} --path "{runtime.tools.xtensa-lx106-elf-gcc.path}/bin" --out "{build.path}/{build.project_name}.bin" 110 | recipe.objcopy.hex.2.pattern="{runtime.tools.python.path}/python" "{runtime.tools.signing}" --mode sign --privatekey "{build.source.path}/private.key" --bin "{build.path}/{build.project_name}.bin" --out "{build.path}/{build.project_name}.bin.signed" 111 | 112 | ## Save hex 113 | recipe.output.tmp_file={build.project_name}.bin 114 | recipe.output.save_file={build.project_name}.{build.variant}.bin 115 | 116 | ## Compute size 117 | recipe.size.pattern="{compiler.path}{compiler.size.cmd}" -A "{build.path}/{build.project_name}.elf" 118 | recipe.size.regex=^(?:\.irom0\.text|\.text|\.text1|\.data|\.rodata|)\s+([0-9]+).* 119 | recipe.size.regex.data=^(?:\.data|\.rodata|\.bss)\s+([0-9]+).* 120 | #recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).* 121 | 122 | # ------------------------------ 123 | 124 | tools.esptool.path= 125 | # Because the variable expansion doesn't allow one tool to find another, the following lines 126 | # will point to "{runtime.platform.path}/tools/python/python" in GIT and 127 | # "{runtime.tools.python.path}/python" for JSON board manager releases. 128 | tools.esptool.cmd={runtime.tools.python.path}/python 129 | tools.esptool.network_cmd={runtime.tools.python.path}/python 130 | 131 | 132 | 133 | tools.esptool.upload.protocol=esp 134 | tools.esptool.upload.params.verbose=--trace 135 | tools.esptool.upload.params.quiet= 136 | 137 | # First, potentially perform an erase or nothing 138 | # Next, do the binary upload 139 | # Combined in one rule because Arduino doesn't suport upload.1.pattern/upload.3.pattern 140 | tools.esptool.upload.pattern="{cmd}" "{runtime.platform.path}/tools/upload.py" --chip esp8266 --port "{serial.port}" --baud 115200 "{upload.verbose}" {upload.erase_cmd} --end --chip esp8266 --port "{serial.port}" --baud 115200 "{upload.verbose}" write_flash 0x0 "{build.path}/{build.project_name}.bin" --end 141 | 142 | tools.esptool.upload.network_pattern="{network_cmd}" "{runtime.platform.path}/tools/espota.py" -i "{serial.port}" -p "{network.port}" "--auth={network.password}" -f "{build.path}/{build.project_name}.bin" 143 | 144 | tools.mkspiffs.cmd=mkspiffs 145 | tools.mkspiffs.cmd.windows=mkspiffs.exe 146 | tools.mkspiffs.path={runtime.tools.mkspiffs.path} 147 | -------------------------------------------------------------------------------- /pal/samples/esp8266/iothub_ll_telemetry_sample/sample_init.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SAMPLE_INIT_H 5 | #define SAMPLE_INIT_H 6 | #if defined(ARDUINO_ARCH_ESP8266) 7 | #define sample_init esp8266_sample_init 8 | #define is_esp_board 9 | void esp8266_sample_init(const char* ssid, const char* password); 10 | #endif // ARDUINO_ARCH_ESP8266 11 | #if defined(ARDUINO_ARCH_ESP32) 12 | #define sample_init esp32_sample_init 13 | #define is_esp_board 14 | void esp32_sample_init(const char* ssid, const char* password); 15 | #endif // ARDUINO_ARCH_ESP32 16 | 17 | #endif // SAMPLE_INIT_H 18 | -------------------------------------------------------------------------------- /pal/src/platform_arduino.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /*Codes_SRS_PLATFORM_ARDUINO_21_001: [ The platform_arduino shall implement the interface provided in the `platfom.h`. ]*/ 5 | #include "azure_c_shared_utility/platform.h" 6 | #include "azure_c_shared_utility/xlogging.h" 7 | #include "azure_c_shared_utility/socketio.h" 8 | #if defined(ARDUINO_ARCH_ESP32) 9 | #include "tlsio_mbedtls.h" 10 | #else 11 | #include "tlsio_arduino.h" 12 | #endif 13 | 14 | /*Codes_SRS_PLATFORM_ARDUINO_21_003: [ The platform_init shall initialize the platform. ]*/ 15 | /*Codes_SRS_PLATFORM_ARDUINO_21_004: [ The platform_init shall allocate any memory needed to control the platform. ]*/ 16 | int platform_init(void) 17 | { 18 | return 0; 19 | } 20 | 21 | /*Codes_SRS_PLATFORM_ARDUINO_21_005: [ The platform_deinit shall deinitialize the platform. ]*/ 22 | /*Codes_SRS_PLATFORM_ARDUINO_21_006: [ The platform_deinit shall free all allocate memory needed to control the platform. ]*/ 23 | void platform_deinit(void) 24 | { 25 | } 26 | 27 | STRING_HANDLE platform_get_platform_info(PLATFORM_INFO_OPTION options) 28 | { 29 | return STRING_construct("(arduino)"); 30 | } 31 | 32 | /*Codes_SRS_PLATFORM_ARDUINO_21_002: [ The platform_arduino shall use the tlsio functions defined by the 'xio.h'.*/ 33 | /*Codes_SRS_PLATFORM_ARDUINO_21_007: [ The platform_get_default_tlsio shall return a set of tlsio functions provided by the Arduino tlsio implementation. ]*/ 34 | const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void) 35 | { 36 | #if defined(ARDUINO_ARCH_ESP32) 37 | return tlsio_mbedtls_get_interface_description(); 38 | #else 39 | return tlsio_arduino_get_interface_description(); 40 | #endif 41 | } 42 | 43 | -------------------------------------------------------------------------------- /pal/src/sslClient_arduino.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include "sslClient_arduino.h" 6 | #include "azure_c_shared_utility/xlogging.h" 7 | 8 | #ifdef ARDUINO_ARCH_ESP8266 9 | #include "ESP8266WiFi.h" 10 | #include "WiFiClientSecureBearSSL.h" 11 | #include "certs/certs.h" 12 | static BearSSL::WiFiClientSecure sslClient; // for ESP8266 13 | static BearSSL::X509List cert(certificates); 14 | #elif ARDUINO_ARCH_ESP32 15 | #include "WiFi.h" 16 | #include "WiFiClientSecure.h" 17 | static WiFiClientSecure sslClient; // for ESP32 18 | #elif WIO_TERMINAL 19 | #include "WiFi.h" 20 | #include "WiFiClientSecure.h" 21 | static WiFiClientSecure sslClient; // for Wio Terminal variant of SAMD 22 | #else 23 | #include "WiFi101.h" 24 | #include "WiFiSSLClient.h" 25 | static WiFiSSLClient sslClient; 26 | #endif 27 | 28 | void sslClient_setTimeout(unsigned long timeout) 29 | { 30 | sslClient.setTimeout(timeout); 31 | } 32 | 33 | uint8_t sslClient_connected(void) 34 | { 35 | return (uint8_t)sslClient.connected(); 36 | } 37 | 38 | int sslClient_connect(const char* name, uint16_t port) 39 | { 40 | #ifdef ARDUINO_ARCH_ESP8266 41 | sslClient.setTrustAnchors(&cert); 42 | #endif 43 | return (int)sslClient.connect(name, port); 44 | } 45 | 46 | void sslClient_stop(void) 47 | { 48 | sslClient.stop(); 49 | } 50 | 51 | size_t sslClient_write(const uint8_t *buf, size_t size) 52 | { 53 | return sslClient.write(buf, size); 54 | } 55 | 56 | size_t sslClient_print(const char* str) 57 | { 58 | return sslClient.print(str); 59 | } 60 | 61 | int sslClient_read(uint8_t *buf, size_t size) 62 | { 63 | return sslClient.read(buf, size); 64 | } 65 | 66 | int sslClient_available(void) 67 | { 68 | return sslClient.available(); 69 | } 70 | 71 | uint8_t sslClient_hostByName(const char* hostName, uint32_t* ipAddress) 72 | { 73 | IPAddress ip; 74 | uint8_t result = WiFi.hostByName(hostName, ip); 75 | (*ipAddress) = (uint32_t)ip; 76 | return result; 77 | } 78 | 79 | -------------------------------------------------------------------------------- /pal/src/threadapi_arduino.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "Arduino.h" 5 | #include "azure_c_shared_utility/xlogging.h" 6 | 7 | /*Codes_SRS_THREADAPI_ARDUINO_21_001: [ The threadapi_arduino shall implement the method sleep defined by the `threadapi.h`. ]*/ 8 | #include "azure_c_shared_utility/threadapi.h" 9 | 10 | /*Codes_SRS_THREADAPI_ARDUINO_21_002: [ The ThreadAPI_Sleep shall receive a time in milliseconds. ]*/ 11 | /*Codes_SRS_THREADAPI_ARDUINO_21_003: [ The ThreadAPI_Sleep shall stop the thread for the specified time. ]*/ 12 | void ThreadAPI_Sleep(unsigned int milliseconds) 13 | { 14 | delay(milliseconds); 15 | } 16 | 17 | /*Codes_SRS_THREADAPI_ARDUINO_21_004: [ The Arduino do not support ThreadAPI_Create, it shall return THREADAPI_ERROR. ]*/ 18 | THREADAPI_RESULT ThreadAPI_Create(THREAD_HANDLE* threadHandle, THREAD_START_FUNC func, void* arg) 19 | { 20 | LogError("Arduino do not support multi-thread function."); 21 | return THREADAPI_ERROR; 22 | } 23 | 24 | /*Codes_SRS_THREADAPI_ARDUINO_21_005: [ The Arduino do not support ThreadAPI_Join, it shall return THREADAPI_ERROR. ]*/ 25 | THREADAPI_RESULT ThreadAPI_Join(THREAD_HANDLE threadHandle, int* res) 26 | { 27 | LogError("Arduino do not support multi-thread function."); 28 | return THREADAPI_ERROR; 29 | } 30 | 31 | /*Codes_SRS_THREADAPI_ARDUINO_21_006: [ The Arduino do not support ThreadAPI_Exit, it shall not do anything. ]*/ 32 | void ThreadAPI_Exit(int res) 33 | { 34 | LogError("Arduino do not support multi-thread function."); 35 | } 36 | -------------------------------------------------------------------------------- /pal/src/xlogging_dump_bytes.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "azure_c_shared_utility/xlogging.h" 5 | #include "azure_c_shared_utility/consolelogger.h" 6 | 7 | 8 | /* Print up to 16 bytes per line. */ 9 | #define LINE_SIZE 16 10 | 11 | /* Return the printable char for the provided value. */ 12 | #define PRINTABLE(c) ((c >= ' ') && (c <= '~')) ? (char)c : '.' 13 | 14 | /* Convert the lower nibble of the provided byte to a hexadecimal printable char. */ 15 | #define HEX_STR(c) (((c) & 0xF) < 0xA) ? (char)(((c) & 0xF) + '0') : (char)(((c) & 0xF) - 0xA + 'A') 16 | 17 | void xlogging_dump_bytes(const void* buf, size_t size) 18 | { 19 | char charBuf[LINE_SIZE + 1]; 20 | char hexBuf[LINE_SIZE * 3 + 1]; 21 | size_t countbuf = 0; 22 | const unsigned char* bufAsChar = (const unsigned char*)buf; 23 | const unsigned char* startPos = bufAsChar; 24 | LOG(AZ_LOG_TRACE, 0, "Buffer length=%d\r\n", size); 25 | 26 | /* Print the whole buffer. */ 27 | size_t i = 0; 28 | for (i = 0; i < size; i++) 29 | { 30 | /* Store the printable value of the char in the charBuf to print. */ 31 | charBuf[countbuf] = PRINTABLE(*bufAsChar); 32 | 33 | /* Convert the high nibble to a printable hexadecimal value. */ 34 | hexBuf[countbuf * 3] = HEX_STR(*bufAsChar >> 4); 35 | 36 | /* Convert the low nibble to a printable hexadecimal value. */ 37 | hexBuf[countbuf * 3 + 1] = HEX_STR(*bufAsChar); 38 | 39 | hexBuf[countbuf * 3 + 2] = ' '; 40 | 41 | countbuf++; 42 | bufAsChar++; 43 | /* If the line is full, print it to start another one. */ 44 | if (countbuf == LINE_SIZE) 45 | { 46 | charBuf[countbuf] = '\0'; 47 | hexBuf[countbuf * 3] = '\0'; 48 | LOG(AZ_LOG_TRACE, 0, "%p: %s %s\r\n", startPos, hexBuf, charBuf); 49 | countbuf = 0; 50 | startPos = bufAsChar; 51 | } 52 | } 53 | 54 | /* If the last line does not fit the line size. */ 55 | if (countbuf > 0) 56 | { 57 | /* Close the charBuf string. */ 58 | charBuf[countbuf] = '\0'; 59 | 60 | /* Fill the hexBuf with spaces to keep the charBuf alignment. */ 61 | while ((countbuf++) < LINE_SIZE - 1) 62 | { 63 | hexBuf[countbuf * 3] = ' '; 64 | hexBuf[countbuf * 3 + 1] = ' '; 65 | hexBuf[countbuf * 3 + 2] = ' '; 66 | } 67 | hexBuf[countbuf * 3] = '\0'; 68 | 69 | /* Print the last line. */ 70 | LOG(AZ_LOG_TRACE, 0, "%p: %s %s\r\n", startPos, hexBuf, charBuf); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sdk_tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #this is CMakeLists.txt for the folder tests of C shared utility 5 | set(SHARED_UTIL_REAL_TEST_FOLDER ${CMAKE_CURRENT_LIST_DIR}/real_test_files CACHE INTERNAL "this is what needs to be included when doing test sources" FORCE) 6 | message(STATUS "including external unit test directory " ${CMAKE_CURRENT_LIST_DIR}) 7 | if(NOT DEFINED MACOSX) 8 | add_subdirectory(tlsioarduino_ut) 9 | add_subdirectory(platformarduino_ut) 10 | endif() 11 | -------------------------------------------------------------------------------- /sdk_tests/platformarduino_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #this is CMakeLists.txt for platform_arduino_ut 5 | cmake_minimum_required(VERSION 2.8.11) 6 | 7 | compileAsC11() 8 | set(theseTestsName platformarduino_ut) 9 | 10 | set(${theseTestsName}_test_files 11 | ${theseTestsName}.c 12 | ) 13 | 14 | set(${theseTestsName}_c_files 15 | ${SHARED_UTIL_SRC_FOLDER}/strings.c 16 | ${EXTERNAL_PAL_REPO_DIR}/pal/src/platform_arduino.c 17 | ) 18 | 19 | include_directories(${EXTERNAL_PAL_REPO_DIR}/pal/inc) 20 | 21 | set(${theseTestsName}_h_files 22 | ) 23 | 24 | build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") 25 | -------------------------------------------------------------------------------- /sdk_tests/platformarduino_ut/main.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "testrunnerswitcher.h" 5 | 6 | int main(void) 7 | { 8 | size_t failedTestCount = 0; 9 | RUN_TEST_SUITE(platformarduino_ut, failedTestCount); 10 | return failedTestCount; 11 | } 12 | -------------------------------------------------------------------------------- /sdk_tests/platformarduino_ut/platformarduino_ut.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifdef __cplusplus 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | static void* my_gballoc_malloc(size_t size) 11 | { 12 | return malloc(size); 13 | } 14 | 15 | static void my_gballoc_free(void* s) 16 | { 17 | free(s); 18 | } 19 | 20 | #ifdef __cplusplus 21 | #include 22 | #else 23 | #include 24 | #endif 25 | 26 | #include "testrunnerswitcher.h" 27 | #include "umock_c.h" 28 | #include "azure_c_shared_utility/macro_utils.h" 29 | #include "umocktypes_charptr.h" 30 | #include "azure_c_shared_utility/xio.h" 31 | #include "azure_c_shared_utility/platform.h" 32 | 33 | #define ENABLE_MOCKS 34 | #include "azure_c_shared_utility/gballoc.h" 35 | #include "tlsio_arduino.h" 36 | 37 | DEFINE_ENUM_STRINGS(UMOCK_C_ERROR_CODE, UMOCK_C_ERROR_CODE_VALUES) 38 | 39 | static void on_umock_c_error(UMOCK_C_ERROR_CODE error_code) 40 | { 41 | char temp_str[256]; 42 | (void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code)); 43 | ASSERT_FAIL(temp_str); 44 | } 45 | 46 | static IO_INTERFACE_DESCRIPTION* my_tlsio_arduino_get_interface_description_return = NULL; 47 | const IO_INTERFACE_DESCRIPTION* my_tlsio_arduino_get_interface_description(void) 48 | { 49 | return my_tlsio_arduino_get_interface_description_return; 50 | } 51 | 52 | static TEST_MUTEX_HANDLE g_testByTest; 53 | static TEST_MUTEX_HANDLE g_dllByDll; 54 | 55 | BEGIN_TEST_SUITE(platformarduino_ut) 56 | 57 | TEST_SUITE_INITIALIZE(a) 58 | { 59 | int result; 60 | 61 | TEST_INITIALIZE_MEMORY_DEBUG(g_dllByDll); 62 | g_testByTest = TEST_MUTEX_CREATE(); 63 | ASSERT_IS_NOT_NULL(g_testByTest); 64 | 65 | (void)umock_c_init(on_umock_c_error); 66 | 67 | result = umocktypes_charptr_register_types(); 68 | ASSERT_ARE_EQUAL(int, 0, result); 69 | 70 | REGISTER_UMOCK_ALIAS_TYPE(IO_INTERFACE_DESCRIPTION, void*); 71 | 72 | REGISTER_GLOBAL_MOCK_HOOK(tlsio_arduino_get_interface_description, my_tlsio_arduino_get_interface_description); 73 | REGISTER_GLOBAL_MOCK_HOOK(gballoc_malloc, my_gballoc_malloc); 74 | REGISTER_GLOBAL_MOCK_HOOK(gballoc_free, my_gballoc_free); 75 | } 76 | 77 | TEST_SUITE_CLEANUP(TestClassCleanup) 78 | { 79 | umock_c_deinit(); 80 | 81 | TEST_MUTEX_DESTROY(g_testByTest); 82 | TEST_DEINITIALIZE_MEMORY_DEBUG(g_dllByDll); 83 | } 84 | 85 | TEST_FUNCTION_INITIALIZE(initialize) 86 | { 87 | umock_c_reset_all_calls(); 88 | } 89 | 90 | TEST_FUNCTION_CLEANUP(cleans) 91 | { 92 | 93 | } 94 | 95 | /*Tests_SRS_PLATFORM_ARDUINO_21_001: [ The platform_arduino shall implement the interface provided in the `platfom.h`. ]*/ 96 | /*Tests_SRS_PLATFORM_ARDUINO_21_003: [ The platform_init shall initialize the platform. ]*/ 97 | /*Tests_SRS_PLATFORM_ARDUINO_21_004: [ The platform_init shall allocate any memory needed to control the platform. ]*/ 98 | TEST_FUNCTION(platform_init__succeed) 99 | { 100 | ///arrange 101 | 102 | ///act 103 | int result = platform_init(); 104 | 105 | ///assert 106 | ASSERT_ARE_EQUAL(int, 0, result); 107 | 108 | ///cleanup 109 | platform_deinit(); 110 | } 111 | 112 | /*Tests_SRS_PLATFORM_ARDUINO_21_005: [ The platform_deinit shall deinitialize the platform. ]*/ 113 | /*Tests_SRS_PLATFORM_ARDUINO_21_006: [ The platform_deinit shall free all allocate memory needed to control the platform. ]*/ 114 | TEST_FUNCTION(platform_deinit__succeed) 115 | { 116 | ///arrange 117 | (void)platform_init(); 118 | 119 | ///act 120 | platform_deinit(); 121 | 122 | ///assert 123 | ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); 124 | 125 | ///cleanup 126 | } 127 | 128 | /*Tests_SRS_PLATFORM_ARDUINO_21_002: [ The platform_arduino shall use the tlsio functions defined by the 'xio.h'.*/ 129 | /*Tests_SRS_PLATFORM_ARDUINO_21_007: [ The platform_get_default_tlsio shall return a set of tlsio functions provided by the Arduino tlsio implementation. ]*/ 130 | TEST_FUNCTION(platform_get_default_tlsio__valid_ptr_succeed) 131 | { 132 | ///arrange 133 | const IO_INTERFACE_DESCRIPTION* result; 134 | my_tlsio_arduino_get_interface_description_return = (IO_INTERFACE_DESCRIPTION*)malloc(sizeof(IO_INTERFACE_DESCRIPTION)); 135 | 136 | umock_c_reset_all_calls(); 137 | 138 | STRICT_EXPECTED_CALL(tlsio_arduino_get_interface_description()); 139 | 140 | (void)platform_init(); 141 | 142 | ///act 143 | result = platform_get_default_tlsio(); 144 | 145 | ///assert 146 | ASSERT_ARE_EQUAL(void_ptr, (void*)my_tlsio_arduino_get_interface_description_return, result); 147 | ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); 148 | 149 | ///cleanup 150 | platform_deinit(); 151 | free(my_tlsio_arduino_get_interface_description_return); 152 | my_tlsio_arduino_get_interface_description_return = NULL; 153 | } 154 | 155 | /*Tests_SRS_PLATFORM_ARDUINO_21_007: [ The platform_get_default_tlsio shall return a set of tlsio functions provided by the Arduino tlsio implementation. ]*/ 156 | TEST_FUNCTION(platform_get_default_tlsio__NULL_failed) 157 | { 158 | ///arrange 159 | const IO_INTERFACE_DESCRIPTION* result; 160 | my_tlsio_arduino_get_interface_description_return = NULL; 161 | 162 | STRICT_EXPECTED_CALL(tlsio_arduino_get_interface_description()); 163 | 164 | (void)platform_init(); 165 | 166 | ///act 167 | result = platform_get_default_tlsio(); 168 | 169 | ///assert 170 | ASSERT_IS_NULL(result); 171 | ASSERT_ARE_EQUAL(char_ptr, umock_c_get_expected_calls(), umock_c_get_actual_calls()); 172 | 173 | ///cleanup 174 | platform_deinit(); 175 | } 176 | 177 | END_TEST_SUITE(platformarduino_ut) 178 | -------------------------------------------------------------------------------- /sdk_tests/tlsioarduino_ut/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #Copyright (c) Microsoft. All rights reserved. 2 | #Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #this is CMakeLists.txt for tlsio_arduino_ut 5 | cmake_minimum_required(VERSION 2.8.11) 6 | 7 | compileAsC11() 8 | set(theseTestsName tlsioarduino_ut) 9 | 10 | set(${theseTestsName}_test_files 11 | ${theseTestsName}.c 12 | ) 13 | 14 | set(${theseTestsName}_c_files 15 | ${SHARED_UTIL_PAL_FOLDER}/tlsio_options.c 16 | ${SHARED_UTIL_SRC_FOLDER}/crt_abstractions.c 17 | ${SHARED_UTIL_SRC_FOLDER}/vector.c 18 | ${SHARED_UTIL_SRC_FOLDER}/optionhandler.c 19 | ${EXTERNAL_PAL_REPO_DIR}/pal/src/tlsio_arduino.c 20 | ) 21 | 22 | include_directories(${EXTERNAL_PAL_REPO_DIR}/pal/inc) 23 | 24 | set(${theseTestsName}_h_files 25 | ) 26 | 27 | build_c_test_artifacts(${theseTestsName} ON "tests/azure_c_shared_utility_tests") 28 | -------------------------------------------------------------------------------- /sdk_tests/tlsioarduino_ut/main.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "testrunnerswitcher.h" 5 | 6 | int main(void) 7 | { 8 | size_t failedTestCount = 0; 9 | RUN_TEST_SUITE(tlsioarduino_ut, failedTestCount); 10 | return failedTestCount; 11 | } 12 | --------------------------------------------------------------------------------