Skip to content

Commit

Permalink
fix: make data retrieval of IOLink sensor more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
bossenti committed Oct 13, 2023
1 parent 905ebd3 commit 6871edb
Showing 1 changed file with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,26 @@ public void onAdapterStarted(IAdapterParameterExtractor extractor,

for (int i = 0; i < ports.size(); i++) {

var portResult = getMap(payload,
"/iolinkmaster/port[%s]/iolinkdevice/pdin".formatted(ports.get(i)));
var eventData = (String) portResult.get("data");

var parsedEvent = sensor.parseEvent(eventData);
parsedEvent.put("timestamp", System.currentTimeMillis() + i);
parsedEvent.put("port", "port" + ports.get(i));
parsedEvent.put(SensorVVB001.IO_LINK_MASTER_SN, serialnumber);

collector.collect(parsedEvent);
try {
var portResult = getMap(payload,
"/iolinkmaster/port[%s]/iolinkdevice/pdin".formatted(ports.get(i)));
var eventData = (String) portResult.get("data");

var parsedEvent = sensor.parseEvent(eventData);
parsedEvent.put("timestamp", System.currentTimeMillis() + i);
parsedEvent.put("port", "port" + ports.get(i));
parsedEvent.put(SensorVVB001.IO_LINK_MASTER_SN, serialnumber);

collector.collect(parsedEvent);
} catch (Exception e) {
adapterRuntimeContext
.getLogger()
.error(e);
LOG.error("Data from IOLink sensor could not be extracted for port {}: {}", i, e);
}
}
});
}
);
} catch (Exception e) {
adapterRuntimeContext
.getLogger()
Expand Down

0 comments on commit 6871edb

Please sign in to comment.