driq 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86bb4b68b453f360be65ef05920fa0a7ec3cb279e8469a23749940e7f5bf7598
4
- data.tar.gz: 659d6c9ff10d20b0eaa1583d8549dd2a8184874e29b6944e7e652f4a9528e438
3
+ metadata.gz: 6c6573ab45c4244f76ce1200a79586589e051ba04dc8562a9f9fd4287260d776
4
+ data.tar.gz: 39613255271061505f6c9ec75462585ecdd1d9872632bd0150940c345ea8f269
5
5
  SHA512:
6
- metadata.gz: cb1042dd7cbe4fee5c7519616ae6e6451eb73fb0cc2579c5c69197daa592592d2d838f15287d363a92d02154e5ada514a3986aca6eb4cebfbcaac3357502803c
7
- data.tar.gz: 9838a1b7ef8ae6444d66fced810abd8876659990f4828f384c8a02aca2d6ab4375db6d8fcd45d29fd3299ec00e702ea6f4c0510b3cd28ca39c10bec22a9cc06f
6
+ metadata.gz: 9debb7db9094ba586049be2bc2bee588c55b91a97b3060feda87528142c78fe9ffb9f324908922bf1a49e1b7c518beab4600c2e297b79c94e1901822f0335995
7
+ data.tar.gz: a533ab6910003aeeb11995cfbd973cff71a4c605030fdbc2bbaf56b43efa698fb92ff8068d3628f83a82fa543ef2c8e275c0ca482b620ebb2a20b6e8814449b5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Masatoshi SEKI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,3 +1,3 @@
1
1
  class Driq
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+
3
+ cd /home/pi/src/Driq/sample/co2
4
+ /usr/bin/ruby -I ../../../ruby-mh-z19/lib co2.rb
@@ -0,0 +1,125 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>CO2</title>
5
+ </head>
6
+ <style type="text/css" media="screen">
7
+ body {
8
+ font-family: Helvetica;
9
+ background: #FFFFFF;
10
+ color: #000000; 
11
+ }
12
+
13
+ #myChart {
14
+ position: relative;
15
+ height:300; width:150
16
+ }
17
+ </style>
18
+ <body>
19
+ <div class="head">
20
+ <h2>CO2 <span id="co2"></span></h2>
21
+ </div>
22
+ <div class="main">
23
+ <canvas id="myChart" style="position: relative; height:100; width:150"></canvas>
24
+ </div>
25
+
26
+ </body>
27
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
28
+ <script>
29
+
30
+ var evt = new EventSource('stream');
31
+
32
+ evt.onmessage = function(e) {
33
+ var it = JSON.parse(e.data);
34
+ console.log(it);
35
+ console.log(new Date(Number(e.lastEventId) * 0.001));
36
+ time = new Date(Number(e.lastEventId) * 0.001);
37
+ add_data(it['concentration'], it['temperature'], time);
38
+ };
39
+
40
+ var co2_text = document.getElementById("co2");
41
+
42
+ function add_data(concentration, temperature, time) {
43
+ chartDataSet.data.datasets[0].data.push({
44
+ y: concentration,
45
+ t: time
46
+ });
47
+ chartDataSet.data.datasets[1].data.push({
48
+ y: temperature,
49
+ t: time
50
+ });
51
+ while (time - chartDataSet.data.datasets[0].data[0].t > 3600000) {
52
+ chartDataSet.data.datasets[0].data.shift();
53
+ chartDataSet.data.datasets[1].data.shift();
54
+ }
55
+ chart.update();
56
+ co2_text.textContent = concentration + 'ppm';
57
+ document.title = concentration + 'ppm';
58
+ }
59
+
60
+ var ctx = document.getElementById("myChart").getContext('2d');
61
+ const chartDataSet = {
62
+ type: 'line',
63
+ responsive: false,
64
+ aspectRatio: 2,
65
+ data: {
66
+ datasets: [{
67
+ label: 'ppm',
68
+ data: [],
69
+ borderColor: "rgb(54, 162, 235)",
70
+ fill: false,
71
+ yAxisID: "y-axis-1"
72
+ }, {
73
+ label: 'temp',
74
+ data: [],
75
+ borderColor: "rgb(235, 0, 0)",
76
+ fill: false,
77
+ yAxisID: "y-axis-2"
78
+ }]
79
+ },
80
+ options: {
81
+ scales: {
82
+ xAxes: [{
83
+ type: 'time',
84
+ time: {
85
+ displayFormats: {
86
+ millisecond: 'h:mm',
87
+ second: 'h:mm',
88
+ minute: 'h:mm'
89
+ },
90
+ unit: 'minute'
91
+ },
92
+ distribution: 'linear',
93
+ ticks: {
94
+ maxTicksLimit:6,
95
+ source: 'data'
96
+ },
97
+ gridLines: {
98
+ display: false
99
+ }
100
+ }],
101
+ yAxes: [{
102
+ id: 'y-axis-1',
103
+ ticks: {
104
+ source: 'data',
105
+ min: 200,
106
+ max: 2000
107
+ }
108
+ }, {
109
+ id: 'y-axis-2',
110
+ position: 'right',
111
+ ticks: {
112
+ source: 'data',
113
+ min: -5,
114
+ max: 40
115
+ },
116
+ gridLines: {
117
+ display: false
118
+ }
119
+ }]
120
+ }
121
+ }
122
+ };
123
+ var chart = new Chart(ctx, chartDataSet);
124
+ </script>
125
+ </html>
@@ -0,0 +1,60 @@
1
+ require 'webrick'
2
+ require 'driq'
3
+ require 'driq/webrick'
4
+ require 'mh-z19'
5
+
6
+ class CO2
7
+ def initialize(port)
8
+ @src = Driq::EventSource.new
9
+ @svr = WEBrick::HTTPServer.new(:Port => port)
10
+
11
+ @svr.mount_proc('/') do |req, res|
12
+ on_index(req, res)
13
+ end
14
+
15
+ @svr.mount_proc('/stream') do |req, res|
16
+ on_stream(req, res)
17
+ end
18
+
19
+ @front = {"src" => @src,
20
+ "webrick" => @svr,
21
+ "body" => File.read('co2.html')}
22
+ end
23
+
24
+ def on_index(req, res)
25
+ res.body = File.read("co2.html")
26
+ end
27
+
28
+ def on_stream(req, res)
29
+ last_event_id = req["Last-Event-ID"] || 0
30
+ res.content_type = 'text/event-stream'
31
+ res.chunked = true
32
+ res.body = WEBrick::ChunkedStream.new(Driq::EventStream.new(@src, last_event_id))
33
+ end
34
+
35
+ def start
36
+ Thread.new { co2_loop }
37
+ @svr.start
38
+ end
39
+
40
+ def co2_loop
41
+ co2 = MH_Z19::Serial.new('/dev/serial0')
42
+ last = nil
43
+ sleep 3
44
+ loop do
45
+ begin
46
+ detail = co2.read_concentration_detail rescue nil
47
+ @src.write(detail) unless last == detail
48
+ last = detail
49
+ rescue MH_Z19::Serial::InvalidPacketException
50
+ p $!
51
+ end
52
+ sleep 60
53
+ end
54
+ end
55
+ end
56
+
57
+ port = Integer(ENV['PORT']) rescue 8080
58
+
59
+ co2 = CO2.new(port)
60
+ co2.start
@@ -0,0 +1,16 @@
1
+ #
2
+
3
+ [Unit]
4
+ Description=MH-Z14A CO2 Server
5
+ After=network.target
6
+ After=syslog.target
7
+
8
+ [Install]
9
+ WantedBy=multi-user.target
10
+
11
+ [Service]
12
+ User=pi
13
+ Group=pi
14
+ Type=simple
15
+ ExecStart=/home/pi/src/Driq/sample/co2/co2-service.sh
16
+ Restart=always
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: driq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masatoshi SEKI
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-01 00:00:00.000000000 Z
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-unit
@@ -75,12 +75,17 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - ".gitignore"
77
77
  - Gemfile
78
+ - LICENSE
78
79
  - README.md
79
80
  - Rakefile
80
81
  - driq.gemspec
81
82
  - lib/driq.rb
82
83
  - lib/driq/version.rb
83
84
  - lib/driq/webrick.rb
85
+ - sample/co2/co2-service.sh
86
+ - sample/co2/co2.html
87
+ - sample/co2/co2.rb
88
+ - sample/co2/co2.service
84
89
  - sample/koto/koto.html
85
90
  - sample/koto/koto.rb
86
91
  homepage: https://github.com/seki/Driq