In a Large enterprise or factories where they do not use access systems, it becomes difficult to track an employee or even to find which place is crowded at a given time. Without an access system in place, the only other device almost everyone carries is a mobile phone. So given a situation if the whole enterprise is Wi-Fi enabled and when people are more inclined to connect to it. We can make use of the different Wi-Fi access points located in the enterprise and track each person based on the access point he connected.

Taking this scenario, If we want to push the current location from a mobile device, we need some broadcasting event from the mobile which fires when there is a change in access point as we can’t continuously run some code and try to check users current location if it is changed. For this we can use Xamarin.forms plugin WifiInfo(Currently this gives only Android platform implementation) which gives us an Wi-Fi signalstrengthchanged event which fires when there is a change in signal strength.

How to use

  1. Create a xamarin.forms portable project and the nuget reference for wifiinfo plugin. This will add each platform specific plugin implementation reference to the respective platform project of your solution.
  2. Define a class called AccessPoint to save mappings of each Wi-Fi access point with the location it is fixed. Each Wi-Fi access point carries a unique id called Bssid(Plugin gives us this value) which we will use to identify the user location.

 

  1. Declare a class called RoomLocator which contains a dictionary of AccessPoint object types with there Bssid’s as keys and a function which searches and return if a particular Bssid is present in the dictionary. Code as below.

 

 

  1. Add below namespace references to your App.cs of your portable Xamarin forms project.

 

Plugin.wifiinfo exposes a static property CrossWifiInfo.Current which gives access to the plugin functions whereas Abstractions is the namespace that defines custom classes used in the plugin.

  1. Add an event handler to CrossWifiInfo.Current.SignalStrengthChanged event and pass the CrossWifiInfo.Current.BestSignal(This returns an object of type WifiAccessPoinntScanResult containing required details of the best Wi-Fi signal available) object to the GetMyAccessPointDetails function defined in RoomLocator class as below.

This would give an alert whenever there is a change in the Wi-Fi signal frequency means whenever the person is moving around the company. Just to avoid this code running even when the user is connected to his home or other Wi-Fi, we can add more logic so as to allow this to execute only when the person is inside the premises by adding one more check with other property called SSID (available in the plugin) which is a unique id given to the Wi-Fi connection you are connected to.