udooneorest 1.0.0 → 1.0.1

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
  SHA1:
3
- metadata.gz: 9c05a465947a23bb721af3753d43b51e74349e64
4
- data.tar.gz: 279e4c8a58466597bfc76e5eae1929353959d790
3
+ metadata.gz: 8423f087b238671a8fe5502d8fbf21576baa1d96
4
+ data.tar.gz: 83933c1d73407f6061f1959a5d8d4a2a3372c872
5
5
  SHA512:
6
- metadata.gz: 8c7ad84f98bfec09920e7e7b0099666972f77767b90296350b273a777b44604502f6ae0ad429dec6ec5764b275bd8f158d0ea4d62fd1b021b39ddcd24102379c
7
- data.tar.gz: b447bdc805ca0875b01aa90f8adf376bebff1e1ab78e105f34f9e83cebd59314e8b92c4f09817111381100f89499e574545963cd0a753a158a8b2ff71b9cfb9c
6
+ metadata.gz: 9248abf15b708af872b9a35ae9b337a21af46bca99f6fc80a6bdfe3e6b6ad3d4adf8aa02265051caa83602c5e45afa5e14fdc685b21d0fb94726f0e9d81b602d
7
+ data.tar.gz: ba619decc1c3d2d05510f5b09e4fa9575bef4d5c779a9df008471b56987274b93c246ebc5429e183d00e219091bd36a941249a3e86bb2fa4d49a08b57856a927
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Mark Sullivan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,267 @@
1
+ = UdooNeoREST
2
+
3
+ This GEM provides REST service for the UDOO NEO GPIO's, the inbuilt motion sensors
4
+ (Accelerometer/Magnetometer/Gyroscope) and the Bricks Snap-in Sensors (Barometer/Temperature)
5
+
6
+ == Why?
7
+
8
+ I wanted to be able to easily manipulate and monitor the GPIOs over HTTP.
9
+
10
+ Why did I choose Ruby when its not installed by default on the UDOO Neo image? No reason other
11
+ than I like coding in Ruby and I have always wanted to give Sinatra a go.
12
+
13
+ == Before you start
14
+
15
+ As of the beta5 release of the UDOO Neo Ubunto image, there remains an issue where you will need to make
16
+ a few changes to allow the udooer account to have sufficent rights to interact with the gpios. This
17
+ is discussed in this forum thread (http://www.udoo.org/forum/threads/gpio-through-sys-class.3020/) but I have
18
+ summarized what you need to do here:
19
+
20
+ 1) Edit the file /etc/udev/rules.d/10-imx.rules
21
+
22
+ sudo vi /etc/udev/rules.d/10-imx.rules
23
+
24
+ 2) Add the following lines:
25
+
26
+ SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chown -R root:ugpio /sys%p'"
27
+ SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chmod -R g+rw /sys%p'"
28
+ SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chown -R root:ugpio /sys/class/gpio/export'"
29
+ SUBSYSTEM=="gpio", ACTION=="add", PROGRAM="/bin/sh -c 'chmod -R g+w /sys/class/gpio/export'"
30
+
31
+ 3) Make the following group/user changes:
32
+
33
+ sudo groupadd -r ugpio
34
+ sudo usermod -a -G ugpio udooer
35
+
36
+ 4) Reboot!
37
+
38
+ sudo shutdown -r now
39
+
40
+ == Installing Ruby
41
+
42
+ These instructions assume you have a fresh UDOO Neo image.
43
+
44
+ 1) Install RVM
45
+
46
+ RVM (https://rvm.io) is nice tool to make installing and managing different versions of Ruby easy.
47
+ Its not a 100% requirement, but the instructions below assume RVM is installed.
48
+
49
+ $ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
50
+
51
+ $ \curl -sSL https://get.rvm.io | bash -s stable
52
+
53
+ Yes the \ before curl is to be included.
54
+
55
+ 2) Load RVM
56
+
57
+ Either logout of your ssh session and log back in, or issue the following command to load rvm manually:
58
+
59
+ source /home/udooer/.rvm/scripts/rvm
60
+
61
+ 3) Install the latest version of Ruby
62
+
63
+ $ rvm install ruby --latest
64
+
65
+ After a few minutes you will be required to enter the udooer account password:
66
+
67
+ udooer password required for 'apt-get --quiet --yes update': <password>
68
+
69
+ 4) Walk away and have a nice beverage of your choosing and come back after watching a rerun of a GoT episode.
70
+
71
+
72
+ == Gem Installation
73
+
74
+ Install the udooneorest gem using rubygems
75
+
76
+ $ gem install udooneorest --no-ri --no-rdoc
77
+
78
+
79
+ == Starting the REST service
80
+
81
+ To start the REST service simply issue the command:
82
+
83
+ $ udooneorest
84
+
85
+
86
+ == The API
87
+
88
+ I've written the API with two slightly different implementations.
89
+
90
+ The first is what you would consider a proper RESTful implementation whereby
91
+ creates use POST, updates use PUT and read uses GET.
92
+
93
+ The second I created because I know many (like me) sometimes would prefer to
94
+ avoid firing up a REST Console when they want some quick data. So my "lazyrest"
95
+ implementation duplicates the API but using gets only (so you can simply use
96
+ your browser).
97
+
98
+ === Port
99
+
100
+ The server listens on 4567 so you can access it in the following way: http://udooneo.local:4567/{api}
101
+
102
+ === GPIO versus PIN
103
+
104
+ The UDOO Neo uses the GPIO in all its commands, but on the board it displays
105
+ the PIN numbers (PCB Names). You can use either the GPIO or the PIN in the
106
+ appropriate API and udooneorest will translate it appropriately.
107
+
108
+ Details of the GPIO to PIN mappings can be found here: http://www.udoo.org/docs-neo/Hardware_&_Accessories/Gpio.html
109
+
110
+ === REST Response
111
+
112
+ The response to the REST call will be JSON structured in the following format:
113
+
114
+ {'status' : 'success|failed', 'message' : 'If it failed, a description of why will be here'}
115
+
116
+ === GPIO Services
117
+
118
+ ==== Export
119
+
120
+ Exporting enables the GPIO if it hasn't been previosly enabled. If you are using
121
+ a specific GPIO for the first time, then you should export it before you will
122
+ be able to set the direction or a value.
123
+
124
+ If you export a GPIO more than once, the successive export will generate a
125
+ failed response.
126
+
127
+ ==== RESTful
128
+
129
+ POST /gpio/{gpio#}/export
130
+ POST /pin/{pin#}/export
131
+
132
+ ==== Lazyrest
133
+
134
+ GET /lazyrest/gpio/{gpio#}/export
135
+ GET /lazyrest/pin/{pin#}/export
136
+
137
+
138
+ ==== Direction
139
+
140
+ To manipulate or read the direction of the GPIO use the following calls.
141
+
142
+ ==== RESTful
143
+
144
+ PUT /gpio/{gpio#}/direction/{in|out}
145
+ PUT /pin/{pin#}/direction/{in|out}
146
+ GET /gpio/{gpio#}/direction
147
+ GET /pin/{pin#}/direction
148
+
149
+ ==== Lazyrest
150
+
151
+ GET /lazyrest/gpio/{gpio#}/direction/{in|out}
152
+ GET /lazyrest/pin/{pin#}/direction/{in|out}
153
+ GET /lazyrest/gpio/{gpio#}/direction
154
+ GET /lazyrest/pin/{pin#}/direction
155
+
156
+
157
+ ==== Value
158
+
159
+ To manipulate or read the value of the GPIO use the following calls. The value can be 0 or 1 (low 0v or high 3v3).
160
+
161
+ If you try to set the value for a GPIO where the direction is "IN" expect an error.
162
+
163
+ Also a warning about reading the value, straight from the UDOO Neo GPIO documentation:
164
+
165
+ "If the direction is set to out and you try to read the value, it is not guaranteed that the kernel value is coherent with the voltage found on the external pinout."
166
+
167
+ ==== RESTful
168
+
169
+ PUT /gpio/{gpio#}/value/{0|1}
170
+ PUT /pin/{pin#}/value/{0|1}
171
+ GET /gpio/{gpio#}/value
172
+ GET /pin/{pin#}/value
173
+
174
+ ==== Lazyrest
175
+
176
+ GET /lazyrest/gpio/{gpio#}/value/{0|1}
177
+ GET /lazyrest/pin/{pin#}/value/{0|1}
178
+ GET /lazyrest/gpio/{gpio#}/value
179
+ GET /lazyrest/pin/{pin#}/value
180
+
181
+ === Motion Sensors
182
+
183
+ ==== Accelerometer
184
+
185
+ To manipulate and read the Accelerometer use the following calls.
186
+
187
+ ==== RESTful
188
+
189
+ PUT /accelerometer/enable
190
+ PUT /accelerometer/disable
191
+ GET /accelerometer/value
192
+
193
+ ==== Lazyrest
194
+
195
+ GET /lazyrest/accelerometer/enable
196
+ GET /lazyrest/accelerometer/disable
197
+ GET /lazyrest/accelerometer/value
198
+
199
+
200
+ ==== Gyroscope
201
+
202
+ To manipulate and read the Gyroscope use the following calls.
203
+
204
+ ==== RESTful
205
+
206
+ PUT /gyroscope/enable
207
+ PUT /gyroscope/disable
208
+ GET /gyroscope/value
209
+
210
+ ==== Lazyrest
211
+
212
+ GET /lazyrest/gyroscope/enable
213
+ GET /lazyrest/gyroscope/disable
214
+ GET /lazyrest/gyroscope/value
215
+
216
+ ==== Magnetometer
217
+
218
+ To manipulate and read the Magnetometer use the following calls.
219
+
220
+ ==== RESTful
221
+
222
+ PUT /magnetometer/enable
223
+ PUT /magnetometer/disable
224
+ GET /magnetometer/value
225
+
226
+ ==== Lazyrest
227
+
228
+ GET /lazyrest/magnetometer/enable
229
+ GET /lazyrest/magnetometer/disable
230
+ GET /lazyrest/magnetometer/value
231
+
232
+
233
+ === Bricks Snap-in Sensors
234
+
235
+ ==== Temperature
236
+
237
+ To read the Temperature use the following calls.
238
+
239
+ ==== RESTful
240
+
241
+ GET /temperature/value
242
+
243
+ ==== Lazyrest
244
+
245
+ GET /lazyrest/temperature/value
246
+
247
+
248
+ ==== Barometer
249
+
250
+ To read the Barometer use the following calls.
251
+
252
+ ==== RESTful
253
+
254
+ GET /barometer/value
255
+
256
+ ==== Lazyrest
257
+
258
+ GET /lazyrest/barometer/value
259
+
260
+ === Example
261
+
262
+ Here is an example using the API to export gpio 25, set the direction to out and
263
+ finally set the value to 1 (3v3).
264
+
265
+ http://udooneo.local:4567/lazyrest/gpio/25/export
266
+ http://udooneo.local:4567/lazyrest/gpio/25/direction/out
267
+ http://udooneo.local:4567/lazyrest/gpio/25/value/1
@@ -96,8 +96,8 @@ module UdooNeoRest
96
96
  return gpio_.error_message unless gpio_.valid?
97
97
 
98
98
  # Validate the value
99
- value = ValidateValue.new value
100
- return value.error_message unless value.valid?
99
+ value_ = ValidateValue.new value
100
+ return value_.error_message unless value_.valid?
101
101
 
102
102
  # Send the command and if no error return an OK result
103
103
  result = UdooNeoRest::Base.echo value, "#{BASE_PATH}gpio#{gpio}/value"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: udooneorest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Sullivan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-07 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -33,6 +33,8 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - Gemfile
36
+ - LICENSE.txt
37
+ - README.rdoc
36
38
  - bin/udooneorest
37
39
  - lib/udooneorest.rb
38
40
  - lib/udooneorest/accelerometer.rb
@@ -64,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
66
  version: '0'
65
67
  requirements: []
66
68
  rubyforge_project:
67
- rubygems_version: 2.2.2
69
+ rubygems_version: 2.2.1
68
70
  signing_key:
69
71
  specification_version: 4
70
72
  summary: Rest API for interacting with UDOO Neo