| |
| |
| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| |
| |
| |
| |
| <title>Adding OIC Sensor Support to the bleprph_oic Application — Apache Mynewt latest documentation</title> |
| |
| |
| |
| |
| <link rel="shortcut icon" href="../../_static/mynewt-logo-only-newt32x32.png"/> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> |
| |
| |
| <link rel="stylesheet" href="../../_static/css/sphinx_theme.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../_static/css/bootstrap-3.0.3.min.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../_static/css/v2.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../_static/css/custom.css" type="text/css" /> |
| |
| <link rel="stylesheet" href="../../_static/css/restructuredtext.css" type="text/css" /> |
| |
| |
| |
| |
| <link rel="stylesheet" href="../../_static/css/overrides.css" type="text/css" /> |
| <link rel="index" title="Index" |
| href="../../genindex.html"/> |
| <link rel="search" title="Search" href="../../search.html"/> |
| <link rel="top" title="Apache Mynewt latest documentation" href="../../index.html"/> |
| <link rel="up" title="Enabling OIC Sensor Data Monitoring" href="sensor_oic_overview.html"/> |
| <link rel="next" title="Air Quality Sensor Project" href="air_quality.html"/> |
| <link rel="prev" title="Enabling OIC Sensor Data Monitoring in the sensors_test Application" href="sensor_nrf52_bno055_oic.html"/> |
| |
| |
| <script src="../../_static/js/modernizr.min.js"></script> |
| |
| |
| <script> |
| (function(i, s, o, g, r, a, m) { |
| i["GoogleAnalyticsObject"] = r; |
| (i[r] = |
| i[r] || |
| function() { |
| (i[r].q = i[r].q || []).push(arguments); |
| }), |
| (i[r].l = 1 * new Date()); |
| (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]); |
| a.async = 1; |
| a.src = g; |
| m.parentNode.insertBefore(a, m); |
| })(window, document, "script", "//www.google-analytics.com/analytics.js", "ga"); |
| |
| ga("create", "UA-72162311-1", "auto"); |
| ga("send", "pageview"); |
| </script> |
| |
| |
| </head> |
| |
| <body class="not-front page-documentation" role="document" > |
| <div id="wrapper"> |
| <div class="container"> |
| <div id="banner" class="row v2-main-banner"> |
| <a class="logo-cell" href="/"> |
| <img class="logo" src="../../_static/img/logo.png"> |
| </a> |
| <div class="tagline-cell"> |
| <h4 class="tagline">An OS to build, deploy and securely manage billions of devices</h4> |
| </div> |
| <div class="news-cell"> |
| <div class="well"> |
| <h4>Latest News:</h4> <a href="/download">Apache Mynewt 1.11.0, Apache NimBLE 1.6.0 </a> released September 7, 2023) |
| </div> |
| </div> |
| </div> |
| </div> |
| |
| <header> |
| <nav id="navbar" class="navbar navbar-inverse" role="navigation"> |
| <div class="container"> |
| <!-- Collapsed navigation --> |
| <div class="navbar-header"> |
| <!-- Expander button --> |
| <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
| <span class="sr-only">Toggle navigation</span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| <span class="icon-bar"></span> |
| </button> |
| |
| </div> |
| |
| <!-- Expanded navigation --> |
| <div class="navbar-collapse collapse"> |
| <!-- Main navigation --> |
| <ul class="nav navbar-nav navbar-right"> |
| <li> |
| <a href="/"><i class="fa fa-home" style="font-size: larger;"></i></a> |
| </li> |
| <li class="important"> |
| <a href="/quick-start/">Quick Start</a> |
| </li> |
| <li> |
| <a href="/about/">About</a> |
| </li> |
| <li> |
| <a href="/talks/">Talks</a> |
| </li> |
| <li class="active"> |
| <a href="/documentation/">Documentation</a> |
| </li> |
| <li> |
| <a href="/download/">Download</a> |
| </li> |
| <li> |
| <a href="/community/">Community</a> |
| </li> |
| <li> |
| <a href="/events/">Events</a> |
| </li> |
| </ul> |
| |
| <!-- Search, Navigation and Repo links --> |
| <ul class="nav navbar-nav navbar-right"> |
| |
| </ul> |
| </div> |
| </div> |
| </nav> |
| </header> |
| <!-- STARTS MAIN CONTENT --> |
| <div id="main-content"> |
| |
| |
| |
| |
| |
| |
| <div id="breadcrumb"> |
| <div class="container"> |
| <a href="/documentation/">Docs</a> / |
| |
| <a href="../tutorials.html">Tutorials</a> / |
| |
| <a href="sensors.html">Sensors</a> / |
| |
| <a href="sensors_framework.html">Sensor Tutorials Overview</a> / |
| |
| <a href="sensor_oic_overview.html">Enabling OIC Sensor Data Monitoring</a> / |
| |
| Adding OIC Sensor Support to the bleprph_oic Application |
| |
| <div class="sourcelink"> |
| <a href="https://github.com/apache/mynewt-documentation/edit/master/docs/tutorials/sensors/sensor_bleprph_oic.rst" class="icon icon-github" |
| rel="nofollow"> Edit on GitHub</a> |
| </div> |
| </div> |
| </div> |
| <!-- STARTS CONTAINER --> |
| <div class="container"> |
| <!-- STARTS .content --> |
| <div id="content" class="row"> |
| |
| <!-- STARTS .container-sidebar --> |
| <div class="container-sidebar col-xs-12 col-sm-3"> |
| <div id="docSidebar" class="sticky-container"> |
| <div role="search" class="sphinx-search"> |
| <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search documentation" class="search-documentation" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| <!-- Note: only works when deployed --> |
| <select class="form-control" onchange="if (this.value) window.location.href=this.value"> |
| <option value="/latest" selected> |
| Version: latest |
| </option> |
| <option value="/v1_11_0" > |
| Version: 1.11.0 |
| </option> |
| <option value="/v1_10_0" > |
| Version: 1.10.0 |
| </option> |
| <option value="/v1_9_0" > |
| Version: 1.9.0 |
| </option> |
| <option value="/v1_8_0" > |
| Version: 1.8.0 |
| </option> |
| <option value="/v1_7_0" selected="selected" > |
| Version: 1.7.0 |
| </option> |
| <option value="/v1_6_0" > |
| Version: 1.6.0 |
| </option> |
| <option value="/v1_5_0" > |
| Version: 1.5.0 |
| </option> |
| <option value="/v1_4_0" > |
| Version: 1.4.0 |
| </option> |
| <option value="/v1_3_0/os/introduction" > |
| Version: 1.3.0 |
| </option> |
| <option value="/v1_2_0/os/introduction" > |
| Version: 1.2.0 |
| </option> |
| <option value="/v1_1_0/os/introduction" > |
| Version: 1.1.0 |
| </option> |
| <option value="/v1_0_0/os/introduction" > |
| Version: 1.0.0 |
| </option> |
| <option value="/v0_9_0/os/introduction" > |
| Version: 0.9.0 |
| </option> |
| </select> |
| <div class="region region-sidebar"> |
| <div class="docs-menu"> |
| |
| |
| |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="../../index.html">Introduction</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../get_started/index.html">Setup & Get Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../concepts.html">Concepts</a></li> |
| <li class="toctree-l1 current"><a class="reference internal" href="../tutorials.html">Tutorials</a><ul class="current"> |
| <li class="toctree-l2"><a class="reference internal" href="../blinky/blinky.html">Project Blinky</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../repo/add_repos.html">Working with repositories</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../slinky/project-slinky.html">Project Slinky for Remote Comms</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../ble/ble.html">Bluetooth Low Energy</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../lora/lorawanapp.html">LoRa</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../os_fundamentals/os_fundamentals.html">OS Fundamentals</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../devmgmt/devmgmt.html">Remote Device Management</a></li> |
| <li class="toctree-l2 current"><a class="reference internal" href="sensors.html">Sensors</a><ul class="current"> |
| <li class="toctree-l3 current"><a class="reference internal" href="sensors_framework.html">Sensor Framework</a><ul class="current"> |
| <li class="toctree-l4"><a class="reference internal" href="sensor_nrf52_bno055.html">Enable an Off-Board Sensor in an Existing Application</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="sensor_offboard_config.html">Change the Default Configuration For a Sensor</a></li> |
| <li class="toctree-l4"><a class="reference internal" href="sensor_thingy_lis2dh12_onb.html">Develope an Application for an Onboard Sensor</a></li> |
| <li class="toctree-l4 current"><a class="reference internal" href="sensor_oic_overview.html">Enable OIC Sensor Data Monitoring</a><ul class="current"> |
| <li class="toctree-l5"><a class="reference internal" href="sensor_nrf52_bno055_oic.html">Enable OIC Sensor Support in the sensors_test Application</a></li> |
| <li class="toctree-l5 current"><a class="current reference internal" href="#">Add OIC Sensor Support to the bleprph_oic Application</a></li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| <li class="toctree-l3"><a class="reference internal" href="air_quality.html">Air Quality Sensor Project</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="nrf52_adc.html">Add an Analog Sensor</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="sensor_nrf52_drv2605.html">Connect a DRV2605 actuator device</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../tooling/tooling.html">Tooling</a></li> |
| <li class="toctree-l2"><a class="reference internal" href="../other/other.html">Other</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../external_links.html">Third-party Resources</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../os/os_user_guide.html">OS User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../network/index.html">BLE User Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../newt/index.html">Newt Tool Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../newtmgr/index.html">Newt Manager Guide</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../mynewt_faq/index.html">Mynewt FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../misc/index.html">Appendix</a></li> |
| </ul> |
| |
| |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS STICKY CONTAINER --> |
| </div> |
| <!-- ENDS .container-sidebar --> |
| |
| <div class="col-xs-12 col-sm-9"> |
| |
| <div class="alert alert-warning"> |
| <p> |
| Version 1.7.0 is not the most recent version of the |
| Apache Mynewt documentation. Click <a href="/latest">here</a> to |
| read the latest version. |
| </p> |
| </div> |
| |
| |
| |
| <div class=""> |
| <div class="rst-content"> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <div class="section" id="adding-oic-sensor-support-to-the-bleprph-oic-application"> |
| <h1>Adding OIC Sensor Support to the bleprph_oic Application<a class="headerlink" href="#adding-oic-sensor-support-to-the-bleprph-oic-application" title="Permalink to this headline">¶</a></h1> |
| <p>This tutorial shows you how to modify and add OIC sensor support to the |
| <strong>bleprph_oic</strong> application. This tutorial assumes that have you |
| completed the <a class="reference internal" href="sensor_nrf52_bno055_oic.html"><span class="doc">Enabling OIC Sensor Data Monitoring in the sensors_test |
| Application Tutorial</span></a></p> |
| <p>Like the other off-board sensor tutorials, this tutorial uses an |
| nRF52-DK board connected to an off-board BNO055 sensor device.</p> |
| <p>This tutorial shows you how to:</p> |
| <ul class="simple"> |
| <li><p>Modify the bleprph_oic application to add OIC sensor support.</p></li> |
| <li><p>Create and build the target for the new application.</p></li> |
| <li><p>Use the Mynewt Smart Device Controller iOS or Android app to view the |
| sensor data from the device.</p></li> |
| </ul> |
| <div class="contents local topic" id="contents"> |
| <ul class="simple"> |
| <li><p><a class="reference internal" href="#prerequisites" id="id1">Prerequisites</a></p></li> |
| <li><p><a class="reference internal" href="#overview-on-how-to-add-oic-sensor-support-to-a-ble-application" id="id2">Overview on How to Add OIC Sensor Support to a BLE Application</a></p></li> |
| <li><p><a class="reference internal" href="#step-1-copying-the-bleprph-oic-source" id="id3">Step 1: Copying the bleprph_oic source</a></p></li> |
| <li><p><a class="reference internal" href="#step-2-adding-package-dependencies" id="id4">Step 2: Adding Package Dependencies</a></p></li> |
| <li><p><a class="reference internal" href="#step-3-setting-syscfg-values-to-enable-oic-support" id="id5">Step 3: Setting Syscfg Values to Enable OIC Support</a></p></li> |
| <li><p><a class="reference internal" href="#step-4-modifying-main-c" id="id6">Step 4: Modifying main.c</a></p> |
| <ul> |
| <li><p><a class="reference internal" href="#adding-the-sensor-package-header-file" id="id7">Adding the Sensor Package Header File:</a></p></li> |
| <li><p><a class="reference internal" href="#modifying-the-omgr-app-init-function" id="id8">Modifying the omgr_app_init() Function</a></p></li> |
| <li><p><a class="reference internal" href="#deleting-the-app-get-light-and-app-set-light-functions" id="id9">Deleting the app_get_light() and app_set_light() Functions</a></p></li> |
| </ul> |
| </li> |
| <li><p><a class="reference internal" href="#step-5-creating-and-building-the-application-image" id="id10">Step 5: Creating and Building the Application Image</a></p></li> |
| <li><p><a class="reference internal" href="#step-6-connecting-the-sensor-and-loading-the-images-to-the-board" id="id11">Step 6: Connecting the Sensor and Loading the Images to the Board</a></p></li> |
| <li><p><a class="reference internal" href="#step-7-viewing-sensor-data-from-the-mynewt-smart-device-controller" id="id12">Step 7: Viewing Sensor Data from the Mynewt Smart Device Controller</a></p></li> |
| </ul> |
| </div> |
| <div class="section" id="prerequisites"> |
| <h2><a class="toc-backref" href="#id1">Prerequisites</a><a class="headerlink" href="#prerequisites" title="Permalink to this headline">¶</a></h2> |
| <ul class="simple"> |
| <li><p>Read the <a class="reference internal" href="sensor_oic_overview.html"><span class="doc">Overview of OIC Support in the Sensor |
| Framework</span></a></p></li> |
| <li><p>Complete the tasks described in the <a class="reference internal" href="sensor_nrf52_bno055_oic.html"><span class="doc">Enabling OIC Sensor Data |
| Monitoring in the sensors_test Application</span></a> |
| tutorial.</p></li> |
| </ul> |
| </div> |
| <div class="section" id="overview-on-how-to-add-oic-sensor-support-to-a-ble-application"> |
| <h2><a class="toc-backref" href="#id2">Overview on How to Add OIC Sensor Support to a BLE Application</a><a class="headerlink" href="#overview-on-how-to-add-oic-sensor-support-to-a-ble-application" title="Permalink to this headline">¶</a></h2> |
| <p>The sensor framework makes it very easy to add OIC sensor support to an |
| existing BLE application. The sensor framework exports the |
| <code class="docutils literal notranslate"><span class="pre">sensor_oic_init()</span></code> function that an application calls to create the |
| OIC resources for the sensors and to set up the handlers to process CoAP |
| requests for the resources.</p> |
| <p>An application uses the <code class="docutils literal notranslate"><span class="pre">oc</span></code> server API in the <code class="docutils literal notranslate"><span class="pre">net/oic</span></code> package to |
| implement OIC server functionality. An application defines an OIC |
| application initialization handler that sets up the OIC resources it |
| supports. The <code class="docutils literal notranslate"><span class="pre">oc_main_init()</span></code> function, that an application calls |
| during initialization in <code class="docutils literal notranslate"><span class="pre">main()</span></code>, calls the OIC application handler.</p> |
| <p>To add OIC sensor support, we modify the bleprph_oic application to |
| call the <code class="docutils literal notranslate"><span class="pre">sensor_oic_init()</span></code> function in the OIC application |
| initialization handler.</p> |
| </div> |
| <div class="section" id="step-1-copying-the-bleprph-oic-source"> |
| <h2><a class="toc-backref" href="#id3">Step 1: Copying the bleprph_oic source</a><a class="headerlink" href="#step-1-copying-the-bleprph-oic-source" title="Permalink to this headline">¶</a></h2> |
| <p>1. Copy the @apache-mynewt-core/apps/bleprph_oic to a new package. We |
| name the new package <strong>apps/bleprph_oic_sensor</strong>. From your project |
| base directory, run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">pkg</span> <span class="pre">copy</span></code> command:</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>newt<span class="w"> </span>pkg<span class="w"> </span>copy<span class="w"> </span>@apache-mynewt-core/apps/bleprph_oic<span class="w"> </span>@apache-mynewt-core/apps/bleprph_oic_sensor |
| <span class="go">Copying package @apache-mynewt-core/apps/bleprph_oic to @apache-mynewt-core/apps/bleprph_oic_sensor</span> |
| </pre></div> |
| </div> |
| <p>2. The newt tools creates the <code class="docutils literal notranslate"><span class="pre">bleprph_oic_sensor</span></code> package in the |
| <code class="docutils literal notranslate"><span class="pre">~/dev/myproj/repos/apache-mynewt-core/apps/bleprph_oic_sensor</span></code> |
| directory. Go to the directory to update the package <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> and |
| source files.</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span><span class="nb">cd</span><span class="w"> </span>repos/apache-mynewt-core/apps/bleprph_oic_sensor |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="step-2-adding-package-dependencies"> |
| <h2><a class="toc-backref" href="#id4">Step 2: Adding Package Dependencies</a><a class="headerlink" href="#step-2-adding-package-dependencies" title="Permalink to this headline">¶</a></h2> |
| <p>Add the <code class="docutils literal notranslate"><span class="pre">hw/sensor/</span></code> and the <code class="docutils literal notranslate"><span class="pre">hw/sensor/creator</span></code> packages as |
| dependencies in the <code class="docutils literal notranslate"><span class="pre">pkg.yml</span></code> file to include the sensor framework and |
| off-board sensor support.</p> |
| <p><strong>Note:</strong> The <code class="docutils literal notranslate"><span class="pre">hw/sensor</span></code> package automatically includes the |
| <code class="docutils literal notranslate"><span class="pre">net/oic</span></code> package when the <code class="docutils literal notranslate"><span class="pre">SENSOR_OIC</span></code> setting is enabled, so you |
| do not need to include the <code class="docutils literal notranslate"><span class="pre">net/oic</span></code> package as a dependency in this |
| package.</p> |
| <div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="nt">pkg.deps</span><span class="p">:</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">kernel/os</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">net/nimble/controller</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">net/nimble/host</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">net/nimble/host/services/gap</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">net/nimble/host/services/gatt</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">net/nimble/host/store/ram</span> |
| <span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">net/nimble/transport/ram</span> |
| <span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">...</span> |
| <span class="hll"><span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">hw/sensor</span> |
| </span><span class="hll"><span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">hw/sensor/creator</span> |
| </span></pre></div> |
| </div> |
| </div> |
| <div class="section" id="step-3-setting-syscfg-values-to-enable-oic-support"> |
| <h2><a class="toc-backref" href="#id5">Step 3: Setting Syscfg Values to Enable OIC Support</a><a class="headerlink" href="#step-3-setting-syscfg-values-to-enable-oic-support" title="Permalink to this headline">¶</a></h2> |
| <p>Add the following setting values to <code class="docutils literal notranslate"><span class="pre">syscfg.vals</span></code> in the |
| <code class="docutils literal notranslate"><span class="pre">syscfg.yml</span></code> file:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">SENSOR_OIC:</span> <span class="pre">1</span></code>: This setting enables OIC sensor support in the |
| <code class="docutils literal notranslate"><span class="pre">hw/sensors</span></code> package.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">OC_SERVER:</span> <span class="pre">1</span></code> : This setting enables OIC server support in the |
| <code class="docutils literal notranslate"><span class="pre">net/oic</span></code> package.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">FLOAT_USER:</span> <span class="pre">1</span></code>: This setting enables floating pointing support in |
| the encoding/tinycbor package.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ADVERTISE_128BIT_UUID:</span> <span class="pre">1</span></code> and <code class="docutils literal notranslate"><span class="pre">ADVERTISE_16BIT_UUID:</span> <span class="pre">0</span></code>: These |
| settings enable BLE 128 bit UUID and disables 16 bit UUID |
| advertisement. The IoTivity library that is used to build the OIC |
| Apps on the iOS and Android devices only sees 128 bit UUID |
| advertisements.</p></li> |
| </ul> |
| <div class="highlight-yaml notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="nt">syscfg.vals</span><span class="p">:</span> |
| <span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">...</span> |
| |
| <span class="hll"><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">SENSOR_OIC</span><span class="p p-Indicator">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span> |
| </span><span class="hll"><span class="w"> </span><span class="nt">OC_SERVER</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span> |
| </span><span class="hll"><span class="w"> </span><span class="nt">FLOAT_USER</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span> |
| </span><span class="hll"><span class="w"> </span><span class="nt">ADVERTISE_128BIT_UUID</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">1</span> |
| </span><span class="hll"><span class="w"> </span><span class="nt">ADVERTISE_16BIT_UUID</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">0</span> |
| </span></pre></div> |
| </div> |
| </div> |
| <div class="section" id="step-4-modifying-main-c"> |
| <h2><a class="toc-backref" href="#id6">Step 4: Modifying main.c</a><a class="headerlink" href="#step-4-modifying-main-c" title="Permalink to this headline">¶</a></h2> |
| <p>The bleprph_oic application defines the <code class="docutils literal notranslate"><span class="pre">omgr_app_init()</span></code> function |
| for the OIC application initialization handler. The function creates an |
| OIC light resource. We modify the function to call the |
| <code class="docutils literal notranslate"><span class="pre">sensor_oic_init()</span></code> function to create the OIC sensor resources |
| instead of creating the OIC light resource.</p> |
| <p>We make the following modifications to main.c:</p> |
| <ul class="simple"> |
| <li><p>Add the sensor package header file.</p></li> |
| <li><p>Modify the <code class="docutils literal notranslate"><span class="pre">omgr_app_init()</span></code> function to call the |
| <code class="docutils literal notranslate"><span class="pre">sensor_oic_init()</span></code> function, and delete the code to create the OIC |
| light resource.</p></li> |
| <li><p>Delete the OIC application request handler functions that process the |
| CoAP requests for the light resource.</p></li> |
| </ul> |
| <div class="section" id="adding-the-sensor-package-header-file"> |
| <h3><a class="toc-backref" href="#id7">Adding the Sensor Package Header File:</a><a class="headerlink" href="#adding-the-sensor-package-header-file" title="Permalink to this headline">¶</a></h3> |
| <p>Add the sensor package header file <code class="docutils literal notranslate"><span class="pre">sensor/sensor.h</span></code> below |
| <code class="docutils literal notranslate"><span class="pre">#include</span> <span class="pre">"bleprph.h"</span></code> file:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="cp">#include</span><span class="w"> </span><span class="cpf">"bleprph.h"</span> |
| |
| <span class="hll"><span class="w"> </span><span class="cp">#include</span><span class="w"> </span><span class="cpf"><sensor/sensor.h></span> |
| </span></pre></div> |
| </div> |
| </div> |
| <div class="section" id="modifying-the-omgr-app-init-function"> |
| <h3><a class="toc-backref" href="#id8">Modifying the omgr_app_init() Function</a><a class="headerlink" href="#modifying-the-omgr-app-init-function" title="Permalink to this headline">¶</a></h3> |
| <p>Make the following modifications to the <code class="docutils literal notranslate"><span class="pre">omgr_app_init()</span></code> function:</p> |
| <p>1. Delete the code segment that creates the OIC device and resource. |
| The lines to delete are highlighted below:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">void</span> |
| <span class="w"> </span><span class="nf">omgr_app_init</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| <span class="hll"><span class="w"> </span><span class="n">oc_resource_t</span><span class="w"> </span><span class="o">*</span><span class="n">res</span><span class="p">;</span> |
| </span> |
| <span class="hll"><span class="w"> </span><span class="n">oc_init_platform</span><span class="p">(</span><span class="s">"MyNewt"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_add_device</span><span class="p">(</span><span class="s">"/oic/d"</span><span class="p">,</span><span class="w"> </span><span class="s">"oic.d.light"</span><span class="p">,</span><span class="w"> </span><span class="s">"MynewtLed"</span><span class="p">,</span><span class="w"> </span><span class="s">"1.0"</span><span class="p">,</span><span class="w"> </span><span class="s">"1.0"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span> |
| </span><span class="hll"><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| </span> |
| <span class="hll"><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">oc_new_resource</span><span class="p">(</span><span class="s">"/light/1"</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_resource_bind_resource_type</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="s">"oic.r.light"</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_resource_bind_resource_interface</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">OC_IF_RW</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_resource_set_default_interface</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">OC_IF_RW</span><span class="p">);</span> |
| </span> |
| <span class="hll"><span class="w"> </span><span class="n">oc_resource_set_discoverable</span><span class="p">(</span><span class="n">res</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_resource_set_periodic_observable</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_resource_set_request_handler</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">OC_GET</span><span class="p">,</span><span class="w"> </span><span class="n">app_get_light</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_resource_set_request_handler</span><span class="p">(</span><span class="n">res</span><span class="p">,</span><span class="w"> </span><span class="n">OC_PUT</span><span class="p">,</span><span class="w"> </span><span class="n">app_set_light</span><span class="p">);</span> |
| </span><span class="hll"><span class="w"> </span><span class="n">oc_add_resource</span><span class="p">(</span><span class="n">res</span><span class="p">);</span> |
| </span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <p>2. Add the following``oc_add_device()`` function call |
| to create an OIC resource for the sensor device:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">void</span> |
| <span class="w"> </span><span class="nf">omgr_app_init</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| |
| <span class="w"> </span><span class="n">oc_init_platform</span><span class="p">(</span><span class="s">"MyNewt"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| |
| <span class="hll"><span class="w"> </span><span class="n">oc_add_device</span><span class="p">(</span><span class="s">"/oic/d"</span><span class="p">,</span><span class="w"> </span><span class="s">"oic.d.sensy"</span><span class="p">,</span><span class="w"> </span><span class="s">"sensy"</span><span class="p">,</span><span class="w"> </span><span class="s">"1.0"</span><span class="p">,</span><span class="w"> </span><span class="s">"1.0"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| </span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| <p>3. Add the call to the <code class="docutils literal notranslate"><span class="pre">sensor_oic_init()</span></code> function to initialize the |
| sensor framework OIC server support:</p> |
| <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">void</span> |
| <span class="w"> </span><span class="nf">omgr_app_init</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span> |
| <span class="w"> </span><span class="p">{</span> |
| |
| <span class="w"> </span><span class="n">oc_init_platform</span><span class="p">(</span><span class="s">"MyNewt"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| |
| <span class="w"> </span><span class="n">oc_add_device</span><span class="p">(</span><span class="s">"/oic/d"</span><span class="p">,</span><span class="w"> </span><span class="s">"oic.d.sensy"</span><span class="p">,</span><span class="w"> </span><span class="s">"sensy"</span><span class="p">,</span><span class="w"> </span><span class="s">"1.0"</span><span class="p">,</span><span class="w"> </span><span class="s">"1.0"</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">,</span><span class="w"> </span><span class="nb">NULL</span><span class="p">);</span> |
| |
| <span class="hll"><span class="w"> </span><span class="n">sensor_oic_init</span><span class="p">();</span> |
| </span> |
| <span class="w"> </span><span class="p">}</span> |
| </pre></div> |
| </div> |
| </div> |
| <div class="section" id="deleting-the-app-get-light-and-app-set-light-functions"> |
| <h3><a class="toc-backref" href="#id9">Deleting the app_get_light() and app_set_light() Functions</a><a class="headerlink" href="#deleting-the-app-get-light-and-app-set-light-functions" title="Permalink to this headline">¶</a></h3> |
| <p>Since we modify the application to no longer create an OIC light |
| resource, the <code class="docutils literal notranslate"><span class="pre">app_get_light()</span></code> and the <code class="docutils literal notranslate"><span class="pre">app_set_light()</span></code> handler |
| functions that process read and write requests are not used. We need to |
| delete the functions to avoid compilation errors. Search for the two |
| functions and delete them.</p> |
| </div> |
| </div> |
| <div class="section" id="step-5-creating-and-building-the-application-image"> |
| <h2><a class="toc-backref" href="#id10">Step 5: Creating and Building the Application Image</a><a class="headerlink" href="#step-5-creating-and-building-the-application-image" title="Permalink to this headline">¶</a></h2> |
| <p>In this step of the tutorial we create and build an application image |
| for the bleprph_oic_sensor application to verify that the application |
| serves sensor data over OIC correctly.</p> |
| <p>We use the same syscfg settings from the <a class="reference internal" href="sensor_nrf52_bno055_oic.html"><span class="doc">Enabling OIC Sensor Data |
| Monitoring in the sensors_test Application Tutorial</span></a></p> |
| <p>1. From your project base directory, run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">create</span> <span class="pre">target</span></code> |
| command to create a new target named <code class="docutils literal notranslate"><span class="pre">nrf52_bleprph_oic_bno055</span></code>:</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>newt<span class="w"> </span>target<span class="w"> </span>create<span class="w"> </span>nrf52_bleprph_oic_bno055 |
| <span class="go">Target targets/nrf52_bleprph_oic_bno055 successfully created</span> |
| </pre></div> |
| </div> |
| <p>2. Run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">target</span> <span class="pre">set</span></code> command to set the app, bsp, and |
| build_profile variables for the target.</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>newt<span class="w"> </span>target<span class="w"> </span><span class="nb">set</span><span class="w"> </span>nrf52_bleprph_oic_bno055<span class="w"> </span><span class="nv">app</span><span class="o">=</span>@apache-mynewt-core/apps/bleprph_oic_sensor<span class="w"> </span><span class="nv">bsp</span><span class="o">=</span>@apache-mynewt-core/hw/bsp/nrf52dk<span class="w"> </span><span class="nv">build_profile</span><span class="o">=</span>debug |
| <span class="go">Target targets/nrf52_bleprph_oic_bno055 successfully set target.app to @apache-mynewt-core/apps/bleprph_oic_sensor</span> |
| <span class="go">Target targets/nrf52_bleprph_oic_bno055 successfully set target.bsp to @apache-mynewt-core/hw/bsp/nrf52dk</span> |
| <span class="go">Target targets/nrf52_bleprph_oic_bno055 successfully set target.build_profile to debug</span> |
| <span class="gp">$</span> |
| </pre></div> |
| </div> |
| <p>3. Run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">target</span> <span class="pre">set</span></code> command to set <code class="docutils literal notranslate"><span class="pre">I2C_0=1</span></code>, |
| <code class="docutils literal notranslate"><span class="pre">BNO055_OFB=1</span></code>, <code class="docutils literal notranslate"><span class="pre">BLE_MAX_CONNECTIONS=4</span></code>, <code class="docutils literal notranslate"><span class="pre">MSYS_1_BLOCK_COUNT=52</span></code>, |
| <code class="docutils literal notranslate"><span class="pre">MSYS_1_BLOCK_SIZE=100</span></code>, and <code class="docutils literal notranslate"><span class="pre">OC_APP_RESOURCES=11</span></code>.</p> |
| <div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>newt<span class="w"> </span>target<span class="w"> </span><span class="nb">set</span><span class="w"> </span>nrf52_bleprph_oic_bno055<span class="w"> </span><span class="nv">syscfg</span><span class="o">=</span><span class="nv">BNO055_OFB</span><span class="o">=</span><span class="m">1</span>:I2C_0<span class="o">=</span><span class="m">1</span>:BLE_MAX_CONNECTIONS<span class="o">=</span><span class="m">4</span>:MSYS_1_BLOCK_COUNT<span class="o">=</span><span class="m">52</span>:MSYS_1_BLOCK_SIZE<span class="o">=</span><span class="m">100</span>:OC_APP_RESOURCES<span class="o">=</span><span class="m">11</span> |
| <span class="go">Target targets/nrf52_bleprph_oic_bno055 successfully set target.syscfg to BNO055_OFB=1:I2C_0=1:BLE_MAX_CONNECTIONS=4:MSYS_1_BLOCK_COUNT=52:MSYS_1_BLOCK_SIZE=100:OC_APP_RESOURCES=11</span> |
| <span class="gp">$</span> |
| </pre></div> |
| </div> |
| <p>4. Run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">build</span> <span class="pre">nrf52_bleprph_oic_bno055</span></code> and |
| <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">create-image</span> <span class="pre">nrf52_bleprph_oic_bno055</span> <span class="pre">1.0.0</span></code> commands to build |
| and create the application image.</p> |
| </div> |
| <div class="section" id="step-6-connecting-the-sensor-and-loading-the-images-to-the-board"> |
| <h2><a class="toc-backref" href="#id11">Step 6: Connecting the Sensor and Loading the Images to the Board</a><a class="headerlink" href="#step-6-connecting-the-sensor-and-loading-the-images-to-the-board" title="Permalink to this headline">¶</a></h2> |
| <p>Perform the following steps to reboot the board with the new images:</p> |
| <ol class="arabic"> |
| <li><p>Connect the BNO055 sensor to the nRF52-DK board. See the <a class="reference internal" href="sensor_offboard_config.html"><span class="doc">Enabling an |
| Off-Board Sensor in an Existing Application |
| Tutorial</span></a> for |
| instructions.</p> |
| <p><strong>Note</strong>: You do not need the serial connection from your computer |
| directly to the nRF52-DK board because we are not using the shell to |
| view the sensor data.</p> |
| </li> |
| <li><p>Run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">load</span> <span class="pre">nrf52_boot</span></code> command to load the bootloader. You |
| should already have this target built from the <a class="reference internal" href="sensor_nrf52_bno055.html"><span class="doc">Enabling an Off-Board |
| Sensor in an Existing Application |
| Tutorial</span></a></p></li> |
| <li><p>Run the <code class="docutils literal notranslate"><span class="pre">newt</span> <span class="pre">load</span> <span class="pre">nrf52_bno055_oic_test</span></code> command to load the |
| application image.</p></li> |
| <li><p>Power the device OFF and ON to reboot.</p></li> |
| </ol> |
| </div> |
| <div class="section" id="step-7-viewing-sensor-data-from-the-mynewt-smart-device-controller"> |
| <h2><a class="toc-backref" href="#id12">Step 7: Viewing Sensor Data from the Mynewt Smart Device Controller</a><a class="headerlink" href="#step-7-viewing-sensor-data-from-the-mynewt-smart-device-controller" title="Permalink to this headline">¶</a></h2> |
| <p>Start the Mynewt Smart Device Controller app on your iOS or Android |
| device to view the sensor data. You should already have the app |
| installed from the <a class="reference internal" href="sensor_nrf52_bno055_oic.html"><span class="doc">Enabling OIC Sensor Data Monitoring in the |
| sensors_test Application Tutorial</span></a></p> |
| <p>The Mynewt Smart Device Controller scans for the devices when it starts |
| up and displays the sensors it can view. The following is an example |
| from the Android App:</p> |
| <img alt="../../_images/smart_controller_main.png" class="align-center" src="../../_images/smart_controller_main.png" /> |
| <ol class="arabic simple"> |
| <li><p>Select <code class="docutils literal notranslate"><span class="pre">Accelerometer</span></code> to see the sensor data samples:</p></li> |
| </ol> |
| <img alt="../../_images/smart_controller_accelerometer.png" class="align-center" src="../../_images/smart_controller_accelerometer.png" /> |
| <p>2. Move your BNO055 sensor device around to see the values for the |
| coordinates change.</p> |
| </div> |
| </div> |
| |
| |
| </div> |
| </div> |
| |
| <div class="rst-footer-buttons row" role="navigation" aria-label="footer navigation"> |
| |
| <a href="air_quality.html" class="btn btn-neutral float-right" title="Air Quality Sensor Project" accesskey="n">Next: Air Quality Sensor Project <span class="fa fa-arrow-circle-right"></span></a> |
| |
| |
| <a href="sensor_nrf52_bno055_oic.html" class="btn btn-neutral" title="Enabling OIC Sensor Data Monitoring in the sensors_test Application" accesskey="p"><span class="fa fa-arrow-circle-left"></span> Previous: Enabling OIC Sensor Data Monitoring in the sensors_test Application</a> |
| |
| </div> |
| |
| </div> |
| </div> |
| </div> |
| <!-- ENDS CONTENT SECTION --> |
| </div> |
| <!-- ENDS .content --> |
| </div> |
| </div> |
| <footer> |
| <div class="container"> |
| <div class="row"> |
| <div class="col-xs-12"> |
| |
| <p class="copyright">Apache Mynewt is available under Apache License, version 2.0.</p> |
| |
| </div> |
| <div class="col-xs-12"> |
| <div class="logos"> |
| <img src="../../_static/img/asf_logo_wide_small.png" alt="Apache" title="Apache"> |
| <small class="footnote"> |
| Apache Mynewt, Mynewt, Apache, the Apache feather logo, and the Apache Mynewt project logo are either |
| registered trademarks or trademarks of the Apache Software Foundation in the United States and other countries. |
| </small> |
| <a href=""> |
| <img src="../../_static/img/add_to_slack.png" alt="Slack Icon" title="Join our Slack Community" /> |
| </a> |
| </div> |
| </div> |
| </div> |
| </div> |
| </footer> |
| </div> |
| <!-- ENDS #wrapper --> |
| |
| |
| |
| <script type="text/javascript"> |
| var DOCUMENTATION_OPTIONS = { |
| URL_ROOT:'../../', |
| VERSION:'latest', |
| COLLAPSE_INDEX:false, |
| FILE_SUFFIX:'.html', |
| HAS_SOURCE: true, |
| SOURCELINK_SUFFIX: '.txt', |
| LINK_SUFFIX: '.html' |
| }; |
| </script> |
| <script type="text/javascript" src="../../_static/jquery.js"></script> |
| <script type="text/javascript" src="../../_static/underscore.js"></script> |
| <script type="text/javascript" src="../../_static/doctools.js"></script> |
| <script type="text/javascript" src="../../_static/js/bootstrap-3.0.3.min.js"></script> |
| <script type="text/javascript" src="../../_static/js/affix.js"></script> |
| <script type="text/javascript" src="../../_static/js/main.js"></script> |
| |
| |
| |
| </body> |
| </html> |