{"id":152,"date":"2007-04-13T15:25:04","date_gmt":"2007-04-13T15:25:04","guid":{"rendered":"http:\/\/dalelane.co.uk\/blog\/?p=152"},"modified":"2007-04-13T17:43:44","modified_gmt":"2007-04-13T17:43:44","slug":"re-where-am-i","status":"publish","type":"post","link":"https:\/\/dalelane.co.uk\/blog\/?p=152","title":{"rendered":"RE: Where am I?"},"content":{"rendered":"<p>I <a href=\"http:\/\/dalelane.co.uk\/blog\/?p=151\">mentioned yesterday<\/a> that I never got round to writing the bit of code for my location service client which would look for known wi-fi access points. <\/p>\n<p>To recap, the idea is that my phone should be able to look for the access points within range, comparing the SSIDs against a list of known locations. If a match is found, it looks up the name and GPS coordinates of the location from the known store, and uses an HTTP request to send the update to <a href=\"http:\/\/dalelane.co.uk\/locserv\/currentloc.php?locusername=dalelane&#038;format=gmap\" target=\"_blank\">the server<\/a>.<\/p>\n<p>It was really easy &#8211; the interesting bit of the code looks like this&#8230;<\/p>\n<p><!--more--><\/p>\n<pre><code>\/\/ get wifi adapters\r\nAdapterCollection adapters = Networking.GetAdapters();\r\n\r\n\/\/ look through each adapter in turn for the Wifi one\r\n\/\/  (e.g. don't use ActiveSync, bluetooth etc.)\r\nforeach (Adapter adapter in adapters)\r\n{\r\n    if (adapter.IsWireless)\r\n    {\r\n        \/\/ look for access points known to the adapter\r\n        AccessPointCollection accessPoints = adapter.NearbyAccessPoints;\r\n\r\n        \/\/ refresh the list of known SSIDs?\r\n        if (blnRefreshList)\r\n        {            \r\n            accessPoints.Refresh();\r\n        }\r\n\r\n        \/\/ look through each known access point in turn\r\n        foreach (AccessPoint ap in accessPoints)\r\n        {\r\n            \/\/ look for the access point name in our \r\n            \/\/  list of known locations \r\n            \/\/ \r\n            \/\/ access point name - the SSID - is    \r\n            \/\/        ap.Name\r\n            \r\n            if (blnMatchFound)\r\n            {\r\n                \/\/ found a SSID which matches a known location\r\n\r\n                \/\/ send the update to the server\r\n                \/\/  using the details from our list of known\r\n                \/\/  locations\r\n\r\n                \/\/ don't bother looking for any other matches\r\n                return;\r\n            }\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Okay, so I admit&#8230; I cheated. Slightly.<\/p>\n<p>I&#8217;m using the <a href=\"http:\/\/www.opennetcf.com\/\" target=\"_blank\">OpenNETCF shared source library<\/a> because there isn&#8217;t really much support to do this in .NET Compact Framework, and I didn&#8217;t fancy having to write it myself \ud83d\ude42<\/p>\n<p>A good introduction to the capabilities of the library for this sort of thing can be found on the <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/aa446491.aspx#build_wifi_discover_app_netcf2_topic4\" target=\"_blank\">MSDN article: Building a Wi-Fi Discovery Application<\/a>, which was a big help in putting the above code together quickly.<\/p>\n<p>After a quick test, it seems to work fine. As a first stab, it&#8217;s fine. I&#8217;m not a big fan of polling for updates like this though, and would rather try and go for a more event-driven approach where the client is notified of updates when a new access point is seen. That&#8217;s something for another time, though &#8211; first I wanna finish off the GPS-checking code&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I mentioned yesterday that I never got round to writing the bit of code for my location service client which would look for known wi-fi access points. To recap, the idea is that my phone should be able to look for the access points within range, comparing the SSIDs against a list of known locations. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-152","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=152"}],"version-history":[{"count":0,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"wp:attachment":[{"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dalelane.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}