Skip to content

Instantly share code, notes, and snippets.

@atarp
Last active January 15, 2022 12:43
Show Gist options
  • Save atarp/1ceb3033d8e00f3dc9e683091e13ef19 to your computer and use it in GitHub Desktop.
Save atarp/1ceb3033d8e00f3dc9e683091e13ef19 to your computer and use it in GitHub Desktop.
Bash script to read data from PPC Smart Meter Gateway Customer Interface (SMGW) via the HAN interface
#!/bin/bash
curl -kis 'https://192.168.1.200/cgi-bin/hanservice.cgi' --digest -u 12345678:secret -o res.txt
cookies="session=$(cat res.txt|\
sed -e "s/[<,>,']//g" -e "s/=/\n/g"|\
grep -A 1 "session"|tail -n 1|cut -d ';' -f 1
token=$(cat res.txt|sed -e "s/[<,>,']//g" -e "s/=/\n/g"|\
grep -A 1 "tkn value"|tail -n 1|cut -d ' ' -f 1)
data="tkn=$token&action=meterform"
curl -kis --cookie "$cookies" --data "$data" "https://192.168.1.200/cgi-bin/hanservice.cgi" -o res.txt
# use the meter name as printed on the device to search for the mid token
meter_id=$(cat res.txt|sed -e "s/[<,>,']//g" -e "s/=/\n/g"|\
grep "1itr0055508382.sm"|cut -d ' ' -f 1)
data="tkn=$token&action=showMeterProfile&mid=$meter_id"
curl -kis --cookie "$cookies" --data "$data" "https://192.168.1.200/cgi-bin/hanservice.cgi" -o res.txt
cat res.txt|sed -e "s/[<,>,']/ /g" -e "s/=/\n/g" |grep table_metervalues_col |\
cut -d '_' -f 4|grep -v sign|\
sed -e 's/\(td\|\/td\| id\)/ /g'\
-e 's/&auml;/ae/g'\
-e 's/^\b[a-z]\{9\}\b /&\t/g'\
-e 's/ [^\t]/\t\t&/g'\
-e 's/ \|class//g'\
-e 's/^[t,w,e,n]/\U&/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment