Skip to content

Commit

Permalink
remove country id (#4)
Browse files Browse the repository at this point in the history
* remove country id

* update env_file for test
  • Loading branch information
maaikelimper authored Nov 24, 2023
1 parent d04a5d2 commit d5c98f0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# wis2box-data-subscriber

Service to subscribe to data published by Automatic Weather Stations and store the data into the wis2box-incoming bucket. It is currently designed to in conjuction with the 'csv2bufr'-plugin and the default mapping-template 'synop_bufr.json' .
Service to subscribe to data published by Automatic Weather Stations and store the data into the wis2box-incoming bucket. It is currently designed to work in conjunction with the 'csv2bufr'-plugin and the default mapping-template 'synop_bufr.json' and is compatible with Campbell scientific data loggers version CR1000X.

## how it works

Expand All @@ -12,9 +12,9 @@ One .csv is created per timestamp for the content of the 'observations'-object i

The .csv is stored as new object into the MINIO-endpoint defined by the environment variables for this services. The path used for the file in the minio-bucket is defined as:

`{COUNTRY_ID}/{CENTRE_ID}/data/core/weather/surface-based-observations/synop/`
`{CENTRE_ID}/data/core/weather/surface-based-observations/synop/`

Where COUNTRY_ID and CENTRE_ID are defined with environment variables.
Where CENTRE_ID is defined with an environment variables.

Processing non-synop data will required an updated version of the current code.

Expand All @@ -27,13 +27,12 @@ wis2box-data-subscriber uses. the following environment-variables:
```bash

AWS_BROKER=mqtt://wis2box:xxx@localhost:1883 # set endpoint for broker where AWS data is published
COUNTRY_ID=zmb # set country_id used in wis2-topic-hierarchy
CENTRE_ID=zmb_met_centre # set centre_id for wis2-topic-hierarchy
CENTRE_ID=zm-zmb_met_centre # set centre_id for wis2-topic-hierarchy
LOGGING_LEVEL=INFO # set logging level

LOGGING_LEVEL=INFO # set logging-level
MINIO_BUCKET=wis2box-incoming
MINIO_ENDPOINT=http://localhost:9000 # set this to the minio-endpoint for your wis2box
MINIO_ROOT_USER=minio # minio username for your minio-endpoint
MINIO_ROOT_USER=wis2box # minio username for your minio-endpoint
MINIO_ROOT_PASSWORD=xxx # minio password for your minio-endpoint
```
1 change: 0 additions & 1 deletion test/docker-compose.data-subscriber.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
environment:
- LOGGING_LEVEL=${LOGGING_LEVEL:-WARNING}
- CENTRE_ID=${CENTRE_ID}
- COUNTRY_ID=${COUNTRY_ID}
- AWS_BROKER=${AWS_BROKER}
- MINIO_BUCKET=${MINIO_BUCKET}
- MINIO_ENDPOINT=${MINIO_ENDPOINT}
Expand Down
3 changes: 1 addition & 2 deletions test/env_file
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
AWS_BROKER=mqtt://wis2box@localhost:5883
COUNTRY_ID=zmb
CENTRE_ID=zmb_met_centre
CENTRE_ID=zm-zmb_met_centre
LOGGING_LEVEL=INFO

MINIO_BUCKET=wis2box-incoming
Expand Down
2 changes: 1 addition & 1 deletion test/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
print('wait 2 seconds')
time.sleep(2)
print('check file is in bucket')
mypath = 'zmb/zmb_met_centre/data/core/weather/surface-based-observations/synop'
mypath = 'zm-zmb_met_centre/data/core/weather/surface-based-observations/synop'
myfilename = 'CR1000X_34769_20230428T153200Z.csv'
res = requests.get(f'http://localhost:9000/wis2box-incoming/{mypath}/{myfilename}')
print(res)
Expand Down
8 changes: 2 additions & 6 deletions wis2box-data-subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@

LOGGING_LOGLEVEL = os.environ.get('LOGGING_LEVEL', 'INFO')
CENTRE_ID = os.environ.get('CENTRE_ID', 'not defined')
COUNTRY_ID = os.environ.get('COUNTRY_ID', 'not defined')
AWS_BROKER = os.environ.get('AWS_BROKER', 'not defined')

MINIO_ENDPOINT = os.environ.get('MINIO_ENDPOINT')
Expand Down Expand Up @@ -94,7 +93,7 @@ def write_csv(topic, headers, logger_id, data):
base_csv += f'"{logger_id}"\n'
base_csv += '"observations:"\n'

prefix = f"{COUNTRY_ID}/{CENTRE_ID}"
prefix = f"{CENTRE_ID}"
prefix += "/data/core/weather/surface-based-observations/synop/"

# create one csv per timestamp
Expand Down Expand Up @@ -181,9 +180,6 @@ def main():
print(f"LOGGING_LOGLEVEL={LOGGING_LOGLEVEL}")
LOGGER.setLevel(LOGGING_LOGLEVEL)

if COUNTRY_ID == 'not defined':
LOGGER.error("COUNTRY_ID is not defined, exiting")
return
if CENTRE_ID == 'not defined':
LOGGER.error("CENTRE_ID is not defined, exiting")
return
Expand All @@ -198,7 +194,7 @@ def main():
LOGGER.info(f"host={broker_url.hostname}")
LOGGER.info(f"user={broker_url.username}")
LOGGER.info(f"port={broker_url.port}")
client_id = f"wis2box-data-subscriber-{COUNTRY_ID}-{CENTRE_ID}"
client_id = f"wis2box-data-subscriber-{CENTRE_ID}"
client = mqtt.Client(client_id=client_id, protocol=mqtt.MQTTv5)
client.on_connect = sub_data_incoming
client.on_message = process_data
Expand Down

0 comments on commit d5c98f0

Please sign in to comment.