Repository navigation
feat(mqtt-bridge): write data points from MQTT, then read the device - #676
Merged
Merged
Conversation
Every bus still on the old reader writes to a device over MQTT, so none
of them can move to the bridge until it can write.
A JSON object on {topicPrefix}/{deviceId}/set is written to a device
with allowWrites: true, in message order, in the same turn on the bus
as the polls. All points are checked first. The device is then read at
once and published on /data, and the result goes to /set/result. The
stored copy of a retained message is ignored, so it is not written
again at every start or reconnect.
Refs #675
@ya-modbus/cli
@ya-modbus/device-profiler
@ya-modbus/driver-dds024mr
@ya-modbus/driver-dds519mr
@ya-modbus/driver-ex9em
@ya-modbus/driver-loader
@ya-modbus/driver-or-we-514
@ya-modbus/driver-or-we-516
@ya-modbus/driver-sdk
@ya-modbus/driver-sdm630
@ya-modbus/driver-types
@ya-modbus/driver-xymd1
@ya-modbus/emulator
@ya-modbus/mqtt-bridge
@ya-modbus/transport
ya-modbus
ya-modbus-bridge
ya-modbus-emulator
ya-modbus-profile
commit: |
After a driver error the points before it stay written on the device, and the result did not say which ones. Every failed result now has `written`: the IDs the driver wrote before the error, in message order, or [] when nothing was written. Refs #675
The read after a write reads only the points a poll reads, so the README must not promise the full state of the device. A timeout can also leave the failed point written without it being in `written`. The tests now check `written` for a device that does not allow writes and for a driver error on the first point. Refs #675
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every bus still on the old reader writes to a device over MQTT, so none of them can move to the bridge until it can write.
What it does
allowWrites: trueon a device (defaultfalse). Without it, every write message gets an error result and nothing is written, so a meter is not written by mistake.{topicPrefix}/{deviceId}/set, one per enabled device. Payload: a JSON object{ "<dataPointId>": value, ... }.written.{topicPrefix}/{deviceId}/data. The read covers the points a poll reads. A failed read here is left to the next poll.{topicPrefix}/{deviceId}/set/result, QoS 0, not retained:{ deviceId, timestamp, ok: true, values }or{ deviceId, timestamp, ok: false, error, values, written }. The error names the point and why;writtenis[]when nothing was written.All of it is in the mqtt-bridge README, section "Writing Data Points".
Notes
written, and the README says so.pollType: 'static'is not read again;/datakeeps the kept value. No driver has a writable static point.Tests
index.writes.test.ts,polling-scheduler.writes.test.ts): one point; several points in order; unknown point; read-only point; device withoutallowWrites; driver error (also on the first point), withwrittenand the/dataafter the partial write; read and publish right after the write; a write waits for a running poll on the same port; retained message; invalid payloads.write.integration.test.ts): real broker and MQTT client, real transport, TCP emulator. Writes a register over/set, sees the new value on/dataandok: trueon the result.Refs #675