FOR TIPS, gUIDES & TUTORIALS

subscribe to our Youtube

GO TO YOUTUBE

14455 questions

17168 answers

28195 comments

0 members

We are migrating to our new platform at https://community.teltonika.lt. Moving forward, you can continue discussions on this new platform. This current platform will be temporarily maintained for reference purposes.
0 votes
351 views 0 comments
by anonymous

I've created some custom Lua scripts on TRB140 which read measurements from different devices via Modbus and do some special processing before the data is sent to cloud. I'm using the custom register block as described here:
https://wiki.teltonika-networks.com/view/TRB140_modbus_custom_register_block?veaction=edit&section=T-4

My custom regfile is located at /tmp/modbus/regfile

When the device is restarted, the regfile is removed (as expected). The problem is that if I create the regfile in my Lua script or shell script after restart, it does not work: The Modbus request test tool just throws the "Unexpected response length" error regardless of contents of the file. However, if I go to Modbus slave settings and change something (like register count) and save, the regfile is created by the system and it works again.

I've also tried different methods for creating the file, like taking a backup of a working regfile and copying to the desired location on device startup, but it still keeps throwing the same error. I've also set identical file permissions so it's not about them either. The only way to create a functioning regfile is by changing the settings and saving. I also tried to inspect how the file is actually created when saving the settings, but I haven't found anything so far.

The device is using firmware version TRB1_R_00.07.01

1 Answer

0 votes
by anonymous
Well...this one got solved sooner than I thought: The regfile was not created on startup because the folder /tmp/modbus did not exist. Things started to work correctly after I added the folder creation script to the startup before Modbus services are started. All good now.

However, if anyone has any insight on why a copied regfile did not do the job, I'd be glad to hear. In other words, what is special about the system-created regfile or what does the system do differently so that things start to work.
Best answer