locked
I need gps&wifi&dataconnection in suspended mode what are your thoughts RRS feed

  • Question

  • Hi as the title says I need gps, wifi and a dataconnection in suspended(or unatended) mode, currently I have no idea on any way this can be acheived.

    i know in unatended mode code still runs but the above connections will not. I was wondering if there is code to enable these i.e. if suspended/unatended mode turns the power off for wifi for example can I turn it back on? using SetPowerRequirement perhaps? for dataconnection maybe the phone is put into gsm mode? could this be the case?

    failing this can I tell my phone to never go into anyother state but fully on? even if the power button is pressed? and then maybe I could try to save a little battery by turning off the screen back light and speaker manually but nothing else?

    Ideally I want to be able to have the phone suspended I use CeRunAppAtTime turn the phone fully on do my buisness then let it go back to sleep.

    If you know anything that might help please post it, even if you think its silly I only have 1 week left to solve this problem
    Monday, September 7, 2009 6:40 PM

Answers

  • Hi,

    You may find Joel's code project page useful regarding powering the wifi on :-

    http://www.codeproject.com/KB/mobile/WiMoPower1.aspx

    I wouldn't go as far as saying the only option is to port to another OS however you may want to rethink the usage of these connections. Maybe, the code that does run when the device is fully powered on can be a little more proactive by checking the availability of connections. Without knowing exactly what you trying to achieve it is slightly tricky to suggest a better strategy. If your application does rely so heavily on data connections then how do you handle the loss of signal or movement out of range?

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked as answer by ZHE ZHAO Monday, September 14, 2009 2:45 AM
    Monday, September 7, 2009 7:28 PM
  • I have gone through the article paul posted above again and noticed a reference to SetSystemPowerState
    there is no code for its use but this may just be the answer to my prayers

    here is the documentation on msdn

    http://msdn.microsoft.com/en-us/library/ms920754.aspx

    I really don't understand it very well can anyone descifer this and show me how I can use it in a c# application

    I have seen DWORD in pinvoked methods but what is LPCWSTR?

    • Marked as answer by ZHE ZHAO Monday, September 14, 2009 2:46 AM
    Monday, September 7, 2009 8:13 PM

All replies

  • Hi,

    Unfortunately, I don't think you are going to be able to prevent the power button from powering the device off. With that in mind, is your requirement slightly unachievable due to this fact?

    Have you tried powering the Wifi radio on in unattended mode?

    Are you targetting a Windows Mobile device?

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    Monday, September 7, 2009 6:54 PM
  • Hi paul,

    my code which uses wifi/data connection does not work when in unattended mode, I'm not quite sure how to power up the wifi radio but I assume it would involve using  SetPowerRequirement. There must be a way to do what I need as emails are still received when the phone is off but maybe this functionality is hidden.

    Do you think I should just forget about trying to figure out this problem?  Just say something like "this is my program it would work if WM allowed data connections / wifi /gps when idle, but as it dosen't the only option is to port it to another OS"

    (also I don't want to prevent a power off just stop it from suspending/turning off my connections)

    also I find unattended mode very confusing as it is ment to turn off screen backlight and speaker(from a description I read somewhere maybe thats the problem), I have found an example of using unattended mode where sound is played so its happy to override its power down of the speaker but not the various connections - strange.

    Monday, September 7, 2009 7:20 PM
  • Hi,

    You may find Joel's code project page useful regarding powering the wifi on :-

    http://www.codeproject.com/KB/mobile/WiMoPower1.aspx

    I wouldn't go as far as saying the only option is to port to another OS however you may want to rethink the usage of these connections. Maybe, the code that does run when the device is fully powered on can be a little more proactive by checking the availability of connections. Without knowing exactly what you trying to achieve it is slightly tricky to suggest a better strategy. If your application does rely so heavily on data connections then how do you handle the loss of signal or movement out of range?

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked as answer by ZHE ZHAO Monday, September 14, 2009 2:45 AM
    Monday, September 7, 2009 7:28 PM
  • As a slight update I have found that in some cases registery hacks allow wifi to stay on in suspended mode so hopefully will also allow turning on/off of wifi. If that works then I still need to find a way to allow dataconnections and gps.
    Monday, September 7, 2009 7:39 PM
  • Hi Paul, thanks for trying to help me out. I have gone through that post and it is excellent but unfortunately dosen't have the answer to my problem.

    The main focus of my app is being able to obtain location in as many situations as possible. if I have gps then great this is prefered, if not I then try using either wifi positioning or using a few online databases of cell ids

    for gps only gps is needed

    for wifi I need both wifi to be on and an active dataconnection, wifi to obtain the mac addresses of any wifi routers and the dataconnection to query online databases

    for cellid's I just need a dataconnection.

    just so I can test it I could keep to phone alway powered on using idletimerreset but that really is horrid as it will be draining power constantly.

    are there any functions which cause the phone to wake up maybe? it might look a bit weird but maybe if there is a notification function or something similar which displays a message to the user then I would assume it would wake up the phone.

    does anyone know of such a function?
    Monday, September 7, 2009 7:49 PM
  • I have gone through the article paul posted above again and noticed a reference to SetSystemPowerState
    there is no code for its use but this may just be the answer to my prayers

    here is the documentation on msdn

    http://msdn.microsoft.com/en-us/library/ms920754.aspx

    I really don't understand it very well can anyone descifer this and show me how I can use it in a c# application

    I have seen DWORD in pinvoked methods but what is LPCWSTR?

    • Marked as answer by ZHE ZHAO Monday, September 14, 2009 2:46 AM
    Monday, September 7, 2009 8:13 PM
  • Correct me if Im wrong but after reading another artilce on codeprojects I think I declare it like

    [DllImport("CoreDll.dll")]
            public static extern int SetSystemPowerState(string psState, int StateFlags, int Options);

    but how on earth do I convert

    POWER_STATE_ON.. etc into an integer value?

    many thanks
    Monday, September 7, 2009 8:32 PM
  • but how on earth do I convert

    POWER_STATE_ON.. etc into an integer value?
    Re-declare these values in your .net code. Simply copy and paste their declarations from a .h file

    Regards,
    Pawel
    • Proposed as answer by Pawel Koselski Tuesday, September 8, 2009 7:14 AM
    Monday, September 7, 2009 9:23 PM
  • but how on earth do I convert

    POWER_STATE_ON.. etc into an integer value?
    Re-declare these values in your .net code. Simply copy and paste their declarations from a .h file

    Regards,
    Pawel
    Hi how do I actually ge hold of the header file to read from the documentation I know its called "Pm.h", I would really like to know this and not just tje value now as in the future I should be able to do my own pinvokes without hasseling everyone on here.
    Monday, September 7, 2009 9:46 PM
  • Hi how do I actually ge hold of the header file to read from the documentation I know its called "Pm.h", I would really like to know this and not just tje value now as in the future I should be able to do my own pinvokes without hasseling everyone on here.
    After installing Windows Mobile SDK you'll have this file in the installation directory. For example I've got it in the directory:
    %PROGRAM_FILES%\Windows Mobile 6 SDK\PocketPC\Include\Armv4i

    Regards,
    Pawel
    • Proposed as answer by Pawel Koselski Tuesday, September 8, 2009 7:14 AM
    Monday, September 7, 2009 9:53 PM
  • Thanks for the answer. I now have a fully functioning SetSystemPowerState in my program and am happy to say that in idle mode (i.e. screen off) wifi and dataconnection are working. Its not 100% full proof just yet as if the user brings the phone out of idle and them presses the power button again while a check is being done then the phone reverts to unatended which cuts the connections, anyway nearly there.

    Tuesday, September 8, 2009 11:11 AM
  • Hi Chris.

    Iam trying to achieve the exact same thing. Just posted this actually
    http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/fccd1bb5-01b5-4049-bc48-cef0d93cf296

    Would you be willing to share your code ?
    Tuesday, September 8, 2009 6:56 PM