SUPLA Filesensors - odczyt danych z API XML/HTML

User avatar
PuteR
Posts: 1473
Joined: Wed Dec 06, 2017 10:07 am

Post

szym3k jeśli dobrze wszystko wypełniłem

Code: Select all

#!/bin/sh

url='http://192.168.1.81/getregister.cgi?device=0'
sciezka='/home/pi/supla-filesensors/var'
user='root'
pass='root'

#temperatura zasilania (temperatura na kotle)
curl -u $user:$pass "$url&tkot_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tkot_value.txt

#temperatura powrotu
curl -u $user:$pass "$url&tpow_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tpow_value.txt

#temperatura podajnika
curl -u $user:$pass "$url&tpod_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tpod_value.txt

#temperatura ciepłej wody użytkowej
curl -u $user:$pass "$url&tcwu_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tcwu_value.txt

#temperatura wewnętrzna
#curl -u $user:$pass "$url&twew_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/twew_value.txt

#temperatura zewnętrzna
#curl -u $user:$pass "$url&tzew_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tzew_value.txt

#temperatura spalin
curl -u $user:$pass "$url&tsp_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tsp_value.txt

#poziom paliwa
curl -u $user:$pass "$url&fuel_level" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/fuel_level.txt

#temperatura czujnika dodatkowego nr 1
curl -u $user:$pass "$url&t1_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/t1_value.txt

#temperatura czujnika dodatkowego nr 2
#curl -u $user:$pass "$url&t2_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/t2_value.txt
to po wykonaniu skryptu dostaję takie coś

Code: Select all

-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
-:6: parser error : Opening and ending tag mismatch: hr line 5 and body
</body>
       ^
-:7: parser error : Opening and ending tag mismatch: body line 3 and html
</html>
       ^
-:8: parser error : Premature end of data in tag html line 1

^
User avatar
fracz
Posts: 2342
Joined: Fri Oct 28, 2016 10:56 pm
Location: Kraków
Has thanked: 4 times
Been thanked: 6 times

Post

Dlatego że to nie jest poprawny XML. pup jest bardziej tolerancyjny, spróbuj tego rozwiązania o którym pisałem wcześniej
szym3k
Posts: 270
Joined: Mon May 15, 2017 10:32 am

Post

Dziś przetestowałem u mnie, wszystko działa.
Image

Widzę, że operujesz na innym IP niż wczoraj tak powinno być? Nie wiem skąd praser widzi u Ciebie body i html w tym zwracanym xml nie powinno nic takiego być.

Rozwiązanie chodzi od wczoraj bez problemu.
User avatar
PuteR
Posts: 1473
Joined: Wed Dec 06, 2017 10:07 am

Post

aaaa nie potrzebnie zawracam głowę, oczywiście że wszystko chodzi wpisałem nie to IP :lol:
User avatar
PuteR
Posts: 1473
Joined: Wed Dec 06, 2017 10:07 am

Post

A pytanko takie jak zrobić żeby z dwóch plików zrobić jeden chodzi o przesyłanie danych do pliku w dwóch liniach

Napisałem coś takiego

Code: Select all

 cat /home/pi/supla-filesensors/var/weather/temp.txt > "$folder_location/temp&humidity.txt";
cat /home/pi/supla-filesensors/var/weather/humidity.txt >> "$folder_location//temp&humidity.txt";
else  
Ale w ten sposób wysyła dane ale w jednej linii.
User avatar
klew
Posts: 13908
Joined: Thu Jun 27, 2019 12:16 pm
Location: Wrocław
Has thanked: 134 times
Been thanked: 137 times

Post

Wstaw coś w stylu
printf "/n" >> plik
Pomiędzy tamtymi cat
Najlepsze suple dla Twojego domu :mrgreen:
User avatar
PuteR
Posts: 1473
Joined: Wed Dec 06, 2017 10:07 am

Post

Super dzięki, udało się :]
szym3k
Posts: 270
Joined: Mon May 15, 2017 10:32 am

Post

Jeśli wykorzystujesz mój skrypt po prostu użyj w drugiej wartości >> zamiast > wtedy doda bufora zamiast go nadpisać ;)

np.

Code: Select all

#temperatura zasilania (temperatura na kotle)
curl -u $user:$pass "$url&tkot_value" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - > $sciezka/tkot_valueandfuel_level.txt

#poziom paliwa
curl -u $user:$pass "$url&fuel_level" --silent | xmllint --xpath "string(//cmd/device/reg /@v)" - >> $sciezka/tkot_valueandfuel_level.txt

User avatar
PuteR
Posts: 1473
Joined: Wed Dec 06, 2017 10:07 am

Post

Próbuję wyciągnąć dane z Airly a konkretnie wartoś CAQI. Wszystkie inne wartości pobierają się bez problemu a z tym jednym jest problem skrypt mam napisany w ten sposób

Code: Select all

curl -s 'https://airapi.airly.eu/v2/measurements/nearest?lat=53.284041&lng=21.865889&maxDistanceKM=30&apikey=API_KEY' | jq '.current.values[] | select(.name=="AIRLY_CAQI") .value' - > $sciezka/caqi.txt
Czy te wskazanie pobiera się inaczej??
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

PuteR wrote: Mon Feb 10, 2020 11:09 pm Próbuję wyciągnąć dane z Airly a konkretnie wartoś CAQI. Wszystkie inne wartości pobierają się bez problemu a z tym jednym jest problem skrypt mam napisany w ten sposób

Code: Select all

curl -s 'https://airapi.airly.eu/v2/measurements/nearest?lat=53.284041&lng=21.865889&maxDistanceKM=30&apikey=API_KEY' | jq '.current.values[] | select(.name=="AIRLY_CAQI") .value' - > $sciezka/caqi.txt
Czy te wskazanie pobiera się inaczej??
Zamień

Code: Select all

'.current.values[] | select(.name=="AIRLY_CAQI") | .value'
na

Code: Select all

'.current.indexes[] | .value'
caqi.png
You do not have the required permissions to view the files attached to this post.
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl

Return to “Pomoc”