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
726 views 6 comments
by anonymous
Hello community.

There is next task: I have TRB245 device with sim card inserted and I want to turn on output (D1 or D3) when GSM signal is lost (in such case I cannot control Teltonika from outside) and turn off output when GSM signal is restored. That output can be connected to alarm indicator (for instance to red LED indicator). I have read an article about TRB245 Input/Output:

https://wiki.teltonika-networks.com/view/TRB245_Input/Output

In trigger section are pin state change options available only. No GSM signal options or something similar. Can I execute above mentioned task using internal Teltonika rules (I/O Juggler)? If yes, how?

1 Answer

0 votes
by anonymous

Hello,

There is no way direct way to achieve what you desire, however, there are a couple of couple of suggestions below, involving CLI/SSH manipulation:

  • Modify hotplug script:
    • Login to the router via SSH;
    • Go to the following directory:
      • cd /etc/hotplug.d/iface
    • edit 89-gsm-event script with a text editor:
      • vi 89-gsm-event
    • append the following lines:
if [ "$MODEM" != "" ]; then
    identify_modem "$MODEM"
    if [ "$ACTION" = "ifup" ] || [ "$iface" -gt 0 ]; then
        mdm_ubus_obj="$(find_mdm_ubus_obj "$MODEM")"
        get_operator
        get_contype
        log "Mobile Data" "Mobile data connected ($MODEM_TYPE modem)"
        log "Network Type" "Joined $CONTYPE network ($MODEM_TYPE modem)"
        log "Network Operator" "Connected to $OPERATOR operator ($MODEM_TYPE modem)"
        ubus call ioman.gpio.dio0 update '{"value":"0"}'
        logger "DOUT off"


    elif [ "$ACTION" = "ifdown" ]; then
        log "Mobile Data" "Mobile data disconnected ($MODEM_TYPE modem)"
        ubus call ioman.gpio.dio0 update '{"value":"1"}'
        logger "DOUT on"
    fi 

The above will change the state of the output on each mobile interface state change from/to up/down. Logger lines are simply for an indication that the added command was executed. 

  • Add custom script:
    • Login to router's WebUI;
    • Navigate to System -> Custom scripts;
    • Add a similar script:
#!/bin/ash
sleep 45
while [ 1 ]; do
 sleep 5
 ping -I wwan0 8.8.8.8 -s 0 -c 3 -q >/dev/null
 ret=$?
 if [ $ret -ne 0 ]; then
 ubus call ioman.gpio.dio0 update '{"value":"1"}'
           logger "Mobile disconnected"
 else
 ubus call ioman.gpio.dio0 update '{"value":"0"}'
           logger "Mobile connected"
 fi
done

The above script checks mobile connection health by periodically sending ping requests to 8.8.8.8 and, if no ping reply is received, it is considered that interface is disconnected and output state is changed. 

Best regards,

by anonymous
Thank you for your answer. As for me, second option is better, because instead of 8.8.8.8 I can put, for instance, client IP. But in this case after trb245 reboot I cannot see I/O status WebUI page (instead of this I see red text pop-up message : Failed to get I/O config!). When I remove script, that WebUI page works correctly. What wrong I do?
by anonymous

I did replicate it as well. I cannot tell at the moment, whether it is related to this specific version of the firmware or something else, as I have not tested it, but adding the following command before sleep 45 seems to resolve it:

  • /etc/init.d/ioman restart

Best regards,

by anonymous

Thank you for your help. It seems to me after adding /etc/init.d/ioman restart line TRB245 works correctly. But in this case after device reboting via WebUI I cannot access to device's WebUI (I have wait more than 5 min - and still no access to WebUI). Only power switching should be done to solve this issue. 

One more question. How can I add some additional dio1 (set as input) pin check. For instance I want to siwtch on/off output dio0 if dio1 is in high level. I mean something like that:

 if [ ioman.gpio.dio1.value = "1" ]; then
    ubus call ioman.gpio.dio0 update '{"value":"1"}'
fi

I know it is not correct syntax in if statement. But I did not find correct.  How can I execute above mentioned task in custom script? Actually, it is my first experience with Teltonika device so any help will be usefull for me.

by anonymous

Hello,

   

The issue with restarts not being performed is most likely related to the infinite while loop. It could be replaced by a Crontab running the script every minute.

As for checking the status, ioman.gpio.dio1.value = "1" will not work, as this ubus call returns a lot of information. Instead, I would recommend installing a package called jq (opkg update && opkg install jq). It is used for parsing JSON messages and is very lightweight. Then, in the script, I would recommend saving the output of the command ubus call ioman.gpio.dout1 status | jq '.value' into a variable, and then using that variable for the IF condition.

  

Best regards,
DaumantasG

by anonymous
If I understand correctly. I should save my script into a file, save it, and then point to this file in Crontab expression? Am I right? If yes, where can I find example (or something similar) of such solution?
by anonymous

That is correct, this script should be added to a file and saved (preferably) in the /etc directory. Then, open the crontab file as explained in the linked article, and generate a crontab using a generator like crontab-generator.org

Some examples can also be found in the Crontab Wiki article.

  

Best regards,
DaumantasG