SUPLA Filesensors - wyślij do SUPLI cokolwiek skądkolwiek

Remi
Posts: 129
Joined: Tue May 22, 2018 4:03 pm

Post

Poniżej skrypt zczytujący dane pogodowe + czystość powietrza. Wystarczy wpisać odpowiednie API, koordynaty i miejscowość.

Code: Select all

#!/bin/bash
#Add script to file /etc/crontab as follow:#* *    * * *   root     /root/supla-filesensors/var/script_name.sh#, then restart cron process: /etc/init.d/cron restart
folder_location=/root/supla-filesensors/var/weather	#set folder for for files with data 
#*****************************************************************************************
int=`date |cut -c23-24`
int2=`date |cut -c23-24`
if [ $int -eq 0 ]; then #this part of script will be executed every 10 minutes
#Air temperature:
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.main.temp' > $folder_location/temp.txt
#Sensed temperature
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.main.feels_like' > $folder_location/feels_like.txt
#Humidity
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.main.humidity' > $folder_location/humidity.txt
#Armospheric pressure hPa
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.main.pressure' > $folder_location/pressure.txt
#Wind speed m/s
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.wind.speed' > $folder_location/wind_speed.txt
#Wind direction
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.wind.deg' > $folder_location/wind_deg.txt
#Cloud cover percentage %
curl -s 'http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.clouds.all' > /root/supla-filesensors/var/weather/clouds.txt
#Rainfall during last hour  mm - looks like not all stations share this value
#curl -s http://api.openweathermap.org/data/2.5/weather?q=Szczecin,pl&units=metric&appid=YourAPI' | jq '.rain.1h' > /root/supla-filesensors/var/weather/rain_1h.txt
cat /root/supla-filesensors/var/weather/temp.txt > "$folder_location/temp&humidity.txt";
cat /root/supla-filesensors/var/weather/humidity.txt >> "$folder_location//temp&humidity.txt";
else
echo
fi
#Air pollution - PM1, PM2.5, PM10. Data updated every 15 minutes.
if [ $int2 -eq 00 ] ; then
  i=1
elif [ $int2 -eq 15 ] ; then
  i=1
elif [ $int2 -eq 30 ] ; then
  i=1
elif [ $int2 -eq 45 ] ; then
  i=1
else
  i=0
fi
sleep 4
if [ $i -eq 1 ] ; then
  AIRLY_DATA=$(curl -s 'https://airapi.airly.eu/v2/measurements/nearest?lat=52.54736&lng=12.95355&maxDistanceKM=10&apikey=YourAPI');
  echo $AIRLY_DATA | jq '.current.values[] | select(.name=="PM25") | .value' > "$folder_location/PM25.txt"
  echo $AIRLY_DATA | jq '.current.values[] | select(.name=="PM10") | .value' > "$folder_location/PM10.txt"
  echo $AIRLY_DATA | jq '.current.values[] | select(.name=="PM1") | .value' > "$folder_location//PM1.txt"
  PM1=`cat $folder_location/PM1.txt`;
  echo "scale=2;$PM1*10" |bc > "$folder_location/PM1.txt"
  PM25=`cat $folder_location/PM25.txt`;
  echo "scale=2;$PM25*10" |bc > "$folder_location/PM25.txt"
  PM10=`cat $folder_location/PM10.txt`;
  echo "scale=2;$PM10*10" |bc > "$folder_location/PM10.txt"
  cat $folder_location/PM25.txt > "$folder_location/PM25&PM10.txt";
  cat $folder_location/PM10.txt >> "$folder_location/PM25&PM10.txt";
else
echo
fi
Last edited by Remi on Wed Feb 12, 2020 12:29 am, edited 1 time in total.
Remi
Posts: 129
Joined: Tue May 22, 2018 4:03 pm

Post

Fracz - myślałeś żeby zrobić coś podobnego ale w drugą strone tj. zczytać dane z chmury do plików? Wówczas można by było zacząć robić złożone logiki ;)
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

Nie rozumiem jak miałoby to działać
Remi
Posts: 129
Joined: Tue May 22, 2018 4:03 pm

Post

Na przykład zczytujesz do pliku wartość z wybranego kanału co jakiś określony przedział czasu - w takiej samej formie jak wartość jest odczytywana przez supla-filesensors. Wówczas lokalnie można na własną rękę procesować dane w preferowanym przez siebie zakresie (długoterminowa historia pomiarów, kalkulacje, predykcje, trendy, logiki etc.).
szym3k
Posts: 270
Joined: Mon May 15, 2017 10:32 am

Post

Przecież po to jest aktualnie API
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

szym3k wrote: Fri Feb 07, 2020 10:58 am Przecież po to jest aktualnie API
Dokładnie :-)
Remi
Posts: 129
Joined: Tue May 22, 2018 4:03 pm

Post

szym3k wrote: Fri Feb 07, 2020 10:58 am Przecież po to jest aktualnie API
Ok, to sobie doszukam w takim razie.
User avatar
lukfud
Posts: 2480
Joined: Thu Nov 23, 2017 11:33 pm
Location: Warszawa
Has thanked: 13 times
Been thanked: 11 times

Post

fracz wrote: Thu Feb 06, 2020 6:25 am Jeśli plik będzie pusty, do supli wyśle się 0 (chyba).
Sprawdzałeś to może?.
Dziś przez chwilę wyłączone było urządzenie z którego odczytuję dane poprzez link bezpośredni i w tym czasie podstawiała się wartość z innego pliku .txt
https://www.facebook.com/groups/supladiy
https://www.facebook.com/groups/suplazamel
https://www.facebook.com/groups/suplaauraton
https://smartnerzeczy.pl
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

No, jest tam coś nie tak :(
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

Return to “Projekty użytkowników”