最小物聯網系統——Dashboard
Dashboard對於一個需要及時檢視應用狀態的物聯網系統來說是一個很不錯的東西,在接觸到了Dashing之後發現可以快速用於這個物聯網系統,於是便試著將他們整合到了一起
最後效果如下圖所示
原始碼地址:https://github.com/gmszone/iot-dashboard
Dashboard是因為 一個最小的物聯網系統設計方案及原始碼 而開發的
Quick Dashboard
如果你看了上一篇介紹的話《Dashboard 框架 dashing 入門及淺析》
- Install the gem from the command line. Make sure you have Ruby 1.9+
$ gem install dashing
- Generate a new project
$ dashing new sweet_dashboard_project
- Change your directory to sweet_dashboard_project and bundle gems
$ bundle
- Start the server!
$ dashing start
- Point your browser at localhost:3030 and have fun!
新增溫度顯示
修改位置
jobs/sample.rb
因為溫度需要用到HTTP請求以及解析JSON,所以需要用到這三個庫
require "json"
require "net/http"
require "uri"
於是我們需要一個function來獲取json資料
def get_data(num)
uri = URI.parse("http://b.phodal.com/athome/"+num.to_s)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
result=JSON.parse(response.body)
result
end
返回的結果,便是
[{"id":1,"temperature":14,"sensors1":18,"sensors2":12,"led1":0}]
我們還需要獲取id為2的資料,以便用來生成溫度對比情況,也就是圖中的綠色部分。於是
current_temperature = get_data(2)[0]["temperature"].to_i
last_temperature = get_data(1)[0]["temperature"].to_i
再將temperature sent出去
send_event('temperature', { current: current_temperature, last: last_temperature })
最後也就有了
require "rubygems"
require "json"
require "net/http"
require "uri"
def get_data(num)
uri = URI.parse("http://b.phodal.com/athome/"+num.to_s)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
result=JSON.parse(response.body)
result
end
SCHEDULER.every '2s' do
current_temperature = get_data(2)[0]["temperature"].to_i
last_temperature = get_data(1)[0]["temperature"].to_i
send_event('temperature', { current: current_temperature, last: last_temperature })
end
新增一個資料大致以上面類似
sensors1 = get_data(2)[0]["sensors1"].to_i
send_event('sensors1', { value: sensors1})
於是也就有了圖2中的sensors1,當然我們還需要新增樣式到erb檔案中
新增溫度趨勢
方法大致以上面類似,主要還是儲存資料到points以及獲取資料
require "rubygems"
require "json"
require "net/http"
require "uri"
def get_data
uri = URI.parse("http://b.phodal.com/athome")
http = Net::HTTP.new(uri.host,uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
response=http.request(request)
result=JSON.parse(response.body)
result.map do |data|
{x: data["id"].to_i, y: data["temperature"].to_i}
end
end
points=get_data
SCHEDULER.every '2s' do
send_event('tempdata', points: points)
end
相關文章
- 物聯網作業系統列表作業系統
- 騰訊物聯網作業系統正式開源,最小體積僅1.8KB作業系統
- 縱論物聯網(六):基於Linux的物聯網作業系統Linux作業系統
- AliOS Things物聯網作業系統iOS作業系統
- 01-物聯網專案-物美智慧-系統搭建
- 縱論物聯網(五):除了Linux,還有什麼物聯網作業系統Linux作業系統
- 物聯網作業系統安全性分析作業系統
- 物聯網開發系統有什麼作用?
- 物聯網系統時代:iOS、安卓拜拜?iOS安卓
- 當物聯網系統出現故障:使用低質量物聯網資料的風險
- 系統架構設計筆記(106)—— 物聯網架構筆記
- 想做物聯網路卡系統 是因為不想忍
- MQTT 安全解析:構建可靠的物聯網系統MQQT
- 5分鐘課程:物聯網的系統設計
- 農田水利工程物聯網系統解決方案
- 工業物聯網智慧儲能系統解決方案
- 物聯網【專案開發】開源系統開發
- NB-IOT物聯網系統的安全架構架構
- 水庫雨量、流量實時監測物聯網系統
- 物聯網時代,智慧家居系統的具體介紹
- 谷歌Android正成為物聯網標準作業系統谷歌Android作業系統
- 【物聯網】物聯網時代,傳統企業終會奪回自己的天下!
- 小型水庫監測預警物聯網系統解決方案
- 消防物聯網系統築牢火災防控安全底線
- 汙水處理物聯網系統下的數採運維分析運維
- 物聯網閘道器助力打造煤礦安全監控系統
- 物聯網安全
- 物聯網概述
- NB物聯網路卡與物聯網路卡的區別
- 工業物聯網體系下的裝置管理系統有什麼功能
- 數字工廠如何建設物聯網資料採集系統
- 雨水情自動監測預警物聯網系統解決方案
- 可擴充套件性對物聯網管理系統有哪些影響?套件
- 物聯網教程Linux系統程式設計——特殊程式之殭屍程式Linux程式設計
- 物聯網教程Linux系統程式設計——特殊程式之守護程式Linux程式設計
- 物聯網學習教程—Linux系統程式設計之程式介紹Linux程式設計
- 數控磨床資料採集遠端監控物聯網系統
- 造紙廢水處理PLC遠端監控物聯網系統
- 現代農業之智慧農業物聯網系統解決方案