alistairphillips.com

I’m : a web and mobile developer based in the Australia.


Automated UnoTelly updates on RouterOS

If you're using UnoTelly on a setup with a dynamic IP address then the following script might be of interest to you. It'll query the UnoTelly API to update your IP address the minute it detects a change. You can safely set this to run every minute as it'll only query the API when a change is detected.

The script stores the IP address in a variable of its own instead of something generic, like previousIP, to ensure that the script will perform the API update. It'll also check the API response for the text "IP Updated!" before recording the fact that it ran.

You'll need to configure waninterface to something like pppoe-out1 and userhash which you'll find over at https://www2.unotelly.com/networks within the bookmarklet text.

# Set needed variables
:local waninterface "<wan_interface>"
:local userhash "<user_hash>"
:global unoTellyPreviousIP

# get the current IP address from
:local currentNET [/ip address get [/ip address find interface=$waninterface] address]
:local currentIP [ :pick $currentNET 0 [ :find $currentNET "/" ] ]

# Did we get an IP address to compare?
:if ([ :typeof $currentIP ] = nil ) do={
    :log info ("UpdateUnoTelly: No IP address present on " . $waninterface . ", please check.")
} else={
    :if (([ :typeof $unoTellyPreviousIP ] = nil) || ($currentIP != $unoTellyPreviousIP)) do={
        :log info ("UpdateUnoTelly: UnoTelly update needed")
        :log info ("UpdateUnoTelly: unoTellyPreviousIP = $unoTellyPreviousIP, currentIP = $currentIP")
        /tool fetch mode=http address="api.unotelly.com" host="api.unotelly.com" src-path="/api/v1/network/update_by_hash_api\?user_hash=$userhash" dst-path="/unotelly.txt"
        :local result [/file get unotelly.txt contents]
        /file remove unotelly.txt
        if ($result = "IP Updated") do={
            :set unoTellyPreviousIP $currentIP
            :log info ("UpdateUnoTelly: Successfully updated IP address")
        } else={
            :log info ("UpdateUnoTelly: API update failed with ".$result)
        }
    } else={
        :log info ("UpdateUnoTelly: No UnoTelly update needed, previous IP $unoTellyPreviousIP is equal to current IP $currentIP")
    }
}