Skip to content

Conversation

@wilbersl
Copy link
Contributor

@wilbersl wilbersl commented Aug 26, 2025

Pull Request Description:

This pull request introduces the creation of complex / combined Measurements to the Modbus plugin, designed to reduce unnecessary data traffic to the cloud. These changes enable users to prioritize high-volume data cloud resource usage for static or infrequently changing data points. This Feature works hand in hand with the on-change keyword to ensure sending fewer measurements with only the needed data.

Motivation

I use thin-edge with my own modbus poller and complex / combined measurements for some time now and want to switch to the official plugin.
Inline with my issue

Features Implemented

The feature generally opt-in, devices who currently use this plugin won't change their behavior. It can be activated on a global level as well as on a per device level, opt-out is also possible per Device.

How it Works: The plugin checks for an optional combinemeasuerments key within the modbus configuration or a device's configuration in the modbus.toml / devices.toml file. When generating the measurements this Key is checked in the Priority 1st Device | 2nd Global . If it is absent in the device, the plugin falls back to the global and if it is absent there it's off, ensuring full backward compatibility.

Example Configurations

Test modbus.toml with feature active:

[modbus]
pollinterval = 5
loglevel = "INFO"
combinemeasurements=true # if not set equals false; 

[thinedge]
mqtthost= "127.0.0.1"
mqttport = 1883

Test devices.toml can still be used to opt-out single devices:

[[device]]
name = "mock_battery1"
address = 1
ip = "127.0.0.1"
port = 502
protocol = "TCP"
combinemeasurements=false # Overrides global setting;

[[device.registers]]
number = 0
startbit = 0
nobits = 16
signed = false
multiplier = 1
input = false
measurementmapping.templatestring = '{"power": %%}'

[[device.registers]]
number = 100
startbit = 0
nobits = 16
signed = false
input = false
measurementmapping.templatestring = '{"error_flag": %%}'
on_change = true # new update

[[device]]
name = "mock_battery_2"
address = 1
ip = "127.0.0.1"
port = 41502
protocol = "TCP"
#combinemeasurements=false # No Override uses the global option

[[device.registers]]
number = 0
startbit = 0
nobits = 16
signed = false
multiplier = 1
input = false
measurementmapping.templatestring = '{"power": %%}'

@C8Y-Mario
Copy link
Collaborator

Thanks for this PR, as well! I think the feature makes sense - I was looking into leveraging bulk creation of Measurements, but this makes also sense for a lot of use cases.

@C8Y-Mario
Copy link
Collaborator

Seems good to me

@github-actions
Copy link

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
15 0 0 15 100 35.8767s

Passed Tests

Name ⏱️ Duration Suite
Device should support the operation c8y_ModbusConfiguration 0.138 s Device
Set values via c8y_ModbusConfiguration Operation 2.444 s Operation
Poll rate and transmit rate should be updated for the Device 0.264 s Operation
Poll rate and transmit rate should be updated on the Device 2.436 s Operation
Device should support the operation c8y_ModbusDevice 0.139 s Device
Device should have installed software tedge-modbus-plugin 0.175 s Debian
Service should be active 2.435 s Debian
ReInstall Modbus Plugin 25.947 s Debian
Device should have the fragment c8y_ModbusConfiguration 0.275 s Device
ChildDevice TestCase1 should be created 0.267 s Device
ChildDevice TestCase1 should have the fragment c8y_ModbusDevice 0.675 s Device
Service tedge-modbus-plugin should be enabled 0.138 s Device
ChildDevice TestCase1 should have a Test.Int16 Measurement 0.274 s Telemetry
ChildDevice TestCase1 should have a Test.Float32 Measurement 0.270 s Telemetry
ChildDevice TestCase1 should have Alarms of type TestAlarm on Coil Value 1 0.001 s Telemetry

Copy link
Contributor

@reubenmiller reubenmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wilbersl Approved. Thanks again for the nice addition

@reubenmiller reubenmiller added this pull request to the merge queue Sep 12, 2025
Merged via the queue into thin-edge:main with commit b7de64a Sep 12, 2025
5 checks passed
@reubenmiller reubenmiller changed the title Feat complex / combine measurements feat: complex / combine measurements Sep 12, 2025
@wilbersl wilbersl deleted the feat-combine-measurements branch September 15, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants