How to Chart IOT Data Using Google Charts
689 Views, 0 Favorites, 0 Comments
How to Chart IOT Data Using Google Charts
Please watch the video first
Supplies
Raspberry Pi or other server with SSH access
OpenweatherMap API credentials
Overview
You may have a requirement to chart your IOT data in order to communicate it to others . This instructable shows how do that quickly, using wind speed from OpenWeatherMap. ConnectMyPlace can also assist you with more complex solutions.
All the code and installation instructions may be obtained from https://github.com/scanos/connectmyplace/tree/mai...
In overview, the instructable shows how to graph IOT data on a chart. The components are as follows:
- A bash script - part 1 - to capture IOT data, in the example, OpenWeather data will be used, and write to a log file - wind.log
- A bash script - part 2 - to combine the log file - wind.log with a header and footer file and copy to web root to make it viewable on the web - windchartline.html.
- A header html file - windheader.html
- A footer html file - windfooter.html
Installation
Full installation instructions are also given on the github repository - https://github.com/scanos/connectmyplace/blob/main...
From the Raspberry Pi or other Linux environment CLI;
- Download this git and copy contents of wind chart to a directory outside web root, e.g. /home/pi if using a Raspberry Pi then
- sudo chmod 755 wi*.*
- sudo sudo chown pi:pi wi*.*
- Check your directory listing ls -ltr wi*.*
- -rwxr-xr-x 1 pi pi 378 Mar 23 09:44 windheader.html
- -rwxr-xr-x 1 pi pi 843 Mar 23 09:44 wind_connectmyplace.sh
- -rwxr-xr-x 1 pi pi 426 Mar 23 09:49 windfooter.html
- -rwxr-xr-x 1 pi pi 934 Mar 23 09:49 windchartline.html
- -rwxr-xr-x 1 pi pi 78 Mar 23 09:55 wind.log
- Replace the lat, long values with those for your location and the term YOUR_API_ID with your OpenweatherMap API id in wind_connectmyplace.sh
- nano wind_connectmyplace.sh
- wind=$( echo $(sudo curl "https://api.openweathermap.org/data/2.5/weather?lat=54.38&lon=-5.54&APPID=YOUR_API_ID" | jq '.wind.speed'))
- Install jq and bc if they aren't preinstalled e.g. sudo apt-get install jq
- create a copy of windchartline.html in your web root , e.g. /var/www/html and ensure that the wind_connectmyplace.sh script owner can access this. For example, sudo chown pi:www-data /var/www/html/windchartline.html
- Set up a crontab e.g. for every half hour 0,20 * * * * cd /home/pi/;./wind_connectmyplace.sh
Final Thoughts
You can implement more complex solutions , e.g.
- Multi-data charts.
- KPI summary data
- By exception information.
- From MQTT or SQL tables
- etc
Good Luck