Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Meter ID/Name to MQTT message. #198

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions cli_meter/meters/sel735/create_message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# <data_type> <output_dir>
#
# Arguments:
# meter_id Meter ID
# event_id event ID
# zip_filename Name of the zipped file
# md5sum_value md5sum of the zipped file
Expand All @@ -20,23 +21,25 @@ current_dir=$(dirname "$(readlink -f "$0")")
script_name=$(basename "$0")
source "$current_dir/../../common_utils.sh"

# Check for exactly 5 arguments
[ "$#" -ne 5 ] && failure $STREAMS_INVALID_ARGS "Usage: $script_name <event_id> <zip_filename> <md5sum_value> <data_type> <output_dir>"
# Check for exactly 6 arguments
[ "$#" -ne 6 ] && failure $STREAMS_INVALID_ARGS "Usage: $script_name <meter_id> <event_id> <zip_filename> <md5sum_value> <data_type> <output_dir>"

event_id="$1"
zip_filename="$2"
md5sum_value="$3"
data_type="$4"
output_dir="$5"
meter_id="$1"
event_id="$2"
zip_filename="$3"
md5sum_value="$4"
data_type="$5"
output_dir="$6"
message_file="$output_dir/${zip_filename}.message"

# Create the JSON payload
json_payload=$(jq -n \
--arg mid "$meter_id" \
--arg eid "$event_id" \
--arg fn "$zip_filename" \
--arg md5s "$md5sum_value" \
--arg dt "$data_type" \
'{event_id: $eid, filename: $fn, md5sum: $md5s, data_type: $dt}')
'{meter_id: $mid, event_id: $eid, filename: $fn, md5sum: $md5s, data_type: $dt}')

# Write the JSON payload to the .message file
echo "$json_payload" > "$message_file" && log "Created message file: $message_file" || failure $STREAMS_FILE_CREATION_FAIL "Failed to write to message file: $message_file"
Expand Down
2 changes: 1 addition & 1 deletion cli_meter/meters/sel735/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ for event_info in $events; do
md5sum_value=$(md5sum "$event_zipped_output_dir/$zip_filename" | awk '{print $1}')

# Create the message file (JSON) for the event
"$current_dir/create_message.sh" "$event_id" "$zip_filename" "$md5sum_value" "$data_type" "$event_zipped_output_dir" || {
"$current_dir/create_message.sh" "$meter_id" "$event_id" "$zip_filename" "$md5sum_value" "$data_type" "$event_zipped_output_dir" || {
handle_fail "$event_id" "$output_dir" "$STREAMS_FILE_CREATION_FAIL" "Failed to create message file for event: $event_id" "$meter_id" "$download_start" "$download_end"
continue
}
Expand Down
Loading