Module nh_ext_geo

The geo extension.

Description

The geo extension.

NervesHub asks with geo:location:request and the device answers with geo:location:update. There is no GPS here, so the answer comes from a GeoIP lookup against the Nerves project's whenwhere service — the same source nerves_hub_link uses by default, and about as accurate as an IP address ever is.

  #{source => <<"geoip">>, latitude => -36.8869, longitude => 174.769}

A failed lookup is reported rather than swallowed, as #{error_code, error_description}, because a device that answers nothing and a device that cannot resolve look identical from the platform.

Running it

resolve/0 makes a network request and blocks until it finishes, so it must not run on the agent's process — that process has heartbeats to send. The agent spawns start_resolve/1, which sends the result back.

Function Index

default_url/0
event/0The scoped event a location is sent as.
parse_response/1Turn a whenwhere response body into the payload NervesHub stores.
resolve/0Equivalent to resolve(default_url()).
resolve/1Ask a whenwhere-shaped service where this device is.
start_resolve/1Resolve in a separate process, sending {nh_ext_geo, Pid, Location}.

Function Details

default_url/0

default_url() -> binary()

event/0

event() -> binary()

The scoped event a location is sent as.

parse_response/1

parse_response(Body::binary()) -> map()

Turn a whenwhere response body into the payload NervesHub stores.

Coordinates come back as strings and are sent as numbers where they parse: the platform draws them on a map, and a string is not a coordinate. One that will not parse is passed through rather than dropped, so a change at the service shows up as odd data instead of no data.

resolve/0

resolve() -> map()

Equivalent to resolve(default_url()).

resolve/1

resolve(Url::binary()) -> map()

Ask a whenwhere-shaped service where this device is.

start_resolve/1

start_resolve(Owner::pid()) -> pid()

Resolve in a separate process, sending {nh_ext_geo, Pid, Location}.


Generated by EDoc