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

Fix undefined path check for edge agent #388

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 2 additions & 4 deletions acs-edge/lib/devices/MQTT.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/*
* Factory+ / AMRC Connectivity Stack (ACS) Edge component
* Copyright 2023 AMRC
* Copyright (c) University of Sheffield AMRC 2025.
*/

import {Device, DeviceConnection, deviceOptions} from "../device.js";
import {DeviceConnection} from "../device.js";
import {log} from "../helpers/log.js";
import {SparkplugNode} from "../sparkplugNode.js";
import {Metrics, writeValuesToPayload} from "../helpers/typeHandler.js";
import * as mqtt from "mqtt";
import {v4 as uuidv4} from 'uuid';
Expand Down
11 changes: 6 additions & 5 deletions acs-edge/lib/helpers/typeHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Factory+ / AMRC Connectivity Stack (ACS) Edge component
* Copyright 2023 AMRC
* Copyright (c) University of Sheffield AMRC 2025.
*/

import {JSONPath} from "jsonpath-plus";
Expand Down Expand Up @@ -365,9 +364,11 @@ export function parseValueFromPayload(msg: any, metric: sparkplugMetric, payload
.split(delimiter) : msg.toString();

// Handle no path parsing
let newVal = (path != '') ? payload[path] : payload;

return parseTypeFromString(metric.type, newVal);
if (path == null || path == '') {
return parseTypeFromString(metric.type, payload);
} else {
return parseTypeFromString(metric.type, payload[path]);
}
case serialisationType.JSON:
try { // Handles error if invalid JSON is sent in
if (typeof msg == "string") {
Expand Down
Loading