- Python 3
You may want to set up a virtual environment to keep this sandbox separate from your other Python work. If you do, use Python virtualenv to do this:
# setup virtualenv
python3 -m venv --system-site-packages {name}
cd {name}
source bin/activateClone this repository so that you have all the necessary configurations and commands:
git clone https://github.com/6a6d74/hello-Oslo.gitNow you're ready to install pywis-pubsub:
pip3 install pywis-pubsubAnd finally, check to see that pywis-pubsub is working
pywis-pubsub --versionJump into the working directory:
cd hello-Oslo/Download the latest schemas so that pywis-pubsub can validate messages:
pywis-pubsub schema syncCreate the target folder that data will be downloaded into:
mkdir ./downloadsSubscribe to Meteo France's live Global Broker fr-meteofrance-global-broker published by DWD's GTS to WIS2 Gateway de-dwd-gts-to-wis and download data objects into ./downloads/ folder:
pywis-pubsub subscribe --config download--fr-meteofrance-global-broker.yml --download --verbosity INFONote that:
- Verbosity is set to
INFO; other options areDEBUG,WARNING, andERROR
Look in ./downloads/ and see some data!
For the tutorial we'll use the MQTTX Web-client - but there are many options. Load the Web-client in a browser window:
Click + New Connection to add a connection to the gb.wis2dev.io MQTT broker
Now add the connection details:
- Name
{your-connection-name} - Host (protocol)
wss:// - Host (name)
gb.wis2dev.io - Port
443 - Path
/mqtt - Username
everyone - Password
everyone - SSL/TLS [yes]
- SSL Secure [no]
... and click Connect
Notes that the Web-client uses wss:// protocol – were running MQTT over Web-socket
Now add the subscriptions:
- origin/a/wis2/#
- monitor/a/wis2/#
Once you confirmed each subscription, select JSON for the message type to see your messages pretty-printed
And that's done.
For convenience, we're publishing to topic using {centre-id} = eu-eumetnet-femdi; this {centre-id} already exists in the official topic hierarchy; the Global Broker will only re-publish messages that use this topic hierarchy
We're using this sample WCMP2 metadata record (or you can use your own): https://raw.githubusercontent.com/6a6d74/hello-Oslo/refs/heads/main/wcmp2-passing.json
This record is based on the wcmp2-passing.json from the pywcmp repository, but modified to use the {centre-id} eu-eumetnet-femdi in the metadata identifier so that it matches the topic we're publishing on
Take a look at the metadata record. Use curl to retrieve the sample metadata record (add -v for verbose output if you want):
curl https://raw.githubusercontent.com/6a6d74/hello-Oslo/refs/heads/main/wcmp2-passing.jsonEdit publish--cloud-hivemq.yml to add the password to the MQTT credentials:
broker: mqtts://publisher:******@48832dd529364f0781bf512d63580fae.s1.eu.hivemq.cloud:8883
Publish the sample WCMP2 metadata record to the HiveMQ broker:
pywis-pubsub publish --config publish--cloud-hivemq.yml -u https://raw.githubusercontent.com/6a6d74/hello-Oslo/refs/heads/main/wcmp2-passing.json --metadata-id "urn:wmo:md:eu-eumetnet-femdi:observations.swob-realtime" --topic origin/a/wis2/eu-eumetnet-femdi/metadata --verbosity INFONote that:
- Verbosity is set to
INFO
Publish an update to an existing metadata record:
pywis-pubsub publish --config publish--cloud-hivemq.yml -u https://raw.githubusercontent.com/6a6d74/hello-Oslo/refs/heads/main/wcmp2-passing-update.json --metadata-id "urn:wmo:md:eu-eumetnet-femdi:observations.swob-realtime" --topic origin/a/wis2/eu-eumetnet-femdi/metadata --verbosity INFONote that:
- On update, the Global Discovery Catalogue determines which record to update based on the metadata identifier
- Here, we use a slightly modified version of the metadata record, wcmp2-passing-update.json, with amended description and updated-time properties; this allows us to see that the update has happened
- Even though we're doing an update operation, we don't need to include the
--operation updatequalifier in the request; the Global Discovery Catalogue processes the new record even though the notification message doesn't sayrel=update
Delete an existing metadata record:
pywis-pubsub publish --config publish--cloud-hivemq.yml -u https://http.codes/204 --metadata-id "urn:wmo:md:eu-eumetnet-femdi:observations.swob-realtime" --topic origin/a/wis2/eu-eumetnet-femdi/metadata --operation delete --verbosity INFONote that:
- To tell the Global Discovery Catalogue that we want to delete a record, we use the
--operation deletequalifier; this tells pywis-pubsub to includerel=deletionin the notification message - On delete, we don't need to include any content so we use the URL
https://http.codes/204which provides a HTTP 204 response "No Content" - The Global Discovery Catalogue determines which record to delete based on the metadata identifier