Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Integration API Geolocate (ichnaea) in Node-Red

97 views
Skip to first unread message

jyc emea

unread,
Feb 20, 2019, 11:59:30 PM2/20/19
to mozilla-dev...@lists.mozilla.org
Hi,
Actually working on a new project, I'm looking to implement MLS /ichnaea/api/geolocate in Node-Red. I saw possible nodes like Skyhook (node-red-contrib-skyhook) but I really would prefer the Mozilla locating service.

Actually I'm receiving the basic infos from a 2G simcard device (gps+wifi+lbs) in Node-Red. With help, I've built a function node in javaScript in Node-Red which can decode the infos from a specific protocole and translate in a more human language.

I would like to know the way to integrate use the API service to get back the positions. I don't know how to write ...

Someone who can help to run my test, please?


Here is the js code actually collecting the datas with flag = A and flag = else:

###################################START###################################

// flag = A
//IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#
// flag = else
//IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97#

let answer = {}
let elements = msg.payload.replace('#','').split(",") // this gives an array containing the bits
// elements[0] is the long string starting IWAP01
answer.command = elements[0].substr(0,6)
let dateStr = elements[0].substr(6,6) // eg "190215" 15th Feb 2019
answer.date = new Date(Number(dateStr.substr(0,2))+2000, Number(dateStr.substr(2,2))-1, dateStr.substr(4,2)) // 080524 - date
answer.valid = (elements[0].substr(12,1) === "A") // true or false - A or V
if (answer.valid) {
let degreesN = Number(elements[0].substr(13,2))
let minutesN = Number(elements[0].substr(15,7))
let ns = elements[0].substr(22,1) // N or S
let degreesE = Number(elements[0].substr(23,3))
let minutesE = Number(elements[0].substr(26,7))
let ew = elements[0].substr(33,1) // E or W
node.warn(`${degreesN} ${minutesN} ${ns} ${degreesE} ${minutesE} ${ew}`)
answer.latitude = degreesN + minutesN/60 // 2232.9806N
if (ns === "S") answer.latitude = -answer.latitude
answer.longitude = degreesE + minutesE/60
if (ew === "W") answer.longitude = -answer.longitude // 11404.9355E
} else {
answer.latitude = 0
answer.longitude = 0
}

answer.speedMoving = elements[0].substr(34,5) // 000.1
answer.angleDirection = elements[0].substr(45,6) // 323.87
answer.signalStrength = elements[0].substr(51,3) // 060
answer.satellites = elements[0].substr(54,3) // 009
answer.batteryLevel = elements[0].substr(57,3) // 080
// LBS datas
answer.mobileCountryCode = elements[1] // 460
answer.mobileNetworkCode = elements[2] // 0
answer.locationAreaCode = elements[3] // 9520
answer.cellId = elements[4] // 3671
// WIFI bases only with flag = else
// answer.wifiAccessPoints = elements[5]
let i;
answer.wifiAccessPoints = []
if (!answer.valid) {
//i = elements[4] + 1 // ns: i never used // move on to wifi bases
let wifiAccessPointsStrings = elements[5].split("&")
let j;
for (j = 0; j < wifiAccessPointsStrings.length; j++) {
let baseElements = wifiAccessPointsStrings[j].split("|")
answer.wifiAccessPoints.push({ ssid: baseElements[0], macAddress: baseElements[1], signalStrength: baseElements[2] }) // Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97
}
}
msg.payload = answer
return msg

###################################END#####################################


Geolocate requests are submitted using a POST request to the URL:

https://location.services.mozilla.com/v1/geolocate?key=<XXXXXX>

A minimal example using only WiFi networks:

{
"wifiAccessPoints": [{
"macAddress": "macAddressDatasFromNodeRedjavascript",
"signalStrength": signalStrengthDatasFromNodeRedjavascript
}, {
"ssid": "ssidDatasFromNodeRedjavascript"
}]
}
A minimal example using a cell network:

{
"cellTowers": [{
"mobileCountryCode": mobileCountryCodeDatasFromNodeRedjavascript,
"mobileNetworkCode": mobileNetworkCodeDatasNodeRedjavascript,
"locationAreaCode": locationAreaCodeDatasNodeRedjavascript,
"cellId": cellIdDatasFromNodeRedjavascript,
"signalStrength": signalStrengthDatasNodeRedjavascript
}]
}


Chris Peterson

unread,
Feb 21, 2019, 3:08:21 AM2/21/19
to mozilla-dev...@lists.mozilla.org
Hi jyc, what is the problem you are running into? Parsing the data
returned from Node-Red or formatting the request data sent to the
Mozilla Location Service? I don't recognize the "IWAP01..." data format
you shared below.

Here is the JavaScript code that Firefox uses to construct the
"wifiAccessPoints" requests to send Wi-Fi MAC addresses to the Mozilla
Location Service:

https://searchfox.org/mozilla-central/rev/4587d146681b16ff9878a6fdcba53b04f76abe1d/dom/system/NetworkGeolocationProvider.jsm#349-418

chris

jyc emea

unread,
Feb 21, 2019, 8:37:54 AM2/21/19
to mozilla-dev...@lists.mozilla.org
Hi Chris,
Thanks for your anwser. I'm really lost. This not my part at all...
You perfectly understood my problem. I'm not able to write a correct js node (or javascript code) using the datas I'm receiving in Node-Red from the device to format the good json request to MLS.

IWAP01 is just a simulated chinese protocol command I'm injecting in my function node to replace the strings the server is usually receiving from the device on a TCP port...

In this function node, 2 options only :
// flag = A
//IWAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671#
Flag = A means the GPS coordinates are directly coming in Node-Red, so no need to use MLS, just have to display on the map. SOLVED!

// flag = else
//IWAP01080524V0000.0000N00000.0000E000.1061830323.8706000908000102,460,0,9520,3671,Home|74-DE-2B-44-88-8C|97&Home1|74-DE-2B-44-88-8C|97&Home2|74-DE-2B-44-88-8C|97&Home3|74-DE-2B-44-88-8C|97#
BUT WHEN Flag = V (or else... in the script), that means the GPS coordinates (0000N00000.0000E000)are not transmitted by the device, but replaced with the WIFI bases around as SSID|MACADDRESS|SIGNALSTRENGTH you can find in the javascript node...

So in this case I need to pick up these datas, to send them to MLS as here there are 4 WIFI bases, to get return the longitude and latitude... I DON'T KNOW WHAT TO WRITE TO SEND THE CORRECT DATAS TO MLS...



Le jeudi 21 février 2019 10:08:21 UTC+2, Chris Peterson a écrit :
> Hi jyc, what is the problem you are running into? Parsing the data
> returned from Node-Red or formatting the request data sent to the
> Mozilla Location Service? I don't recognize the "IWAP01..." data format
> you shared below.
>
> Here is the JavaScript code that Firefox uses to construct the
> "wifiAccessPoints" requests to send Wi-Fi MAC addresses to the Mozilla
> Location Service:
>
> https://searchfox.org/mozilla-central/rev/4587d146681b16ff9878a6fdcba53b04f76abe1d/dom/system/NetworkGeolocationProvider.jsm#349-418
>
> chris
>
>
> On 2/20/2019 8:59 PM, jyc emea wrote:
> > Hi,
> > Actually working on a new project, I'm looking to implement MLS /ichnaea/api/geolocate in Node-Red. I saw possible nodes like Skyhook (node-red-contrib-skyhook) but I really would prefer the Mozilla locating ...

Chris Peterson

unread,
Feb 21, 2019, 4:45:07 PM2/21/19
to mozilla-dev...@lists.mozilla.org
Here is the MLS API documentation with example HTTP POST requests that
your application would send to MLS:

https://mozilla.github.io/ichnaea/api/geolocate.html

For information on obtaining your own MLS API key or understanding MLS
error message, see:

https://mozilla.github.io/ichnaea/api/index.html


chris

jyc emea

unread,
Feb 22, 2019, 1:30:35 AM2/22/19
to mozilla-dev...@lists.mozilla.org

Hi, thanks for your link... but in my 1st post the json code was already extracted from the same page :) https://mozilla.github.io/ichnaea/api/geolocate.html#api-geolocate-latest

I'am not able to integrate this API code in my function node... to get the position.

Chris Peterson

unread,
Feb 22, 2019, 4:12:17 AM2/22/19
to mozilla-dev...@lists.mozilla.org
On 2/21/2019 10:30 PM, jyc emea wrote:
>
> Hi, thanks for your link... but in my 1st post the json code was already extracted from the same page :) https://mozilla.github.io/ichnaea/api/geolocate.html#api-geolocate-latest

Sorry I missed that. I didn't recognize the example JSON code with the
string "macAddressDatasFromNodeRedjavascript" replacing "01:23:45:67:89:ab".


> I'am not able to integrate this API code in my function node... to get the position.

What do you mean by "integrate this API code"? Is your code able to send
HTTP requests to
https://location.services.mozilla.com/v1/geolocate?key=test and get a
JSON response back from the server?

You can use "test" as the MLS API key for your personal development, but
you can email me directly to get a real API key if you will have more users.

To test that MLS is working for your location, you can send an empty
request to the server (such as opening
"https://location.services.mozilla.com/v1/geolocate?key=test" in your
browser). If you don't include any Wi-Fi MAC addresses, MLS will try to
return your location using GeoIP.

jyc emea

unread,
Feb 25, 2019, 11:43:29 AM2/25/19
to mozilla-dev...@lists.mozilla.org
Hi Cris,

When using "https://location.services.mozilla.com/v1/geolocate?key=test" directly in my browser, I get an answer as : {"location": {"lat": 46.5251, "lng": 21.5184}, "accuracy": 20000.0} which is really far from my real position an accuracy is really big...

And when using the geolocate API in Node-Red, I get errors in Node-Red and No response object with this :

msg.payload : string[157]
"{"considerIp":"false","wifiAccessPoints":[{"macAddress":"C8:3A:35:21:69:00","signalStrength":"82"},{"macAddress":"00:16:0A:1B:34:F2","signalStrength":"84"}]}"


25/02/2019 à 18:08:20node: 431ee23a.e4bbac
msg.payload : string[122]
"{"error":{"code":404,"message":"Not found","errors":[{"domain":"geolocation","message":"Not found","reason":"notFound"}]}}"

25/02/2019 à 18:08:20node: ba6c6cdc.23755
msg : string[18]
"No response object"

Can you please tell me from where the problem is coming?
Thanks

Best regards.
jycemea

Garvan Keeley

unread,
Feb 25, 2019, 11:54:18 AM2/25/19
to Discussion about Geo location services
>
> When using "https://location.services.mozilla.com/v1/geolocate?key=test" directly in my browser, I get an answer as : {"location": {"lat": 46.5251, "lng": 21.5184}, "accuracy": 20000.0} which is really far from my real position an accuracy is really big...

This is a GeoIP-only query, and that is the info in the geolocation DB for your IP. There might be example of sending a curl query with mac addresses in the ichnaea docs, perhaps someone else knows for sure.


> And when using the geolocate API in Node-Red, I get errors in Node-Red and No response object with this :
>
> msg.payload : string[157]
> "{"considerIp":"false","wifiAccessPoints":[{"macAddress":"C8:3A:35:21:69:00","signalStrength":"82"},{"macAddress":"00:16:0A:1B:34:F2","signalStrength":"84"}]}"
>

This is Google Location Service query? It appears the WiFi MAC addresses were sent automatically, which provides higher accuracy that GeoIP if the WiFis have been recorded in the geolocation db. Does this API require that you handle the failure to provide a location and re-request using GeoIP-only?

jyc emea

unread,
Feb 26, 2019, 2:43:22 AM2/26/19
to mozilla-dev...@lists.mozilla.org

Hi,
I'm actually doing some tests with GOOGLE API and Mozilla API in Node-Red... with the same JSON request.


It is working with a high precision in Google, I always get Lat+long+accuracy<52

But with MLS API in Node-Red, I always get this message :
"{"error":{"code":404,"message":"Not found","errors":[{"domain":"geolocation","message":"Not found","reason":"notFound"}]}}"

This seems to indicate that MLS can't get no position informations
as it's written at https://mozilla.github.io/ichnaea/api/geolocate.html#api-geolocate-latest

If no position information could be determined, a HTTP status code 404 will be returned:

{
"error": {
"errors": [{
"domain": "geolocation",
"reason": "notFound",
"message": "Not found",
}],
"code": 404,
"message": "Not found",
}
}

Looks strange cause, if I'm using the API directly in a browser https://location.services.mozilla.com/v1/geolocate?key=test

It is locating!!
0 new messages