XavierBerger / RPi-Monitor

Real time monitoring for embedded devices
https://xavierberger.github.io/RPi-Monitor-docs/index.html
GNU General Public License v3.0
1.16k stars 176 forks source link

Add a demo pannel and statistics for local weather data #377

Open psa-jforestier opened 3 years ago

psa-jforestier commented 3 years ago

This conf file add a panel with weather data provided by OpenWeatherMap. You will find :

Statistics are also collected for some metrics :

This config file use the OpenWeatherMap API, for which you have to subscribe (for free) to have an AppId. Set the AppId in the weather.conf file, or you will have "undefined" error on the report. You can find some AppId on the wild by using your favorite search engine.

Your RPi will make regular https connection to the api, please allow connection to api.openweathermap.org on your firewall. The connection frequency is about 1 call every 5 minutes (may be changed in the weather.conf).

The report will display icon of weather (sun, cloud...) which are hosted on openweathermap.org . For privacy concern, be warned that your RPi-monitor instance may be exposed by the "referer" http header to the internet.

telemaxx commented 3 years ago

cool, i will try.temp gauge/statistic from owm I have already.

Robyxxx commented 2 years ago

Added "weather.conf" in "/ect/rpimonitor/template" using my API key, checked that every 5 min the file "/tmp/weather.dat" was written. Data in weather.dat are correct (checked using nano). But no data appears in RPI web interface, only a new tab called "weather" both in "status" and in "statistics". What can be the problem?

weather.dat {"coord":{"lon":9.7891,"lat":42.8264},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":"temp":26.59,"feels_like":26.59,"temp_min":25.92,"temp_max":27.76,"pressure":1021,"humidity":55,"sea_level":1021,"grnd_level":1004},"visibility":10000,"wind":{"speed":4.99,"deg":89,"gust":5.79},"clouds":{"all":14},"dt":1652873439,"sys"{"type":1,"id":6744,"country":"IT","sunrise":1652845717,"sunset":1652899468},"timezone":7200,"id":3168627,"name":"Rome","cod":200}

psa-jforestier commented 2 years ago

Can you check in the log file of RPIMonitor (should be /var/log/rpimonitor.log ). Is there any error related to access to weather.dat ?

Robyxxx commented 2 years ago

Thanks for the suggestion... anyway I think no error related to weather.dat

/var/log/rpimonitor.log

[2022/05/18-16:26:29] RPi-Monitor has been started Log level can be increased or decreased during runtime by sending signal USR1 or USR2 with the command killall -USRx rpimonitord Use of uninitialized value in vec at /usr/share/perl5/HTTP/Daemon.pm line 111. sysread() on closed filehandle GEN1 at /usr/share/perl5/HTTP/Daemon.pm line 344. Use of uninitialized value in vec at /usr/share/perl5/HTTP/Daemon.pm line 111. sysread() on closed filehandle GEN2 at /usr/share/perl5/HTTP/Daemon.pm line 344. Use of uninitialized value in vec at /usr/share/perl5/HTTP/Daemon.pm line 111. sysread() on closed filehandle GEN3 at /usr/share/perl5/HTTP/Daemon.pm line 344.

psa-jforestier commented 2 years ago

Maybe you missed the copy/paste of the weather.dat, but this element is invalid : "main":"temp":26.59 I will check later why you have such data in the file.

Robyxxx commented 2 years ago

Thansk a lot. There is a mistake in my previous copy/paste. This is my correct "weather.dat".

{"coord":{"lon":9.7891,"lat":42.8264},"weather":[{"id":801,"main":"Clouds","description":"few clouds","icon":"02d"}],"base":"stations","main":{"temp":26.34,"feels_like":26.34,"temp_min":26.34,"temp_max":26.92,"pressure":1022,"humidity":70,"sea_level":1022,"grnd_level":1005},"visibility":10000,"wind":{"speed":5.98,"deg":92,"gust":9.68},"clouds":{"all":11},"dt":1652892179,"sys":{"type":1,"id":6744,"country":"IT","sunrise":1652845717,"sunset":1652899468},"timezone":7200,"id":3168627,"name":"Rome","cod":200}

psa-jforestier commented 2 years ago

I cant reproduce the problem you had with your coordinates ("lon":9.7891,"lat":42.8264) and I got the correct graph in "statistics" and correct info on "Status" section of RPIMonitor. Some advices :

Robyxxx commented 2 years ago

Attributes for /tmp/weather.dat are -rw-rw-rw- and the file is updated every about 5 minutes. After increasing the log level, my log is:

[2022/05/31-12:02:41] RPi-Monitor has been started Log level can be increased or decreased during runtime by sending signal USR1 or USR2 with the command killall -USRx rpimonitord [[2022/05/31-12:02:422022/05/31-12:02:42] Change loglevel to ] Change loglevel to 11

[2022/05/31-12:02:42] Change loglevel to 1 [2022/05/31-12:02:43] Change loglevel to 2 [2022/05/31-12:02:43] Change loglevel to [22022/05/31-12:02:43 ] Change loglevel to 2 [2022/05/31-12:02:43] Monitor::Process Processing dynamic [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'vcgencmd measure_volts core 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'vcgencmd measure_temp 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command '/bin/bash -c "m=\$(expr \$(date '+%M') % 5); if [[ \$m == 0 ]]; then curl -m 10 -s \"https://api.openweathermap.org/data/2.5/weather?units=metric&lat=42.8264&lon=9.7891&appid=xxxx&lang=en\" --output /tmp/weather.dat; fi" 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'df / 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'df /boot 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'df /media/pi/VOLUME 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'netstat -nlt 2>/dev/null |' [2022/05/31-12:02:43] Monitor::ParseCommand Parsing command 'netstat -nlt 2>/dev/null |' [2022/05/31-12:02:43] Monitor::Alert [2022/05/31-12:02:43] Monitor::Status [2022/05/31-12:02:50] Server::DoGET [2022/05/31-12:02:50] Server::DoGET /dynamic.json [2022/05/31-12:02:50] Server::SendStatus Use of uninitialized value in vec at /usr/share/perl5/HTTP/Daemon.pm line 111. sysread() on closed filehandle GEN3 at /usr/share/perl5/HTTP/Daemon.pm line 344. [2022/05/31-12:02:53] Monitor::Process Processing dynamic [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'vcgencmd measure_volts core 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'vcgencmd measure_temp 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command '/bin/bash -c "m=\$(expr \$(date '+%M') % 5); if [[ \$m == 0 ]]; then curl -m 10 -s \"https://api.openweathermap.org/data/2.5/weather?units=metric&lat=42.8264&lon=9.7891&appid=xxxx&lang=en\" --output /tmp/weather.dat; fi" 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'df / 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'df /boot 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'df /media/pi/VOLUME 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'netstat -nlt 2>/dev/null |' [2022/05/31-12:02:53] Monitor::ParseCommand Parsing command 'netstat -nlt 2>/dev/null |' [2022/05/31-12:02:53] Monitor::Alert [2022/05/31-12:02:53] Monitor::Status [2022/05/31-12:03:02] Server::DoGET [2022/05/31-12:03:02] Server::DoGET /dynamic.json [2022/05/31-12:03:02] Server::SendStatus

psa-jforestier commented 2 years ago

I have no idea... may be related to https://github.com/XavierBerger/RPi-Monitor/issues/393 ? I will check later if I have the same problem on my installation. @Robyxxx : You should edit your log snippet and remove the value of appid.

Robyxxx commented 2 years ago

My current version is 2.12 r0, launching "sudo /etc/init.d/rpimonitor update" no update occurs. However the lastest version should be 2.13 The strange things is that in "/var/lib/rpimonitor/stat" I can found weather statistics (e.g. weather_temp.rrd, etc.)

MatthK commented 2 years ago

Thanks for this. I just saw this branch and tried it out.

At first I had the same problems, it just wouldn't show up. When I tried to get the weather tab, it showed ActivePage=1 in the URL. When I changed that to ActivePage=2 it did show up.

I then modified the weather.conf by commenting out the two lines at the top after "Add new pages", and changed the 3 to 1 in the web.status.X below to have it all on the same page.

Really neat!

And you can copy this PNG to /usr/share/rpimonitor/web/img/weather.png. Adjust the web.status.1.content.1.icon=weather.png line accordingly to have a more appropriate weather icon. Found this here.

weather