Skip to content

Instantly share code, notes, and snippets.

@Ayouuuu
Created February 29, 2024 13:20
Show Gist options
  • Save Ayouuuu/505109038f57df11f10a804f728c9ac4 to your computer and use it in GitHub Desktop.
Save Ayouuuu/505109038f57df11f10a804f728c9ac4 to your computer and use it in GitHub Desktop.
A script for get hnie room electricity
#!/bin/bash
xiaoquId=
buildingId=
roomName=
host=
influxdb=url.../api/v2/write?org=org&bucket=bucket
token=
cookie=$(curl -s -i "$host/isimshngc/loginServlet" -H 'Content-Type: application/x-www-form-urlencoded' -d "xiaoquId=$xiaoquId" -d "buildingId=$buildingId" -d "roomName=$roomName" | awk -F= '/^Set-Cookie:/ { print $2; exit }')
session=${cookie/; Path/}
get_bill() {
local type="$1"
local tag="$2"
local response
local format
local bill
response=$(curl -s "$host/isimshngc/monServlet?monType=$type" -H "Cookie: JSESSIONID=$session" | grep "content1" | head -n 1)
format=${response:22}
bill=$(echo ${format/'</div>'/} | grep -Eo '(-[0-9.]+|[0-9.]+)')
curl -L "$influx" -H "Authorization: Token $token" -H 'Content-Type: text/plain' -d "bill,xiaoqu=$xiaoquId,building=$buildingId,room=$roomName,type=$tag _value=$bill"
echo $bill
}
echo "Bill $(get_bill "0" "bill" )"
echo "light $(get_bill "1" "light" )"
echo "kongtiao $(get_bill "2" "kongtiao" )"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment