Skip to content

Instantly share code, notes, and snippets.

@Brunas
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Brunas/096b35e9a550f1d80ed1 to your computer and use it in GitHub Desktop.
Save Brunas/096b35e9a550f1d80ed1 to your computer and use it in GitHub Desktop.
Quick camera widget
@urlsConfig = 'assets/config/q_cam_urls.json'
# function to validate json
def valid_json? (json)
JSON.parse(json)
return true
rescue JSON::ParserError
return false
end
SCHEDULER.every '30s', :first_in => 0 do |job|
str = File.open(@urlsConfig, 'r+:utf-8').read()
if valid_json?(str)
JSON.parse(str).each { |widget, url| send_event(widget, image: url+'#'+Time.now.to_i.to_s) }
end
end
{"cafe":"http://127.0.0.1/url_to_cafe_camera_image","football_table":"http://127.0.0.1/url_to_football_table_camera_image"}

Description

This is simple Dashing widget to display images from any URL, e.g. WebCam pointed to your favorite place like football table, cafe, etc.

##Usage

The widget needs my slightly improved standard image widget. Put the q_cam.rb file in your /jobs folder. Put q_cam_urls.json to /assets/config/.

Make sure directory /assets/config is accessible by Dashing user.

To include the widget in a dashboard, add the following snippet to the dashboard layout file:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
  <div data-id="football_table" data-view="Image" data-width="100%"></div>
</li>

##Settings

Amend /assets/config/q_cam_urls.json to have proper WebCam URLs.

There is no need to restart service if job is already running and configuration file is amended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment