Reading UPLOAD / DOWNLOAD from TomatoUSB

Moderator: leecollings

Post Reply
User avatar
sincze
Posts: 1302
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Reading UPLOAD / DOWNLOAD from TomatoUSB

Post by sincze »

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
Shibby.JPG (31.91 KiB) Viewed 1037 times
The script is running on the router itself and posts the data to 2 virtual sensors (COUNTERS).
Shibby.JPG
Shibby.JPG (31.91 KiB) Viewed 1037 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

SCRIPT="/var/spool/script.sh"
cat << "EOF" > $SCRIPT
#!/bin/sh

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
then
        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"
else
        echo "File not created!"
fi
EOF
chmod +x $SCRIPT
# uncomment the following line if you want it to execute immediately
#$SCRIPT &
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/script.sh 2>&1 >> /dev/null
Attachments
e3000-script.JPG
e3000-script.JPG (25.66 KiB) Viewed 1032 times
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest