Try it

This simulates listening to the lightning service and displaying the recordings in a list and on a map. It also displays the heartbeat messages. These are faster in this demo (5 sec) than in the production system (30 sec). You can stop and start the recordings to look at any particular lightning. The actual WebSocket communication is mocked since the service itself is only available for paying customers. This means that all data is fake. View the Source and check out the console output for examples.

Recordings

Client

The demo client can be used as a starting point when developing for this service if you use java. It consists of a maven project and can be downloded here pls-client.tar.gz.

$ tar –xvzf pls-client.tar.gz
$ cd pls-client
$ mvn clean install
$ java -jar target/pls-client-1.0-SNAPSHOT-jar-with-dependencies.jar <username> <password>

If you just want to test your connectivity you can download the binary here: pls-client-1.0-SNAPSHOT-jar-with-dependencies.jar.

$ java -jar pls-client-1.0-SNAPSHOT-jar-with-dependencies.jar <username> <password>

For this to work you need java (JRE) installed, and maven if you want to compile the source code.

Normal execution looks something like this

2016-01-20 19:59:15.808:INFO::main: Logging initialized @82ms
2016-01-20 19:59:15.847:INFO:sspc.PlsClient:main: connecting to ws://data-push.smhi.se/api/category/lightning-strike/version/1/country-code/SE/data.json
2016-01-20 19:59:16.077:INFO:sspc.MessageSocket:WebSocketClient@1338668845-13: [onConnect]
2016-01-20 19:59:37.130:INFO:sspc.MessageSocket:WebSocketClient@1338668845-17: [onMessage] {"time":"2016-01-20T18:59:36.000Z","countryCode":"ZZ","pos":{"lat":0,"lon":0,"proj":"EPSG:4326"},"meta":{"peakCurrent":0,"cloudIndicator":0}}
2016-01-20 20:00:07.128:INFO:sspc.MessageSocket:WebSocketClient@1338668845-14: [onMessage] {"time":"2016-01-20T19:00:07.000Z","countryCode":"ZZ","pos":{"lat":0,"lon":0,"proj":"EPSG:4326"},"meta":{"peakCurrent":0,"cloudIndicator":0}}
[Ctrl-C]
2016-01-20 20:00:11.074:INFO:sspc.MessageSocket:Thread-0: [onClose] 1001 - Shutdown
2016-01-20 20:00:11.075:INFO:sspc.PlsClient:main: Bye

One usual error is invalid username or password. This will render the following (not so obvious) stacktrace.

2016-01-20 19:57:41.890:WARN:sspc.MessageSocket:WebSocketClient@1338668845-15: [onError]
org.eclipse.jetty.websocket.api.UpgradeException: Didn't switch protocols, expected status <101>, but got <401>
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.validateResponse(UpgradeConnection.java:352)
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.read(UpgradeConnection.java:280)
	at org.eclipse.jetty.websocket.client.io.UpgradeConnection.onFillable(UpgradeConnection.java:196)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
	at java.lang.Thread.run(Thread.java:745)

This demo client is not for production use in any way!