Commit 27a709ea authored by Neil Gershenfeld's avatar Neil Gershenfeld
Browse files

add prior node version

parent 05682b77
<pre>
shopcam server, prior node version
to clone: git clone https://gitlab.cba.mit.edu/pub/cams.git
to reinitialize: ./init
to run: node cams.js
uses ffmpeg for screen capture
uses convert to make thumbnails
uses compare to measure activity
can use uvcdynctrl -f to list resolutions
can use sudo guvcview to adjust camera
can use http-server-with-auth to serve:
http-server-with-auth -p port --username username --password password
http-server-with-auth -p port --username username --password password --ssl --cert cert.pem --key key.pem
index is at http://this_address:this_port
last image is at http://this_address:this_port/oldimage.jpg
can use Ubuntu MATE on Raspberry Pi 3:
sudo apt-get install nodejs-legacy npm ffmpeg imagemagick guvcview
sudo npm install -g http-server-with-auth
System -> Administration -> Time and Date -> Keep synchronized with internet servers
can use Logitech C920 HD Webcam
can start cams script on boot with cams.service:
edit cams script with port, username, and password
sudo cp cams.service /lib/systemd/system
sudo systemctl daemon-reload
sudo systemctl enable cams.service
sudo systemctl start cams.service
journalctl -u cams.service
#!/bin/bash
cd /home/fab/cams
node cams.js &
http-server-with-auth -p set_port_number --username set_username --password set_password &
//
// cams.js
// shopcam activity monitor
// Neil Gershenfeld
// 12/11/17
//
// settings
//
var image_width = 1600
var image_height = 1200
var thumbnail_size = 200
var video_filter = 'vflip,hflip'
var difference_threshold = .05
var millisecond_image_delay = 15000
var days_to_save = 150
//
// requires
//
const fs = require('fs')
const exec = require('child_process').exec
const execSync = require('child_process').execSync
//
// image update function
//
function update() {
//
// name image with time
//
var date = new Date()
var year = date.getFullYear()
var month = ('0'+(1+parseInt(date.getMonth()))).slice(-2)
var day = ('0'+date.getDate()).slice(-2)
var hour = ('0'+date.getHours()).slice(-2)
var minute = ('0'+date.getMinutes()).slice(-2)
var second = ('0'+date.getSeconds()).slice(-2)
var name = year+'-'+month+'-'+day+'-'+hour+'-'+minute+'-'+second+'.jpg'
//
// take new image
//
console.log('\ncapture '+name)
var success = true
do {
try {
execSync('ffmpeg -y -f v4l2 -s '+image_width+'x'+image_height+' -i /dev/video0 -vframes 1 -vf '+video_filter+' image.jpg')
}
catch(err) {
success = false
}
}
while (success != true)
//
// remove prior images
//
date.setDate(date.getDate()-days_to_save)
var oldyear = date.getFullYear()
var oldmonth = ('0'+(1+parseInt(date.getMonth()))).slice(-2)
var oldday = ('0'+date.getDate()).slice(-2)
var oldhour = ('0'+date.getHours()).slice(-2)
var oldminute = ('0'+date.getMinutes()).slice(-2)
var prefix = oldyear+'-'+oldmonth+'-'+oldday+'-'+oldhour+'-'+oldminute+'*'
console.log('remove '+prefix)
execSync('rm -f images/'+prefix+'*')
execSync('rm -f thumbnails/'+prefix+'*')
//
// check if image has changed beyond threshold
//
try {
execSync('compare -metric RMSE image.jpg oldimage.jpg null: 2>&1')
}
catch(err) {
var ret = String(err.stdout).split(' ')
var ptrl = ret[1].indexOf('(')
var ptrr = ret[1].indexOf(')')
var diff = parseFloat(ret[1].slice(ptrl+1,ptrr))
console.log('image difference: '+diff)
}
if (diff > difference_threshold) {
//
// size has changed, keep image
//
console.log('activity detected, save image')
execSync('convert image.jpg -resize '+thumbnail_size+'x'+thumbnail_size+' thumbnails/'+name)
execSync('cp image.jpg images/'+name)
//
// rebuild day's index
//
console.log('reindex day')
execSync("echo '<html><body>' > index/newindex.html")
execSync("echo '<script src=../display.js></script>' > index/newindex.html")
execSync('ls images | awk \'/^'+year+'-'+month+'-'+day+'/ { print "<img src=\\"../thumbnails/" $1 "\\" id=\\"" $1 "\\" style=\\"width:20%;height:auto;cursor:pointer;\\" onmousedown=display(\\"" $1 "\\")>" }\' >> index/newindex.html')
execSync("mv index/newindex.html index/"+month+"-"+day+".html")
//
// delay before next image
//
console.log('delay before next image')
execSync('mv image.jpg oldimage.jpg')
setTimeout(update,millisecond_image_delay)
}
else {
//
// size hasn't changed
//
console.log('no activity detected, don\'t save image')
//
// no delay before next image
//
execSync('mv image.jpg oldimage.jpg')
setTimeout(update,0)
}
}
//
// take initial image
//
var success = true
do {
try {
execSync('ffmpeg -y -f v4l2 -s '+image_width+'x'+image_height+' -i /dev/video0 -vframes 1 -vf '+video_filter+' oldimage.jpg')
}
catch(err) {
success = false
}
}
while (success != true)
//
// start update
//
update()
[Unit]
Description=cams
After=network.target
[Service]
Type=forking
ExecStart=/bin/bash /home/fab/cams/cams
[Install]
WantedBy=multi-user.target
var lastid
function display(id) {
var img = document.getElementById(lastid)
if (img != null) {
img.src = "../thumbnails/"+id
img.style.width = "20%"
}
var img = document.getElementById(id)
img.src = "../images/"+id
img.style.width = "100%"
lastid = id
}
<html><body>
<a href=index/01-01.html>01-01</a>
<a href=index/01-02.html>01-02</a>
<a href=index/01-03.html>01-03</a>
<a href=index/01-04.html>01-04</a>
<a href=index/01-05.html>01-05</a>
<a href=index/01-06.html>01-06</a>
<a href=index/01-07.html>01-07</a>
<a href=index/01-08.html>01-08</a>
<a href=index/01-09.html>01-09</a>
<a href=index/01-10.html>01-10</a>
<a href=index/01-11.html>01-11</a>
<a href=index/01-12.html>01-12</a>
<a href=index/01-13.html>01-13</a>
<a href=index/01-14.html>01-14</a>
<a href=index/01-15.html>01-15</a>
<a href=index/01-16.html>01-16</a>
<a href=index/01-17.html>01-17</a>
<a href=index/01-18.html>01-18</a>
<a href=index/01-19.html>01-19</a>
<a href=index/01-20.html>01-20</a>
<a href=index/01-21.html>01-21</a>
<a href=index/01-22.html>01-22</a>
<a href=index/01-23.html>01-23</a>
<a href=index/01-24.html>01-24</a>
<a href=index/01-25.html>01-25</a>
<a href=index/01-26.html>01-26</a>
<a href=index/01-27.html>01-27</a>
<a href=index/01-28.html>01-28</a>
<a href=index/01-29.html>01-29</a>
<a href=index/01-30.html>01-30</a>
<a href=index/01-31.html>01-31</a>
<a href=index/02-01.html>02-01</a>
<a href=index/02-02.html>02-02</a>
<a href=index/02-03.html>02-03</a>
<a href=index/02-04.html>02-04</a>
<a href=index/02-05.html>02-05</a>
<a href=index/02-06.html>02-06</a>
<a href=index/02-07.html>02-07</a>
<a href=index/02-08.html>02-08</a>
<a href=index/02-09.html>02-09</a>
<a href=index/02-10.html>02-10</a>
<a href=index/02-11.html>02-11</a>
<a href=index/02-12.html>02-12</a>
<a href=index/02-13.html>02-13</a>
<a href=index/02-14.html>02-14</a>
<a href=index/02-15.html>02-15</a>
<a href=index/02-16.html>02-16</a>
<a href=index/02-17.html>02-17</a>
<a href=index/02-18.html>02-18</a>
<a href=index/02-19.html>02-19</a>
<a href=index/02-20.html>02-20</a>
<a href=index/02-21.html>02-21</a>
<a href=index/02-22.html>02-22</a>
<a href=index/02-23.html>02-23</a>
<a href=index/02-24.html>02-24</a>
<a href=index/02-25.html>02-25</a>
<a href=index/02-26.html>02-26</a>
<a href=index/02-27.html>02-27</a>
<a href=index/02-28.html>02-28</a>
<a href=index/02-29.html>02-29</a>
<a href=index/02-30.html>02-30</a>
<a href=index/02-31.html>02-31</a>
<a href=index/03-01.html>03-01</a>
<a href=index/03-02.html>03-02</a>
<a href=index/03-03.html>03-03</a>
<a href=index/03-04.html>03-04</a>
<a href=index/03-05.html>03-05</a>
<a href=index/03-06.html>03-06</a>
<a href=index/03-07.html>03-07</a>
<a href=index/03-08.html>03-08</a>
<a href=index/03-09.html>03-09</a>
<a href=index/03-10.html>03-10</a>
<a href=index/03-11.html>03-11</a>
<a href=index/03-12.html>03-12</a>
<a href=index/03-13.html>03-13</a>
<a href=index/03-14.html>03-14</a>
<a href=index/03-15.html>03-15</a>
<a href=index/03-16.html>03-16</a>
<a href=index/03-17.html>03-17</a>
<a href=index/03-18.html>03-18</a>
<a href=index/03-19.html>03-19</a>
<a href=index/03-20.html>03-20</a>
<a href=index/03-21.html>03-21</a>
<a href=index/03-22.html>03-22</a>
<a href=index/03-23.html>03-23</a>
<a href=index/03-24.html>03-24</a>
<a href=index/03-25.html>03-25</a>
<a href=index/03-26.html>03-26</a>
<a href=index/03-27.html>03-27</a>
<a href=index/03-28.html>03-28</a>
<a href=index/03-29.html>03-29</a>
<a href=index/03-30.html>03-30</a>
<a href=index/03-31.html>03-31</a>
<a href=index/04-01.html>04-01</a>
<a href=index/04-02.html>04-02</a>
<a href=index/04-03.html>04-03</a>
<a href=index/04-04.html>04-04</a>
<a href=index/04-05.html>04-05</a>
<a href=index/04-06.html>04-06</a>
<a href=index/04-07.html>04-07</a>
<a href=index/04-08.html>04-08</a>
<a href=index/04-09.html>04-09</a>
<a href=index/04-10.html>04-10</a>
<a href=index/04-11.html>04-11</a>
<a href=index/04-12.html>04-12</a>
<a href=index/04-13.html>04-13</a>
<a href=index/04-14.html>04-14</a>
<a href=index/04-15.html>04-15</a>
<a href=index/04-16.html>04-16</a>
<a href=index/04-17.html>04-17</a>
<a href=index/04-18.html>04-18</a>
<a href=index/04-19.html>04-19</a>
<a href=index/04-20.html>04-20</a>
<a href=index/04-21.html>04-21</a>
<a href=index/04-22.html>04-22</a>
<a href=index/04-23.html>04-23</a>
<a href=index/04-24.html>04-24</a>
<a href=index/04-25.html>04-25</a>
<a href=index/04-26.html>04-26</a>
<a href=index/04-27.html>04-27</a>
<a href=index/04-28.html>04-28</a>
<a href=index/04-29.html>04-29</a>
<a href=index/04-30.html>04-30</a>
<a href=index/04-31.html>04-31</a>
<a href=index/05-01.html>05-01</a>
<a href=index/05-02.html>05-02</a>
<a href=index/05-03.html>05-03</a>
<a href=index/05-04.html>05-04</a>
<a href=index/05-05.html>05-05</a>
<a href=index/05-06.html>05-06</a>
<a href=index/05-07.html>05-07</a>
<a href=index/05-08.html>05-08</a>
<a href=index/05-09.html>05-09</a>
<a href=index/05-10.html>05-10</a>
<a href=index/05-11.html>05-11</a>
<a href=index/05-12.html>05-12</a>
<a href=index/05-13.html>05-13</a>
<a href=index/05-14.html>05-14</a>
<a href=index/05-15.html>05-15</a>
<a href=index/05-16.html>05-16</a>
<a href=index/05-17.html>05-17</a>
<a href=index/05-18.html>05-18</a>
<a href=index/05-19.html>05-19</a>
<a href=index/05-20.html>05-20</a>
<a href=index/05-21.html>05-21</a>
<a href=index/05-22.html>05-22</a>
<a href=index/05-23.html>05-23</a>
<a href=index/05-24.html>05-24</a>
<a href=index/05-25.html>05-25</a>
<a href=index/05-26.html>05-26</a>
<a href=index/05-27.html>05-27</a>
<a href=index/05-28.html>05-28</a>
<a href=index/05-29.html>05-29</a>
<a href=index/05-30.html>05-30</a>
<a href=index/05-31.html>05-31</a>
<a href=index/06-01.html>06-01</a>
<a href=index/06-02.html>06-02</a>
<a href=index/06-03.html>06-03</a>
<a href=index/06-04.html>06-04</a>
<a href=index/06-05.html>06-05</a>
<a href=index/06-06.html>06-06</a>
<a href=index/06-07.html>06-07</a>
<a href=index/06-08.html>06-08</a>
<a href=index/06-09.html>06-09</a>
<a href=index/06-10.html>06-10</a>
<a href=index/06-11.html>06-11</a>
<a href=index/06-12.html>06-12</a>
<a href=index/06-13.html>06-13</a>
<a href=index/06-14.html>06-14</a>
<a href=index/06-15.html>06-15</a>
<a href=index/06-16.html>06-16</a>
<a href=index/06-17.html>06-17</a>
<a href=index/06-18.html>06-18</a>
<a href=index/06-19.html>06-19</a>
<a href=index/06-20.html>06-20</a>
<a href=index/06-21.html>06-21</a>
<a href=index/06-22.html>06-22</a>
<a href=index/06-23.html>06-23</a>
<a href=index/06-24.html>06-24</a>
<a href=index/06-25.html>06-25</a>
<a href=index/06-26.html>06-26</a>
<a href=index/06-27.html>06-27</a>
<a href=index/06-28.html>06-28</a>
<a href=index/06-29.html>06-29</a>
<a href=index/06-30.html>06-30</a>
<a href=index/06-31.html>06-31</a>
<a href=index/07-01.html>07-01</a>
<a href=index/07-02.html>07-02</a>
<a href=index/07-03.html>07-03</a>
<a href=index/07-04.html>07-04</a>
<a href=index/07-05.html>07-05</a>
<a href=index/07-06.html>07-06</a>
<a href=index/07-07.html>07-07</a>
<a href=index/07-08.html>07-08</a>
<a href=index/07-09.html>07-09</a>
<a href=index/07-10.html>07-10</a>
<a href=index/07-11.html>07-11</a>
<a href=index/07-12.html>07-12</a>
<a href=index/07-13.html>07-13</a>
<a href=index/07-14.html>07-14</a>
<a href=index/07-15.html>07-15</a>
<a href=index/07-16.html>07-16</a>
<a href=index/07-17.html>07-17</a>
<a href=index/07-18.html>07-18</a>
<a href=index/07-19.html>07-19</a>
<a href=index/07-20.html>07-20</a>
<a href=index/07-21.html>07-21</a>
<a href=index/07-22.html>07-22</a>
<a href=index/07-23.html>07-23</a>
<a href=index/07-24.html>07-24</a>
<a href=index/07-25.html>07-25</a>
<a href=index/07-26.html>07-26</a>
<a href=index/07-27.html>07-27</a>
<a href=index/07-28.html>07-28</a>
<a href=index/07-29.html>07-29</a>
<a href=index/07-30.html>07-30</a>
<a href=index/07-31.html>07-31</a>
<a href=index/08-01.html>08-01</a>
<a href=index/08-02.html>08-02</a>
<a href=index/08-03.html>08-03</a>
<a href=index/08-04.html>08-04</a>
<a href=index/08-05.html>08-05</a>
<a href=index/08-06.html>08-06</a>
<a href=index/08-07.html>08-07</a>
<a href=index/08-08.html>08-08</a>
<a href=index/08-09.html>08-09</a>
<a href=index/08-10.html>08-10</a>
<a href=index/08-11.html>08-11</a>
<a href=index/08-12.html>08-12</a>
<a href=index/08-13.html>08-13</a>
<a href=index/08-14.html>08-14</a>
<a href=index/08-15.html>08-15</a>
<a href=index/08-16.html>08-16</a>
<a href=index/08-17.html>08-17</a>
<a href=index/08-18.html>08-18</a>
<a href=index/08-19.html>08-19</a>
<a href=index/08-20.html>08-20</a>
<a href=index/08-21.html>08-21</a>
<a href=index/08-22.html>08-22</a>
<a href=index/08-23.html>08-23</a>
<a href=index/08-24.html>08-24</a>
<a href=index/08-25.html>08-25</a>
<a href=index/08-26.html>08-26</a>
<a href=index/08-27.html>08-27</a>
<a href=index/08-28.html>08-28</a>
<a href=index/08-29.html>08-29</a>
<a href=index/08-30.html>08-30</a>
<a href=index/08-31.html>08-31</a>
<a href=index/09-01.html>09-01</a>
<a href=index/09-02.html>09-02</a>
<a href=index/09-03.html>09-03</a>
<a href=index/09-04.html>09-04</a>
<a href=index/09-05.html>09-05</a>
<a href=index/09-06.html>09-06</a>
<a href=index/09-07.html>09-07</a>
<a href=index/09-08.html>09-08</a>
<a href=index/09-09.html>09-09</a>
<a href=index/09-10.html>09-10</a>
<a href=index/09-11.html>09-11</a>
<a href=index/09-12.html>09-12</a>
<a href=index/09-13.html>09-13</a>
<a href=index/09-14.html>09-14</a>
<a href=index/09-15.html>09-15</a>
<a href=index/09-16.html>09-16</a>
<a href=index/09-17.html>09-17</a>
<a href=index/09-18.html>09-18</a>
<a href=index/09-19.html>09-19</a>
<a href=index/09-20.html>09-20</a>
<a href=index/09-21.html>09-21</a>
<a href=index/09-22.html>09-22</a>
<a href=index/09-23.html>09-23</a>
<a href=index/09-24.html>09-24</a>
<a href=index/09-25.html>09-25</a>
<a href=index/09-26.html>09-26</a>
<a href=index/09-27.html>09-27</a>
<a href=index/09-28.html>09-28</a>
<a href=index/09-29.html>09-29</a>
<a href=index/09-30.html>09-30</a>
<a href=index/09-31.html>09-31</a>
<a href=index/10-01.html>10-01</a>
<a href=index/10-02.html>10-02</a>
<a href=index/10-03.html>10-03</a>
<a href=index/10-04.html>10-04</a>
<a href=index/10-05.html>10-05</a>
<a href=index/10-06.html>10-06</a>
<a href=index/10-07.html>10-07</a>
<a href=index/10-08.html>10-08</a>
<a href=index/10-09.html>10-09</a>
<a href=index/10-10.html>10-10</a>
<a href=index/10-11.html>10-11</a>
<a href=index/10-12.html>10-12</a>
<a href=index/10-13.html>10-13</a>
<a href=index/10-14.html>10-14</a>
<a href=index/10-15.html>10-15</a>
<a href=index/10-16.html>10-16</a>
<a href=index/10-17.html>10-17</a>
<a href=index/10-18.html>10-18</a>
<a href=index/10-19.html>10-19</a>
<a href=index/10-20.html>10-20</a>
<a href=index/10-21.html>10-21</a>
<a href=index/10-22.html>10-22</a>
<a href=index/10-23.html>10-23</a>
<a href=index/10-24.html>10-24</a>
<a href=index/10-25.html>10-25</a>
<a href=index/10-26.html>10-26</a>
<a href=index/10-27.html>10-27</a>
<a href=index/10-28.html>10-28</a>
<a href=index/10-29.html>10-29</a>
<a href=index/10-30.html>10-30</a>
<a href=index/10-31.html>10-31</a>
<a href=index/11-01.html>11-01</a>
<a href=index/11-02.html>11-02</a>
<a href=index/11-03.html>11-03</a>
<a href=index/11-04.html>11-04</a>
<a href=index/11-05.html>11-05</a>
<a href=index/11-06.html>11-06</a>
<a href=index/11-07.html>11-07</a>
<a href=index/11-08.html>11-08</a>
<a href=index/11-09.html>11-09</a>
<a href=index/11-10.html>11-10</a>
<a href=index/11-11.html>11-11</a>
<a href=index/11-12.html>11-12</a>
<a href=index/11-13.html>11-13</a>
<a href=index/11-14.html>11-14</a>
<a href=index/11-15.html>11-15</a>
<a href=index/11-16.html>11-16</a>
<a href=index/11-17.html>11-17</a>
<a href=index/11-18.html>11-18</a>
<a href=index/11-19.html>11-19</a>
<a href=index/11-20.html>11-20</a>
<a href=index/11-21.html>11-21</a>
<a href=index/11-22.html>11-22</a>
<a href=index/11-23.html>11-23</a>
<a href=index/11-24.html>11-24</a>
<a href=index/11-25.html>11-25</a>
<a href=index/11-26.html>11-26</a>
<a href=index/11-27.html>11-27</a>
<a href=index/11-28.html>11-28</a>
<a href=index/11-29.html>11-29</a>
<a href=index/11-30.html>11-30</a>
<a href=index/11-31.html>11-31</a>
<a href=index/12-01.html>12-01</a>
<a href=index/12-02.html>12-02</a>
<a href=index/12-03.html>12-03</a>
<a href=index/12-04.html>12-04</a>
<a href=index/12-05.html>12-05</a>
<a href=index/12-06.html>12-06</a>
<a href=index/12-07.html>12-07</a>
<a href=index/12-08.html>12-08</a>
<a href=index/12-09.html>12-09</a>
<a href=index/12-10.html>12-10</a>
<a href=index/12-11.html>12-11</a>
<a href=index/12-12.html>12-12</a>
<a href=index/12-13.html>12-13</a>
<a href=index/12-14.html>12-14</a>
<a href=index/12-15.html>12-15</a>
<a href=index/12-16.html>12-16</a>
<a href=index/12-17.html>12-17</a>
<a href=index/12-18.html>12-18</a>
<a href=index/12-19.html>12-19</a>
<a href=index/12-20.html>12-20</a>
<a href=index/12-21.html>12-21</a>
<a href=index/12-22.html>12-22</a>
<a href=index/12-23.html>12-23</a>
<a href=index/12-24.html>12-24</a>
<a href=index/12-25.html>12-25</a>
<a href=index/12-26.html>12-26</a>
<a href=index/12-27.html>12-27</a>
<a href=index/12-28.html>12-28</a>
<a href=index/12-29.html>12-29</a>
<a href=index/12-30.html>12-30</a>
<a href=index/12-31.html>12-31</a>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment