Reading UPLOAD / DOWNLOAD from TomatoUSB

Post Reply
User avatar
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands

Reading UPLOAD / DOWNLOAD from TomatoUSB

Post by sincze » Friday 26 January 2018 19:20

I've been searching the forum to see if it would be possible to read data from my TomatoUSB/ shibby router.
Unfortunately my search was not good enough as I could not find any results.
So I had to build something myself.

To see if all is working I enabled the rsync feature to replicate data from and to a remote location.
This to emulate upload and download.
Shibby.JPG (31.91 KiB) Viewed 708 times
The script is running on the router itself and posts the data to 2 virtual sensors (COUNTERS).
Shibby.JPG (31.91 KiB) Viewed 708 times
At the moment it runs every minute or so, but that can be changed to every 5 minutes or every hour.
Probably the /tmp/var/spool is not the best directory but this is just an initial test. :lol:
After a reboot it will be gone.
Just add the following to the Administration -> scripts -> init.

Code: Select all

cat << "EOF" > $SCRIPT

DOMO_IP="***.***.***.***"         # Domoticz IP Address
DOMO_PORT="8080"               # Domoticz Port
UPLOAD_IDX="***"              # Upload IDX
DOWNLOAD_IDX="***"            # Download IDX

killall -USR2 rstats           # Create the statistics
sleep 2                        # Just wait for statistics to be created

if [ -e /var/spool/rstats-history.js ]            # Execute only if file exists
        input=$(cat /var/spool/rstats-history.js | grep -A 1 'daily' | grep "[[A-Za-z]]" | sed 's/\],\[/\n/g' | tr -d '[' | tr -d '];' | tail -1)

        download=$(echo $input | cut -f2 -d ',')
        upload=$(echo $input | cut -f3 -d ',')

        upload=$((upload/1024))             # HEX -> DEC conversion and in MB 
        download=$((download/1024))         # HEX -> DEC conversion and in MB

        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$UPLOAD_IDX&svalue=$upload"
        curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DOWNLOAD_IDX&svalue=$download"
        echo "File not created!"
chmod +x $SCRIPT
# uncomment the following line if you want it to execute immediately
the script file will be created.
You will only have to run it every x minutes or so via: administration -> scheduler.

Code: Select all

/tmp/var/spool/ 2>&1 >> /dev/null
e3000-script.JPG (25.66 KiB) Viewed 703 times
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests