ardtweeno 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,10 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
- # @author David Kirwan <davidkirwanirl@gmail.com>
3
- # @description Configuration Reader Class for the Ardtweeno system
3
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 07-11-2012
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
7
8
 
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
8
25
  require 'rubygems'
9
26
  require 'yaml'
10
27
 
data/lib/ardtweeno/db.rb CHANGED
@@ -1,10 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
- # @author David Kirwan <davidkirwanirl@gmail.com>
3
- # @description API class for the Ardtweeno system
3
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 08-01-2013
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
7
8
 
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
8
25
  # Imports
9
26
  require 'rubygems'
10
27
  require 'logger'
@@ -1,10 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
3
  # @author David Kirwan https://github.com/davidkirwan/ardtweeno
3
- # @description Ardtweeno dispatcher system
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 2013-08-18
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
7
8
 
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
8
25
  # Imports
9
26
  require 'serialport'
10
27
  require 'logger'
@@ -73,6 +90,24 @@ module Ardtweeno
73
90
 
74
91
 
75
92
 
93
+ ##
94
+ # Ardtweeno::Dispatcher#constructLineplot method for constructing the line plot graph
95
+ #
96
+ # * *Args* :
97
+ # - ++ ->
98
+ # * *Returns* :
99
+ # - Array data containing the 168 hourly packet totals for the last week,
100
+ # Array of strings containing the names of the last 7 days
101
+ # * *Raises* :
102
+ #
103
+ #
104
+ def construct_lineplot(params)
105
+ theData = Ardtweeno::API.buildLineplot(@nodeManager.nodeList, params)
106
+
107
+ return theData
108
+ end
109
+
110
+
76
111
  ##
77
112
  # Ardtweeno::Dispatcher#constructTopology method for constructing the topology graph
78
113
  #
@@ -358,7 +393,9 @@ module Ardtweeno
358
393
 
359
394
  @log.debug "Constructing a new Ardtweeno::Packet from the payload.."
360
395
  packet = Ardtweeno::Packet.new(Ardtweeno.nextSeq(), payload["key"], payload["data"])
361
-
396
+
397
+ if packet.data.size > node.sensors.size then raise Ardtweeno::SensorException, "Mismatch between sensors and sensor data counts"; end
398
+
362
399
  @log.debug "Adding packet to the node.."
363
400
  node.enqueue(packet)
364
401
 
@@ -496,24 +533,6 @@ module Ardtweeno
496
533
  return false
497
534
 
498
535
  end
499
-
500
-
501
-
502
- ##
503
- # Ardtweeno::Dispatcher#reboot which flushes data then reboots the Ardtweeno Gateway host
504
- #
505
- # * *Args* :
506
- # - ++ ->
507
- # * *Returns* :
508
- # -
509
- # * *Raises* :
510
- #
511
- def reboot()
512
- @log.debug "Dispatcher#reboot has been called, restarting the gateway host.."
513
-
514
- cmd = 'ls -l' #'sudo reboot'
515
- sh "#{cmd}"
516
- end
517
536
 
518
537
 
519
538
 
@@ -557,14 +576,14 @@ module Ardtweeno
557
576
  rawdata.each do |i|
558
577
  cpu << [start, i[:cpuload]]
559
578
  mem << [start, i[:memload]]
560
- running << [start, i[:running]]
579
+ if i[:running] then running << [start, 100]; else running << [start, 0]; end
561
580
 
562
581
  start += 10000
563
582
  end
564
583
 
565
584
  cpuseries = {:label=>"CPU &#37;", :data=>cpu, :color=>"#ED0E0E"}
566
585
  memseries = {:label=>"MEM &#37;", :data=>mem, :color=>"#0E7AED"}
567
- runningseries = {:label=>"Active", :data=>running}
586
+ runningseries = {:label=>"Parser Active", :data=>running, :color=>"#088A08"}
568
587
 
569
588
  return [cpuseries, memseries, runningseries]
570
589
 
@@ -1,4 +1,28 @@
1
- require 'rubygems'
1
+ =begin
2
+ ####################################################################################################
3
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
4
+ # @description Ardtweeno Gateway
5
+ #
6
+ # @date 2014-08-12
7
+ ####################################################################################################
8
+
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
25
+
2
26
  require 'ardtweeno'
3
27
 
4
28
  module Ardtweeno
@@ -36,4 +60,6 @@ module Ardtweeno
36
60
  class AlreadyWatched < Exception
37
61
  end
38
62
 
63
+ class SensorException < Exception
64
+ end
39
65
  end
@@ -1,9 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
- # @author David Kirwan <davidkirwanirl@gmail.com>
3
- # @description Class to model an Ardtweeno Mesh Network Node
3
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 21-02-2013
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
8
+
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
7
25
  # Imports
8
26
  require 'rubygems'
9
27
  require 'logger'
@@ -1,10 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
- # @author David Kirwan <davidkirwanirl@gmail.com>
3
- # @description Node Management class for the Ardtweeno Mesh Network
3
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 21-02-2013
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
7
8
 
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
8
25
  # Imports
9
26
  require 'rubygems'
10
27
  require 'logger'
@@ -1,10 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
- # @author David Kirwan <davidkirwanirl@gmail.com>
3
- # @description Packet Communication storage class for the Ardtweeno system
3
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 14-11-2012
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
7
8
 
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
8
25
  # Imports
9
26
  require 'rubygems'
10
27
  require 'logger'
@@ -21,7 +38,7 @@ module Ardtweeno
21
38
  class Packet
22
39
 
23
40
  # Class fields
24
- attr_accessor :key, :seqNo, :date, :hour, :minute, :node, :data
41
+ attr_accessor :key, :seqNo, :date, :hour, :minute, :second, :node, :data
25
42
 
26
43
  ##
27
44
  # Ardtweeno::Packet#new for the Packet class
@@ -41,6 +58,7 @@ module Ardtweeno
41
58
  @date = theDate
42
59
  @hour = ("%02d" % today.hour).to_s
43
60
  @minute = ("%02d" % today.min).to_s
61
+ @second = ("%02d" % today.sec).to_s
44
62
  @data = newData
45
63
  @key = newKey
46
64
 
@@ -68,7 +86,7 @@ module Ardtweeno
68
86
  def to_s
69
87
  # Build the string up from field data
70
88
  str = "Packet No: " + @seqNo.to_s + " Key: " + @key + " Node: " + @node + " Date: " + @date +
71
- " " + @hour + ":" + @minute + " Data: " + @data.to_s
89
+ " " + @hour + ":" + @minute + ":" + @second + " Data: " + @data.to_s
72
90
 
73
91
  # Returns the built string
74
92
  return str
@@ -87,7 +105,7 @@ module Ardtweeno
87
105
  def to_json(options={})
88
106
 
89
107
  jsonStr = '{"date":"' + @date + '","hour":"' + @hour + '","minute":"' +
90
- @minute.to_s + '","node":"' + @node + '","key":"' + @key + '","seqNo":' +
108
+ @minute + '","second":"' + @second + '","node":"' + @node + '","key":"' + @key + '","seqNo":' +
91
109
  @seqNo.to_s + ',"data":' + @data.to_json + '}'
92
110
 
93
111
  return jsonStr
@@ -1,16 +1,34 @@
1
1
  $stdout.sync = true
2
+
3
+ =begin
2
4
  ####################################################################################################
3
- # @author David Kirwan <davidkirwanirl@gmail.com>
4
- # @description Ardtweeno Application Gateway HTTP REST API Sinatra Web App
5
+ # @author David Kirwan https://github.com/davidkirwan/ardtweeno
6
+ # @description Ardtweeno Gateway
5
7
  #
6
- # @date 14-06-2013
8
+ # @date 2014-08-12
7
9
  ####################################################################################################
10
+
11
+ This file is part of Ardtweeno.
12
+
13
+ Ardtweeno is free software: you can redistribute it and/or modify
14
+ it under the terms of the GNU General Public License as published by
15
+ the Free Software Foundation, either version 3 of the License, or
16
+ any later version.
17
+
18
+ Ardtweeno is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
25
+ =end
26
+
8
27
  ##### Require statements
9
28
  require 'rubygems'
10
29
  require 'sinatra/base'
11
- require 'ardtweeno'
12
30
  require 'logger'
13
-
31
+ require 'ardtweeno'
14
32
 
15
33
  class RESTAPI < Sinatra::Base
16
34
 
@@ -19,7 +37,7 @@ class RESTAPI < Sinatra::Base
19
37
  set :root, File.join(File.dirname(__FILE__) + '/../../')
20
38
  set :public_folder, File.join(root, '/public')
21
39
  set :views, File.join(root, '/views')
22
-
40
+ set :server, :puma
23
41
  #############################################################################################
24
42
 
25
43
  # Create the logger instance
@@ -123,7 +141,7 @@ class RESTAPI < Sinatra::Base
123
141
 
124
142
  get '/graph/v1/punchcard/:node' do |node|
125
143
  begin
126
- theData, theDays, theRange= @@theDispatcher.constructPunchcard(params)
144
+ theData, theDays, theRange = @@theDispatcher.constructPunchcard(params)
127
145
 
128
146
  rescue Exception => e
129
147
  throw :halt, [ 500, "500 Internal Server Error" ]
@@ -133,6 +151,19 @@ class RESTAPI < Sinatra::Base
133
151
  end
134
152
 
135
153
 
154
+ get '/graph/v1/lineplot/:node' do |node|
155
+ begin
156
+ theData = @@theDispatcher.construct_lineplot(params)
157
+
158
+ rescue Exception => e
159
+ raise e
160
+ #throw :halt, [ 500, "500 Internal Server Error" ]
161
+ end
162
+
163
+ erb :lineplot, :locals => {:data=>theData, :node=>node}
164
+ end
165
+
166
+
136
167
  get "/#{settings.newsURI}/create/post" do
137
168
  running = @@theDispatcher.running?
138
169
  erb :createpost, :locals => {:running => running}
@@ -230,6 +261,8 @@ class RESTAPI < Sinatra::Base
230
261
 
231
262
  rescue Ardtweeno::NodeNotAuthorised => e
232
263
  throw :halt, [ 401, "401 Unauthorised" ]
264
+ rescue Ardtweeno::SensorException
265
+ throw :halt, [ 400, "400 Bad Request" ]
233
266
  rescue Exception => e
234
267
  throw :halt, [ 400, "400 Bad Request" ]
235
268
  end
@@ -1,10 +1,27 @@
1
+ =begin
1
2
  ####################################################################################################
2
3
  # @author David Kirwan https://github.com/davidkirwan/ardtweeno
3
- # @description Ardtweeno::RingBuffer storage class
4
+ # @description Ardtweeno Gateway
4
5
  #
5
- # @date 2013-08-18
6
+ # @date 2014-08-12
6
7
  ####################################################################################################
7
8
 
9
+ This file is part of Ardtweeno.
10
+
11
+ Ardtweeno is free software: you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation, either version 3 of the License, or
14
+ any later version.
15
+
16
+ Ardtweeno is distributed in the hope that it will be useful,
17
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ GNU General Public License for more details.
20
+
21
+ You should have received a copy of the GNU General Public License
22
+ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
23
+ =end
24
+
8
25
  require 'ardtweeno'
9
26
 
10
27