<?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>Waking a Thingy 52 from python</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/71236/waking-a-thingy-52-from-python</link><description>I have the thingy52.py script running on a Raspberry Pi 4, and I can successfully poll the sensors when the Thing52 is awake (recently tapped) but when I try to poll in a once-per-hour cron job, I find that the script cannot connect to the T52. (The T52</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 Feb 2021 15:11:44 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/71236/waking-a-thingy-52-from-python" /><item><title>RE: Waking a Thingy 52 from python</title><link>https://devzone.nordicsemi.com/thread/292732?ContentTypeID=1</link><pubDate>Wed, 03 Feb 2021 15:11:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7c86b4e8-8944-46ba-968c-e600e4ee85c0</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t think the Thingy52 phone app can actually connect to a thingy that is in sleep mode. If so, it is not advertising, and there is no way to connect to it. Please note that the thingy wakes up on an accelerometer, so perhaps it was moved (it doesn&amp;#39;t take much. Just a bump in the table that it is laying on is sufficient, I think).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, it is possible&amp;nbsp; to disable the sleep time in the thingy app (or in the application code, of course). It is also possible to do this from the raspberry pi. Allow me to copy an answer I gave in a similar (non-public) question a while back. As it answers specific questions, the wording may be a bit off, but it looks like it will be applicable for you as well:&lt;/p&gt;
&lt;p&gt;-------------------------------------&lt;/p&gt;
&lt;p&gt;When the device disconnects, it automatically starts advertising. The default behavior when the Thingy advertises, and doesn&amp;#39;t get any connection requests, they will go to sleep.&lt;/p&gt;
&lt;p&gt;You can see this in m_ble.c in on_adv_evt() on line 323:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void on_adv_evt(ble_adv_evt_t ble_adv_evt)
{
    uint32_t      err_code;
    m_ble_evt_t evt;

    switch (ble_adv_evt)
    {
        case BLE_ADV_EVT_FAST:
            NRF_LOG_INFO(&amp;quot;on_adv_evt: BLE_ADV_EVT_FAST\r\n&amp;quot;);
            break;
        case BLE_ADV_EVT_IDLE:
            NRF_LOG_INFO(&amp;quot;on_adv_evt: BLE_ADV_EVT_IDLE\r\n&amp;quot;);
            evt.evt_type = thingy_ble_evt_timeout;
            m_evt_handler(&amp;amp;evt);

            err_code = ble_advertising_start(BLE_ADV_MODE_FAST);
            APP_ERROR_CHECK(err_code);

            break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It hits the BLE_ADV_EVT_IDLE, which triggers the event handler in main.c on line 229:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static void thingy_ble_evt_handler(m_ble_evt_t * p_evt)
{
    switch (p_evt-&amp;gt;evt_type)
    {
        case thingy_ble_evt_connected:
            NRF_LOG_INFO(NRF_LOG_COLOR_CODE_GREEN &amp;quot;Thingy_ble_evt_connected \r\n&amp;quot;);
            break;

        case thingy_ble_evt_disconnected:
            NRF_LOG_INFO(NRF_LOG_COLOR_CODE_YELLOW &amp;quot;Thingy_ble_evt_disconnected \r\n&amp;quot;);
            NRF_LOG_FINAL_FLUSH();
            nrf_delay_ms(5);
            NVIC_SystemReset();
            break;

        case thingy_ble_evt_timeout:
            NRF_LOG_INFO(NRF_LOG_COLOR_CODE_YELLOW &amp;quot;Thingy_ble_evt_timeout \r\n&amp;quot;);
            sleep_mode_enter();         // &amp;lt;-- THIS ONE ENTERS SLEEP MODE
            NVIC_SystemReset();
            break;
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;As mentioned, you can either change this by changing the source code, but luckily, the thingy can be configured during runtime as well.&lt;/p&gt;
&lt;p&gt;If you experiment with this using the Nordic&amp;#39;s Thingy app, and connect to a thingy, you can press the menu button (three horisontal lines) in the top left corner, and select &amp;quot;configuration&amp;quot;, and set the &amp;quot;Advertising&amp;quot; -&amp;gt; &amp;quot;Timeout&amp;quot; to 0.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you try to connect to the device with nRF Connect, you will see that it has a service called &amp;quot;Thingy Configuration&amp;quot; with a characteristic called &amp;quot;Advertising Parameters&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1612365059968v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;The default value of this is 0x 60 02 B4&lt;/p&gt;
&lt;p&gt;The two first bytes (LSB) is 0x0260 = 608 decimal, is the advertising interval in units of 0.625 ms, that is 380ms&lt;/p&gt;
&lt;p&gt;The last byte 0xB4 is the advertising timeout. 0xB4 = 180, which is the timeout in seconds.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So if you want it to advertise with the same advertising interval, but never time out, write (0x) 60 02 00 to this characteristic, and it will update the advertising configurations.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To save you some work, the thingy configuration service is the service with:&lt;/p&gt;
&lt;p&gt;UUID: EF6801009B3549339B1052FFA9740042&lt;/p&gt;
&lt;p&gt;and the Advertising characteristic has:&lt;/p&gt;
&lt;p&gt;UUID: EF6801029B3549339B1052FFA9740042&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So if the RPi is connected to the thingy, you can probably use the RPi to write to this characteristic, to prevent the Thingy from going to sleep when it is not in a connection.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>