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
292 views 4 comments
by anonymous
I have a Teltonika with 6.09.02 firmware.

I have an external device that is writing to Register 1025 a bit that represents the state of my process.  I am using 1025 because I read that was the first Unused Holding register.  This status value is either 0 or 1. The status changes approximately every minute, but I only want to take action (change relay state) every 4 hours when the status goes to a high level.

I would then like to use the Teltonika to read this value from as the Modbus Master.

I then created two alarms that with change the status of the Relay output

I added a redundancy protection so the Relay output can only turn off once every 4 hours (14400 seconds).  

I cannot get it to work.

I am testing it in the lab by connecting with ComTestPro App and writing to the Holding Register 1025.  I get a Valid Response, but the relay does not change state.  I can use ComTestPro to write to Register 202 and the Relay changes state.

My questions:

1. Is there a better way to do this that allows me to build in the 4 hour delay on activating the relay?

2. Am I allowed to have the Teltonika read from itself (Master to Slave)?

3. Am I allowed to have multiple Masters like this?  (ComTestPro and Teltonika are both Masters to Teltonika)

4.  The attached pdf has screen shots of the Teltonika config

5. Thanks in advance!

1 Answer

+1 vote
by anonymous

Hello,

First, I noticed you are using a legacy firmware version. If possible, I recommend updating to the latest firmware version for your device.

To better assist you, I need some clarification on your requirements:

  • If the Modbus value is 1, the relay output should turn on for 4 hours or does it need to turn on only after 4 hours? After the 4 hours, should it turn off automatically or only turn off if the value is 0? Additionally, if it needs to turn off after 4 hours even when the value is still 1, how long should it wait before turning on again?
  • Are you writing to register 1025 of the RUT955? If so, do you have the custom register block enabled? You can find information about custom Modbus registers here and here.

Regarding your other questions:

  • Yes, the router can be configured as both a Modbus master and Modbus slave at the same time, allowing it to read data from itself (using the localhost address 127.0.0.1).
  • Yes, it is possible to have multiple Modbus Master instances.

Additionally, please note that Teltonika devices use Register numbers rather than addresses. Register numbers start at 1, while addresses start at 0. For example, if the register has an address of 200, the register number will be 201 (+1).

Based on your requirements, achieving the desired functionality through the WebUI alone may or may not be possible. However, a custom script should be able to fulfil your needs. Hence, please provide more details about the desired behaviour and logic.

Kind Regards,

Andzej

by anonymous
Andzej,

Thanks for your reply.  I left the fw on the old version from a recommendation from a consultant.  I will see about getting it updated.  

The desired behavior is:
If the relay is off, and the Status goes to 1, the relay will turn on and stay on for 4 hours.  After this 4 hour timer has expired, then the Status value going to 0 will cause the relay to turn off.  The next time the Status value goes to 1, the relay should again turn on and stay on for 4 hours.  During the 4 hours that the relay is held on, the Status will cycle many times between 1 and 0.  

I have configured the custom register block. I tried writing to the 1024 and 1026 register with no effect either.

If this is better to do with a custom script, do you have some examples of how I might do this?

Thanks greatly!
by anonymous

Hi,

There can be issues if you try to configure it by this logic via WebUI, since you will have 2 timers that are not aware of each other.

You can write a shell script, but this task is up to you. We do not have examples, but you can check this forum for similar threads and refer to other resources available online too.

To read from modbus slave, you can use the following command (you can change it to your needs):

  • ubus call modbus_master tcp.test

For information:

  • ubus -v list modbus_master 

You will need to parse the response. For example:

  • ubus call modbus_master tcp.test '{"id":1,"timeout":15,"function":3,"first_reg":1025,"reg_count":"1","data_type":"16bit_int_hi_first","no_brackets":1,"ip":"127.0.0.1","port":502,"delay":0}' | sed -n 's/.*"result": "\(.*\)".*/\1/p'
Function 3 for read, function 6 for write.
Regarding the available data types, you can configure a modbus request in modbus master in the WebUI and check the data type in the modbus_master config file:
  • cat /etc/config/modbus_master
The config will show you your configured requests and their data types. So you can use those in your modbus tcp.test command.
So, check the values, and based on that turn on/off relay. You will need to add a timer too. For example (relay_time is your 4hour time in seconds):
  • timer_started=$(date +%s)
  • timer_end_time=$((timer_started + RELAY_TIME))
  • if [ "$(date +%s)" -ge "$timer_end_time" ]; then
You can change the state of the relay or any other IO via ubus, or by setting register 203 (for relay) via Modbus using the commands I have mentioned before.
Ubus commands for relay:
  • ubus call ioman.relay.relay0 update '{"state":"open"}'
  • ubus call ioman.relay.relay0 update '{"state":"close"}'
  • ubus call ioman.relay.relay0 status
  • ubus -v list ioman


Kind Regards,

Andzej

by anonymous

Thanks again Andzej,

It has been a while, but I am finally able to come back to this project.  I am missing something simple.

I tried to upgrade the firmware, but it looks like my 955 is too old and will not allow me to install anything past the 6.09.02 that I have.

When I have the Teltonika configured to be the Master of itself, and using ComTestPro to write to the Register, I cannot get the Relay to change state.  I can see in Wireshark that the Register in the Teltonika is being written to.  Also, when I try to read the register from the Teltonika interface in the Requests Configuration tab to see that it is working, I get a message "read: Resource temporarily unavailable"

If I setup the Teltonika to read from my laptop, then I can change the Relay state easily.  But something about having the Teltonika read from itself is messing it up?

Any ideas what I am doing wrong?

Thanks again,

Mike

by anonymous

Hello,

I'm unable to test this on the legacy firmware at the moment, but perhaps you could provide the register numbers and the value you are using to change the state of the relay.

I'd also recommend trying to use <register_number>+1 and <register_number>-1 as the register to write to, as it depends on the application whether it uses the Modbus register number or register address.

Best regards,
DaumantasG