Skip to content

Conversation

@zhongys-c8y
Copy link
Contributor

@zhongys-c8y zhongys-c8y commented Sep 18, 2025

Added set_coil.py and set_register.py under tedge_modbus for writing values to modbus. One for register, one for coil. In the reader.py, added on_message function to subscribe to the tedge local MQTT topics of child devices' operations. The operation payload was based on the internal docs 'cloud fieldbus specification'. The c8y operation will be first mapper from c8y/devicecontrol/notifications topic to tedge local topics by using tedge custom operation template.

It was tested with the simulator in this project. It can successfully change the register and coil value.

@github-actions
Copy link

github-actions bot commented Sep 18, 2025

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
22 0 0 22 100 41.379714s

Passed Tests

Name ⏱️ Duration Suite
Device should support the operation c8y_ModbusConfiguration 0.106 s Device
Set values via c8y_ModbusConfiguration Operation 2.335 s Operation
Poll rate and transmit rate should be updated for the Device 0.192 s Operation
Poll rate and transmit rate should be updated on the Device 2.330 s Operation
Device should support the operation c8y_ModbusDevice 0.105 s Device
Device should support the operation c8y_SerialConfiguration 0.108 s Device
Set values via c8y_SerialConfiguration Operation 2.325 s Operation
Serial configuration should be updated for the Device 0.196 s Operation
Serial configuration should be updated on the Device 2.324 s Operation
Device should have installed software tedge-modbus-plugin 0.142 s Debian
Service should be active 2.329 s Debian
ReInstall Modbus Plugin 22.672 s Debian
Device should have the fragment c8y_ModbusConfiguration 0.209 s Device
ChildDevice TestCase1 should be created 0.201 s Device
ChildDevice TestCase1 should have the fragment c8y_ModbusDevice 0.503 s Device
Service tedge-modbus-plugin should be enabled 0.103 s Device
Device should set supported operations for writing to registers and coils 0.099 s Operations
Device should write to a registers 2.351 s Operations
Device should write to a coil 2.339 s Operations
ChildDevice TestCase1 should have a Test.Int16 Measurement 0.204 s Telemetry
ChildDevice TestCase1 should have a Test.Float32 Measurement 0.205 s Telemetry
ChildDevice TestCase1 should have Alarms of type TestAlarm on Coil Value 1 0.001 s Telemetry

@reubenmiller
Copy link
Contributor

@zhongys-c8y Can you run the formatting and linting and address any of the reported issues?

just format
just lint

Copy link
Member

@rina23q rina23q left a comment

Choose a reason for hiding this comment

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

Need to be changed a bit.

@reubenmiller reubenmiller changed the title Add update_coil and update_register feat: Add set_coil and set_register Sep 19, 2025
@zhongys-c8y
Copy link
Contributor Author

Added tedge_modbus/operations/topic_switcher.py to map the messages from c8y/devicecontrol/notifications to te/device/<childdevice>///cmd/<operation> topic. Please check the .template files for it, not sure if I wrote it in the right way.

@zhongys-c8y
Copy link
Contributor Author

Now the set_coil and set_register operations will be mapped from c8y/devicecontrol/notification topic to /te/device////cmd//# topic. Added a topics-subscriber in reader/reader.py which will react to these two topics and call operation/update_register.py and update_coil.py to write the register and coil.

@zhongys-c8y
Copy link
Contributor Author

TODOs:

  1. Need to publish 'te/device////cmd/command' '{}' for each child modbus device.
  2. Need to know how to change the operation status of a child device's operation.

Copy link

@didier-wenzek didier-wenzek left a comment

Choose a reason for hiding this comment

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

I confirm the interactions between the plugin and thin-edge are correctly implemented

test.py Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this file? It doesn't seem to be providing any value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, also only for my local test, I should not publish it

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.

4 participants