snapshot.jpg of Camera IP(D-LINK DSC 4201) 在 Dashing 中不刷新
snapshot.jpg of Camera IP(D-LINK DSC 4201) not refresh in Dashing
感谢点击此 post,我的 RPI 3 上有一个由 Dashing 驱动的仪表板,我在其中为我的相机 IP 添加了一个小部件 (D-link DSC 4201).
有 ruby 个工作捕捉到我相机的 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 像我的工作一样实时刷新,但是仪表板没有显示它。
那么为什么仪表板不采用刷新图像..?
今天刚 运行 讨论这个问题。最终重写了一些东西。很确定这是浏览器缓存问题,因为文件名相同。只是附加日期时间并推送它似乎有效。
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
感谢点击此 post,我的 RPI 3 上有一个由 Dashing 驱动的仪表板,我在其中为我的相机 IP 添加了一个小部件 (D-link DSC 4201).
有 ruby 个工作捕捉到我相机的 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 像我的工作一样实时刷新,但是仪表板没有显示它。
那么为什么仪表板不采用刷新图像..?
今天刚 运行 讨论这个问题。最终重写了一些东西。很确定这是浏览器缓存问题,因为文件名相同。只是附加日期时间并推送它似乎有效。
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