Bring it back to live after power suspend/off

Topics: Bluetooth - BlueSoliel
May 2, 2012 at 5:28 PM

The device no longer listens to incoming connections after power suspend/off.    Everything works great until I power the device off and then back on.  At this point, the other device can no longer see this Bluetopia device in range.

I implemented some code to notify me when the device is powered on and then I set the radio to discoverable and connectable again.  This works however is not how it should work.   The user should not have to turn the device on to keep connected.

So then I tried to implement PowerPolicyNotify(PPN_UNATTENDEDMODE, True) to keep the device in unnatended mode but it didn't work either. 

What should I do?

 

Developer
May 9, 2012 at 7:56 PM

Sorry missed this message.

For my original client for Bluetopia they wanted the device to be able to sleep, and supported Widcomm and Bluetopia stacks.  So in my application for them whenever the app started to use Bluetooth -- it was a client-side app so whenever it did a discovery or connect -- it checked if the device had just resumed and if so waited 15seconds for things to settle down (mainly for Widcom IIRC) and (for Bluetopia) ensured the radio was on (turn it on and wait for the status to reflect that).  For the resume monitoring it used used th system power notifications (RequestPowerNotifications).

So the top-level function was like:

       internal void EnsureRadioOn()
       {
           Power2.EnsureResumeOk();
           //
           // Note: Bluetopia Radio defaults to off at start-up
           if (_radio.Mode != RadioMode.PowerOff) {
               return;
           }
           _radio.Mode = RadioMode.Connectable;
           this.BeginInvoke((Action)delegate { // Likely called from UI thread but make sure...
               this.textBox1.Text += "Turned radio on\r\n\r\n";
           });
           if (_radio.Mode != RadioMode.PowerOff) {
               return;
           }
           for (int i = 0; i < 6; ++i) {
               Thread.Sleep(250);
               if (_radio.Mode != RadioMode.PowerOff) {
                   return;
               }
           }//for
           Debug.WriteLine("Radio.mode: " + _radio.Mode);
       }

 And Power2.EnsureResumeOk did the 'wait 15 seconds after resume' handling.