<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/42948/nrf52832-sleep-mode-from-android-app</link><description>I am currently looking at how to put the nrf52 development board to sleep (and wake up) by sending a command from an android application (with SDK v15.2). 
 I have been experimenting with the nrfBlinky app and wanted to know if anyone has some advice</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 03 Feb 2019 22:47:52 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/42948/nrf52832-sleep-mode-from-android-app" /><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/169195?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2019 22:47:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:85aba55e-3851-46ff-b9a6-4de586e146b2</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I am happy&amp;nbsp;to hear you figured it out! Please ask if you encounter any more problems.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/169175?ContentTypeID=1</link><pubDate>Sun, 03 Feb 2019 12:16:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea9984c5-2130-4214-bd3b-4910743d8415</guid><dc:creator>mialo_5</dc:creator><description>&lt;p&gt;Thanks, figured it out, used the pwr_mgmt_example added the shutdown_handler event and set the priority, then as you indicated called&amp;nbsp;..STAY_IN_SYSOFF. I checked the events&amp;nbsp;by using the serial port to the dev board and&amp;nbsp;outputting to&amp;nbsp;PuTTY to see what was happening.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/169165?ContentTypeID=1</link><pubDate>Sat, 02 Feb 2019 21:19:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:269b8bf9-9219-43f8-a16e-871bd52a05bc</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Try changing&amp;nbsp;&lt;em&gt;NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF&lt;/em&gt;&lt;span&gt;&amp;nbsp; with&lt;/span&gt;&amp;nbsp;&lt;em&gt;NRF_PWR_MGMT_SHUTDOWN_STAY_IN_SYSOFF.&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/168539?ContentTypeID=1</link><pubDate>Tue, 29 Jan 2019 16:40:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d2b6dcd9-1cbf-4c4f-864a-d47781b8672d</guid><dc:creator>mialo_5</dc:creator><description>&lt;p&gt;Yes&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/168529?ContentTypeID=1</link><pubDate>Tue, 29 Jan 2019 15:51:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6aa4b952-abfa-4b2c-a665-6e23eac2c179</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Have you taken a look at the nrf_pwr_mgmt example? That might give you a better understanding of the System OFF sleep mode.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/168305?ContentTypeID=1</link><pubDate>Mon, 28 Jan 2019 16:17:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4229ca99-c913-4138-b42b-e899361934cd</guid><dc:creator>mialo_5</dc:creator><description>&lt;p&gt;Thanks for your help although I don&amp;#39;t believe I am getting to the answer I&amp;#39;m looking for.&lt;/p&gt;
&lt;p&gt;Maybe if I rephrase the question as follows:&lt;/p&gt;
&lt;p&gt;I am using the&amp;nbsp;nrfBlinky Android app with an nrf52832. I would like to press a button on the dev board to put the board into a system off (&lt;strong&gt;sd_power_system_off()&lt;/strong&gt; or &lt;strong&gt;nrf_pwr_mgmt._shutdown()&lt;/strong&gt;) sleep mode where I can only recover by pressing RESET button on the board.&lt;/p&gt;
&lt;p&gt;If I&amp;nbsp;create a static variable &amp;quot;m_is_sleep_mode&amp;quot;&amp;nbsp;to store&amp;nbsp;if BSP_BUTTON_1 is pressed and check that it is true in the main function (in the for(;;) loop I assume), see code snippet,&amp;nbsp;the board seems to perform a reset (the connection drops and comes back up immediately)&amp;nbsp;but has not gone into a power down mode.&lt;/p&gt;
&lt;p&gt;Thoughts this time?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void button_event_handler(uint8_t pin_no, uint8_t button_action)
{
    ret_code_t err_code;

    switch (pin_no)
    {
        case LEDBUTTON_BUTTON:
            NRF_LOG_INFO(&amp;quot;Send button state change.&amp;quot;);
            err_code = ble_lbs_on_button_change(m_conn_handle, &amp;amp;m_lbs, button_action);
            if (err_code != NRF_SUCCESS &amp;amp;&amp;amp;
                err_code != BLE_ERROR_INVALID_CONN_HANDLE &amp;amp;&amp;amp;
                err_code != NRF_ERROR_INVALID_STATE &amp;amp;&amp;amp;
                err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
            {
                APP_ERROR_CHECK(err_code);
            }
            break;

        case SLEEPBUTTON_BUTTON:
            m_is_sleep_mode = true;
            break;

        default:
            APP_ERROR_HANDLER(pin_no);
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void buttons_init(void)
{
    ret_code_t err_code;

    //The array must be static because a pointer to it will be saved in the button handler module.
    static app_button_cfg_t buttons[] =
    {
        {LEDBUTTON_BUTTON, false, BUTTON_PULL, button_event_handler},
        {SLEEPBUTTON_BUTTON, false, BUTTON_PULL, button_event_handler}
    };

    err_code = app_button_init(buttons, ARRAY_SIZE(buttons),
                               BUTTON_DETECTION_DELAY);
    APP_ERROR_CHECK(err_code);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;int main(void)
{
    // Initialize.
    ....

    // Enter main loop.
    for (;;)
    {
        if (m_is_sleep_mode)
        {
            nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_SYSOFF);
        }
        else
        {
            idle_state_handle();        
        }
    }
}

&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/168206?ContentTypeID=1</link><pubDate>Mon, 28 Jan 2019 12:25:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8534a403-5def-41d3-88f1-217c61a08584</guid><dc:creator>Simon</dc:creator><description>[quote user="mialo_5"]Therefore based on your reply for Question 1, you mention looking at the ble_uart example which uses a softdevice which I don&amp;#39;t believe I am using. Is this then the only way to get the device to sleep in a System OFF mode and why my test didn&amp;#39;t work or have I missed something?&amp;nbsp;[/quote]
&lt;p&gt;Why does it not work? Have you tried to debug and see what error messages you get?&lt;/p&gt;
[quote user="mialo_5"]Therefore based on your reply for Question 1, you mention looking at the ble_uart example which uses a softdevice which I don&amp;#39;t believe I am using. Is this then the only way to get the device to sleep in a System OFF mode and why my test didn&amp;#39;t work or have I missed something?&amp;nbsp;[/quote]
&lt;p&gt;If you want control your device from an android app you need a SoftDevice (which handles all low level BLE activity). The reason I recommended you the ble_app_uart example is because it is a quite simple example which uses the SoftDevice.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/168022?ContentTypeID=1</link><pubDate>Fri, 25 Jan 2019 17:42:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f760144c-b40d-45ff-aaaf-8f360e9961c1</guid><dc:creator>mialo_5</dc:creator><description>&lt;p&gt;Thanks again&amp;nbsp;for the reply and ideas on how to solve my questions.&lt;/p&gt;
&lt;p&gt;So just to make sure, if I use the SDK blinky app example, I believe it already implements System ON mode, as I can see that &amp;nbsp;&lt;strong&gt;nrf_pwr_mgmt_run()&lt;/strong&gt; is run in a &lt;strong&gt;for(;;)&lt;/strong&gt; loop. So what I tried was to add another button event handler in the SDK&amp;nbsp;to say Button 2 of the dev board, that calls &lt;strong&gt;sd_power_system_off() &lt;/strong&gt;to test if i can put the board in system OFF mode but that doesn&amp;#39;t seem to work.&lt;/p&gt;
&lt;p&gt;Therefore based on your reply for Question 1, you mention looking at the ble_uart example which uses a softdevice which I don&amp;#39;t believe I am using. Is this then the only way to get the device to sleep in a System OFF mode and why my test didn&amp;#39;t work or have I missed something?&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/168017?ContentTypeID=1</link><pubDate>Fri, 25 Jan 2019 17:12:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34148f4a-4a07-4fd5-9954-7f4110890499</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Question 1&lt;/p&gt;
&lt;p&gt;There are many ways of doing this, but here I am presenting one approach. You could use the&amp;nbsp;&lt;a href="https://www.nordicsemi.com/DocLib/Content/SDK_Doc/nRF5_SDK/v15-2-0/ble_sdk_app_nus_eval"&gt;ble_app_uart&amp;nbsp;peripheral example&lt;/a&gt; along with &lt;a href="https://www.nordicsemi.com/Software-and-Tools/Development-Tools/nRF-Connect-for-mobile"&gt;nRF Connect for Mobile&lt;/a&gt;&amp;nbsp;as a starting point. Then you could put the board into System OFF sleep mode, if a specific message (e.g. 123) is received.&amp;nbsp;In order to achieve this you&amp;nbsp;have to modify the function&amp;nbsp;&lt;em&gt;nus_data_handler(),&lt;/em&gt; specifically you need to check if the received data is equal to the correct value &lt;span&gt;(e.g. 123)&lt;/span&gt;, and run &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.s132.api.v3.0.0%2Fgroup___n_r_f___s_o_c___f_u_n_c_t_i_o_n_s.html"&gt;sd_power_system_off()&lt;/a&gt;&amp;nbsp;if that is the case.&lt;/p&gt;
&lt;p&gt;If you are developing your own&amp;nbsp;mobile app, you could make a button that only sends out the specific message.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;Question 2&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;For putting the board into System ON,&amp;nbsp;you could use the same approach as explained above, just with another&amp;nbsp;value (e.g. 456). I would recommend you to take a look at the Button handling library, which will generate GPIOTE events when a button is pressed, and consecutively wake&amp;nbsp;the device up from System ON sleep.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/167959?ContentTypeID=1</link><pubDate>Fri, 25 Jan 2019 14:04:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27f62fdd-6cde-466f-8599-faeb2c6a40e2</guid><dc:creator>mialo_5</dc:creator><description>&lt;p&gt;Thank you for the reply Simon.&lt;/p&gt;
&lt;p&gt;So I am aware of the SDK samples, probably didn&amp;#39;t fully understand what they were doing, so thank you (and Ashish) for clarifying.&lt;/p&gt;
&lt;p&gt;For the project that I am working on, I would like to send a sleep command to the BLE board from an Android device (untethered so not through uart), similar to the Blinky app where you press a switch control to turn a light on the board. I was unsure the correct steps to follow to&amp;nbsp;simulate this event and how one would get the board to go to sleep.&lt;/p&gt;
&lt;p&gt;1. So for now&amp;nbsp;what I would&amp;nbsp;like to do is&amp;nbsp;to&amp;nbsp;create an LED type event structure&amp;nbsp;for an Android app (e.g. sleep button)&amp;nbsp;that could put the board into sleep mode (System OFF), essentially turn it off where a person would have to press the reset button on the board to wake it up (how do you put the board into System OFF sleep?).&lt;/p&gt;
&lt;p&gt;2. Then as a later goal to implement the System ON mode where an event from the Android app could put the board to sleep and then another event (say turning a switch control on/off) to wake it up.&lt;/p&gt;
&lt;p&gt;Any ideas?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/167726?ContentTypeID=1</link><pubDate>Thu, 24 Jan 2019 16:18:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:beaed8e8-40e9-4079-a352-faaa4f543ad8</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;Have you taken a look at the examples in SDK 15.2? In most of the examples, the chip is in System ON sleep mode most of the time. The way it is done is by putting the sleep function in a for loop (as Ashish mentioned). Most of the functionality related to the nRF52 chip is event driven, and is perfectly compatible with this approach.&lt;/p&gt;
&lt;p&gt;E.g, in the SAADC example, the chip is put to System ON sleep in a while(1) loop through the function&amp;nbsp;&lt;em&gt;nrf_pwr_mgmt_run()&lt;/em&gt;, then if&amp;nbsp; ADC&amp;nbsp;data is received, the chip breaks the sleeps mode, handles the ADC event, then continues on the line after&amp;nbsp;&lt;em&gt;nrf_pwr_mgmt_run().&amp;nbsp;&lt;/em&gt;Since the function is inside a while loop, it will loop around and go to sleep once again.&amp;nbsp;&lt;em&gt;&amp;nbsp;&lt;/em&gt;The BLE examples are also event driven, and works in the same manner as the ADC example.&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This approach only works for System ON sleep mode, and event driven activity.&lt;/p&gt;
&lt;p&gt;However, please tell me if you are aware of this and have a reason for invoking sleep mode yourself. If you could explain your project in more details, I would be able to give you a more constructive answer.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52832 sleep mode from android app</title><link>https://devzone.nordicsemi.com/thread/167596?ContentTypeID=1</link><pubDate>Thu, 24 Jan 2019 10:31:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:05867d3b-90f1-4a6d-8024-80bd0d68c7db</guid><dc:creator>Ashish</dc:creator><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First, I would advise you to try the &lt;strong&gt;ble_uart&lt;/strong&gt; example in the peripheral folder. With that you can set up a simple uart link between your nrf52 board and android device and send messages either way.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To put the board into low power, with the softdevice enabled, you should use the &lt;strong&gt;sd_app_evt_wait function&lt;/strong&gt;. You can put this in your main loop so that the device goes to sleep when it has nothing else to do. This&amp;nbsp;will be &lt;strong&gt;SYSTEM ON&lt;/strong&gt; mode. So you can send a message from the android device and it will wake up the nrf.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;You can also use&amp;nbsp;&lt;strong&gt;SYSTEM OFF&amp;nbsp;&lt;/strong&gt;mode, as you said. When you put the device in&amp;nbsp;&lt;strong&gt;SYSTEM OFF&amp;nbsp;&lt;/strong&gt;mode, the BLE link will be closed, the device will be disconnected. You can wake up the device using a GPIO interrupt ,NFC or LPCOMP interrupt. This will provide you with lowest power consumption but the nrf when wakes up, will be like it has been reset.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Also, do check the&amp;nbsp;&lt;a href="https://www.nordicsemi.com/DocLib" rel="noopener noreferrer" target="_blank"&gt;documentation&lt;/a&gt;&amp;nbsp;if you have any further question.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>