攝影機已建立。攝影機 token: GVwnUd2QeMcqAuRa2enpssQp
攝影機已建立。攝影機 token: 4D7xqxJT4NnFJ28EM1Vsanmu
攝影機已建立。攝影機 token: dKTMjiMp57TS7UWSJLm46YRs
[說明]
[緣由]
最一開始的設計,就是工研院的 v1.0 API 版本,以工研院的網址當 Server,網頁系統當 client,已經全都寫好了這種方式的設計。後來因為討論到工研院的系統,每家店會安裝一套,且會在內部網路,就沒有對外可連線的 API URL 網址可以當 Server 溝通了,因此決定改成彼此用 websocket 溝通。
[遇到的困難]
再來網頁系統這邊花了相當多的時間去改版 websocket 溝通方式,也終於全部都改好了,讓原本 v1.0 API 的每項呼叫都可以使用,完全移植過來 websocket 版本,也是以工研院的系統端當成存放攝影機/網格設定的Server,網頁這邊只當做client端顯示與送出設定資料。 但實測後, websocket 光要一直保持著連線,似乎就是個大問題了..光要測試就很難找到一直連線著的狀態,結果網頁這邊所有的頁面呈現時,都會先去 websocket 要資料,變成一直 timeout 整個網頁都很奇怪,設定的出現與否也時有時無。
| #!/usr/bin/env ruby | |
| require 'open-uri' | |
| require 'JSON' | |
| require 'digest/sha2' | |
| require 'pry' | |
| require 'bigdecimal' | |
| require 'bitcoin' # Because I need to cheat every now and then | |
| # Usage: | |
| # gem install pry json ffi ruby-bitcoin |
| module RedisHelper | |
| # decode Redis value back to Ruby object | |
| def self.decode(json) | |
| self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"]) | |
| end | |
| # encode Ruby object for Redis | |
| def encoded | |
| self.updated_at = nil | |
| self.to_json |
| <html> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> | |
| <meta name="format-detection" content="telephone=no" /> | |
| <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" /> | |
| <link rel="stylesheet" type="text/css" href="css/index.css" /> | |
| <title>Hello World</title> | |
| </head> | |
| <body> | |
| <div class="app"> |
| Started POST "/messages" for 114.32.134.221 at 2010-11-06 00:31:55 +0000 | |
| Processing by MessagesController#create as HTML | |
| Parameters: {"receiver"=>"0952635533", "message"=>{"medium_id"=>"196"}} | |
| User Load (1.9ms) SELECT `users`.* FROM `users` WHERE (`users`.`UUID` = '2de9f74e-e937-11df-880f-12313909e161') LIMIT 1 | |
| User Load (19.9ms) SELECT `users`.* FROM `users` WHERE (`users`.`number` = '0952635533') LIMIT 1 | |
| SQL (1.6ms) BEGIN | |
| SQL (2.0ms) describe `messages` | |
| SQL (1.7ms) INSERT INTO `messages` (`created_at`, `mask_id`, `medium_id`, `receiver_id`, `sender_id`, `updated_at`) VALUES ('2010-11-06 00:31:56', NULL, 196, 40, 39, '2010-11-06 00:31:56') | |
| SQL (29.4ms) COMMIT | |
| SQL (1.6ms) BEGIN |