Some Bits: Nelson's log

9 posts about iphone

Wanderings tracker vs GPSLogger

Summary: after 9 months, the GPS data being logged by GPSLogger on Android looks good to me. At least good enough for Wanderings’ location tracking and heatmap.

One casualty of my switch from iPhone to Android is my own Wanderings app, a lightweight GPS tracker that Brad and I worked on together. There’s an iPhone app that tracks your movements and records data and a webapp that displays the data. But we don’t have an Android version of our tracker and I’ve been unmotivated to learn enough Android to write one.

I have been running Mendahk’s excellent GPSLogger though and it is faithfully recording my location every day to GeoJSON and CSV files in Google Drive. I finally got around to collecting all that data and visualizing it with our web app. Qualitatively it looks the same as the data collected a year ago by the Wanderings tracker. That’s good! See screenshots below.

I haven’t done a deep quantitative comparison. But GPSLogger recorded 218,451 points over 284 days, of which 90,877 points were more than one minute apart from each other (a cutoff we use). By comparison our own tracker only stored 6248 locations for me over 574 days. That’s 319 points a day compared to 11! GPSLogger calmed down a whole lot though starting in September, down to about 70 points a day. I suspect that’s when I disabled passive location tracking, resulting in many fewer points logged.

Still GPSLogger is recording 7x as many points as Wanderings. The extra points are harmless to the visualization output but they do incur some storage and processing overhead. The Wanderings tracker is using the iOS Significant Location Change service and only seems to record points when you’re really moving. GPSLogger is configurable in recording granularity. I have it being somewhat aggressive: GPS/GNSS locations, network locations, and a 60 second logging interval with a 10 meter distance filter to log a new point.

I went ahead and looked at distances between points in the GPSLogger output using geopy’s calculation. A whole lot of pairs of points are less than 20 meters apart. I don’t really know what’s correct here, since you do want to capture data with fidelity when the subject is moving. Probably overthinking it. Here’s a quick and dirty histogram of distances for all pairs less than 100 meters apart.

And here’s the promised gallery of app screenshots. Two similar time periods, one year apart. The older is the iPhone tracker and the newer is GPSLogger on Android. They really do look similar.

Cellular data tracking on iOS

My Wanderings app has a problem; when it’s running it sometimes induces iOS to consume a lot of data in the Time & Location service. Like 30MB a day. Because the data usage isn’t in our own app, but rather the iOS, it’s hard to figure out what’s going on. I ended up setting up a second iPhone with a prepaid account just to have a phone that is running nothing but Wanderings to try to figure out what is going on.

Still tricky to monitor cellular data usage on an iPhone. The Settings / Cellular page does give info but you have to think to look at it regularly to record data. Not sure there’s any good way to automate that, but I’ve tried a couple of apps that are aimed at helping people monitor their cellular contract usage.

MyDataManager is the most promising so far. It has a graph of hourly data usage. What’s promising is it sets up some sort of VPN config on the phone that it uses for monitoring. They promise your traffic isn’t actually routed through a network VPN, so my guess is it’s a local-to-iPhone thing that gives them more monitoring ability. Just set it up. Update: not impressed with the app. It only measures when you launch the app, so no graph of history. And it seems to consume a lot of data itself.

MobiStats is what I tried first. It also has an hourly graph but near as I can tell the data is only populated when you launch the app, not regularly in the background. That may be an iOS limitation, dunno.

Both apps also have a feature to record where you are using data, not just when, using location services. Neat idea! But because I’m testing iOS Location Services myself I don’t want to muddy the water turning that on.

Update: neither app seemed to track usefully, they both only recorded new data when I ran the app in the foreground. A little surprised that was the case with MyDataManager, I’d hoped the VPN would give it more logging ability. Also that app used a bunch of data on its own.

 

Copying music to an iPhone in 2018

I tried to copy some new music I bought to my iPhone. In 2018 this is apparently impossible if you want to use iTunes / Apple Music on the phone to play it.

Well it is possible, if you happen to be sitting in front of the One True Computer that has been managing your iPhone sync all along. You can just add some new music and press the sync button again and it works. But if you have the temerity to have a second computer and try to copy music from that computer via iTunes sync, it will fail. Because iTunes will first insist you delete all the music on your phone that’s not present on this second computer. Apple doesn’t deign to let you keep your music. I’m not sure if this is because they assume you are a criminal or if they are just incompetent at multi-way sync.

There used to be a variety of hacks to work around this. For awhile you could clone the library key and fool iTunes into thinking two computers were the same; this no longer works. Some advice has you clicking “manage music manually” in iTunes; I think this sort of helps, but only still if you have access to the full original music library on the second computer. Finally there’s a bunch of third party programs that claim to be file explorers for iTunes that let you copy in music in an unsanctioned / flexible way. I tried several of these for Windows and literally none of them worked. Also none seem really free; they want to charge $40 for the ability to copy a few files. (I fear I may have gotten Computer Herpes installing all this sketchy software.)

Anyway, the only solution I’ve really found is VLC Mobile. It’s back on the App Store, or maybe it never left. And it will play files you copy over via the iTunes File Sharing tab. You won’t be able to play them in the usual Apple Music app, but you will be able to play them. I also fear VLC Mobile doesn’t support CarPlay, another Apple lock-in system, but I haven’t tried it.

While I’m here; playing video files has the same library problem. For that I use Infuse, a third party movie player which is excellent and has its own file store.

(The music in question is Autechre NTS Sessions: 8 hours of glorious bleepy bloopy glitches from Bleep / Warp. Good stuff.)

Observed iPhone location accuracy

Our Wanderings project uploads location fixes with the iOS significant location changes APIs. It includes an accuracy number, distance in meters, and occasionally we get points with accuracies > 1000m. We’re about to stop displaying those, but before I do here’s what the data looks like:

Screenshot_1.png

That shows most points have an accuracy of 10m, a significant number have an accuracy of 65m, and a few have 1414m. This histogram tool is misleading, there are also 15 points with an accuracy > 1414m. (Shout out to 7094 meters; you did your best, little iPhone).

If I had to guess, I’d say 1414m means “location from a single cell tower” and 65m means “location from a single wifi access point”. But who knows. It’s possible to ask the iPhone to give you more accurate fixes, we’re deliberately only using the most low power location monitoring to conserve battery life.

 

MQTT, OwnTracks, and location tracking

I want a passive location tracker on my phone, something to tell me where I’ve been over the span of years. Google Timeline + Android does this pretty nicely and this blog also has previous notes on Fog of War and other gamified apps. I was using OpenPaths on my iPhone to do something similar, but it was abandoned. The backing server is already gone and the app will die with iOS 11.

So what to do? A friend suggested OwnTracks, an iOS tracker. This isn’t civilian software; there’s no public service. The docs are all about running your own custom server to collect your location data. But the iOS tracker is capable. In particular you can choose battery vs. accuracy. You can either record your position every N seconds / every M meters, which takes about 10% of your battery an hour. Or you can use a more passive “significant movement” mode that is less sensitive but uses very little battery, maybe 1% an hour. I think that’s what OpenPaths did; I ran it for years without a problem. (There’s also a newer iOS API for “Visits” that also looks useful).

OwnTracks publishes data via MQTT, a message queue protocol designed for Internet of Things apps. It seems awfully complicated and a bit fusty, but if they’ve thought through reliable, low power connections for limited devices I’m glad to use it. The OwnTracks docs have some info on running your own MQTT server but that seemed complicated, so I’ve started with CloudMQTT which has a nice free level.

I created a CloudMQTT account and then just plugged in the Instance Info username/password into OwnTracks and set it to logging. CloudMQTT has a “Websocket UI” that shows you the message stream to verify the plumbing is working. OwnTracks reports look like this:

{
"batt":98,
"lon":13.41240532107618,
"acc":1414,
"vac":10,
"lat":52.53526024421524,
"t":"t",
"_cp":true,
"conn":"m",
"tst":1505981237,
"alt":53,
"_type":"location",
"tid":"fi"
}

So that all works. Now what about capturing that data for myself? After some false starts I ended up at paho-mqtt, a Python client. The example client on that page more or less works, except you have to modify the on_connect() function to take a fourth flags parameter. (That’s a hint this code is musty.) The example connects to some public MQTT endpoint with a bunch of events flying by so you know it worked. Eventually one sent non-UTF8 and broke the Python code, but at least it was working.

Last step was to reconfigure the sample client to connect to my CloudMQTT instance. To get that working I had to create a new user and set it up with the ACL controls. (Wildcard access, read/write). For some reason the main user/login didn’t work; maybe because it was in use by OwnTracks? I also had to call client.subscribe() to get messages on my specific OwnTracks topic; not sure if that is supposed to be necessary.

Cloud MQTT also has support for forwarding events to Amazon Kinesis. I set this up hoping it was an easy way to get at the data but it just adds complexity and another system for me right now. There’s probably some way to feed the data into a database with AWS plumbing that might be nice. And it’ll scale!

Things to learn more about with MQTT:

  • Is MQTT a living tech, or is it abandoned?
  • CloudMQTT user management
  • paho.mqtt: naked TCP vs TLS vs Websockets
  • MQTT topics and subscriptions
  • Is Amazon Kinesis interesting for my application? Would be nice to have less code + servers to manage

 

3d touch on iPhone 6S

I was curious how the 3D Touch feature worked on the iPhone 6S. Here’s a reasonable explanation based on a iFixit teardown. tl;dr: low resolution capacitive sensors measure the distance between your finger and the base of the phone. The glass bends a bit.

I can’t say I find the UI gesture very useful. The lack of true tactile feedback makes it hard to know which gesture you’re making, and the lack of much in the UI using the sensor means often nothing happens. We need someone to figure out a great use for it, and that in turn probably requires more market saturation.

Notes on an iPhone upgrade

I just upgraded my iPhone 5S to a 6S. The basic backup-and-restore process works remarkably well, as did Verizon’s activation. However a bunch of stuff didn’t carry over. Some of this is my own fault, some of it is security, and some of it is just dumb.

  • Logins. I had to log back in to all these apps like Twitter, Gmail, etc. I’m not using the iCloud Keychain, perhaps that would have solved this. Some apps like Uber, Nest, and TriMet Tickets seem to not work after the restore to new device; the login hangs. It’s not consistent, some apps worked fine. Uber even asked for a password, then hung. I had to delete and reinstall it.
  • Authenticator tokens. I have three MFA tokens on Google Authenticator as well as a separate authenticator from Blizzard. Had to manually set those up again on the new device, which in many cases requires access to the old device’s authenticator. Again I think iCloud Keychain might have helped with this.
  • Music. None of my music copied over. That’s probably because I got hit with another iTunes debacle at some point and iTunes on my computer didn’t have access to my music library. Apple refuses to copy music off of an iPhone, I guess because they think that’s a meaningful piracy prevention mechanism.
  • Cached app data. Some apps cache data locally, like Overcast’s podcasts. That cache seems to have not been copied over. That’s not terrible, but mildly inconvenient.
  • Application data. iOS has a sort of per-app filesystem you can find, where some apps like Wiki Offline store data they downloaded. None of that data was saved or restored. This seems like a serious flaw to me; oftentimes that data is irreplaceable, or at least inconvenient to restore. I ended up copying it over manually.
  • OpenVPN setup. The basic “enable VPN” button still works, so something carried over. But the OpenVPN app was not installed correctly; greyed out for some reason. Also the OpenVPN app has a file in the per-app filesystem I need.

iPhone consolidated.db location tracking notes

I’m trying to understand the consolidated.db iPhone location database, which means understanding how iOS stores and managing data. Here’s some notes.

Resources

  1. @aallan’s original announcement
  2. iPhone Tracker (Objective C code)
  3. Technical instructions from howto.wired
  4. nphonetrack (.NET code)
  5. iPhoneLs.py
  6. iphone-tracker.py
  7. Quick start for sqlite3
Notes
  • When you make a backup of an iPhone, it creates a big directory full of files with random 160 bit filenames. These are named files in the iPhone that iphonels.py can display. My 3 biggest files are named
    HomeDomain::Library/Caches/com.apple.WebAppCache/ApplicationCache.db
    AppDomain-com.foreflight.ForeFlightMobile::Documents/Procedures.zip
    RootDomain::Library/Caches/locationd/consolidated.db
  • consolidated.db is the file with the location data in it. It’s a sqlite3 database.
  • The juicy tables are (apparently) CellLocation and WifiLocation. The *Counts tables seem to contain just a row count. Presumably the Boxes tables are some sort of spatial index. I can find no record of how often I was at a specific location other than what’s implicit in the timestamps and density of cell/wifi locations.
  • I have 32,013 rows in CellLocation, 171,040 rows in WifiLocation
  • Timestamps are like 309803342: I believe this is NSDate seconds since 1 Jan 2001. Add 978307200 to get it in seconds since Unix 1970 epoch.
  • HorizontalAccuracy varies from 50-300 for WifiLocation, and up to 80,000 for CellLocation.
  • Confidence is 0, 50, 60, 65, 68, or 70
  • Speed and Course are always -1 (no surprise).
Some quicky sqlite3 shell code
.mode csv
.output wifilocation.csv
select Timestamp, Latitude, Longitude from WifiLocation order by Timestamp;
.output CellLocation.csv
select Timestamp, Latitude, Longitude from CellLocation order by Timestamp;
Some pasted info from sqlite3
sqlite> .tables
CdmaCellLocation                   CellLocationCounts
CdmaCellLocationBoxes              CellLocationHarvest
CdmaCellLocationBoxes_node         CellLocationHarvestCounts
CdmaCellLocationBoxes_parent       CellLocationLocal
CdmaCellLocationBoxes_rowid        CellLocationLocalBoxes
CdmaCellLocationCounts             CellLocationLocalBoxes_node
CdmaCellLocationHarvest            CellLocationLocalBoxes_parent
CdmaCellLocationHarvestCounts      CellLocationLocalBoxes_rowid
CdmaCellLocationLocal              CellLocationLocalCounts
CdmaCellLocationLocalBoxes         CompassCalibration
CdmaCellLocationLocalBoxes_node    Fences
CdmaCellLocationLocalBoxes_parent  Location
CdmaCellLocationLocalBoxes_rowid   LocationHarvest
CdmaCellLocationLocalCounts        LocationHarvestCounts
Cell                               TableInfo
CellLocation                       Wifi
CellLocationBoxes                  WifiLocation
CellLocationBoxes_node             WifiLocationCounts
CellLocationBoxes_parent           WifiLocationHarvest
CellLocationBoxes_rowid            WifiLocationHarvestCounts

CREATE TABLE CellLocation (
  MCC INTEGER,
  MNC INTEGER,
  LAC INTEGER,
  CI INTEGER,
  Timestamp FLOAT,
  Latitude FLOAT,
  Longitude FLOAT,
  HorizontalAccuracy FLOAT,
  Altitude FLOAT,
  VerticalAccuracy FLOAT,
  Speed FLOAT,
  Course FLOAT,
  Confidence INTEGER,
PRIMARY KEY (MCC, MNC, LAC, CI));

CREATE TABLE WifiLocation (
  MAC TEXT,
  Timestamp FLOAT,
  Latitude FLOAT,
  Longitude FLOAT,
  HorizontalAccuracy FLOAT,
  Altitude FLOAT,
  VerticalAccuracy FLOAT,
  Speed FLOAT,
  Course FLOAT,
  Confidence INTEGER,
  PRIMARY KEY (MAC));

mobile safari and viewport

Apple’s mobile browser is great, but the viewport meta tag is kind of a hash. There seems to be two conflicting ways to hint to the iPhone or iPad how big to draw things.

  1. width and height. Tells the browser this content is going to render best at a certain width, so render it to that size. width=device-width or width=320 is one way to tell the iPhone not to scale at all. width=600 or the like often solves the problem of stuff looking too small on the iPhone, while still letting it scale. If you set a small width the iPad will scale content up, making it bigger.
  2. initial-scale, minimum-scale, maximum-scale. Gives an explicit scaling factor. The user can override this (unless you disable it).

What’s confusing is if you set both a width and scaling behaviour: which takes precedence?

Mike suggested what seems to work well for maps is setting initial-scale to 1.0 and maximum-scale to 1.0. This keeps Safari from doing its own scaling on the page at all. Even better, when you rotate the device it doesn’t try to scale the width to match the old view; instead it just loads some stuff that was previously off-screen. The only drawback is this effectively sets the width to 320px on an iPhone, you no longer get any in-browser scaling.

What I really want is no scaling at all on the iPad, and 1.5 scaling on the iPhone. I can’t figure out a way to do that without changing the tags depending on what device loaded the page.