yashsingh1/xdaforums huggingface dataset:
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
For the developers

The code for unattended mode. So far it's working just fine, and it can be dynamically enabled / disabled. Remember, this is only for PocketPC - Smartphones do not have a "suspended" mode. Let me know if you find any problems.

Some more info on unattended mode:

Power to the System

Power to the PocketPC

Power to the People

Power to the Developers part 1

Power to the Developers part 2

The code is attached.
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Aarg. I have unattended mode complete, but I ran into a problem when syncing the device database and desktop database - if you delete the database on the device, you cannot upload all the data from the desktop again. Problem. This will affect the database structure.

So, to not waste any more time, I'm attaching an update which includes "unattended" mode, plus a number of fixes, but logging to a local database will be disabled for now, until I sort this out.

So, changelog for 0.4:

Added unattended mode for PocketPC

Fixed "apply" or "save" button not refreshing the service settings when clicked for the first time.

Made changes to the service consume a bit less battery life.

Added error message in PocketPC version preventing it from being run on SmartPhone.

Added error checking when retrieving cell info - the Last Update field in the app will now say RILApiException if it cannot successfully get the cell info (see previous discussions with dzalbo).

Added support for logging unique cells to local database + syncing, but it is disabled for now.

Edit: PocketPC version withdrawn. Please get it from the next page.
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
A further explanation of unattended mode

Hi guys,

Just wanted to tell you what the expected behavior should be when unattended mode is enabled.

As previously mentioned, this only applies to Pocket PCs, since Smartphones don't go into suspended mode.

So, on your Pocket PC, if you have enabled unattended mode in the app, the following should happen:

When your device times out because of inactivity (and the screen switches off), it will go into unattended mode instead of suspended mode, allowing the app to keep running, as well as your data connection to be kept alive.

The same should be observed if you hit the power button on the device, which usually suspends it (if unattended mode is enabled, hitting the power button will make it go into unattended mode, rather than suspend mode).

While in unattended mode, the app periodically resets the system idle timer so that the device does not go into suspended mode, from unattended mode. Without resetting the idle timer, the device does indeed transition from unattended to suspend mode.

The system idle timer is not reset if the device is not in unattended mode, otherwise your screen would never turn off due to inactivity.

Please let me know if you find any problems.
[Tilt, TyTN II, MDA Vario III Themes and Apps] andyb2000:
Nice work.

I've installed and got the app setup to run using unattended, so will report back in a day or so with the results on battery life (I'm sure mine already uses this mode so I'll probably not see any change there) and to confirm that it continues to upload, etc on change of cell, etc.

Cheers!
[Tilt, TyTN II, MDA Vario III Themes and Apps] khaytsus:
Could you quickly explain the impact of Unattended vs Suspend in terms of battery life (any anything else... any latency concerns, or interaction with other software such as S2U2, FlexMail, IM+, stuff like that?)

I've read your posts on it, but I'm not sure what conclusion to draw for the 'bottom line' for the end user. :)

EDIT: Aha, I see your note in the application itself, mentioning it might use more battery. But if you're already using background apps (IM+, Flexmail with IMAPD Idle, etc), there is probably no difference? Does it matter if CellID itself is in unattended mode with these types of apps?

I'm running it regardless, just thinking of questions that I have and others might be curious about too. :)
[Tilt, TyTN II, MDA Vario III Themes and Apps] khaytsus:
Excellent information, thanks for typing all of that out! This whole thread is great insight into how WM works. I had no idea how different 'Smartphone' is vs 'Professional' until several weeks into owning my Kaiser/Tilt, and I'm sure I still know very little currently. :)

Sounds like given my usage of FlexMail already puts the phone in Unattended mode, so I'm going to run with it in that mode for now to help see if there are any bugs associated with it.

I, too, tend to charge mid-way because of using online imap and IM, but I'm generally okay as long as I'm on EDGE. HSPA is a much different story (charge 3x a day? Bleh..)

So if I need to really extend battery life, I'll turn off the Unattended mode (after exiting my online apps, etc). My current 'idle' power usage is about 22ma, so that's about 60h with the previous version. Honestly I don't know if it was already in Unattended or not, is there any way to check that? Would be interesting to see. I have a bunch of random stuff installed, but only a handful I think run periodically that could put it into that mode.

Cheers!
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
I think the only way to check (from the user perspective) is to observe the time it takes for "everything to return to normal" when you turn on the device display. If it is a bit sluggish, your device was suspended. If it's instant, then it was unattended. I'll write a little app that logs the power state transitions so one can see exactly what is going on. This is interesting.

Unfortunately I found a bug in the latest update :(

The system idle timer stops resetting if certain other power notifications are communicated to the app in unattended mode, so the device ends up going into suspended mode after a while.

I'll edit this post shortly with an update to the PocketPC version and the code.

Edit: Ok, it has been running for 11 mins now without the device being suspended and the screen is off. Letting it run a little longer.

Edit2: Right, 25 mins of testing and it's working as expected.

Changelog (from 0.4 to 0.4_fix)

Device was going into suspended mode after a while, even if unattended mode was enabled. Fixed.

For the developers, just change the ProcessPowerBroadcast method to the following:

private void ProcessPowerBroadcast(POWER_BROADCAST pbr)
{
bool? isUnattended = null;
switch (pbr.Message)
{
case PowerEventType.PBT_RESUME:
isUnattended = false;
break;
case PowerEventType.PBT_TRANSITION:
if ((pbr.Flags & PowerState.Unattended) == PowerState.Unattended || pbr.SystemPowerState.ToLower() == "unattended")
isUnattended = true;
else
isUnattended = false;
break;
}
if (isUnattended.HasValue)
{
if (isUnattended.Value && !unattended)
{
unattended = true;
timer.Change(5000, IdleResetInterval);
}
else if (unattended && !isUnattended.Value)
{
timer.Change(Timeout.Infinite, IdleResetInterval);
unattended = false;
}
}
}
[Tilt, TyTN II, MDA Vario III Themes and Apps] andyb2000:
Righto,

Reporting back in as had the app (latest) installed and running. At first it appeared to be working fine, I had it on my desk and uploading cell information (my cell switches about every 15 mins, I'm guessing I sit between two cells)

I got home, and it was still uploading, etc, so all looked fine, but overnight/this morning I notice there haven't been consistant uploads. I'll show you what I mean:

So the overnight ones I can understand as I've got the 'dont send if cell is the same' checked, so that'll be why I don't get many of them, but this morning I was sitting in the office at 8:50 and noticed no uploads. I then pressed power on the phone and immediately saw an upload. So perhaps it's not quite keeping awake when the phone is off or something?

Any way I can put on any debug or anything that can help diagnose??

I'll also post up my php scripts that I'm using shortly, that plots the cells onto google maps using a mysql database backend for logging, etc.
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Hi andyb2000,

The update that I published in the previous post should fix that. Can you retest with 0.4_fixed?
[Tilt, TyTN II, MDA Vario III Themes and Apps] andyb2000:
Sorry, should have mentioned I updated to the fixed version before going to sleep last night so it is running the fixed version

(also, could you perhaps display the current running version in the settings screen for easy reference?)
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Ah I see. Good idea about the version number in the settings screen.

I can send you the debug build that I use - it generates quite a lot of log messages and saves them to a trace file.

Will PM you shortly.

EDIT: I never knew that one cannot send attachments with a PM. Anyway, I'm attaching the debug version here.

Make sure you stop the service.

Replace cidservice.exe with the one contained in the .zip file. The executable is located either in "Program Files\CellID Updater" or "Storage Card\Program Files\CellID Updater" depending on where you chose to install it.

Then start the service.

Now, a file called trace.txt will be created in the same folder as cidservice.exe. It will keep getting larger and larger, unless you stop and start the service - then the trace file is recreated from scratch. If you can, let the service run overnight and do not stop it. Then in the morning, please send me the trace file (you can edit out the urls for privacy reasons if you want, but I need the rest of the information).

Another note - please don't open trace.txt on the phone - Word Mobile locks the file and the service will be unable to append to it.

Thanks for helping out!
[Tilt, TyTN II, MDA Vario III Themes and Apps] andyb2000:
lol, i didn't realise that either tbh!

Thats installed and running now so I'll post it over to you tomorrow after its had a chance to run/test things out.

Thanks!
[Tilt, TyTN II, MDA Vario III Themes and Apps] khaytsus:
I'm pretty confident I can confirm this as well, using Fixed with Unattended checked (but as we discussed, I was probably always in Unattended mode anyway).

I typically have a post hourly or more at my house, as there seem to be four towers in a circle around me, about 40% of the time I'm on Tower 1 or 2, about 10% of the time I'm on tower 3 or 4. So from my house, I routinely see one of four towers, and I tend to bounce around a lot. In fact I've even 'had' to write in some heuristics into my CGI to ignore a datapoint if it was one of the last two datapoints to reduce the redundant data from this.

And overnight, I only saw a handful of posts. I compared it to the last three nights, of which I see 10-11 overnight each night.

So not concrete evidence, but fits with what's already been observed.
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Thanks khaytsus.

So you're saying that you're seeing less updates with Unattended mode enabled, than with it disabled? That's really strange.

The trace file that gets generated from the debug version will show us if the app stops working at a certain time (every log entry is timestamped) and what the state of the app is when there is a power transition (for example, from On to Backlight off to Unattended), so we should be able to see why this is occurring.

You're welcome to try it as well if you like, using the instructions from the previous post. The more data the beter.

Personally, the way I tested the app today is that I set it to send out updates through my wifi connection "even if the cell is the same". I just use a server on the local network at work :D. After several hours, the app was still sending out updates. The trace file was around 300kb. I should note that I did power my phone on a number of times though (because of normal usage) so my tests would not be as accurate as an "overnight test".
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Here's that little app that I promised that will show you some of the power notifications that the OS sends out.

This app is not linked in any way to the cellid app. It will not request unattended mode, it just shows the transitions and battery notifications.

Enabling / disabling unattended mode in the main app should yield different results in this app (taking into account my previous posts).

What you'll be interested is if your device goes into the "suspended" state.

The app should work on WM5 / 6 PocketPCs and SmartPhones.
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Hi guys,

I tested the app again last night.

What I did is, I started the service in one room, the phone went into unattended mode, I moved it to another room where I left it charging all night. I set the app to send out updates only if a new cell is encountered.

I was using WiFi to send out updates to one of my PCs.

[The reason I was using WiFi is that it's quite a job to set up DyDNS and get the correct routing in place so that I can expose my PC to the internet - I'm running a script on my router which routes traffic through multiple PPPoE connections. I will eventually set it up though.]

Anyway, so my phone was charging all night, sending out updates through WiFi.

According to the attached trace file (which has the URLs edited out), the app did not stop running at all, until I stopped it this morning. It did not send out many any updates though, but this could be due to the fact that the phone was in one position all night.

So what the trace file shows is that the phone did not go into suspend mode with unattended mode enabled and it kept checking for new cells all night.

I'll run it again tonight with the app set to send out updates even if the cell is the same.

I did find a small issue though - you may have noticed that you get a ThreadAbortedException when you stop the service - that's because if the service is busy with a web update and you press Stop, the thread responsible for the update is almost immediately stopped. I'll fix this in an upcoming update.

@andyb2000: Did you manage to generate a trace file?
[Tilt, TyTN II, MDA Vario III Themes and Apps] PizzaRoll:
CeRunAppAtTime

I am new to the world of the Kaiser and C# development on WM but when I was reading the above, I remembered seeing this function a few weeks ago. The function sets an event with windows and will wake the system from suspend. It might be valuable for those us who don't need to always be in unattended mode.

BOOL CeRunAppAtTime(

TCHAR* pwszAppName,

SYSTEMTIME* lpTime

);

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

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

Any thoughts?

Is this a good idea and can it easily be integrated?
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
CeRunAppAtTime is obsolete and has been replaced with SetUserNotificationEx.

See one of my previous posts for an implementation using CeSetUserNotificationEx. I used named events instead of launching an app, which makes things much easier.

The first issue I had with this is that every device has a Real Time Clock Accuracy that it reports to the OS. If the device doesn't report it, then a value of 10 seconds is assumed (but it can be between 1 and 60 seconds). If you specify that an app or named event is to be run within the RTC Accuracy, then it is scheduled immediately, and not according to the time that you specify.

What this means is that if you're creating a timer based on CeSetUserNotificationEx, your timer interval cannot be less than or equal to the RTC Accuracy. This is not a big issue, but it could mean that your timer interval must be greater than 60 seconds (depending on the device).

The second issue which is more problematic, is that if your timer interval is less than the system idle timeout interval, then the device screen never turns off using this method. In fact, it seems that whenever an app is launched or a named event is set, the system idle timer is reset. That is a problem. This is the main reason why I didn't go with SetUserNotificationEx and instead went with Unattended mode and resetting the system idle timer only if in Unattended mode.

The third issue is that if your device is suspended and the time comes to launch the app or set the named event, the device wakes up for 15 seconds (I think it was 15). If your app (or any other app) does not set the system power state to some other value, the device will go back to suspend after the 15 seconds have elapsed. Now, is 15 seconds enough time? That depends. I've noticed some of the web requests can take up to 8 seconds. Before that, if the data connection is not active, if would take time to activate it. So a reliable method would be to always set the system power state to unattended, which would give you more time. But unattended mode also goes back into suspend mode after a certain time if the system idle timer is not reset. This can be solved programmatically, so it's not a major issue.

Also, remember, resuming the device from suspend mode is much more work for the OS than resuming from unattended mode. So, if your timer interval is in seconds, not minutes, then it's probably better to go with unattended mode, rather than CeSetUserNotificationEx. CeSetUserNotificationEx does make a lot of sense for something which does not occur that often (for example every 5 minutes or more) or something which should happen at a certain time (like an alarm), but for doing something every 30 seconds, my choice was unattended mode.

See this page for the method and notes on RTC accuracy.
[Tilt, TyTN II, MDA Vario III Themes and Apps] PizzaRoll:
It is clear why you decided against the functions. The only bad thing about the unattended mode is other programs do have a chance to consume cpu cycles and thus heavily effect battery life. I guess I will just have to be careful of what I install on my Kaiser.

Thanks for the info
[Tilt, TyTN II, MDA Vario III Themes and Apps] newb5000:
Yes, that is true.

I guess it would be possible to implement a "hybrid" type of timer that, depending on the interval, uses unattended mode if, for example, the interval is less than (as an example) 5 minutes and uses SetUserNotificationEx if the interval is greater - but it will be quite time consuming to create, and testing would be a bit of a pain :D But yeah, something to consider for future updates. We definitely need to test unattended mode more, though.

The big question is: at what point does SetUserNotificationEx become more battery friendly than unattended mode? When the interval is 2 minutes? 5 minutes?

Unattended mode can be disabled in the app currently. Have you seen your battery life being affected when unattended mode is enabled? Is it severely affected?

Edit: Just wanted to add, that it is not difficult to make an app consume less battery life. .NET CF already has OnActivated and OnDeactivate events which can be used to start / stop animations, for example, as described by Mike Calligaro. Also, the code that I posted can also be adapted to notify an app when the power state of the device is "on". Any other power state means that animations should stop (even "backlightoff").

I'm sure that a lot of apps already have power saving features built in.
[Tilt, TyTN II, MDA Vario III Themes and Apps] PizzaRoll:
Last night, i played around with the unattended mode and i lost about 25% of my battery in only 3 hours. Something mean is going on my Kaiser and pretty sure its not the program.

Typically, i check two email accounts about every 15 mins and with the program running in normal operation, there is NO impact on battery life. Plus i get the benefit of every time my device will wake up from suspend to do the email routines, your program will activate and update my position :) or at least that is what appears to happening.

I think for today im gonna switch back normal operations until i find out what is killing my battery so quickly. Ill let you know what i find out
[Tilt, TyTN II, MDA Vario III Themes and Apps] :
Hi Guys,

I've just come across this thread and thought I'd add my comments.

Unattended mode is definitely the right way to go here - I've been doing something similar with GPS rather than CellID for several years. Just in case you haven't, even with unattended mode you need to call SystemIdleTimerReset. The backlight timer is independant of the System Idle timer.

Feel free to have a look at www.wheresadam.co.uk

Not sending updates unless the CellID has changed is good as well to save data.

I'd suggest that knowingthe CellID you've been in and the power - and the CellID you are now in and the power will give you a pretty good idea of heading and a slightly more accurate location.

The next hurdle will be that, running at startup, GPRS can sometimes have problems. You'll need to initate a net connection first before doing anything using OpenNETCF.

Feel free to shout if you want any help or ideas or anything?

Adam

Disclaimer: I produce GPS CF applications commercially and so will help where I can but, as I'm sure you can appreciate, some things will cross over to be a breach of NDA / Conflict of Interest and so I won't be able to comment.
[Tilt, TyTN II, MDA Vario III Themes and Apps] LeeCHeSSS:
Web-updates seem to stop after roughly a day?

I have had the program running in Unattended mode, and it seems to work pretty well. However I do have the impression that it stops sending updates to my webserver after roughly a day.

I have attached my trace log, so you can see if there's something wrong (I don't know what exactly it all means, but around 25-7-08 17:49:54 in my log file, the amount of Power Broadcasts seems to have increased a lot compared to the first part of the log).
[Tilt, TyTN II, MDA Vario III Themes and Apps] acedish:
baeeo.com

Using newb's app (which is very cool!!) I made a site at www.baeeo.com that will geocode users cellid and display it on Google maps. I am working on a facebook api as well so you can share your location with your facebook friends. I also created a simple API to the site to allow developers to build there on app like Newbs for other phones. (I am working on one for a Blackberry now)

I did however run into some glitches on a couple phones, a Blackjack I (upgraded to WM6) and Pantech Duo(WM6). The Duo received a RILException error and on the Blackjack it never displayed an error and would seem to lock up in start mode if I recall, i will check the details and post them here.

Newb if you can email me I would like to give you some credit on the baeeo site and also had a request.

Enjoy.

ACE
[Tilt, TyTN II, MDA Vario III Themes and Apps] LeeCHeSSS:
Nice site, except that it doesn't work in Firefox :)
[Tilt, TyTN II, MDA Vario III Themes and Apps] khaytsus:
I haven't signed in, but the front page works fine here.. Just jumps around quite a lot, but I get the impression that's intentional.

Looks like a great site for stalking, there's some plain hotties on there ;-)
[Tilt, TyTN II, MDA Vario III Themes and Apps] acedish:
I corrected the issue for firefox so it should work now, thanks