感谢您点击这篇文章,我的RPI 3上有一个由Dashing提供支持的仪表板,我为我的摄像机IP添加了一个小部件(D-link DSC 4201)。
有红宝石的工作人员抓住了我相机的snapshot.jpeg:
require 'net/http'
@cameraDelay = 1 # Needed for image sync.
@fetchNewImageEvery = '3s'
@camera1Host = "192.168.0.20" ## CHANGE
@camera1Port = "80" ## CHANGE
@camera1Username = 'admin' ## CHANGE
@camera1Password ='*****'
@camera1URL = "/dms?nowprofileid=1&"
@newFile1 = "assets/images/cameras/snapshot1_new.jpg"
@oldFile1 = "assets/images/cameras/snapshot1_old.jpg"
def fetch_image(host,old_file,new_file, cam_user, cam_pass, cam_url)
`rm #{old_file}`
`mv #{new_file} #{old_file}`
Net::HTTP.start(host) do |http|
req = Net::HTTP::Get.new(cam_url)
if cam_user != "None" ## if username for any particular camera is set to 'None' then assume auth not required.
req.basic_auth cam_user, cam_pass
end
response = http.request(req)
open(new_file, "wb") do |file|
file.write(response.body)
end
end
new_file
end
def make_web_friendly(file)
"/" + File.basename(File.dirname(file)) + "/" + File.basename(file)
end
SCHEDULER.every @fetchNewImageEvery do
new_file1 = fetch_image(@camera1Host,@oldFile1,@newFile1,@camera1Username,@camera1Password,@camera1URL)
if not File.exists?(@newFile1)
warn "Failed to Get Camera Image"
end
send_event('camera1', image: make_web_friendly(@oldFile1))
sleep(@cameraDelay)
send_event('camera1', image: make_web_friendly(new_file1))
end
实际上我的作业只显示前两个图像(在@ oldFile1,@ newFile1中),并且在他在一个循环中存货后,他只在我的仪表板上显示前两个图像。
所以,我已经查看了/ assets,我看到我的两个snapshots.jpg像我的工作一样实时刷新,但这个仪表板没有显示它。
那么为什么仪表板没有拍摄刷新图像..?
答案 0 :(得分:0)
今天刚遇到这个问题。结束了重写一些事情。很确定这是一个浏览器缓存问题,因为文件名是相同的。只需添加日期时间并推送就好了。
require 'net/http'
require 'open-uri'
@url = 'http://172.1.1.16/image.jpg'
SCHEDULER.every '4s', :first_in => 0 do |job|
`find '/dashing/f12dash/assets/images/cameras/' -type f -mmin +1 -print0 | xargs -0 rm -f`
@currentTime = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
@newFile1 = "assets/images/cameras/snapshot-" + @currentTime + "_new.jpeg"
open(@url, :http_basic_authentication => ['root', 'CamPW']) do |f|
open(@newFile1,'wb') do |file|
file.puts f.read
end
end
send_event('camera1', image: ("/" + File.basename(File.dirname(@newFile1)) + "/" + File.basename(@newFile1)))
end