You are here

Cinterion EHS8 GPS location using JSR179 Java Location API

Showcase, November 15, 2017 - 4:17pm, 1100 views

This project shows how to get the current GPS position of an EHS8 module using the Java APIs; we do not need to use AT Commands to drive the GPS engine.

If using the EHS8 JSR179 API you will need to link a recent version of the "cwmlib_1.0.jar" to your project. This is included in the standard Java Installation CDROM from EHS8 rel 3 arn28 onwards, but also included below for convenience.

If using the EHS8 evaluation unit, on a B80 starter kit for example, then please check the wiring of your u.fl connectors before starting.

eval

The very simplest form of the demo source code looks something like this, but the ZIP file below has a more fully featured demonstrator that you can run.

// Java src code from Alex S. Originally by Michal W.

import javax.microedition.location.*;

Criteria criteria = null;
LocationProvider provider = null;
Location location = null;
criteria = new Criteria();
criteria.setCostAllowed(false);

try {
    provider = LocationProvider.getInstance(criteria);
} catch (Exception e) { e.printStackTrace(); } 

if (provider != null) {
    try {
        location = provider.getLocation(-1);
    } catch (Exception e) { e.printStackTrace(); }

    System.out.println("Location = " + location);
}

// Success:
// Location = "la = xx.987531, lo = yy.911074, al = 99.0, hA = NaN, vA = NaN, tstamp = 1457616936000"

// Fail:
// Location = null

The demo can be installed and run with the following AT Commands - AT^SJAM=0,"a:/GPSfix.jad","" and AT^SJAM=1,"a:/GPSfix.jad",""

Typical working output from the demo will look like this:

[Used indoors with no GPS coverage]

[11:23:40.6] [Main]: Constructor
[11:23:40.6] [Main]: startApp

[11:23:40.6] GPS fix - shows GPS location using Cinterion EHS8 via JSR179 Java Location API.

[11:23:40.6] [MyTestThread]: Test thread waiting to start.
[11:23:40.6] [MyTestThread]: Test thread started.
[11:23:40.6] [MyTestThread]: [MyTestThread]: location = provider.getLocation() javax.microedition.location.LocationException: location could not be retrieved or timeout expired
[11:26:12.2] ... Location = null
[11:26:12.2] [MyTestThread]: Location = null

[11:26:17.4] [MyTestThread]: [MyTestThread]: location = provider.getLocation() javax.microedition.location.LocationException: location could not be retrieved or timeout expired
[11:28:49.7] ... Location = null
[11:28:49.7] [MyTestThread]: Location = null

[11:28:54.8] [MyTestThread]: [MyTestThread]: location = provider.getLocation() javax.microedition.location.LocationException: location could not be retrieved or timeout expired
[11:31:27.1] ... Location = null
[11:31:27.1] [MyTestThread]: Location = null

--

[Used outdoors with acceptable GPS coverage (xx and yy would be substituted for your actual coordinates)]

[11:43:06.5] [Main]: Constructor
[11:43:06.5] [Main]: startApp

[11:43:06.5] GPS fix - shows GPS location using Cinterion EHS8 via JSR179 Java Location API.

[11:43:06.6] [MyTestThread]: Test thread waiting to start.
[11:43:06.6] [MyTestThread]: Test thread started.

[11:43:06.6] [MyTestThread]: Location = la = xx.044703, lo = yy.712823, al = 122.0, hA = NaN, vA = NaN, tstamp = 1510746249000
[11:44:08.6] [MyTestThread]: Location = N xx:02.68218, W yy:42.76938

[11:44:13.7] [MyTestThread]: Location = la = xx.044757, lo = yy.712974, al = 130.0, hA = NaN, vA = NaN, tstamp = 1510746264000
[11:44:23.7] [MyTestThread]: Location = N xx:02.68542, W yy:42.77844

[11:44:28.7] [MyTestThread]: Location = la = xx.044757, lo = yy.712866, al = 138.0, hA = NaN, vA = NaN, tstamp = 1510746283000

[11:44:42.7] [MyTestThread]: Location = N xx:02.68542, W yy:42.77196

--

The demo will not stop until you issue the following AT Command - AT^SJAM=2,"a:/GPSfix.jad",""

[12:25:02.3] [MyTestThread]: [Main]: destroyApp(true)

[12:25:05.8] [MyTestThread]: location = provider.getLocation() javax.microedition.location.LocationException: location could not be retrieved or timeout expired
[12:25:05.8] Location = null
[12:25:05.8] [MyTestThread]: Location = null

[12:25:05.8] [MyTestThread]: Exception java.lang.InterruptedException

[12:25:05.8] [MyTestThread]: continueEx is 'false' so Test thread has finished.
[12:25:05.8] [Main]: destroyApp(true)
[12:25:05.9] MIDlet:Main terminated

mullengers