Skip to content

How to: Store data to and display from database

and7ey edited this page Mar 5, 2016 · 3 revisions

The Dashing by default just displays the data just received. If you would like to store the data received and then send it to your widget, you may use Redis datastore.

The job should be modified to store and read the data, see below the example how to do it with simple Number widget:

require 'redis' # https://github.com/redis/redis-rb
redis_uri = URI.parse(ENV["REDISTOGO_URL"])
redis = Redis.new(:host => redis_uri.host, :port => redis_uri.port, :password => redis_uri.password)

SCHEDULER.every '20s', :first_in => 0 do |job|
  rand_value = rand(1000) # replace this line with the code to get your data
  prev_value = redis.get("widget-id-prev-value") # read previous value from the Redis datastore
  redis.set("widget-id-prev-value", rand_value) # store current value to the Redis datastore

  send_event('karma', { current: rand_value, last: prev_value })
end
Clone this wiki locally