This page describe how to retrieve the real-time location of a station using the REST API provided by Accuware Indoor Tracking. To run these examples you need:
- a set of Accuware credentials (username and password)
- the siteID
- the pMAC (pseudo MAC address) of the station registered with your Accuware site.
These information are used to create the URL for the request. The URL provides access to a JSON representation of the last station position.
HTTP 404 – Not Found: querying a station that was not active in the site for the past two hours and not registered in the list of known devices will cause the server to return a HTTP 404 – Not Found status code.
Browser access
For debugging and testing, you can retrieve the location of a device using a browser. We recommend installing a plugin such as:
- JSONView and JSONLint for Google Chrome
- or JSONovich for Firefox.
After you have installed the plugin, simply:
- type the URL in the image below with your siteID and the MAC address of the station.
- and supply your Accuware credentials when prompted.
RESTful client (for Chrome)
POSTman is a powerful HTTP client to help test web services easily and efficiently. POSTman can be easily downloaded from the Chrome Webstore at this link.
To retrieve the location of the station with MAC address E8:92:A4:99:36:F9 inside site 1001, you have to:
- Install POSTman from the link above and access the POSTman app in Chrome by clicking the Apps button (located in the top-left corner of your browser) and the Postman – REST Client icon.
- Insert the following URL into the Enter request URL here text field: https://its.accuware.com/api/v1/sites/1001/stations/E8:92:A4:99:36:F9/
- Choose GET from the drop-down menu.
- Click on the button URL params.
- Click on the Basic Auth tab.
- Username: your_username.
- Password: your_password.
- Click on the Refresh Header button.
- Click on Send.
Additional REST clients for your browser:
- for CHROME: ADVANCED REST CLIENT: https://chrome.google.com/
webstore/detail/advanced-rest- client/ hgmloofddffdnphfgcellkdfbfbjel oo?utm_source=chrome-ntp-icon - for FIREFOX: RESTClient: https://addons.mozilla.org/en-
us/firefox/addon/restclient/
cURL (command line)
Another easy way to access the Indoors for Tracking REST API is using the command line tool cURL freely available at https://curl.haxx.se/. cURL is a command line tool for transferring data with URL syntax. To install and use cURL:
- Download cURL at this URL: https://curl.haxx.se/download.
html - Unzip cURL in a folder on your PC (e.g. C:\curl).
- Open a shell/command line and go in the cURL folder (e.g. C:\curl).
- Type the following string in your shell substituting:
- username, password and {siteId} with the information provided in the Accuware Activation email.
- {pMac}: with the pseudo MAC address of the station registered with your Accuware site.
1 |
curl -u username:password https://its.accuware.com/api/v1/sites/{siteId}/stations/{pMac}/ |
Objective-C
Source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
NSString *site_id = @"0000"; NSString *station_mac = @"00:00:00:00:00:00"; NSURLCredential *credential = [NSURLCredential credentialWithUser: @"username" password: @"password" persistence: NSURLCredentialPersistenceForSession]; NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc] initWithHost: @"its.accuware.com" port: 80 protocol: @"http" realm: @"Accuware Wi-Fi Location Monitor" authenticationMethod: NSURLAuthenticationMethodHTTPBasic]; [[NSURLCredentialStorage sharedCredentialStorage] setDefaultCredential: credential forProtectionSpace: protectionSpace]; [protectionSpace release]; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat: @"https://its.accuware.com/api/v1/sites/%@/stations/%@/", site_id, station_mac]]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL: url]; NSURLResponse *response = nil; NSError *error = nil; NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error]; NSDictionary *jsonObj = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &error]; NSLog(@"Station: %@", [jsonObj objectForKey:@"mac"]); NSLog(@"loc.lat: %.6f", [[[jsonObj objectForKey: @"loc"] objectForKey: @"lat"] doubleValue]); NSLog(@"loc.lng: %.6f", [[[jsonObj objectForKey: @"loc"] objectForKey: @"lng"] doubleValue]); |
Java
The Restlet framework provides a convenient access the API from Java. Download the Java SE edition archive and extracts the files in a directory of your choice.
Locate and add to your CLASSPATH the following JAR files:
1 2 3 |
org.restlet.jar org.restlet.ext.json.jar org.json.jar |
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import org.json.JSONObject; import org.restlet.data.ChallengeScheme; import org.restlet.ext.json.JsonRepresentation; import org.restlet.resource.ClientResource; public class ItsClient { private final static String BASE_URL = "https://its.accuware.com/api/v1/"; private final static String SITE_ID = "0000"; // Your site ID here private final static String STATION_MAC = "00:00:00:00:00:00"; // The station's MAC address private final static String USERNAME = "username"; // Your username private final static String PASSWORD = "password"; // Your password public static void main(String[] args) throws Exception { // Set the request parameters String url = BASE_URL + "sites/" + SITE_ID + "/stations/" + STATION_MAC + "/"; ClientResource itsClient = new ClientResource(url); itsClient.setChallengeResponse(ChallengeScheme.HTTP_BASIC, USERNAME, PASSWORD); // Retrieve and parse the JSON representation JsonRepresentation jsonRep = new JsonRepresentation(itsClient.get()); JSONObject jsonObj = jsonRep.getJsonObject(); // Output results System.out.printf("Station: %s\n", jsonObj.getString("mac")); System.out.printf("loc.lat: %.6f\n", jsonObj.getJSONObject("loc").getDouble("lat")); System.out.printf("loc.lng: %.6f\n", jsonObj.getJSONObject("loc").getDouble("lng")); } } |
C#
The C# example uses JSON.NET to parse the response. The library is available at json.codeplex.com.
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
using System; using System.Collections.Generic; using System.Text; using System.Net; using System.IO; using Newtonsoft.Json.Linq; namespace ItsClient { class Program { private const string BASE_URL = "https://its.accuware.com/api/v1/"; private const string SITE_ID = "0000"; // Your site ID here private const string STATION_MAC = "00:00:00:00:00:00"; // The station's MAC address private const string USERNAME = "username"; // Your username private const string PASSWORD = "password"; // Your password static void Main(string[] args) { // Set the request parameters string url = BASE_URL + "sites/" + SITE_ID + "/stations/" + STATION_MAC + "/"; HttpWebRequest webreq = (HttpWebRequest)System.Net.HttpWebRequest.Create(url); string authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(USERNAME + ":" + PASSWORD)); webreq.Headers["Authorization"] = "Basic " + authInfo; // Retrieve and parse the JSON representation StreamReader strReader = new StreamReader(webreq.GetResponse().GetResponseStream()); String response = strReader.ReadToEnd(); JObject jsonObj = JObject.Parse(response); // Output results Console.Out.WriteLine("Station: " + (string) jsonObj["mac"]); Console.Out.WriteLine("loc.lat: " + (double) (jsonObj["loc"])["lat"]); Console.Out.WriteLine("loc.lng: " + (double) (jsonObj["loc"])["lng"]); } } } |
Ruby
This example uses the JSON library for Ruby available as a gem:
1 |
gem install json |
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
require 'rubygems' require 'json' require 'net/http' SERVER = 'its.accuware.com' SITE_ID = '0000' # Your site ID here STATION_MAC = '00:00:00:00:00:00' # The station's MAC address USERNAME = 'username' # Your username PASSWORD = 'password' # Your password Net::HTTP.start(SERVER) {|http| # Set the request parameters req = Net::HTTP::Get.new("/api/v1/sites/#{SITE_ID}/stations/#{STATION_MAC}/") req.basic_auth USERNAME, PASSWORD # Retrieve and parse the JSON representation response = http.request(req) obj = JSON.parse(response.body) # Output the results puts "Station: #{obj['mac']}" puts "loc.lat: #{obj['loc']['lat']}" puts "loc.lng: #{obj['loc']['lng']}" } |
HTML/Javascript
The source code for the Base 64 library is available at this page. To run this example save the code in a file named Base64.js in the same directory as the HTML file below.
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<!DOCTYPE html> <html> <head> <title>Accuware Indoors for Tracking Javascript Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="Base64.js"></script> </head> <body> <h1>Accuware Indoors for Tracking Javascript Example</h1> <div id="results"></div> <script type="text/javascript"> $(document).ready(function() { var BASE_URL = "https://its.accuware.com/api/v1/", SITE_ID = "0000", // Your site ID here STATION_MAC = "00:00:00:00:00:00", // The station's MAC address USERNAME = "username", // Your username PASSWORD = "password"; // Your password // Send the request jQuery.support.cors = true; // enable cross-site scripting $.ajax({ type: "GET", url: BASE_URL + "sites/" + SITE_ID + "/stations/" + STATION_MAC + "/", beforeSend: function(jqXHR) { jqXHR.setRequestHeader("Authorization", "Basic " + Base64.encode(USERNAME + ":" + PASSWORD)); }, success: function(station) { // Output the results if (typeof station === "string") { station = JSON.parse(station); } $("#results").html( "Station: " + station.mac + "<br />" + "loc.lat: " + station.loc.lat + "<br />" + "loc.lng: " + station.loc.lng + "<br />" ); }, error: function(jqXHR, textStatus, errorThrown) { alert('Error'); } }); }); </script> </body> </html> |