├── DISCLAIMER.md ├── LICENSE.md ├── Readme.md ├── SConscript ├── SConstruct ├── SVR-OCF1.3-Server.json ├── advanced.md ├── install.sh ├── install2.0.sh ├── install_DeviceBuilder.sh ├── install_IOTivity.sh ├── install_IOTivity2.0.sh ├── install_MRAA.sh ├── pi-boards ├── examplecode │ ├── readme.md │ ├── server_automationphat.cpp │ ├── server_envirophat.cpp │ └── server_example.cpp ├── input-AutomationPhat.json ├── input-EnviroPhat.json └── readme.md ├── svr2cbor.sh └── update_repos.sh /DISCLAIMER.md: -------------------------------------------------------------------------------- 1 | THIS SOFTWARE IS PROVIDED BY THE OPEN CONNECTIVITY FOUNDATION, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR WARRANTIES OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE OPEN CONNECTIVITY FOUNDATION, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Open Connectivity Foundation 2 | 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | 16 | ``` 17 | ------------------------------------------------------------------------- 18 | Apache License 19 | Version 2.0, January 2004 20 | http://www.apache.org/licenses/ 21 | 22 | 23 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 24 | 25 | 1. Definitions. 26 | 27 | "License" shall mean the terms and conditions for use, reproduction, 28 | and distribution as defined by Sections 1 through 9 of this document. 29 | 30 | "Licensor" shall mean the copyright owner or entity authorized by 31 | the copyright owner that is granting the License. 32 | 33 | "Legal Entity" shall mean the union of the acting entity and all 34 | other entities that control, are controlled by, or are under common 35 | control with that entity. For the purposes of this definition, 36 | "control" means (i) the power, direct or indirect, to cause the 37 | direction or management of such entity, whether by contract or 38 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 39 | outstanding shares, or (iii) beneficial ownership of such entity. 40 | 41 | "You" (or "Your") shall mean an individual or Legal Entity 42 | exercising permissions granted by this License. 43 | 44 | "Source" form shall mean the preferred form for making modifications, 45 | including but not limited to software source code, documentation 46 | source, and configuration files. 47 | 48 | "Object" form shall mean any form resulting from mechanical 49 | transformation or translation of a Source form, including but 50 | not limited to compiled object code, generated documentation, 51 | and conversions to other media types. 52 | 53 | "Work" shall mean the work of authorship, whether in Source or 54 | Object form, made available under the License, as indicated by a 55 | copyright notice that is included in or attached to the work 56 | (an example is provided in the Appendix below). 57 | 58 | "Derivative Works" shall mean any work, whether in Source or Object 59 | form, that is based on (or derived from) the Work and for which the 60 | editorial revisions, annotations, elaborations, or other modifications 61 | represent, as a whole, an original work of authorship. For the purposes 62 | of this License, Derivative Works shall not include works that remain 63 | separable from, or merely link (or bind by name) to the interfaces of, 64 | the Work and Derivative Works thereof. 65 | 66 | "Contribution" shall mean any work of authorship, including 67 | the original version of the Work and any modifications or additions 68 | to that Work or Derivative Works thereof, that is intentionally 69 | submitted to Licensor for inclusion in the Work by the copyright owner 70 | or by an individual or Legal Entity authorized to submit on behalf of 71 | the copyright owner. For the purposes of this definition, "submitted" 72 | means any form of electronic, verbal, or written communication sent 73 | to the Licensor or its representatives, including but not limited to 74 | communication on electronic mailing lists, source code control systems, 75 | and issue tracking systems that are managed by, or on behalf of, the 76 | Licensor for the purpose of discussing and improving the Work, but 77 | excluding communication that is conspicuously marked or otherwise 78 | designated in writing by the copyright owner as "Not a Contribution." 79 | 80 | "Contributor" shall mean Licensor and any individual or Legal Entity 81 | on behalf of whom a Contribution has been received by Licensor and 82 | subsequently incorporated within the Work. 83 | 84 | 2. Grant of Copyright License. Subject to the terms and conditions of 85 | this License, each Contributor hereby grants to You a perpetual, 86 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 87 | copyright license to reproduce, prepare Derivative Works of, 88 | publicly display, publicly perform, sublicense, and distribute the 89 | Work and such Derivative Works in Source or Object form. 90 | 91 | 3. Grant of Patent License. Subject to the terms and conditions of 92 | this License, each Contributor hereby grants to You a perpetual, 93 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 94 | (except as stated in this section) patent license to make, have made, 95 | use, offer to sell, sell, import, and otherwise transfer the Work, 96 | where such license applies only to those patent claims licensable 97 | by such Contributor that are necessarily infringed by their 98 | Contribution(s) alone or by combination of their Contribution(s) 99 | with the Work to which such Contribution(s) was submitted. If You 100 | institute patent litigation against any entity (including a 101 | cross-claim or counterclaim in a lawsuit) alleging that the Work 102 | or a Contribution incorporated within the Work constitutes direct 103 | or contributory patent infringement, then any patent licenses 104 | granted to You under this License for that Work shall terminate 105 | as of the date such litigation is filed. 106 | 107 | 4. Redistribution. You may reproduce and distribute copies of the 108 | Work or Derivative Works thereof in any medium, with or without 109 | modifications, and in Source or Object form, provided that You 110 | meet the following conditions: 111 | 112 | (a) You must give any other recipients of the Work or 113 | Derivative Works a copy of this License; and 114 | 115 | (b) You must cause any modified files to carry prominent notices 116 | stating that You changed the files; and 117 | 118 | (c) You must retain, in the Source form of any Derivative Works 119 | that You distribute, all copyright, patent, trademark, and 120 | attribution notices from the Source form of the Work, 121 | excluding those notices that do not pertain to any part of 122 | the Derivative Works; and 123 | 124 | (d) If the Work includes a "NOTICE" text file as part of its 125 | distribution, then any Derivative Works that You distribute must 126 | include a readable copy of the attribution notices contained 127 | within such NOTICE file, excluding those notices that do not 128 | pertain to any part of the Derivative Works, in at least one 129 | of the following places: within a NOTICE text file distributed 130 | as part of the Derivative Works; within the Source form or 131 | documentation, if provided along with the Derivative Works; or, 132 | within a display generated by the Derivative Works, if and 133 | wherever such third-party notices normally appear. The contents 134 | of the NOTICE file are for informational purposes only and 135 | do not modify the License. You may add Your own attribution 136 | notices within Derivative Works that You distribute, alongside 137 | or as an addendum to the NOTICE text from the Work, provided 138 | that such additional attribution notices cannot be construed 139 | as modifying the License. 140 | 141 | You may add Your own copyright statement to Your modifications and 142 | may provide additional or different license terms and conditions 143 | for use, reproduction, or distribution of Your modifications, or 144 | for any such Derivative Works as a whole, provided Your use, 145 | reproduction, and distribution of the Work otherwise complies with 146 | the conditions stated in this License. 147 | 148 | 5. Submission of Contributions. Unless You explicitly state otherwise, 149 | any Contribution intentionally submitted for inclusion in the Work 150 | by You to the Licensor shall be under the terms and conditions of 151 | this License, without any additional terms or conditions. 152 | Notwithstanding the above, nothing herein shall supersede or modify 153 | the terms of any separate license agreement you may have executed 154 | with Licensor regarding such Contributions. 155 | 156 | 6. Trademarks. This License does not grant permission to use the trade 157 | names, trademarks, service marks, or product names of the Licensor, 158 | except as required for reasonable and customary use in describing the 159 | origin of the Work and reproducing the content of the NOTICE file. 160 | 161 | 7. Disclaimer of Warranty. Unless required by applicable law or 162 | agreed to in writing, Licensor provides the Work (and each 163 | Contributor provides its Contributions) on an "AS IS" BASIS, 164 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 165 | implied, including, without limitation, any warranties or conditions 166 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 167 | PARTICULAR PURPOSE. You are solely responsible for determining the 168 | appropriateness of using or redistributing the Work and assume any 169 | risks associated with Your exercise of permissions under this License. 170 | 171 | 8. Limitation of Liability. In no event and under no legal theory, 172 | whether in tort (including negligence), contract, or otherwise, 173 | unless required by applicable law (such as deliberate and grossly 174 | negligent acts) or agreed to in writing, shall any Contributor be 175 | liable to You for damages, including any direct, indirect, special, 176 | incidental, or consequential damages of any character arising as a 177 | result of this License or out of the use or inability to use the 178 | Work (including but not limited to damages for loss of goodwill, 179 | work stoppage, computer failure or malfunction, or any and all 180 | other commercial damages or losses), even if such Contributor 181 | has been advised of the possibility of such damages. 182 | 183 | 9. Accepting Warranty or Additional Liability. While redistributing 184 | the Work or Derivative Works thereof, You may choose to offer, 185 | and charge a fee for, acceptance of support, warranty, indemnity, 186 | or other liability obligations and/or rights consistent with this 187 | License. However, in accepting such obligations, You may act only 188 | on Your own behalf and on Your sole responsibility, not on behalf 189 | of any other Contributor, and only if You agree to indemnify, 190 | defend, and hold each Contributor harmless for any liability 191 | incurred by, or claims asserted against, such Contributor by reason 192 | of your accepting any such warranty or additional liability. 193 | 194 | END OF TERMS AND CONDITIONS 195 | ``` 196 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # IoTivity Classic setup 2 | 3 | This repo contains bash scripts to setup a build enviroment to use DeviceBuilder with IoTivity Classic. 4 | The scripts setup the next repos (from git) in the folders: 5 | - IoTivity Classic (IOTivity 1.3.1 or 2.0.0) 6 | - DeviceBuilder (latest version) 7 | - mraa (MRAA library to interact with HW) 8 | 9 | All repos are being set up 1 level above the folder of IOTivity-setup folder. 10 | 11 | Running the curl command below installs the development environment with IOTivity 1.3.1: 12 | 13 | ```curl https://openconnectivity.github.io/IOTivity-setup/install.sh | bash``` 14 | 15 | Running the curl command below installs the development environment with IOTivity 2.0.0: 16 | 17 | ```curl https://openconnectivity.github.io/IOTivity-setup/install2.0.sh | bash``` 18 | 19 | 20 | for manual installation instructions see: 21 | https://github.com/openconnectivity/IOTivity-setup/blob/master/advanced.md 22 | 23 | # Folder structure 24 | 25 | Folder structure after everything is installed: 26 | 27 | ~/iot 28 | |-- core core resource definitions (in swagger) 29 | |-- DeviceBuilder The device builder tool chain 30 | |-- device_output The output of device builder. 31 | | | 32 | | |-- code The generated code. 33 | | | the files will be copied to folder iotivity/examples/OCFDeviceBuilder 34 | | |- server.cpp 35 | | |- server_security.dat SVR data 36 | | |- server_introspection.dat introspection device data 37 | | 38 | |-- iotivity IOTivity source code 39 | | | 40 | | |-- examples 41 | | | | 42 | | | |- OCFDeviceBuilder The folder with the project to build. 43 | | | |- server.cpp file that is being build and edited. 44 | | | 45 | | |-- out 46 | | |-- linux ARCH=x86_64:Ubuntu, ARCH=armv71:pi 47 | | |-- /release/examples/OCFDeviceBuilder executable folder 48 | | |- server executable 49 | | |- server_security.dat SVR data 50 | | |- server_introspection.dat introspection device data 51 | | 52 | |-- IOTDataModels oneIOTa resource definitions (in swagger) 53 | |-- mraa MRAA library to talk to HW attached to the pi boards 54 | |-- IOTivity-setup This repo. 55 | |-- iotivity-tool Tool to convert the SVR json in to cbor (and visa versa) 56 | |-- mraa MRAA library to talk to HW attached to the pi boards 57 | |-- swagger2x swagger2x code generation 58 | |- gen.sh generation command to convert the example.json in to code 59 | |- build.sh building the generated code 60 | |- run.sh run the generated code 61 | |- reset.sh reset the device to ready for onboarding state. 62 | |- edit_code.sh edits the iotivity/examples/OCFDeviceBuilder/server.cpp file with nano. 63 | |- edit_input.sh edits the input file for device builder with nano. 64 | |- example.json the input for device builder. 65 | 66 | 67 | legenda: folder 68 | |-- folder 69 | |-- folder/subfolder 70 | |- file 71 | 72 | 73 | 74 | The installDeviceBuilder script generates scripts in the folder above this repo. 75 | These scripts are convienent scripts, e.g. they are short cuts for entering generation, build, excute and reset commands. 76 | 77 | 78 | referenced information: 79 | 80 | | repo | description | location | 81 | | ----- | ----- | -------| 82 | | DeviceBuilder | tool chain | https://github.com/openconnectivityfoundation/DeviceBuilder | 83 | | swagger2x | code generation | https://github.com/openconnectivityfoundation/swagger2x | 84 | | iotivity-tool | cbor conversion for IOTivity Security | https://github.com/alshafi/iotivity-tool.git | 85 | | IoTivity Classic | C++ code (v1.3.1 or v2.0.0) | https://iotivity.org/ https://github.com/iotivity/iotivity | 86 | | MRAA | code library, communication abstracting hardware | https://github.com/intel-iot-devkit/mraa.git | 87 | | IOTdataModels | oneIOTa data models https://oneiota.org |https://github.com/openconnectivityfoundation/IoTDataModels | 88 | | core | OCF core data models | https://github.com/openconnectivityfoundation/core | 89 | 90 | 91 | 92 | # development flow 93 | 94 | The development flow is depicted the figure below: 95 | 96 | start 97 | | 98 | v 99 | -------------- 100 | | | 101 | | edit_input.sh| --- edit the input file for the code generation 102 | | | default file contains the binary switch resource 103 | -------------- 104 | | 105 | | 106 | v 107 | -------------- 108 | | | 109 | | gen.sh | --- generates the code & introspection file 110 | | | --- script contains the device type, 111 | -------------- change the argument to change the device type. 112 | | 113 | | initial code --- in iotivity classic tree, to build 114 | v --- introspection/security files 115 | -------------- in the iotivity executable folder 116 | | | 117 | | edit_code.sh |<-------- --- edit the generated code 118 | | | | 119 | -------------- | 120 | | | 121 | | edited code | 122 | v | 123 | -------------- | 124 | | | build | 125 | | build.sh |---->----| --- build the executable 126 | | | failed | 127 | -------------- | 128 | | | 129 | | ok | 130 | v | 131 | -------------- | 132 | run | | modify | 133 | --------->| run.sh |---->---- --- onboarding will change the security file 134 | clients | | behaviour in the executable folder 135 | against -------------- to refresh/reset the security file execute reset.sh 136 | application | 137 | v 138 | finished 139 | 140 | Note: if gen.sh is run again, the generated code is overwritten. 141 | e.g. before running that tool again, safe the file in the iotivivty tree to another name 142 | if one wants to keep that code as reference 143 | 144 | 145 | ### OCF clients 146 | information about the clients for development support can be found at: 147 | 148 | https://github.com/openconnectivityfoundation/development-support 149 | 150 | ## edit_input.sh 151 | This scripts edits the device builder input file with nano. 152 | 153 | ### Nano 154 | Nano is supplied on various linux systems like ubuntu and pi. 155 | The file being edited is the file in IoTivity classic tree. 156 | so please make sure when generating a new version, that a changed file is saved under a different name. 157 | 158 | nano beginners guide: 159 | 160 | https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/ 161 | 162 | ### input file 163 | Device Builder input file information can be found at: 164 | https://github.com/openconnectivityfoundation/DeviceBuilder/tree/master/DeviceBuilderInputFormat-file-examples 165 | 166 | ## gen.sh 167 | This script runs the DeviceBuilder with the arguments: 168 | - ~IOT/example.json as input file 169 | - light device as device type 170 | 171 | when the device type needs to change from oic.d.light to something else 172 | the next mechanisms are available to change the device type: 173 | - change the server code from oic.d.light to the specific value 174 | - search for oic.d.light in the server code, and change the value. 175 | - no need to re-generate the server code 176 | - can be done when one is already changing the server code. 177 | - change the gen.sh file e.g. replace oic.d.light to something 178 | - to see the changes the code needs to be re-generated by running gen.sh 179 | - can be done when no code has been changed yet. 180 | 181 | 182 | Running this script generates the device_output folder AND copies the result to the correct executable folder in the IoTivity classic tree structure. 183 | 184 | copied to the executable folder from the device: 185 | - server.cpp to simpleserver.cpp in the examples/OCFDeviceBuilder folder 186 | - introspection file (in CBOR format) to the out/linux/$ARCH/release/examples/OCFDeviceBuilder directory 187 | - security file (in CBOR format) to the out/linux/$ARCH/release/examples/OCFDeviceBuilder directory 188 | - The original JSON file is using "just works" onboarding 189 | 190 | ## edit_code.sh 191 | This scripts edits the code with nano. 192 | The file being edited is the file in IoTivity classic tree. 193 | so please make sure when generating a new version, that a changed file is saved under a different name. 194 | 195 | 196 | ## build.sh 197 | This script builds the examples/OCFDeviceBuilder by means of scons. 198 | e.g. run in the IoTivity classic folder the ```scons examples/OCFDeviceBuilder``` command 199 | 200 | ## run.sh 201 | This script executes the executable in the folder where the executable resides in. 202 | 203 | linux executes in folder: 204 | 205 | ./iotivity/out/linux/x86_64/release/examples/OCFDeviceBuilder 206 | 207 | pi executes in folder: 208 | 209 | ./iotivity/out/linux/armv7l/release/examples/OCFDeviceBuilder 210 | 211 | note that the executable needs to be started in folder where it recides to avoid issues with reading the security and introspection files. 212 | 213 | 214 | # reset.sh 215 | This script overwrites the SVR settings in the security file from the device_output folder to the 216 | out/linux/$ARCH/release/examples/OCFDeviceBuilder folder. 217 | 218 | Note execute this command only when the device is not running. 219 | The device will go to the ready for onboarding state. 220 | 221 | 222 | 223 | # advanced usage 224 | 225 | see https://github.com/openconnectivity/IOTivity-setup/blob/master/advanced.md 226 | 227 | # Device Builder OCF developer kit info 228 | 229 | https://github.com/openconnectivity/IOTivity-setup/tree/master/pi-boards 230 | -------------------------------------------------------------------------------- /SConscript: -------------------------------------------------------------------------------- 1 | # /****************************************************************** 2 | # * 3 | # * 4 | # * 5 | # * 6 | # * Licensed under the Apache License, Version 2.0 (the "License"); 7 | # * you may not use this file except in compliance with the License. 8 | # * You may obtain a copy of the License at 9 | # * 10 | # * http://www.apache.org/licenses/LICENSE-2.0 11 | # * 12 | # * Unless required by applicable law or agreed to in writing, software 13 | # * distributed under the License is distributed on an "AS IS" BASIS, 14 | # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # * See the License for the specific language governing permissions and 16 | # * limitations under the License. 17 | # * 18 | # ***************************************************************** 19 | # \author Rami Alshafi 20 | # */ 21 | 22 | Import('env') 23 | import os 24 | import os.path 25 | import platform as p 26 | target_os = env.get('TARGET_OS') 27 | target_arch = env.get('TARGET_ARCH') 28 | samples_env = env.Clone() 29 | src_dir = env.get('SRC_DIR') 30 | build_dir = env.get('BUILD_DIR') 31 | 32 | ###################################################################### 33 | # Build flags 34 | ###################################################################### 35 | samples_env.PrependUnique(CPPPATH=[ 36 | '#/resource/include', 37 | '#/resource/csdk/include', 38 | '#/resource/csdk/stack/include', 39 | '#/resource/csdk/stack/include/internal', 40 | '#/resource/csdk/security/include', 41 | '#/resource/csdk/connectivity/api', 42 | '#/resource/csdk/logger/include', 43 | '#/resource/oc_logger/include' 44 | 45 | ]) 46 | cpp_defines = ['__WITH_DTLS__', 'TB_LOG'] 47 | libraries = ['octbstack'] 48 | libraries.append('oc') 49 | #libraries.append('log') 50 | 51 | platform_info = p.platform() 52 | joule = 'Linux' in platform_info and 'joule' in platform_info and \ 53 | 'Ubuntu' in platform_info 54 | raspberry_pi = 'Linux' in platform_info and \ 55 | ('armv7l' in platform_info or 'armv6l' in platform_info) and \ 56 | 'debian' in platform_info 57 | if joule or raspberry_pi: 58 | conf = Configure(env) 59 | if not conf.CheckCXXHeader('mraa.hpp'): 60 | print("required library mraa not installed! ") 61 | if joule and not raspberry_pi: 62 | print(" To install mraa\n\ 63 | $sudo add-apt-repository ppa:mraa/mraa\n\ 64 | $sudo apt-get update\n\ 65 | $sudo apt-get install libmraa1 libmraa-dev\ 66 | mraa-tools python-mraa python3-mraa\n") 67 | elif not joule and raspberry_pi: 68 | print("to install mraa\n\ 69 | $git clone https://github.com/intel-iot-devkit/\ 70 | mraa.git ../mraa\n\ 71 | $mkdir ../mraa/build && cd ../mraa/build && cmake .. && make\n\ 72 | $sudo make install") 73 | else: 74 | print("please install mraa") 75 | else: 76 | cpp_defines.append('MRAA') 77 | libraries.append('mraa') 78 | if joule and not raspberry_pi: 79 | cpp_defines.append('JOULE') 80 | elif not joule and raspberry_pi: 81 | cpp_defines.append('RASPBERRY') 82 | else: 83 | print "ERROR: unknown board" 84 | conf.Finish() 85 | samples_env.AppendUnique(RPATH=[build_dir]) 86 | samples_env.AppendUnique(CPPDEFINES=cpp_defines) 87 | samples_env.AppendUnique(CFLAGS=['-std=c99']) 88 | samples_env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-Wextra', '-Werror', 89 | '-pthread', '-fpermissive']) 90 | samples_env.PrependUnique(LIBS=libraries) 91 | if target_arch in ['x86_64', 'arm64']: 92 | samples_env.AppendUnique(CPPFLAGS=['-Llib64']) 93 | else: 94 | samples_env.AppendUnique(CPPFLAGS=['-Llib']) 95 | if env.get('SECURED') == '1': 96 | samples_env.AppendUnique(LIBS=['mbedtls', 'mbedx509', 'mbedcrypto']) 97 | if target_os in ['linux']: 98 | samples_env.ParseConfig('pkg-config --cflags --libs sqlite3') 99 | 100 | ###################################################################### 101 | # Source files and Targets 102 | ###################################################################### 103 | #client = samples_env.Program('client', ['client.c']) 104 | server = samples_env.Program('server', ['server.cpp']) 105 | examples_dir = '/examples/OCFDeviceBuilder/' 106 | #client_dat = samples_env.Install( 107 | # build_dir + examples_dir, src_dir + examples_dir + 'ocf_svr_db_client.dat') 108 | #client_dev = samples_env.Install( 109 | # build_dir + examples_dir, src_dir + examples_dir + 'device_properties.dat') 110 | #server_dat = samples_env.Install( 111 | # build_dir + examples_dir, src_dir + examples_dir + 'ocf_svr_db_server.dat') 112 | 113 | #list_of_samples = [client, client_dat, client_dev, server, server_dat] 114 | list_of_samples = [server] 115 | 116 | Alias("OCFDeviceBuilder", list_of_samples) 117 | 118 | env.AppendTarget('OCFDeviceBuilder') 119 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | #****************************************************************** 2 | # 3 | # 4 | #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 19 | 20 | ## 21 | # The main build script 22 | # 23 | ## 24 | import os 25 | 26 | # Load common build config 27 | SConscript('build_common/SConscript') 28 | 29 | # The construction environment named 'env' is set up in build_common 30 | # and should be imported by all other scripts which need access to it. 31 | # Scripts which do not need to modify the global construction environment 32 | # should Clone() this environment and modify the clone. 33 | # Scripts which need to modify the global environment should not 34 | # work on a clone, since those changes will not propagate. 35 | # Normally global changes should be limited to build_common and 36 | # the extlibs scripts. 37 | Import('env') 38 | 39 | if os.environ.get('TERM') is not None: 40 | env['ENV']['TERM'] = os.environ['TERM'] 41 | 42 | # Load extra options 43 | SConscript('extra_options.scons') 44 | 45 | target_os = env.get('TARGET_OS') 46 | if target_os == 'arduino': 47 | SConscript('arduino.scons') 48 | 49 | # By default, src_dir is the current dir, build_dir is: 50 | # ./out//// 51 | # 52 | # The build_dir is a Variant directory of the source directory. 53 | # iotivity variant directories are set up with argument "duplicate=0", 54 | # which means build_dir files will behave like soft links to src_dir files. 55 | # For more reading on this: 56 | # http://www.scons.org/doc/production/HTML/scons-user.html#f-VariantDir 57 | # 58 | # Any way, to make the output is in build_dir, when load scripts, the path should 59 | # be relevant to build_dir. 60 | build_dir = env.get('BUILD_DIR') 61 | 62 | # Build 'resource' sub-project 63 | SConscript(build_dir + 'resource/SConscript') 64 | 65 | if target_os not in ['arduino','darwin','ios', 'android', 'msys_nt', 'windows']: 66 | SConscript(build_dir + 'examples/OICMiddle/SConscript') 67 | if env.get('SECURED') == '1': 68 | SConscript(build_dir + 'examples/OCFSecure/SConscript') 69 | SConscript(build_dir + 'examples/OCFDeviceBuilder/SConscript') 70 | 71 | java_build = None 72 | if (env.get('BUILD_JAVA') and env.get('JAVA_HOME')) or target_os == 'android': 73 | java_build = SConscript(build_dir + 'java/SConscript') 74 | 75 | # Build 'service' sub-project 76 | service_build = SConscript(build_dir + 'service/SConscript') 77 | 78 | if java_build: 79 | Depends(service_build, java_build) 80 | 81 | # Build other sub-projects 82 | SConscript(dirs=[ 83 | build_dir + 'cloud', 84 | build_dir + 'plugins', 85 | build_dir + 'bridging', 86 | ]) 87 | 88 | # Append target information to the help information (if needed) 89 | # To see help info, execute: 90 | # $ scons [options] -h 91 | # Note some help is option-dependent, e.g. java-related options are 92 | # not added to the help unless BUILD_JAVA is seen 93 | # 94 | # This is not really needed unless requesting help, consider adding check: 95 | #if env.GetOption('help'): 96 | env.PrintTargets() 97 | 98 | # Print bin upload command line (arduino only) 99 | if target_os == 'arduino': 100 | env.UploadHelp() 101 | 102 | # to install the generated pc file into custom prefix location 103 | env.UserInstallTargetPCFile('iotivity.pc', 'iotivity.pc') 104 | -------------------------------------------------------------------------------- /SVR-OCF1.3-Server.json: -------------------------------------------------------------------------------- 1 | { 2 | "acl": { 3 | "aclist2": [ 4 | { 5 | "aceid": 1, 6 | "subject": { "conntype": "anon-clear" }, 7 | "resources": [ 8 | { "href": "/oic/res" }, 9 | { "href": "/oic/d" }, 10 | { "href": "/oic/p" } 11 | ], 12 | "permission": 2 13 | }, 14 | { 15 | "aceid": 2, 16 | "subject": { "conntype": "auth-crypt" }, 17 | "resources": [ 18 | { "href": "/oic/res" }, 19 | { "href": "/oic/d" }, 20 | { "href": "/oic/p" } 21 | ], 22 | "permission": 2 23 | }, 24 | { 25 | "aceid": 3, 26 | "subject": { "conntype": "anon-clear" }, 27 | "resources": [ 28 | { "href": "/oic/sec/doxm" } 29 | ], 30 | "permission": 6 31 | }, 32 | { 33 | "aceid": 4, 34 | "subject": { "conntype": "auth-crypt" }, 35 | "resources": [ 36 | { "href": "/oic/sec/doxm" } 37 | ], 38 | "permission": 6 39 | } 40 | ], 41 | "rowneruuid": "00000000-0000-0000-0000-000000000000", 42 | "rt": ["oic.r.acl2"], 43 | "if": ["oic.if.baseline"] 44 | }, 45 | "pstat": { 46 | "dos": { "s": 1, "p": false }, 47 | "isop": false, 48 | "cm": 2, 49 | "tm": 0, 50 | "om": 4, 51 | "sm": 4, 52 | "rowneruuid": "00000000-0000-0000-0000-000000000000", 53 | "rt": ["oic.r.pstat"], 54 | "if": ["oic.if.baseline"] 55 | }, 56 | "doxm": { 57 | "oxms": [0], 58 | "oxmsel": 0, 59 | "sct": 1, 60 | "owned": false, 61 | "deviceuuid": "12345678-1234-1234-1234-123456789012", 62 | "devowneruuid": "00000000-0000-0000-0000-000000000000", 63 | "rowneruuid": "00000000-0000-0000-0000-000000000000", 64 | "rt": ["oic.r.doxm"], 65 | "if": ["oic.if.baseline"] 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /advanced.md: -------------------------------------------------------------------------------- 1 | # Advanced usage 2 | Scripts that are intended for usage after initial setup or more info of the internals. 3 | 4 | 5 | ## manual installation (not using curl) 6 | 7 | 8 | Typical folder layout to start from (e.g. create the iot folder in the home folder) 9 | 10 | 11 | ~/iot 12 | 13 | 14 | clone in this folder: 15 | 16 | ```git clone https://github.com/openconnectivity/IOTivity-setup.git``` 17 | 18 | This command will give the next folder structure : 19 | 20 | ~/iot 21 | |-IOTivity-setup 22 | 23 | From the IOTivity-setup folder run the scripts (in order): 24 | - install_IOTivity.sh (1.3.1) or install_IOTivity2.0.sh (2.0.0) 25 | - install_DeviceBuilder.sh 26 | - install_MRAA.sh 27 | 28 | e.g. exectute in the ~/IOT/IOTivity-setup folder: sh install_<>.sh 29 | 30 | 31 | 32 | # update_repos.sh 33 | The update_repos.sh script updates the: 34 | - tooling repos 35 | - datamodels repos 36 | 37 | The script does NOT update the code repos: 38 | - iotivity 39 | - mraa 40 | The code repo iotivity is pulled at start up with a specific version. 41 | To get a fresh copy, delete the folder and rerun the install_IOTivity.sh script. 42 | 43 | # security 44 | svr2cbor.sh 45 | 46 | This script is run once during setup by install_DeviceBuilder.sh. 47 | It converts the SVR-OCF1.3-Server.json security json file into cbor. 48 | This file contains the default settings for the SVRs for an OCF1.3 device. 49 | 50 | When running the script the result (server_security.dat) will be placed in ../device_output/code. 51 | The script can also be used to convert the ../device_output/code/server_security.dat file back to json. 52 | When converting the dat back to json the result will be placed ../device_output/code/server_security.dat.json (appending .json). 53 | This is done to avoid overwriting the default SVR settings. 54 | 55 | 56 | Note that one has to edit the SVR-OCF1.3-Server.json to get a different file installed. 57 | 58 | The commands to do the conversions: (to be excuted in the IOTivity-setup folder) 59 | 60 | to convert SVR-OCF1.3-Server.json to cbor: ```sh svr2cbor.sh tocbor``` 61 | 62 | to convert ../device_output/code/security.dat to json: ```sh svr2cbor.sh tojson``` 63 | 64 | 65 | action per script 66 | 67 | 68 | | script | source | action | destination | 69 | | ------- | ----- | -------| ----| 70 | | install_DeviceBuilder.sh | IOTivity-setup/SVR-OCF1.3-Server.json | NA (convert disabled) | ../device_output/code/server_security.dat | 71 | | install_DeviceBuilder.sh | ../iotivity/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat | copy | ../device_output/code/server_security.dat | 72 | | install_DeviceBuilder.sh | ../device_output/code/server_security.dat | copy | ../device_output/code/server_security.dat | 73 | | gen.sh | ../device_output/code/server_security.dat | copy | ../iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_security.dat | 74 | | reset.sh | cbor conversion for IOTivity Security | https://github.com/alshafi/iotivity-tool.git | 75 | | svr2cbor.sh tocbor | IOTivity-setup/SVR-OCF1.3-Server.json | converts | ../device_output/code/server_security.dat | 76 | | svr2cbor.sh tojson | ../device_output/code/server_security.dat | converts | ../device_output/code/server_security.dat.json | 77 | 78 | 79 | 80 | more info about security: 81 | 82 | https://github.com/iotivity/iotivity/blob/master/resource/csdk/security/README-building-and-running-secure-IoTivity-stack.txt 83 | 84 | more about provisioning 85 | 86 | https://github.com/iotivity/iotivity/tree/master/resource/csdk/security/provisioning 87 | 88 | 89 | security sample files: 90 | 91 | https://github.com/iotivity/iotivity/tree/master/resource/csdk/security/provisioning/sample 92 | 93 | 94 | # SConscript and SConstruct 95 | 96 | SConstruct 97 | 98 | Sconstruct is the main build file. 99 | An addition is made to add the example/OCFDeviceBuilder target. 100 | 101 | SConscript 102 | 103 | The scon script to build the (generated) server it the folder: 104 | 105 | ```iotivity/examples/OCFDeviceBuilder``` 106 | 107 | This build script will: 108 | - have all includes to build the C++ server code 109 | - MRAA linkage 110 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x #echo on 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | ############################# 20 | 21 | mkdir iot 22 | cd iot 23 | # system update 24 | sudo apt-get -y update 25 | sudo apt-get -y upgrade 26 | sudo apt-get -y update 27 | # make sure that git is there, because the scripts are using git. 28 | # nano and automake are needed for artik 29 | sudo apt-get -y install git nano automake 30 | 31 | git clone https://github.com/openconnectivity/IOTivity-setup.git 32 | cd IOTivity-setup 33 | sh install_IOTivity.sh 34 | sh install_DeviceBuilder.sh 35 | if [ -d /home/artik ] 36 | then 37 | sudo apt-get install libartik-sdk-dev 38 | else 39 | sh install_MRAA.sh 40 | fi 41 | -------------------------------------------------------------------------------- /install2.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x #echo on 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | ############################# 20 | 21 | mkdir iot 22 | cd iot 23 | # system update 24 | sudo apt-get -y update 25 | sudo apt-get -y upgrade 26 | sudo apt-get -y update 27 | # make sure that git is there, because the scripts are using git. 28 | # nano and automake are needed for artik 29 | sudo apt-get -y install git nano automake 30 | 31 | git clone https://github.com/openconnectivity/IOTivity-setup.git 32 | cd IOTivity-setup 33 | sh install_IOTivity2.0.sh 34 | sh install_DeviceBuilder.sh 35 | sh install_MRAA.sh -------------------------------------------------------------------------------- /install_DeviceBuilder.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x #echo on 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | ############################# 20 | CURPWD=`pwd` 21 | 22 | #path of the code 23 | code_path=OCFDeviceBuilder 24 | 25 | # linux pi 26 | # default 27 | ARCH=`uname -m` 28 | 29 | echo "using architecture: $ARCH" 30 | 31 | cd .. 32 | # clone the repo 33 | git clone https://github.com/openconnectivityfoundation/DeviceBuilder.git 34 | # get the initial example 35 | cp DeviceBuilder/DeviceBuilderInputFormat-file-examples/input-lightdevice.json example.json 36 | 37 | # clone the iotivity cbor conversion tool 38 | git clone https://github.com/alshafi/iotivity-tool.git 39 | # install the python libraries that are needed for iotivity-tool 40 | cd iotivity-tool 41 | pip3 install -U -r requirements.txt 42 | 43 | # create the initial security file and place it in the code directory. 44 | cd $CURPWD 45 | sh svr2cbor.sh tocbor 46 | cd .. 47 | 48 | # create the generation script 49 | echo "#!/bin/bash" > gen.sh 50 | echo "cd DeviceBuilder" >> gen.sh 51 | echo "sh ./DeviceBuilder_C++IotivityServer.sh ../example.json ../device_output \"oic.d.light\"" >> gen.sh 52 | echo "cd .." >> gen.sh 53 | echo "# copying source code to compile location" >> gen.sh 54 | echo "cp ./device_output/code/server.cpp ./iotivity/examples/${code_path}/server.cpp " >> gen.sh 55 | echo "# making executable folder" >> gen.sh 56 | echo "mkdir -p ./iotivity/out/linux/${ARCH}/release/examples/${code_path} >/dev/null 2>&1" >> gen.sh 57 | echo "# copying the introspection file to the executable folder" >> gen.sh 58 | echo "cp ./device_output/code/server_introspection.dat ./iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_introspection.dat" >> gen.sh 59 | echo "# quick fix: using the iotivity supplied oic_svr_db_server_justworks.dat file" >> gen.sh 60 | # working copy line of clarke 61 | # copying the file so that reset.sh works 62 | #cp ~/iot/iotivity/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat ~/iot/device_output/code/server_security.dat 63 | echo "cp ./iotivity/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat ./device_output/code/server_security.dat" 64 | # working copy line from clarke : 65 | # cp ~/IOT/iotivity/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat ~/IOT/iotivity/out/linux/armv7l/release/examples/OCFDeviceBuilder/server_security.dat 66 | echo "cp ./iotivity/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat ./iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_security.dat" >> gen.sh 67 | #echo "cp ./device_output/code/server_security.dat ./iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_security.dat" >> gen.sh 68 | 69 | 70 | # create the build script 71 | echo "#!/bin/bash" > build.sh 72 | echo "cd iotivity" >> build.sh 73 | echo "#uncomment next line for building without security" >> build.sh 74 | echo "#scons examples/${code_path} SECURED=0" >> build.sh 75 | echo "scons examples/${code_path}" >> build.sh 76 | echo "cd .." >> build.sh 77 | 78 | # create the edit code script 79 | echo "#!/bin/bash" > edit_code.sh 80 | echo "nano ./iotivity/examples/${code_path}/server.cpp" >> edit_code.sh 81 | 82 | # create the edit input script 83 | echo "#!/bin/bash" > edit_input.sh 84 | echo "nano ./example.json" >> edit_input.sh 85 | 86 | # create the run script 87 | echo "#!/bin/bash"> run.sh 88 | echo 'CURPWD=`pwd`'>> run.sh 89 | #echo 'CURPWD=$(pwd -P)'>> run.sh 90 | echo "env LD_LIBRARY_PATH=${CURPWD}/mraa/build/src" >> run.sh 91 | echo "sudo ldconfig" >> run.sh 92 | echo "cd ./iotivity/out/linux/${ARCH}/release/examples/${code_path}" >> run.sh 93 | echo "pwd" >> run.sh 94 | echo "ls" >> run.sh 95 | echo "./server" >> run.sh 96 | echo 'cd $CURPWD' >> run.sh 97 | 98 | # create the reset script 99 | echo "#!/bin/bash"> reset.sh 100 | echo "mkdir -p ./iotivity/out/linux/${ARCH}/release/examples/${code_path} >/dev/null 2>&1" >> reset.sh 101 | echo "rm -f ./iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_security.dat" >> reset.sh 102 | echo "#cp ./device_output/code/server_security.dat ./iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_security.dat" >> reset.sh 103 | echo "cp ./iotivity/resource/csdk/security/provisioning/sample/oic_svr_db_server_justworks.dat ./iotivity/out/linux/${ARCH}/release/examples/${code_path}/server_security.dat" >> reset.sh 104 | 105 | 106 | cd $CURPWD 107 | 108 | echo "making the example directory" 109 | mkdir -p ../iotivity/examples/${code_path} 110 | # add the build file 111 | cp ./SConscript ../iotivity/examples/${code_path}/SConscript 112 | # add the build dir 113 | cp ./SConstruct ../iotivity/. 114 | 115 | 116 | 117 | chmod a+x ../*.sh -------------------------------------------------------------------------------- /install_IOTivity.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | ############################# 20 | 21 | curpwd=`pwd` 22 | cd .. 23 | 24 | # step 1 25 | sudo apt-get -y install build-essential git scons libtool \ 26 | autoconf valgrind doxygen wget unzip cmake libboost-dev \ 27 | libboost-program-options-dev libboost-thread-dev uuid-dev \ 28 | libexpat1-dev libglib2.0-dev libsqlite3-dev libcurl4-gnutls-dev 29 | 30 | # step 2 31 | git clone https://gerrit.iotivity.org/gerrit/iotivity 32 | cd iotivity 33 | git checkout 1.3-rel 34 | 35 | # step 3 36 | git clone https://github.com/01org/tinycbor.git \ 37 | extlibs/tinycbor/tinycbor -b v0.4.1 38 | 39 | git clone https://github.com/ARMmbed/mbedtls.git \ 40 | extlibs/mbedtls/mbedtls -b mbedtls-2.4.2 41 | 42 | # step 4 - not needed anymore, since the git pull request is now integraged in 1.3-rel 43 | #git fetch origin refs/changes/13/22513/12 44 | #git checkout FETCH_HEAD 45 | 46 | cd $curpwd -------------------------------------------------------------------------------- /install_IOTivity2.0.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | ############################# 20 | 21 | curpwd=`pwd` 22 | cd .. 23 | 24 | # step 1 25 | sudo apt-get -y install build-essential git scons libtool \ 26 | autoconf valgrind doxygen wget unzip cmake libboost-dev \ 27 | libboost-program-options-dev libboost-thread-dev uuid-dev \ 28 | libexpat1-dev libglib2.0-dev libsqlite3-dev libcurl4-gnutls-dev 29 | 30 | # step 2 31 | git clone https://gerrit.iotivity.org/gerrit/iotivity 32 | cd iotivity 33 | git checkout 2.0.0 34 | 35 | # step 3 36 | git clone https://github.com/01org/tinycbor.git \ 37 | extlibs/tinycbor/tinycbor -b v0.4.1 38 | 39 | git clone https://github.com/ARMmbed/mbedtls.git \ 40 | extlibs/mbedtls/mbedtls -b mbedtls-2.4.2 41 | 42 | cd $curpwd 43 | -------------------------------------------------------------------------------- /install_MRAA.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x #echo on 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | ############################# 20 | CURPWD=`pwd` 21 | cd .. 22 | # step 1 23 | git clone https://github.com/intel-iot-devkit/mraa.git 24 | # step 2 25 | mkdir mraa/build 26 | cd mraa/build 27 | # build 28 | cmake .. && make && sudo make install 29 | 30 | # step 3 31 | #cd ./examples 32 | #sudo ./blink-io 7 33 | #cd $CURPWD -------------------------------------------------------------------------------- /pi-boards/examplecode/readme.md: -------------------------------------------------------------------------------- 1 | # example code 2 | 3 | 4 | ## server_automationphat.cpp 5 | 6 | File created by using: 7 | https://github.com/openconnectivity/IOTivity-setup/blob/master/pi-boards/input-AutomationPhat.json 8 | as input of the tool chain. 9 | 10 | This file has been edited to talk to the AutomationPhat hardware using MRAA 11 | 12 | 13 | ## server_envirophat.cpp 14 | 15 | File created by using: 16 | https://github.com/openconnectivity/IOTivity-setup/blob/master/pi-boards/input-EnviroPhat.json 17 | as input of the tool chain. 18 | 19 | This file has been edited to talk to the EnviroPhat hardware using MRAA. 20 | 21 | 22 | 23 | ## server_example.cpp 24 | 25 | File created by using the initial example file 26 | as input of the tool chain. 27 | 28 | This file has been edited to talk to the hardware using MRAA. 29 | 30 | 31 | -------------------------------------------------------------------------------- /pi-boards/examplecode/server_example.cpp: -------------------------------------------------------------------------------- 1 | //****************************************************************** 2 | // 3 | // Copyright 2017 Open Connectivity Foundation 4 | // 5 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 6 | // 7 | // Licensed under the Apache License, Version 2.0 (the "License"); 8 | // you may not use this file except in compliance with the License. 9 | // You may obtain a copy of the License at 10 | // 11 | // http://www.apache.org/licenses/LICENSE-2.0 12 | // 13 | // Unless required by applicable law or agreed to in writing, software 14 | // distributed under the License is distributed on an "AS IS" BASIS, 15 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | // See the License for the specific language governing permissions and 17 | // limitations under the License. 18 | // 19 | //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef HAVE_WINDOWS_H 28 | #include 29 | #endif 30 | 31 | #ifdef MRAA 32 | #include "mraa.hpp" 33 | #endif 34 | 35 | #include "ocstack.h" 36 | #include "OCPlatform.h" 37 | #include "OCApi.h" 38 | #include "ocpayload.h" 39 | 40 | using namespace OC; 41 | namespace PH = std::placeholders; 42 | 43 | /* 44 | tool_version : 20171123 45 | input_file : ../device_output/out_codegeneration_merged.swagger.json 46 | version of input_file : v1.1.0-20160519 47 | title of input_file : Binary Switch 48 | */ 49 | 50 | #define INTERFACE_KEY "if" 51 | 52 | /* 53 | * default class, so that we have to define less variables/functions. 54 | */ 55 | class Resource 56 | { 57 | protected: 58 | OCResourceHandle m_resourceHandle; 59 | OC::OCRepresentation m_rep; 60 | virtual OCEntityHandlerResult entityHandler(std::shared_ptr request)=0; 61 | }; 62 | 63 | 64 | /* 65 | * class definition for class that handles /binaryswitch 66 | * 67 | * This resource describes a binary switch (on/off). 68 | * The value is a boolean. 69 | * A value of 'true' means that the switch is on. 70 | * A value of 'false' means that the switch is off. 71 | 72 | */ 73 | class BinaryswitchResource : public Resource 74 | { 75 | public: 76 | /* 77 | * constructor 78 | * 79 | * @param resourceUri the uri for this resource 80 | */ 81 | BinaryswitchResource(std::string resourceUri = "/binaryswitch"); 82 | 83 | /* 84 | * destructor 85 | */ 86 | virtual ~BinaryswitchResource(void); 87 | 88 | /* 89 | * Register the resource with the server 90 | * 91 | * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource 92 | * setting resourceProperty as OC_OBSERVABLE will allow observation 93 | * setting resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and observation 94 | * setting resourceProperty as OC_SECURE the resource supports access via secure endpoints 95 | * setting resourceProperty as OC_NONSECURE the resource supports access via non-secure endpoints 96 | * setting resourceProperty as OC_SECURE | OC_NONSECURE will allow access via secure and non-secure endpoints 97 | * 98 | * @param resourceProperty indicates the property of the resource. Defined in octypes.h. 99 | */ 100 | OCStackResult registerResource(uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE); 101 | 102 | /* 103 | * Attempt to send out notifications to observing clients 104 | * if no value on the device has been changed no notification 105 | * will be sent. 106 | * 107 | * @return OC_STACK_OK on success 108 | */ 109 | OCStackResult sendNotification(); 110 | 111 | mraa::Gpio *gpio; 112 | int ledPin = 7; 113 | 114 | private: 115 | 116 | /* 117 | * Make the payload for the retrieve function (e.g. GET) /binaryswitch 118 | * This resource describes a binary switch (on/off). 119 | * The value is a boolean. 120 | * A value of 'true' means that the switch is on. 121 | * A value of 'false' means that the switch is off. 122 | 123 | * @param queries the query parameters for this call 124 | */ 125 | OCRepresentation get(OC::QueryParamsMap queries); 126 | 127 | /* 128 | * Parse the payload for the update function (e.g. POST) /binaryswitch 129 | 130 | * @param queries the query parameters for this call 131 | * @param rep the response to get the property values from 132 | * @return OCEntityHandlerResult ok or not ok indication 133 | */ 134 | OCEntityHandlerResult post(OC::QueryParamsMap queries, const OC::OCRepresentation& rep); 135 | 136 | 137 | std::string m_resourceUri; 138 | // resource types and interfaces as array.. 139 | std::string m_RESOURCE_TYPE[1] = {"oic.r.switch.binary"}; // rt value (as an array) 140 | std::string m_RESOURCE_INTERFACE[2] = {"oic.if.a","oic.if.baseline"}; // interface if (as an array) 141 | std::string m_IF_UPDATE[3] = {"oic.if.a", "oic.if.rw", "oic.if.baseline"}; // updateble interfaces 142 | ObservationIds m_interestedObservers; 143 | 144 | // member variables for path: "/binaryswitch" 145 | std::vector m_var_value_if; // the value for the array attribute "if": The interface set supported by this resource 146 | std::string m_var_name_if = "if"; // the name for the attribute "if" 147 | std::string m_var_value_n; // the value for the attribute "n": Friendly name of the resource 148 | std::string m_var_name_n = "n"; // the name for the attribute "n" 149 | std::vector m_var_value_rt; // the value for the array attribute "rt": Resource Type 150 | std::string m_var_name_rt = "rt"; // the name for the attribute "rt" 151 | bool m_var_value_value; // the value for the attribute "value": Status of the switch 152 | std::string m_var_name_value = "value"; // the name for the attribute "value" 153 | 154 | protected: 155 | /* 156 | * Check if the interface is 157 | * @param interface_name the interface name used during the request 158 | * @return true: updatable interface 159 | */ 160 | bool in_updatable_interfaces(std::string interface_name); 161 | 162 | /* 163 | * the entity handler for this resource 164 | * @param request the incoming request to handle 165 | * @return OCEntityHandlerResult ok or not ok indication 166 | */ 167 | virtual OCEntityHandlerResult entityHandler(std::shared_ptr request); 168 | }; 169 | 170 | /* 171 | * Constructor code 172 | */ 173 | BinaryswitchResource::BinaryswitchResource(std::string resourceUri) 174 | { 175 | std::cout << "- Running: BinaryswitchResource constructor" << std::endl; 176 | 177 | m_resourceUri = resourceUri; 178 | // initialize member variables /binaryswitch 179 | // initialize vector if The interface set supported by this resource 180 | m_var_value_if.push_back("oic.if.a"); 181 | m_var_value_if.push_back("oic.if.baseline"); 182 | m_var_value_n = ""; // current value of property "n" Friendly name of the resource 183 | // initialize vector rt Resource Type 184 | m_var_value_rt.push_back("oic.r.switch.binary"); 185 | m_var_value_value = false; // current value of property "value" Status of the switch 186 | 187 | gpio = new mraa::Gpio(ledPin); 188 | if (!gpio) 189 | { 190 | std::cout << "Error instantiating gpio" << std::endl; 191 | } 192 | gpio->dir(mraa::DIR_OUT); 193 | 194 | gpio->write(1); 195 | sleep(1); 196 | gpio->write(0); 197 | } 198 | 199 | /* 200 | * Destructor code 201 | */ 202 | BinaryswitchResource::~BinaryswitchResource() { } 203 | 204 | OCStackResult BinaryswitchResource::registerResource(uint8_t resourceProperty) 205 | { 206 | OCStackResult result = OC_STACK_ERROR; 207 | EntityHandler cb = std::bind(&BinaryswitchResource::entityHandler, this,PH::_1); 208 | result = OCPlatform::registerResource(m_resourceHandle, 209 | m_resourceUri, 210 | m_RESOURCE_TYPE[0], 211 | m_RESOURCE_INTERFACE[0], 212 | cb, 213 | resourceProperty); 214 | if(OC_STACK_OK != result) 215 | { 216 | std::cerr << "Failed to register BinaryswitchResource." << std::endl; 217 | return result; 218 | } 219 | 220 | /// add the additional resource types 221 | for( unsigned int a = 1; a < (sizeof(m_RESOURCE_TYPE)/sizeof(m_RESOURCE_TYPE[0])); a++ ) 222 | { 223 | result = OCPlatform::bindTypeToResource(m_resourceHandle, m_RESOURCE_TYPE[a].c_str()); 224 | if(OC_STACK_OK != result) 225 | { 226 | std::cerr << "Could not bind resource type:" << m_RESOURCE_INTERFACE[a] << std::endl; 227 | return result; 228 | } 229 | } 230 | // add the additional interfaces 231 | for( unsigned int a = 1; a < (sizeof(m_RESOURCE_INTERFACE)/sizeof(m_RESOURCE_INTERFACE[0])); a++) 232 | { 233 | result = OCPlatform::bindInterfaceToResource(m_resourceHandle, m_RESOURCE_INTERFACE[a].c_str()); 234 | if(OC_STACK_OK != result) 235 | { 236 | std::cerr << "Could not bind interface:" << m_RESOURCE_INTERFACE[a] << std::endl; 237 | return result; 238 | } 239 | } 240 | 241 | std::cout << "BinaryswitchResource:" << std::endl; 242 | std::cout << "\t" << "# resource interfaces: " 243 | << sizeof(m_RESOURCE_INTERFACE)/sizeof(m_RESOURCE_INTERFACE[0]) << std::endl; 244 | std::cout << "\t" << "# resource types : " 245 | << sizeof(m_RESOURCE_TYPE)/sizeof(m_RESOURCE_TYPE[0]) << std::endl; 246 | 247 | return result; 248 | } 249 | 250 | OCStackResult BinaryswitchResource::sendNotification(void) 251 | { 252 | OCStackResult sResult = OC_STACK_OK; 253 | if ( m_interestedObservers.size() > 0) { 254 | std::cout << "Notifying list " << m_interestedObservers.size() << " of observers\n"; 255 | auto pResponse = std::make_shared(); 256 | sResult = OCPlatform::notifyListOfObservers(m_resourceHandle, 257 | m_interestedObservers, 258 | pResponse); 259 | } 260 | return sResult; 261 | } 262 | 263 | /* 264 | * Make the payload for the retrieve function (e.g. GET) /binaryswitch 265 | * @param queries the query parameters for this call 266 | */ 267 | OCRepresentation BinaryswitchResource::get(QueryParamsMap queries) 268 | { 269 | OC_UNUSED(queries); 270 | 271 | // TODO: SENSOR add here the code to talk to the HW if one implements a sensor. 272 | // the calls needs to fill in the member variable before it is returned. 273 | // alternative is to have a callback from the hardware that sets the member variables 274 | 275 | std::cout << "\t\t" << "property 'n' : "<< m_var_value_n << std::endl; 276 | std::cout << "\t\t" << "property 'value' : "<< ((m_var_value_value) ? "true" : "false") << std::endl; 277 | 278 | m_rep.setValue(m_var_name_if, m_var_value_if ); 279 | m_rep.setValue(m_var_name_n, m_var_value_n ); 280 | m_rep.setValue(m_var_name_rt, m_var_value_rt ); 281 | m_rep.setValue(m_var_name_value, m_var_value_value ); 282 | 283 | return m_rep; 284 | } 285 | 286 | /* 287 | * Parse the payload for the update function (e.g. POST) /binaryswitch 288 | * @param queries the query parameters for this call 289 | * @param rep the response to get the property values from 290 | * @return OCEntityHandlerResult ok or not ok indication 291 | */ 292 | OCEntityHandlerResult BinaryswitchResource::post(QueryParamsMap queries, const OCRepresentation& rep) 293 | { 294 | OCEntityHandlerResult ehResult = OC_EH_OK; 295 | OC_UNUSED(queries); 296 | 297 | // TODO: missing code: add check on array contents out of range 298 | // such a check is resource specific 299 | try { 300 | if (rep.hasAttribute(m_var_name_if)) 301 | { 302 | // value exist in payload 303 | 304 | // check if "if" is read only 305 | ehResult = OC_EH_ERROR; 306 | std::cout << "\t\t" << "property 'if' is readOnly "<< std::endl; 307 | 308 | } 309 | } 310 | catch (std::exception& e) 311 | { 312 | std::cout << e.what() << std::endl; 313 | } 314 | 315 | try { 316 | if (rep.hasAttribute(m_var_name_n)) 317 | { 318 | // value exist in payload 319 | 320 | // check if "n" is read only 321 | ehResult = OC_EH_ERROR; 322 | std::cout << "\t\t" << "property 'n' is readOnly "<< std::endl; 323 | 324 | } 325 | } 326 | catch (std::exception& e) 327 | { 328 | std::cout << e.what() << std::endl; 329 | } 330 | 331 | // TODO: missing code: add check on array contents out of range 332 | // such a check is resource specific 333 | try { 334 | if (rep.hasAttribute(m_var_name_rt)) 335 | { 336 | // value exist in payload 337 | 338 | // check if "rt" is read only 339 | ehResult = OC_EH_ERROR; 340 | std::cout << "\t\t" << "property 'rt' is readOnly "<< std::endl; 341 | 342 | } 343 | } 344 | catch (std::exception& e) 345 | { 346 | std::cout << e.what() << std::endl; 347 | } 348 | try { 349 | if (rep.hasAttribute(m_var_name_value)) 350 | { 351 | // value exist in payload 352 | 353 | } 354 | } 355 | catch (std::exception& e) 356 | { 357 | std::cout << e.what() << std::endl; 358 | } 359 | if (ehResult == OC_EH_OK) 360 | { 361 | // no error: assign the variables 362 | // array only works for integer, boolean, numbers and strings 363 | // TODO: missing code, make it also work with array of objects 364 | try { 365 | if (rep.hasAttribute(m_var_name_if)) 366 | { 367 | rep.getValue(m_var_name_if, m_var_value_if); 368 | int first = 1; 369 | std::cout << "\t\t" << "property 'if' UPDATED: " ; 370 | for(auto myvar: m_var_value_if) 371 | { 372 | if(first) 373 | { 374 | std::cout << myvar; 375 | first = 0; 376 | } 377 | else 378 | { 379 | std::cout << "," << myvar; 380 | } 381 | } 382 | std::cout << std::endl; 383 | } 384 | else 385 | { 386 | std::cout << "\t\t" << "property 'if' not found in the representation" << std::endl; 387 | } 388 | } 389 | catch (std::exception& e) 390 | { 391 | std::cout << e.what() << std::endl; 392 | } 393 | try { 394 | // value exist in payload 395 | std::string temp; 396 | if (rep.getValue(m_var_name_n, temp )) 397 | { 398 | m_var_value_n = temp; 399 | std::cout << "\t\t" << "property 'n' UPDATED: " << m_var_value_n << std::endl; 400 | } 401 | else 402 | { 403 | std::cout << "\t\t" << "property 'n' not found in the representation" << std::endl; 404 | } 405 | } 406 | catch (std::exception& e) 407 | { 408 | std::cout << e.what() << std::endl; 409 | }// array only works for integer, boolean, numbers and strings 410 | // TODO: missing code, make it also work with array of objects 411 | try { 412 | if (rep.hasAttribute(m_var_name_rt)) 413 | { 414 | rep.getValue(m_var_name_rt, m_var_value_rt); 415 | int first = 1; 416 | std::cout << "\t\t" << "property 'rt' UPDATED: " ; 417 | for(auto myvar: m_var_value_rt) 418 | { 419 | if(first) 420 | { 421 | std::cout << myvar; 422 | first = 0; 423 | } 424 | else 425 | { 426 | std::cout << "," << myvar; 427 | } 428 | } 429 | std::cout << std::endl; 430 | } 431 | else 432 | { 433 | std::cout << "\t\t" << "property 'rt' not found in the representation" << std::endl; 434 | } 435 | } 436 | catch (std::exception& e) 437 | { 438 | std::cout << e.what() << std::endl; 439 | } 440 | try { 441 | bool temp; 442 | if (rep.getValue(m_var_name_value, temp )) 443 | { 444 | m_var_value_value = temp; 445 | std::cout << "\t\t" << "property 'value' UPDATED: " << ((m_var_value_value) ? "true" : "false") << std::endl; 446 | } 447 | else 448 | { 449 | std::cout << "\t\t" << "property 'value' not found in the representation" << std::endl; 450 | } 451 | } 452 | catch (std::exception& e) 453 | { 454 | std::cout << e.what() << std::endl; 455 | } 456 | // TODO: ACTUATOR add here the code to talk to the HW if one implements an actuator. 457 | // one can use the member variables as input to those calls 458 | // the member values have been updated already with the request data 459 | gpio->write(m_var_value_value); 460 | } 461 | return ehResult; 462 | } 463 | /* 464 | * Check if the interface name is an registered interface name 465 | */ 466 | bool BinaryswitchResource::in_updatable_interfaces(std::string interface_name) 467 | { 468 | for (unsigned int i=0; i < (sizeof(m_IF_UPDATE)/sizeof(m_IF_UPDATE[0])); i++) 469 | { 470 | if (m_IF_UPDATE[i].compare(interface_name) == 0) 471 | return true; 472 | } 473 | return false; 474 | } 475 | 476 | /* 477 | * the entity handler 478 | */ 479 | OCEntityHandlerResult BinaryswitchResource::entityHandler(std::shared_ptr request) 480 | { 481 | OCEntityHandlerResult ehResult = OC_EH_ERROR; 482 | //std::cout << "In entity handler for BinaryswitchResource " << std::endl; 483 | 484 | if(request) 485 | { 486 | std::cout << "In entity handler for BinaryswitchResource, URI is : " 487 | << request->getResourceUri() << std::endl; 488 | 489 | // Check for query params (if any) 490 | QueryParamsMap queries = request->getQueryParameters(); 491 | if (!queries.empty()) 492 | { 493 | std::cout << "\nQuery processing up to entityHandler" << std::endl; 494 | } 495 | for (auto it : queries) 496 | { 497 | std::cout << "Query key: " << it.first << " value : " << it.second 498 | << std::endl; 499 | } 500 | // get the value, so that we can AND it to check which flags are set 501 | int requestFlag = request->getRequestHandlerFlag(); 502 | 503 | if(requestFlag & RequestHandlerFlag::RequestFlag) 504 | { 505 | // request flag is set 506 | auto pResponse = std::make_shared(); 507 | pResponse->setRequestHandle(request->getRequestHandle()); 508 | pResponse->setResourceHandle(request->getResourceHandle()); 509 | 510 | if(request->getRequestType() == "GET") 511 | { 512 | std::cout<<"BinaryswitchResource Get Request"<< std::endl; 513 | 514 | pResponse->setResourceRepresentation(get(queries), ""); 515 | if(OC_STACK_OK == OCPlatform::sendResponse(pResponse)) 516 | { 517 | ehResult = OC_EH_OK; 518 | } 519 | } 520 | 521 | else if(request->getRequestType() == "POST") 522 | { 523 | std::cout <<"BinaryswitchResource Post Request"< 0) 527 | { 528 | for (const auto &eachQuery : queries) 529 | { 530 | std::string key = eachQuery.first; 531 | if (key.compare(INTERFACE_KEY) == 0) 532 | { 533 | std::string value = eachQuery.second; 534 | if (in_updatable_interfaces(value) == false) 535 | { 536 | std::cout << "Update request received via interface: " << value 537 | << " . This interface is not authorized to update resource!!" << std::endl; 538 | pResponse->setResponseResult(OCEntityHandlerResult::OC_EH_FORBIDDEN); 539 | handle_post = false; 540 | ehResult = OC_EH_ERROR; 541 | break; 542 | } 543 | } 544 | } 545 | } 546 | if (handle_post) 547 | { 548 | ehResult = post(queries, request->getResourceRepresentation()); 549 | if (ehResult == OC_EH_OK) 550 | { 551 | pResponse->setResourceRepresentation(get(queries), ""); 552 | if (OC_STACK_OK == OCPlatform::sendResponse(pResponse)) 553 | { 554 | if (OC_STACK_OK != sendNotification() ) 555 | { 556 | std::cerr << "NOTIFY failed." << std::endl; 557 | } 558 | } 559 | } 560 | else 561 | { 562 | pResponse->setResponseResult(OCEntityHandlerResult::OC_EH_ERROR); 563 | } 564 | } 565 | } 566 | else 567 | { 568 | std::cout << "BinaryswitchResource unsupported request type (delete,put,..)" 569 | << request->getRequestType() << std::endl; 570 | pResponse->setResponseResult(OC_EH_ERROR); 571 | OCPlatform::sendResponse(pResponse); 572 | ehResult = OC_EH_ERROR; 573 | } 574 | } 575 | 576 | if(requestFlag & RequestHandlerFlag::ObserverFlag) 577 | { 578 | // observe flag is set 579 | ObservationInfo observationInfo = request->getObservationInfo(); 580 | std::cout << "\t\trequestFlag : observer "; 581 | if (ObserveAction::ObserveRegister == observationInfo.action) 582 | { 583 | std::cout << "register" << std::endl; 584 | } 585 | else 586 | { 587 | std::cout << "unregister" << std::endl; 588 | } 589 | 590 | if(ObserveAction::ObserveRegister == observationInfo.action) 591 | { 592 | // add observer 593 | m_interestedObservers.push_back(observationInfo.obsId); 594 | } 595 | else if(ObserveAction::ObserveUnregister == observationInfo.action) 596 | { 597 | // delete observer 598 | m_interestedObservers.erase(std::remove( 599 | m_interestedObservers.begin(), 600 | m_interestedObservers.end(), 601 | observationInfo.obsId), 602 | m_interestedObservers.end()); 603 | } 604 | ehResult = OC_EH_OK; 605 | } 606 | } 607 | return ehResult; 608 | } 609 | 610 | 611 | 612 | class IoTServer 613 | { 614 | public: 615 | /** 616 | * constructor 617 | * creates all resources from the resource classes. 618 | */ 619 | IoTServer(); 620 | 621 | /** 622 | * destructor 623 | */ 624 | ~IoTServer(); 625 | 626 | /* 627 | * Register the resources with the server 628 | * 629 | * setting resourceProperty as OC_DISCOVERABLE will allow Discovery of this resource 630 | * setting resourceProperty as OC_OBSERVABLE will allow observation 631 | * setting resourceProperty as OC_DISCOVERABLE | OC_OBSERVABLE will allow both discovery and observation 632 | * setting resourceProperty as OC_SECURE the resource supports access via secure endpoints 633 | * setting resourceProperty as OC_NONSECURE the resource supports access via non-secure endpoints 634 | * setting resourceProperty as OC_SECURE | OC_NONSECURE will allow access via secure and non-secure endpoints 635 | * 636 | * @param resourceProperty indicates the property of the resources. Defined in octypes.h. 637 | */ 638 | OCStackResult registerResources(uint8_t resourceProperty = OC_DISCOVERABLE | OC_OBSERVABLE | OC_SECURE); 639 | 640 | private: 641 | BinaryswitchResource m_binaryswitchInstance;}; 642 | 643 | IoTServer::IoTServer() 644 | :m_binaryswitchInstance() 645 | { 646 | std::cout << "Running IoTServer constructor" << std::endl; 647 | } 648 | 649 | IoTServer::~IoTServer() 650 | { 651 | std::cout << "Running IoTServer destructor" << std::endl; 652 | } 653 | 654 | OCStackResult IoTServer::registerResources(uint8_t resourceProperty) 655 | { 656 | OCStackResult result = OC_STACK_ERROR; 657 | result = m_binaryswitchInstance.registerResource(resourceProperty); 658 | if(OC_STACK_OK != result) 659 | { 660 | return result; 661 | }return result; 662 | } 663 | 664 | class Platform 665 | { 666 | public: 667 | /* 668 | * Platform constructor 669 | */ 670 | Platform(void); 671 | 672 | /* 673 | * Platform destructor 674 | */ 675 | virtual ~Platform(); 676 | 677 | /* 678 | * Start the platform 679 | */ 680 | OCStackResult start(); 681 | 682 | /* 683 | * Register all platform info 684 | * This will register the platformId, manufaturerName, manufacturerUrl, 685 | * modelNumber, dateOfManufacture, platformVersion, operatingSystemVersion, 686 | * hardwareVersion, firmwareVersion, supportUrl, and systemTime 687 | */ 688 | OCStackResult registerPlatformInfo(void); 689 | 690 | /* 691 | * Get OCPlatformInfo pointer 692 | */ 693 | OCPlatformInfo* getPlatformInfo(void); 694 | 695 | /* 696 | * Stop the platform 697 | */ 698 | OCStackResult stop(void); 699 | 700 | /* 701 | * SetDeviceInfo 702 | * Sets the device information ("/oic/d") 703 | * 704 | * @return OC_STACK_OK on success OC_STACK_ERROR on failure 705 | */ 706 | OCStackResult setDeviceInfo(void); 707 | 708 | // Set of strings for each of device info fields 709 | std::string deviceName = "Binary Switch"; 710 | std::string deviceType = "oic.d.light"; 711 | std::string specVersion = "ocf.1.0.0"; 712 | std::vector dataModelVersions; 713 | 714 | std::string protocolIndependentID = "fa008167-3bbf-4c9d-8604-c9bcb96cb712"; 715 | 716 | private: 717 | // Set of strings for each of platform Info fields 718 | std::string m_platformId = "0A3E0D6F-DBF5-404E-8719-D6880042463A"; 719 | std::string m_manufacturerName = "ocf"; 720 | std::string m_manufacturerLink = "https://ocf.org/"; 721 | std::string m_modelNumber = "ModelNumber"; 722 | std::string m_dateOfManufacture = "2017-12-01"; 723 | std::string m_platformVersion = "1.0"; 724 | std::string m_operatingSystemVersion = "myOS"; 725 | std::string m_hardwareVersion = "1.0"; 726 | std::string m_firmwareVersion = "1.0"; 727 | std::string m_supportLink = "https://ocf.org/"; 728 | std::string m_systemTime = "2017-12-01T12:00:00.52Z"; 729 | 730 | /* 731 | * duplicateString 732 | * 733 | * @param targetString destination string, will be allocated 734 | * @param sourceString source string, e.g. will be copied 735 | */ 736 | void duplicateString(char ** targetString, std::string sourceString); 737 | 738 | /** 739 | * SetPlatformInfo 740 | * Sets the platform information ("oic/p") 741 | * 742 | * @param platformID the platformID 743 | * @param manufacturerName the manufacturerName 744 | * @param manufacturerUrl the manufacturerUrl 745 | * @param modelNumber the modelNumber 746 | * @param platformVersion the platformVersion 747 | * @param operatingSystemVersion the operatingSystemVersion 748 | * @param hardwareVersion the hardwareVersion 749 | * @param firmwareVersion the firmwareVersion 750 | * @param supportUrl the supportUrl 751 | * @param systemTime the systemTime 752 | * @return OC_STACK_ERROR or OC_STACK_OK 753 | */ 754 | void setPlatformInfo(std::string platformID, 755 | std::string manufacturerName, 756 | std::string manufacturerUrl, 757 | std::string modelNumber, 758 | std::string dateOfManufacture, 759 | std::string platformVersion, 760 | std::string operatingSystemVersion, 761 | std::string hardwareVersion, 762 | std::string firmwareVersion, 763 | std::string supportUrl, 764 | std::string systemTime); 765 | 766 | /* 767 | * deletePlatformInfo 768 | * Deleted the allocated platform information 769 | */ 770 | void deletePlatformInfo(void); 771 | 772 | // OCPlatformInfo Contains all the platform info 773 | OCPlatformInfo platformInfo; 774 | }; 775 | 776 | /** 777 | * server_fopen 778 | * opens file 779 | * implements redirection to open: 780 | * - initial security settings 781 | * - introspection file 782 | * @param path path+filename of the file to open 783 | * @param mode mode of the file to open 784 | * @return the filehandle of the opened file (or error) 785 | */ 786 | FILE* server_fopen(const char* path, const char* mode) 787 | { 788 | FILE* fileptr = NULL; 789 | 790 | if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME)) 791 | { 792 | // reading the security initial setup file 793 | fileptr = fopen("server_security.dat", mode); 794 | std::cout << "reading security file 'server_security.dat' ptr: " << fileptr << std::endl; 795 | return fileptr; 796 | } 797 | else if (0 == strcmp(path, OC_INTROSPECTION_FILE_NAME)) 798 | { 799 | // reading the introspection file 800 | fileptr = fopen("server_introspection.dat", mode); 801 | std::cout << "reading introspection file 'server_introspection.dat' ptr: " << fileptr << std::endl; 802 | return fileptr; 803 | } 804 | else 805 | { 806 | std::cout << "persistent storage - server_fopen: " << path << std::endl; 807 | return fopen(path, mode); 808 | } 809 | } 810 | 811 | // Create persistent storage handlers 812 | OCPersistentStorage ps{server_fopen, fread, fwrite, fclose, unlink}; 813 | 814 | /* 815 | * Platform Constructor 816 | */ 817 | Platform::Platform(void) 818 | { 819 | std::cout << "Running Platform constructor" << std::endl; 820 | dataModelVersions.push_back("ocf.res.1.3.0"); 821 | dataModelVersions.push_back("ocf.sh.1.3.0"); 822 | 823 | // create the platform 824 | PlatformConfig cfg 825 | { 826 | ServiceType::InProc, 827 | ModeType::Server, 828 | &ps 829 | }; 830 | OCPlatform::Configure(cfg); 831 | setPlatformInfo(m_platformId, m_manufacturerName, m_manufacturerLink, 832 | m_modelNumber, m_dateOfManufacture, m_platformVersion, 833 | m_operatingSystemVersion, m_hardwareVersion, 834 | m_firmwareVersion, m_supportLink, m_systemTime); 835 | } 836 | 837 | /* 838 | * Platform Destructor 839 | */ 840 | Platform::~Platform(void) 841 | { 842 | std::cout << "Running Platform destructor" << std::endl; 843 | deletePlatformInfo(); 844 | } 845 | 846 | OCStackResult Platform::start(void) 847 | { 848 | return OCPlatform::start(); 849 | } 850 | 851 | OCStackResult Platform::registerPlatformInfo(void) 852 | { 853 | OCStackResult result = OC_STACK_ERROR; 854 | result = OCPlatform::registerPlatformInfo(platformInfo); 855 | return result; 856 | } 857 | 858 | OCPlatformInfo* Platform::getPlatformInfo(void) 859 | { 860 | return &platformInfo; 861 | } 862 | 863 | OCStackResult Platform::stop(void) 864 | { 865 | return OCPlatform::stop(); 866 | } 867 | 868 | void Platform::duplicateString(char ** targetString, std::string sourceString) 869 | { 870 | *targetString = new char[sourceString.length() + 1]; 871 | strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1)); 872 | } 873 | 874 | void Platform::setPlatformInfo(std::string platformID, 875 | std::string manufacturerName, 876 | std::string manufacturerUrl, 877 | std::string modelNumber, 878 | std::string dateOfManufacture, 879 | std::string platformVersion, 880 | std::string operatingSystemVersion, 881 | std::string hardwareVersion, 882 | std::string firmwareVersion, 883 | std::string supportUrl, 884 | std::string systemTime) 885 | { 886 | duplicateString(&platformInfo.platformID, platformID); 887 | duplicateString(&platformInfo.manufacturerName, manufacturerName); 888 | duplicateString(&platformInfo.manufacturerUrl, manufacturerUrl); 889 | duplicateString(&platformInfo.modelNumber, modelNumber); 890 | duplicateString(&platformInfo.dateOfManufacture, dateOfManufacture); 891 | duplicateString(&platformInfo.platformVersion, platformVersion); 892 | duplicateString(&platformInfo.operatingSystemVersion, operatingSystemVersion); 893 | duplicateString(&platformInfo.hardwareVersion, hardwareVersion); 894 | duplicateString(&platformInfo.firmwareVersion, firmwareVersion); 895 | duplicateString(&platformInfo.supportUrl, supportUrl); 896 | duplicateString(&platformInfo.systemTime, systemTime); 897 | } 898 | 899 | void Platform::deletePlatformInfo() 900 | { 901 | delete[] platformInfo.platformID; 902 | delete[] platformInfo.manufacturerName; 903 | delete[] platformInfo.manufacturerUrl; 904 | delete[] platformInfo.modelNumber; 905 | delete[] platformInfo.dateOfManufacture; 906 | delete[] platformInfo.platformVersion; 907 | delete[] platformInfo.operatingSystemVersion; 908 | delete[] platformInfo.hardwareVersion; 909 | delete[] platformInfo.firmwareVersion; 910 | delete[] platformInfo.supportUrl; 911 | delete[] platformInfo.systemTime; 912 | } 913 | 914 | /** 915 | * SetDeviceInfo 916 | * Sets the device information ("oic/d"), from the globals 917 | 918 | * @return OC_STACK_ERROR or OC_STACK_OK 919 | */ 920 | OCStackResult Platform::setDeviceInfo() 921 | { 922 | OCStackResult result = OC_STACK_ERROR; 923 | 924 | OCResourceHandle handle = OCGetResourceHandleAtUri(OC_RSRVD_DEVICE_URI); 925 | if (handle == NULL) 926 | { 927 | std::cout << "Failed to find resource " << OC_RSRVD_DEVICE_URI << std::endl; 928 | return result; 929 | } 930 | result = OCBindResourceTypeToResource(handle, deviceType.c_str()); 931 | if (result != OC_STACK_OK) 932 | { 933 | std::cout << "Failed to add device type" << std::endl; 934 | return result; 935 | } 936 | result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DEVICE_NAME, deviceName); 937 | if (result != OC_STACK_OK) 938 | { 939 | std::cout << "Failed to set device name" << std::endl; 940 | return result; 941 | } 942 | result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_DATA_MODEL_VERSION, 943 | dataModelVersions); 944 | if (result != OC_STACK_OK) 945 | { 946 | std::cout << "Failed to set data model versions" << std::endl; 947 | return result; 948 | } 949 | result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_SPEC_VERSION, specVersion); 950 | if (result != OC_STACK_OK) 951 | { 952 | std::cout << "Failed to set spec version" << std::endl; 953 | return result; 954 | } 955 | result = OCPlatform::setPropertyValue(PAYLOAD_TYPE_DEVICE, OC_RSRVD_PROTOCOL_INDEPENDENT_ID, 956 | protocolIndependentID); 957 | if (result != OC_STACK_OK) 958 | { 959 | std::cout << "Failed to set piid" << std::endl; 960 | return result; 961 | } 962 | 963 | return OC_STACK_OK; 964 | } 965 | 966 | #ifdef __unix__ 967 | // global needs static, otherwise it can be compiled out and then Ctrl-C does not work 968 | static int quit = 0; 969 | // handler for the signal to stop the application 970 | void handle_signal(int signal) 971 | { 972 | OC_UNUSED(signal); 973 | quit = 1; 974 | } 975 | #endif 976 | 977 | // main application 978 | // starts the server 979 | int main(void) 980 | { 981 | Platform platform; 982 | if(OC_STACK_OK != platform.start()) 983 | { 984 | std::cerr << "Failed to start the IoTivity platform." << std::endl; 985 | return 1; 986 | } 987 | 988 | std::cout << "/oic/p" << std::endl; 989 | // initialize "/oic/p" 990 | if (OC_STACK_OK != platform.registerPlatformInfo()) 991 | { 992 | std::cerr << "Failed platform registration (/oic/p)." << std::endl; 993 | } 994 | // initialize "/oic/d" 995 | std::cout << "/oic/d" << std::endl; 996 | if (OC_STACK_OK != platform.setDeviceInfo()) 997 | { 998 | std::cerr << "Failed device registration (/oic/d)." << std::endl; 999 | } 1000 | 1001 | std::cout << "device type: " << platform.deviceType << std::endl; 1002 | std::cout << "platformID: " << platform.getPlatformInfo()->platformID << std::endl; 1003 | std::cout << "platform independent: " << platform.protocolIndependentID << std::endl; 1004 | 1005 | // create the server 1006 | IoTServer server; 1007 | if (OC_STACK_OK != server.registerResources()) 1008 | { 1009 | std::cerr << "Failed to register server resources." << std::endl; 1010 | return 1; 1011 | } 1012 | 1013 | #ifdef __unix__ 1014 | struct sigaction sa; 1015 | sigfillset(&sa.sa_mask); 1016 | sa.sa_flags = 0; 1017 | sa.sa_handler = handle_signal; 1018 | sigaction(SIGINT, &sa, NULL); 1019 | std::cout << "Press Ctrl-C to quit...." << std::endl; 1020 | do 1021 | { 1022 | usleep(2000000); 1023 | } 1024 | while (quit != 1); 1025 | #endif 1026 | 1027 | 1028 | #if defined(_WIN32) 1029 | std::cout << "Press Ctrl-C to quit...." << std::endl; 1030 | // we will keep the server alive for at most 30 minutes 1031 | std::this_thread::sleep_for(std::chrono::minutes(30)); 1032 | OC_VERIFY(OCPlatform::stop() == OC_STACK_OK); 1033 | #endif 1034 | 1035 | return 0; 1036 | } -------------------------------------------------------------------------------- /pi-boards/input-AutomationPhat.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "path" : "/ADC1", 4 | "rt" : [ "oic.r.energy.electrical" ], 5 | "if" : ["oic.if.baseline", "oic.if.s" ], 6 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 7 | "remove_methods" : ["post"] 8 | }, 9 | { 10 | "path" : "/ADC2", 11 | "rt" : [ "oic.r.energy.electrical" ], 12 | "if" : ["oic.if.baseline", "oic.if.s" ], 13 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 14 | "remove_methods" : ["post"] 15 | }, 16 | { 17 | "path" : "/ADC3", 18 | "rt" : [ "oic.r.energy.electrical" ], 19 | "if" : ["oic.if.baseline", "oic.if.s" ], 20 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 21 | "remove_methods" : ["post"] 22 | }, 23 | { 24 | "path" : "/ADC4", 25 | "rt" : [ "oic.r.energy.electrical" ], 26 | "if" : ["oic.if.baseline", "oic.if.s" ], 27 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 28 | "remove_methods" : ["post"] 29 | }, 30 | { 31 | "path" : "/output1", 32 | "rt" : [ "oic.r.switch.binary" ], 33 | "if" : ["oic.if.baseline", "oic.if.a" ], 34 | "remove_properties" : [ "range", "step" , "id", "precision" ] 35 | }, 36 | { 37 | "path" : "/output2", 38 | "rt" : [ "oic.r.switch.binary" ], 39 | "if" : ["oic.if.baseline", "oic.if.a" ], 40 | "remove_properties" : [ "range", "step" , "id", "precision" ] 41 | }, 42 | { 43 | "path" : "/output3", 44 | "rt" : [ "oic.r.switch.binary" ], 45 | "if" : ["oic.if.baseline", "oic.if.a" ], 46 | "remove_properties" : [ "range", "step" , "id", "precision" ] 47 | }, 48 | { 49 | "path" : "/input1", 50 | "rt" : [ "oic.r.switch.binary" ], 51 | "if" : ["oic.if.baseline", "oic.if.a" ], 52 | "remove_properties" : [ "range", "step" , "id", "precision" ], 53 | "remove_methods" : ["post"] 54 | }, 55 | { 56 | "path" : "/input2", 57 | "rt" : [ "oic.r.switch.binary" ], 58 | "if" : ["oic.if.baseline", "oic.if.a" ], 59 | "remove_properties" : [ "range", "step" , "id", "precision" ], 60 | "remove_methods" : ["post"] 61 | }, 62 | { 63 | "path" : "/input3", 64 | "rt" : [ "oic.r.switch.binary" ], 65 | "if" : ["oic.if.baseline", "oic.if.a" ], 66 | "remove_properties" : [ "range", "step" , "id", "precision" ], 67 | "remove_methods" : ["post"] 68 | }, 69 | { 70 | "path" : "/relay1", 71 | "rt" : [ "oic.r.switch.binary" ], 72 | "if" : ["oic.if.baseline", "oic.if.a" ], 73 | "remove_properties" : [ "range", "step" , "id", "precision" ] 74 | }, 75 | { 76 | "path" : "/relay2", 77 | "rt" : [ "oic.r.switch.binary" ], 78 | "if" : ["oic.if.baseline", "oic.if.a" ], 79 | "remove_properties" : [ "range", "step" , "id", "precision" ] 80 | }, 81 | { 82 | "path" : "/relay3", 83 | "rt" : [ "oic.r.switch.binary" ], 84 | "if" : ["oic.if.baseline", "oic.if.a" ], 85 | "remove_properties" : [ "range", "step" , "id", "precision" ] 86 | }, 87 | { 88 | "path" : "/PowerLight", 89 | "rt" : [ "oic.r.switch.binary" ], 90 | "if" : ["oic.if.baseline", "oic.if.a" ], 91 | "remove_properties" : [ "range", "step" , "id", "precision" ] 92 | }, 93 | { 94 | "path" : "/CommsLight", 95 | "rt" : [ "oic.r.switch.binary" ], 96 | "if" : ["oic.if.baseline", "oic.if.a" ], 97 | "remove_properties" : [ "range", "step" , "id", "precision" ] 98 | }, 99 | { 100 | "path" : "/WarnLight", 101 | "rt" : [ "oic.r.switch.binary" ], 102 | "if" : ["oic.if.baseline", "oic.if.a" ], 103 | "remove_properties" : [ "range", "step" , "id", "precision" ] 104 | }, 105 | { 106 | "path" : "/oic/p", 107 | "rt" : [ "oic.wk.p" ], 108 | "if" : ["oic.if.baseline", "oic.if.r" ], 109 | "remove_properties" : [ "n", "range", "value", "step", "precision", "vid" ] 110 | } 111 | ] 112 | -------------------------------------------------------------------------------- /pi-boards/input-EnviroPhat.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "path" : "/binaryswitch", 4 | "rt" : [ "oic.r.switch.binary" ], 5 | "if" : ["oic.if.baseline", "oic.if.a" ], 6 | "remove_properties" : [ "range", "step" , "id", "precision" ] 7 | }, 8 | { 9 | "path" : "/brightness", 10 | "rt" : [ "oic.r.light.brightness" ], 11 | "if" : ["oic.if.baseline", "oic.if.s" ], 12 | "remove_properties" : [ "range", "step" , "id", "precision" ], 13 | "remove_methods" : ["post"] 14 | }, 15 | { 16 | "path" : "/colourRGB", 17 | "rt" : [ "oic.r.colour.rgb" ], 18 | "if" : ["oic.if.baseline", "oic.if.s" ], 19 | "remove_properties" : [ "range", "step" , "id", "precision" ], 20 | "remove_methods" : ["post"] 21 | }, 22 | { 23 | "path" : "/temperature", 24 | "rt" : [ "oic.r.temperature" ], 25 | "if" : ["oic.if.baseline", "oic.if.s" ], 26 | "remove_properties" : [ "range", "value" , "step", "precision" ], 27 | "remove_methods" : ["post"] 28 | }, 29 | { 30 | "path" : "/pressure", 31 | "rt" : [ "oic.r.sensor.atmosphericpressure" ], 32 | "if" : ["oic.if.baseline", "oic.if.s" ], 33 | "remove_properties" : [ "range", "value" , "step", "precision" ], 34 | "remove_methods" : ["post"] 35 | }, 36 | { 37 | "path" : "/xmotion", 38 | "rt" : [ "oic.r.sensor.acceleration" ], 39 | "if" : ["oic.if.baseline", "oic.if.s" ], 40 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 41 | "remove_methods" : ["post"] 42 | }, 43 | { 44 | "path" : "/ymotion", 45 | "rt" : [ "oic.r.sensor.acceleration" ], 46 | "if" : ["oic.if.baseline", "oic.if.s" ], 47 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 48 | "remove_methods" : ["post"] 49 | }, 50 | { 51 | "path" : "/zmotion", 52 | "rt" : [ "oic.r.sensor.acceleration" ], 53 | "if" : ["oic.if.baseline", "oic.if.s" ], 54 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 55 | "remove_methods" : ["post"] 56 | }, 57 | { 58 | "path" : "/heading", 59 | "rt" : [ "oic.r.sensor.magneticfielddirection" ], 60 | "if" : ["oic.if.baseline", "oic.if.s" ], 61 | "remove_properties" : [ "range", "step", "id" , "precision"], 62 | "remove_methods" : ["post"] 63 | }, 64 | { 65 | "path" : "/voltage0", 66 | "rt" : [ "oic.r.energy.electrical" ], 67 | "if" : ["oic.if.baseline", "oic.if.s" ], 68 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 69 | "remove_methods" : ["post"] 70 | }, 71 | { 72 | "path" : "/voltage1", 73 | "rt" : [ "oic.r.energy.electrical" ], 74 | "if" : ["oic.if.baseline", "oic.if.s" ], 75 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 76 | "remove_methods" : ["post"] 77 | }, 78 | { 79 | "path" : "/voltage2", 80 | "rt" : [ "oic.r.energy.electrical" ], 81 | "if" : ["oic.if.baseline", "oic.if.s" ], 82 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 83 | "remove_methods" : ["post"] 84 | }, 85 | { 86 | "path" : "/voltage3", 87 | "rt" : [ "oic.r.energy.electrical" ], 88 | "if" : ["oic.if.baseline", "oic.if.s" ], 89 | "remove_properties" : [ "range", "step", "value" , "id" , "precision"], 90 | "remove_methods" : ["post"] 91 | }, 92 | { 93 | "path" : "/oic/p", 94 | "rt" : [ "oic.wk.p" ], 95 | "if" : ["oic.if.baseline", "oic.if.r" ], 96 | "remove_properties" : [ "n", "range", "value", "step", "precision", "vid" ] 97 | } 98 | ] 99 | -------------------------------------------------------------------------------- /pi-boards/readme.md: -------------------------------------------------------------------------------- 1 | # developer-kit 2 | 3 | 4 | see also: https://openconnectivity.org/developer-kit 5 | 6 | 7 | ## automation phat board 8 | 9 | 10 | The file input-AutomationPhat.json is the DeviceBuilder input file for the 11 | the automation phat board. 12 | 13 | https://github.com/openconnectivity/IOTivity-setup/blob/master/pi-boards/input-AutomationPhat.json 14 | 15 | Description (from the website): 16 | 17 | We've pulled together a great set of features into this home monitoring and automation controller. 18 | With a relay, analog channels, powered outputs, and buffered inputs (all 24V tolerant) you can now hook up a plethora of goodies to your Raspberry Pi all at once. 19 | 20 | https://shop.pimoroni.com/products/automation-phat 21 | 22 | 23 | | path | rt | sensor/actuator | resource | 24 | | ----- | ----- | -------| -------| 25 | | /ADC1 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 26 | | /ADC2 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 27 | | /ADC3 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 28 | | /ADC4 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 29 | | /output1 | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 30 | | /output2 | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 31 | | /output3 | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 32 | | /input1 | "oic.r.switch.binary" | sensor | https://oneiota.org/revisions/1393 | 33 | | /input2 | "oic.r.switch.binary" | sensor | https://oneiota.org/revisions/1393 | 34 | | /input3 | "oic.r.switch.binary" | sensor | https://oneiota.org/revisions/1393 | 35 | | /relay | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 36 | | /PowerLight | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 37 | | /CommsLight | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 38 | | /WarnLight | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 39 | 40 | 41 | note that the implementation needs to make the connection from the resource to the actual hardware. 42 | 43 | To install the python libraries: 44 | 45 | curl https://get.pimoroni.com/automationhat | bash 46 | 47 | ## enviro phat board 48 | 49 | The file input-EnviroPhat.json is the DeviceBuilder input file for the 50 | the enviro-phat board. 51 | 52 | https://github.com/openconnectivity/IOTivity-setup/blob/master/pi-boards/input-EnviroPhat.json 53 | 54 | Description (from the website): 55 | 56 | Enviro pHAT packs 4 different sensors, letting you measure temperature, pressure, light level, colour, 3-axis motion, compass heading, and analog inputs. 57 | 58 | https://shop.pimoroni.com/products/enviro-phat 59 | 60 | 61 | | path | rt | sensor/actuator | resource | 62 | | ----- | ----- | -------| -------| 63 | | /binaryswitch | "oic.r.switch.binary" | actuator | https://oneiota.org/revisions/1393 | 64 | | /brightness | "oic.r.light.brightness" | sensor | https://oneiota.org/revisions/1393 | 65 | | /colourRGB | "oic.r.colour.rgb" | sensor | https://oneiota.org/revisions/1797 | 66 | | /temperature | "oic.r.temperature" | sensor | https://oneiota.org/revisions/2991 | 67 | | /pressure | "oic.r.sensor.atmosphericpressure" | sensor | https://oneiota.org/revisions/1387 | 68 | | /xmotion | "oic.r.sensor.acceleration" | sensor | https://oneiota.org/revisions/1381 | 69 | | /ymotion | "oic.r.sensor.acceleration" | sensor | https://oneiota.org/revisions/1381 | 70 | | /zmotion | "oic.r.sensor.acceleration" | sensor | https://oneiota.org/revisions/1381 | 71 | | /heading | "oic.r.sensor.magneticfielddirection" | sensor | https://oneiota.org/revisions/2041 | 72 | | /voltage0 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 73 | | /voltage1 | "oic.r.energy.electrical" |sensor | https://oneiota.org/revisions/2732 | 74 | | /voltage2 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 75 | | /voltage3 | "oic.r.energy.electrical" | sensor | https://oneiota.org/revisions/2732 | 76 | 77 | note that the implementation needs to make the connection from the resource to the actual hardware. 78 | 79 | To install the python libraries: 80 | 81 | curl https://get.pimoroni.com/envirophat | bash 82 | 83 | ## code examples 84 | some code examples can be found at: 85 | 86 | https://github.com/openconnectivity/IOTivity-setup/tree/master/pi-boards/examplecode 87 | -------------------------------------------------------------------------------- /svr2cbor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x #echo on 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 1. Redistributions of source code must retain the above copyright notice, 9 | # this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation and/or other materials provided 12 | # with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE OPEN CONNECTIVITY FOUNDATION, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 15 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR 16 | # WARRANTIES OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE OPEN INTERCONNECT CONSORTIUM, INC. OR 17 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 19 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 20 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 21 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | # 23 | ############################# 24 | 25 | a=$1 26 | b="tocbor" 27 | c="tojson" 28 | 29 | echo "1=$a " 30 | # supplied tocbor on the command line, overwrite the ../device_output/code/server_security.dat file 31 | if [ "$a" = "$b" ]; then 32 | mkdir -p ../device_output/code >/dev/null 2>&1 33 | python3 ../iotivity-tool/cborjsoncon.py -i SVR-OCF1.3-Server.json -o ../device_output/code/server_security.dat 34 | fi 35 | 36 | if [ "$a" = "$c" ]; then 37 | python3 ../iotivity-tool/cborjsoncon.py -i ../device_output/code/server_security.dat -o ../device_output/code/server_security.dat.json 38 | fi 39 | -------------------------------------------------------------------------------- /update_repos.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -x #echo on 3 | ############################# 4 | # 5 | # copyright 2018 Open Connectivity Foundation, Inc. All rights reserved. 6 | # Redistribution and use in source and binary forms, with or without modification, 7 | # are permitted provided that the following conditions are met: 8 | # 1. Redistributions of source code must retain the above copyright notice, 9 | # this list of conditions and the following disclaimer. 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation and/or other materials provided 12 | # with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE OPEN CONNECTIVITY FOUNDATION, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 15 | # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE OR 16 | # WARRANTIES OF NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE OPEN INTERCONNECT CONSORTIUM, INC. OR 17 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 19 | # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 20 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 21 | # EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 22 | # 23 | ############################# 24 | CURPWD=`pwd` 25 | 26 | # 27 | # tools 28 | # 29 | cd ../DeviceBuilder 30 | # clone the repo 31 | git pull 32 | cd $CURPWD 33 | 34 | cd ../swagger2x 35 | # clone the repo 36 | git pull 37 | cd $CURPWD 38 | 39 | cd ../iotivity-tool 40 | # clone the repo 41 | git pull 42 | cd $CURPWD 43 | 44 | # 45 | # Data models 46 | # 47 | 48 | cd ../core 49 | # clone the repo 50 | git pull 51 | cd $CURPWD 52 | 53 | cd ../IoTDataModels 54 | # clone the repo 55 | git pull 56 | cd $CURPWD 57 | 58 | --------------------------------------------------------------------------------