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 subjectsgeonet.quakes.new
andgeonet.quakes.updated
(username ofclient
and empty password) - WebSockets via
ws://quakes.nz/events
- MQTT via
mqtt://quakes.nz:8883
(COMING SOON)
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.
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.
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.
{
"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
]
}
}
{
"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"
]
}
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)
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])