Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. server=https://stanleyroad.co.za:8123
  4. token=
  5.  
  6. # Retrieving ABB Usage Data
  7. cookie="$(mktemp)"
  8. waterusage=$(curl -c $cookie -b $cookie  -H 'Connection: keep-alive' -H 'sap-alias: <uname>' -H 'sap-password: <pwd>' 'https://eservices1.capetown.gov.za/coct/api/zuces/device/JJK5176?partner_id=1001532966&account_number=000226025214&contract=0006509716&_=1582468908478')
  9. rm $cookie
  10.  
  11. echo $waterusage
  12.  
  13. # Get Variables from String
  14. deviceID=$(echo "$waterusage" | jq '.["device"]')
  15. address=$(echo "$waterusage" | jq '.["ad_formatted"]')
  16. unitsMeasure=$(echo "$waterusage" | jq '.["mr_unit"]')
  17. lastUpdated=$(echo "$waterusage" | jq '.["mr_last_date"]')
  18. meterReading=$(echo "$waterusage" | jq '.["meter_reading"]')
  19.  
  20. # Build JSON output
  21. waterusagejson='{"state":"","attributes":{"usage":"","deviceID":'"$deviceID"',"address":'"$address"',"unitsMeasure":'"$unitsMeasure"',"lastUpdated":'"$lastUpdated"',"meterReading":'"$meterReading"'}}'
  22.  
  23. echo $waterusagejson
  24.  
  25. curl -X POST -H "Authorization: Bearer $token" \
  26.      -H "Content-Type: application/json" \
  27.      -d "$waterusagejson" \
  28.      "$server"/api/states/sensor.cct_water_usage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement