{"id":1107,"date":"2014-05-27T20:22:39","date_gmt":"2014-05-27T20:22:39","guid":{"rendered":"https:\/\/zogspat.tk\/blog\/?p=1107"},"modified":"2014-05-27T20:22:39","modified_gmt":"2014-05-27T20:22:39","slug":"location-display-arduino-based-clock","status":"publish","type":"post","link":"https:\/\/the-plot.com\/blog\/?p=1107","title":{"rendered":"Location Display &#8211; Arduino Based Clock"},"content":{"rendered":"<p>Once I finally got everything working with the <a href=\"https:\/\/the-plot.com\/blog\/?p=1070\">weather station clock<\/a>, predictably, it started to lose its appeal. So I&#8217;ve taken the bones of it and refactored to display my current location. The source of the location data is another little iOS app, this time using background fetch.<\/p>\n<p>I may split the various moving parts of this into a couple of posts. There are 6 in all, most of which I&#8217;ve cannibalised from the weather app. I&#8217;ll only talk about the new [or what I think are more interesting pieces]. And as I&#8217;ve mentioned before, messing with this kind of data has personal privacy implications. While people may not be interested, it&#8217;s best to make it difficult. The components are:<\/p>\n<ul>\n<li>The iOS app generating the data.<\/li>\n<li>This posts to my hosting service via a rest interface called <a href=\"https:\/\/github.com\/gilbitron\/Arrest-MySQL\">Arrest-MySQL<\/a>.<\/li>\n<li>There is a database behind the REST interface, which is on my hosting service.<\/li>\n<li>In order to limit the number of annotations \/ pins on the iOS app, I trim them with a SQL script embedded in PHP [the latter is a restriction imposed by my hosting service]. I call this as a nightly cron job from the Pi.<\/li>\n<li>I then display this via pretty much the same Arduino sketch that for the clock for the weather data.<\/li>\n<li>This receives data via Serial USB from the Pi based on a &#8216;nohup&#8217; Perl script. I start and check this is running every 10 minutes using cron.<\/li>\n<\/ul>\n<p>There is a 7th: we are going to South East Asia in a while, so I&#8217;ve written another little iPad app which my mother in law can use to track us with. My idea; I thought she&#8217;d be interested :).<\/p>\n<p>I&#8217;ll start with the iOS app.\u00a0One of the most immediate points to note about the iOS 7 background fetch capability is that, in comparison to using the Significant Change mechanism I&#8217;ve <a href=\"https:\/\/the-plot.com\/blog\/?p=931\">implemented before<\/a>, it&#8217;s a lot gentler on the battery. While we are comparing the two, the fetch has two frequency settings: &#8216;none&#8217; and &#8216;a lot&#8217;. I guess this might be something that Apple might increase the granularity on at some point in the future.<\/p>\n<p>I guess there is a shopping list of features that I&#8217;ve picked up along the line which raise this above &#8216;bare bones&#8217;. The first is that if there is no network, I allow a manual &#8216;pin drop&#8217; which writes the current coordinates to Core Data. Each time the background fetch fires [only when the network is available], I try to post these via the REST interface.<\/p>\n<p>I also attempt to use Google&#8217;s GeoCoding API, which converts the latitude and longitude into a string for the given address, which then subsequently appears on the map annotation, or on the clock&#8217;s LCD display. I have to admit that in both instances, this is a bit of a dog, due to character limits, and custom annotations with mapping &#8211; well, while I&#8217;ve done it <a href=\"https:\/\/itunes.apple.com\/gb\/app\/pin-your-pics\/id592822522?mt=8\">before<\/a>, it&#8217;s substantially more effort than what this app warrants . I&#8217;m also not too sure what Google is going to return if we happen to be dropping location data in a jungle location with fantastic WiFi [!].<\/p>\n<p>One more confession on the Core Data approach: originally I thought I would store failed writers to the database based on Reachability telling me I was offline when the background event fired. Actually, iOS does this for you: no network, no attempt to do a background fetch. While this is obvious, it never occurred to me based on prior experience with the Significant Change functionality which percolates away based on cell tower activity.<\/p>\n<p>One or two more points of interest for the mobile app. There are limits on what you can do with the network in terms of libraries used \/ delegates available, so <a href=\"http:\/\/stackoverflow.com\/questions\/21032751\/ios-background-processes-and-afnetworking\">no AFNetworking<\/a>. Actually for what I want to do in the foreground, AFNetworking is much too rich: for instance, I had to Google to find a workaround to its rather sticky caching. Also, something that really stumped me until I thought about it: if you are dynamically returning results [such as from the REST interface] don&#8217;t bother trying to plumb in a network progress indicator, unless your server is also setting a Content Length header. That&#8217;s a couple of hours of my life I&#8217;m not getting back :).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Once I finally got everything working with the weather station clock, predictably, it started to lose its appeal. So I&#8217;ve taken the bones of it and refactored to display my current location. The source of the location data is another &hellip; <a href=\"https:\/\/the-plot.com\/blog\/?p=1107\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-1107","post","type-post","status-publish","format-standard","hentry","category-ios-development","category-tech"],"_links":{"self":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1107"}],"version-history":[{"count":1,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions"}],"predecessor-version":[{"id":1108,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1107\/revisions\/1108"}],"wp:attachment":[{"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/the-plot.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}