Skip to content

A server that polls the Geonet.org.nz API and publishes new and updated quakes to Websockets, NATS and MQTT.

Notifications You must be signed in to change notification settings

penguinpowernz/go-geonet-events

Repository files navigation

Geonet Quake Events Forwarder

This is completely unofficial and unaffiliated with Geonet

This is a free service which forwards events from the Geonet API in an evented manner. This means you don't need to poll the Geonet API for quakes anymore, they can be delivered via the following protocols:

  • NATS via nats://quakes.nz:4222 on subjects geonet.quakes.new and geonet.quakes.updated (username of client and empty password)
  • WebSockets via ws://quakes.nz/events
  • MQTT via mqtt://quakes.nz:8883 (COMING SOON)

How does it work

Basically it does the polling for you, every second, of the Geonet API. Then your scripts can just connect to one of the protocols at quakes.nz and sit back and wait to be alerted.

Contributing

We would love and appreciate contributions to the code but would prefer if the only running instance was at quakes.nz given that many people running it could overload Geonets servers.

Payloads

There are two event types; new and updated. The latter is only sent when there is an update to a previous quake that was sent out. This is usually due to revisions to the magnitude and depth of the quakes, the quality field can be used to determine the usefulness of the event.

New

{
    "type": "new",
    "quake": {
        "publicID": "2020p203673",
        "time": "2020-03-16T08:37:10.376Z",
        "depth": 10.83877039,
        "magnitude": 1.021546187,
        "locality": "10 km north-east of Matawai",
        "mmi": -1,
        "quality": "preliminary",
        "coordinates": [
            177.6768036,
            -38.28015518
        ]
    }
}

Updated

{
    "type": "update",
    "quake": {
        "publicID": "2020p203673",
        "time": "2020-03-16T08:37:10.376Z",
        "depth": 23.87388039,
        "magnitude": 1.222926187,
        "locality": "10 km north-east of Matawai",
        "mmi": -1,
        "quality": "best",
        "coordinates": [
            177.6768036,
            -38.28015518
        ]
    },
    "updated_fields": [
        "quality",
        "magnitude",
        "depth"
    ]
}

Usage

NATS

Golang:

import "github.com/nats-io/nats.go"

nc, err := nats.Connect("nats://quakes.nz:4222", nats.UserInfo("client", ""))

sub, err := nc.SubscribeSync("geonet.quakes.>")
msg := sub.Next()

fmt.Printf("Received: %s", msg.Data)

Websocket

Golang:

import "golang.org/x/net/websocket"

url := "ws://quakes.nz/events"
origin := "http://quakes.nz/"
ws, err := websocket.Dial(url, "", origin)

var msg = make([]byte, 512)
n, err := ws.Read(msg)

fmt.Printf("Received: %s.\n", msg[:n])

About

A server that polls the Geonet.org.nz API and publishes new and updated quakes to Websockets, NATS and MQTT.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published