Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log tab on the website #101

Open
mdbrewer opened this issue Jan 3, 2019 · 3 comments
Open

Log tab on the website #101

mdbrewer opened this issue Jan 3, 2019 · 3 comments

Comments

@mdbrewer
Copy link

mdbrewer commented Jan 3, 2019

Feature request:
Have a tab on the website that displays the log info either from syslog (grep garage_controller) or the files dumped to a specific file.

@NCAvian
Copy link

NCAvian commented Feb 16, 2019

This assumes the user that is running the controller is the user "pi". If you've set up another user on your Raspberry Pi, you'll need to change the user accordingly. Where the notes say "pi" below, substitute the user you've configured.

As the user pi, do the following:

cd /home/pi
touch garage-door-controller/www/garage_door.html

Create the file 'command' in /home/pi with your text editor. It will contain the following:

#!/bin/bash

cat /var/log/syslog | grep 'garage_controller' | awk -f /home/pi/parse.awk > /home/pi/garage-door-controller/www/garage_door.html

Make this file executable:

chmod +x command

Create the file 'parse.awk' in /home/pi with your text editor. It will contain the following:

BEGIN {print "<html><link href='/css/txtstyle.css' rel='stylesheet' type='text/css' /><p>"}
! /toggled/ {print substr($0,1,16) substr($0,45) "<br>"}
END {print "</p></html>"}

Create the file 'txtstyle.css' in /home/pi/garage-door-controller/www/css. It will contain the following:

html, body {font-family:Helvetica, Arial, sans-serif; line-height: 10px; white-space: pre-wrap;}

Edit the 'index.html' file in /home/pi/garage-door-controller/www with your text editor. Below these lines:

<div class="content-primary">
<ul id="doorlist" data-role="listview"></ul>
</div>

Insert this line:
<div id="list"><p><iframe src="garage_door.html" width=400 height=600 frameborder=0 ></iframe></p></div>

Now set the command to be automatically executed periodically. You'll be editing the system crontab, so be careful not to change things already there. You're going to add a line to the file that will execute the command to populate garage_door.html ever 10 minutes. With your text editor do the following:

sudo nano /etc/crontab

Add this line:

*/10 * * * * root /home/pi/command

Save and exit nano (or whatever text editor you're using).

Notes:
The files 'txtstyle.css' and 'garage_door.html' must be owned by the pi user in order to work properly. If root owns them, you'll get missing file errors in the web browser.

Every 10 minutes, the system will execute /home/pi/command. The command pulls every line containing "garage_controller" and passes them to the awk script which converts the text to some minimal html. The script only passes along the lines that don't contain the word "toggled", and pulls out the timestamp and the relevant text. The output of the script is written to the garage_door.html file in the www folder. Whenever you browse to the web page, index.html will pull in the text in the garage_door.html file and display it on the page.

Voila!

@Gilles94500
Copy link

Gilles94500 commented Feb 16, 2019 via email

@NCAvian
Copy link

NCAvian commented Feb 16, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants