coap 0.0.16 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +13 -2
- data/Gemfile +0 -1
- data/LICENSE +2 -2
- data/README.md +37 -33
- data/Rakefile +12 -3
- data/bin/coap +111 -0
- data/coap.gemspec +34 -29
- data/lib/coap.rb +3 -34
- data/lib/core.rb +11 -0
- data/lib/core/coap.rb +42 -0
- data/lib/core/coap/block.rb +98 -0
- data/lib/core/coap/client.rb +314 -0
- data/lib/core/coap/coap.rb +26 -0
- data/lib/core/coap/coding.rb +146 -0
- data/lib/core/coap/fsm.rb +82 -0
- data/lib/core/coap/message.rb +203 -0
- data/lib/core/coap/observer.rb +40 -0
- data/lib/core/coap/options.rb +44 -0
- data/lib/core/coap/registry.rb +32 -0
- data/lib/core/coap/registry/content_formats.yml +7 -0
- data/lib/core/coap/resolver.rb +17 -0
- data/lib/core/coap/transmission.rb +165 -0
- data/lib/core/coap/types.rb +69 -0
- data/lib/core/coap/utility.rb +34 -0
- data/lib/core/coap/version.rb +5 -0
- data/lib/core/core_ext/socket.rb +19 -0
- data/lib/core/hexdump.rb +18 -0
- data/lib/core/link.rb +97 -0
- data/lib/core/os.rb +15 -0
- data/spec/block_spec.rb +160 -0
- data/spec/client_spec.rb +86 -0
- data/spec/fixtures/coap.me.link +1 -0
- data/spec/link_spec.rb +98 -0
- data/spec/registry_spec.rb +39 -0
- data/spec/resolver_spec.rb +19 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/transmission_spec.rb +70 -0
- data/test/helper.rb +15 -0
- data/test/test_client.rb +99 -228
- data/test/test_message.rb +99 -71
- metadata +140 -37
- data/bin/client +0 -42
- data/lib/coap/block.rb +0 -45
- data/lib/coap/client.rb +0 -364
- data/lib/coap/coap.rb +0 -273
- data/lib/coap/message.rb +0 -187
- data/lib/coap/mysocket.rb +0 -81
- data/lib/coap/observer.rb +0 -41
- data/lib/coap/version.rb +0 -3
- data/lib/misc/hexdump.rb +0 -17
- data/test/coap_test_helper.rb +0 -2
- data/test/disabled_econotag_blck.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56fd9991ac9ab886355fcce10739897c5ead898c
|
4
|
+
data.tar.gz: 53cf80a9babac55dd80aebe62741be8d13b3b1f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01be6617acec7d215ddf15fdd34e443f6114f6677d5d2de3292298bd7e28c30c90f5a97f66f7aa3b08fd2d4853c3451f0159b41ef09ae1d675fcaa43727006ad
|
7
|
+
data.tar.gz: be1e122636bf35da1cd884cfaa663bd48539879b8607a96de3c53190045e10307193d84847048e981abe04f727cf621fb9041baa347d02856cbad004ece38ef0
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2014 Simon Frerichs,
|
3
|
+
Copyright (c) 2014 Carsten Bormann, Simon Frerichs, henning mueller
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,32 +1,31 @@
|
|
1
|
-
[![Gem Version](https://
|
2
|
-
[![Dependency Status](https://
|
3
|
-
[![Build Status](https://
|
4
|
-
[![Coverage Status](https://
|
5
|
-
[![Code Climate](https://
|
1
|
+
[![Gem Version](https://img.shields.io/gem/v/coap.svg)](http://badge.fury.io/rb/coap)
|
2
|
+
[![Dependency Status](https://img.shields.io/gemnasium/nning/coap.svg)](https://gemnasium.com/nning/coap)
|
3
|
+
[![Build Status](https://img.shields.io/travis/nning/coap.svg)](https://travis-ci.org/nning/coap)
|
4
|
+
[![Coverage Status](https://img.shields.io/coveralls/nning/coap.svg)](https://coveralls.io/r/nning/coap)
|
5
|
+
[![Code Climate](https://img.shields.io/codeclimate/github/nning/coap.svg)](https://codeclimate.com/github/nning/coap)
|
6
6
|
|
7
|
-
#
|
7
|
+
# CoAP
|
8
8
|
|
9
|
-
Ruby
|
10
|
-
|
9
|
+
This Ruby gem implements client functionality for [RFC
|
10
|
+
7252](http://tools.ietf.org/html/rfc7252), the Constrained Application Protocol
|
11
|
+
(CoAP). The message parsing code included is written by Carsten Bormann, one of
|
12
|
+
the RFC authors.
|
11
13
|
|
12
|
-
The Constrained Application Protocol (CoAP) is a specialized web
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
building automation.<br>
|
14
|
+
The Constrained Application Protocol (CoAP) is a specialized web transfer
|
15
|
+
protocol for use with constrained nodes and constrained (e.g., low-power,
|
16
|
+
lossy) networks. The nodes often have 8-bit microcontrollers with small
|
17
|
+
amounts of ROM and RAM, while constrained networks such as 6LoWPAN often have
|
18
|
+
high packet error rates and a typical throughput of 10s of kbit/s. The
|
19
|
+
protocol is designed for machine-to-machine (M2M) applications such as smart
|
20
|
+
energy and building automation.
|
20
21
|
|
22
|
+
Additionally supported extensions of the CoAP protocol:
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
-
Additionally implemented:
|
25
|
-
|
26
|
-
- Blockwise Transfer http://tools.ietf.org/html/draft-ietf-core-block-14
|
27
|
-
- Observe http://tools.ietf.org/html/draft-ietf-core-observe-13
|
24
|
+
* [Blockwise Transfer](http://tools.ietf.org/html/draft-ietf-core-block-14)
|
25
|
+
* [Observe](http://tools.ietf.org/html/draft-ietf-core-observe-13)
|
28
26
|
|
29
27
|
## Install
|
28
|
+
|
30
29
|
Add this line to your application's Gemfile:
|
31
30
|
|
32
31
|
gem 'coap'
|
@@ -41,24 +40,29 @@ Or install it yourself as:
|
|
41
40
|
|
42
41
|
## Usage
|
43
42
|
|
44
|
-
### In your
|
43
|
+
### In your Ruby (on Rails) application
|
45
44
|
|
45
|
+
require 'coap'
|
46
|
+
CoAP::Client.new.get_by_uri('coap://coap.me/hello').payload
|
46
47
|
|
47
|
-
|
48
|
-
answer = client.get('coap.me', 5683, '/hello')
|
49
|
-
p answer.payload
|
48
|
+
See `test/test_client.rb` for more examples.
|
50
49
|
|
51
|
-
|
52
|
-
Code is commented in rdoc format
|
50
|
+
### Command Line Client
|
53
51
|
|
54
|
-
|
52
|
+
The command line client supports the basic CoAP methods.
|
55
53
|
|
56
|
-
|
54
|
+
coap get coap://coap.me/.well-known/core
|
57
55
|
|
58
56
|
## Testing
|
59
57
|
|
60
|
-
rake
|
58
|
+
rake
|
61
59
|
|
62
60
|
## Copyright
|
63
|
-
|
64
|
-
|
61
|
+
|
62
|
+
The code is published under the MIT license (see the LICENSE file).
|
63
|
+
|
64
|
+
### Authors
|
65
|
+
|
66
|
+
* Carsten Bormann
|
67
|
+
* Simon Frerichs
|
68
|
+
* [henning mueller](https://henning.orgizm.net)
|
data/Rakefile
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'coveralls/rake/task'
|
2
3
|
require 'rake/testtask'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
Coveralls::RakeTask.new
|
3
7
|
|
4
8
|
Rake::TestTask.new do |t|
|
5
9
|
t.libs << 'test'
|
6
10
|
end
|
7
11
|
|
8
|
-
|
9
|
-
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
|
+
|
14
|
+
desc 'Run tests.'
|
15
|
+
task default: [:spec, :test]
|
16
|
+
|
17
|
+
desc 'Tun tests and push coverage to coveralls.'
|
18
|
+
task coveralls: [:default, 'coveralls:push']
|
data/bin/coap
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'getoptlong'
|
4
|
+
require 'pp'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
8
|
+
require 'coap'
|
9
|
+
|
10
|
+
def usage
|
11
|
+
$stderr.puts <<EOF
|
12
|
+
Usage: #{File.basename($0)} [options] <method> <uri>
|
13
|
+
|
14
|
+
--debug, -d Extra debug output.
|
15
|
+
--output, -o <target> Redirect payload output. Target can be "-" for
|
16
|
+
STDOUT or a file path.
|
17
|
+
--payload, -p <string> Payload for POST and PUT as string.
|
18
|
+
--payload-file, -f <file> Read payload for POST and PUT from file.
|
19
|
+
--type, -t <type> Message type (con, non, ack, rst).
|
20
|
+
--help, -h This usage message.
|
21
|
+
|
22
|
+
EOF
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
METHODS = CoAP::METHODS + [:observe]
|
27
|
+
|
28
|
+
opts = GetoptLong.new(
|
29
|
+
['--debug', '-d', GetoptLong::NO_ARGUMENT],
|
30
|
+
['--output', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
31
|
+
['--payload', '-p', GetoptLong::REQUIRED_ARGUMENT],
|
32
|
+
['--payload-file', '-f', GetoptLong::REQUIRED_ARGUMENT],
|
33
|
+
['--type', '-t', GetoptLong::REQUIRED_ARGUMENT],
|
34
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT]
|
35
|
+
)
|
36
|
+
|
37
|
+
$DEBUG = false
|
38
|
+
output = nil
|
39
|
+
payload = nil
|
40
|
+
options = {}
|
41
|
+
|
42
|
+
opts.each do |opt, arg|
|
43
|
+
case opt
|
44
|
+
when '--debug'
|
45
|
+
$DEBUG = true
|
46
|
+
when '--output'
|
47
|
+
if arg == '-'
|
48
|
+
output = $stdout
|
49
|
+
else
|
50
|
+
output = File.open(arg, 'w')
|
51
|
+
end
|
52
|
+
when '--payload'
|
53
|
+
payload = arg
|
54
|
+
when '--payload-file'
|
55
|
+
payload = File.read(arg)
|
56
|
+
when '--type'
|
57
|
+
options[:tt] = arg.to_sym
|
58
|
+
when '--help'
|
59
|
+
usage
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
usage if ARGV.size != 2
|
64
|
+
|
65
|
+
method = ARGV.shift
|
66
|
+
uri = ARGV.shift
|
67
|
+
|
68
|
+
method = method.to_sym
|
69
|
+
usage unless METHODS.include? method
|
70
|
+
|
71
|
+
uri = 'coap://' + uri unless uri[/^coap[s]?:\/\//]
|
72
|
+
uri = URI.parse(uri)
|
73
|
+
|
74
|
+
usage unless uri.scheme[/^coap/]
|
75
|
+
|
76
|
+
client = CoAP::Client.new
|
77
|
+
|
78
|
+
answer = case method
|
79
|
+
when :get
|
80
|
+
client.get_by_uri(uri, payload, options)
|
81
|
+
|
82
|
+
when :post
|
83
|
+
client.post_by_uri(uri, payload, options)
|
84
|
+
|
85
|
+
when :put
|
86
|
+
client.put_by_uri(uri, payload, options)
|
87
|
+
|
88
|
+
when :delete
|
89
|
+
client.delete_by_uri(uri, payload, options)
|
90
|
+
|
91
|
+
when :observe
|
92
|
+
callback = ->(socket, message) do
|
93
|
+
if output
|
94
|
+
output.puts message.payload
|
95
|
+
else
|
96
|
+
pp message
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
begin
|
101
|
+
client.observe_by_uri(uri, callback)
|
102
|
+
rescue Interrupt
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
if output
|
108
|
+
output.puts answer.payload
|
109
|
+
else
|
110
|
+
pp answer
|
111
|
+
end
|
data/coap.gemspec
CHANGED
@@ -1,33 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'coap/version'
|
1
|
+
$:.unshift File.expand_path('lib', File.dirname(__FILE__))
|
2
|
+
require 'core/coap/version'
|
5
3
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
9
|
-
spec.authors = ["Carsten Bormann","Simon Frerichs"]
|
10
|
-
spec.email = ["morpheus@morphhome.net"]
|
11
|
-
spec.summary = %q{Ruby Gem for RFC 7252 - Constrained Application Protocol (CoAP)}
|
12
|
-
spec.description = %q{Ruby Gem for RFC 7252 - Constrained Application Protocol (CoAP)
|
13
|
-
The Constrained Application Protocol (CoAP) is a specialized web
|
14
|
-
transfer protocol for use with constrained nodes and constrained
|
15
|
-
(e.g., low-power, lossy) networks. The nodes often have 8-bit
|
16
|
-
microcontrollers with small amounts of ROM and RAM, while constrained
|
17
|
-
networks such as 6LoWPAN often have high packet error rates and a
|
18
|
-
typical throughput of 10s of kbit/s. The protocol is designed for
|
19
|
-
machine-to-machine (M2M) applications such as smart energy and
|
20
|
-
building automation}
|
21
|
-
spec.homepage = "https://github.com/SmallLars/coap"
|
22
|
-
spec.license = "MIT"
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'coap'
|
6
|
+
s.version = CoRE::CoAP::VERSION
|
23
7
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
8
|
+
s.summary = 'Pure Ruby implementation of RFC 7252 (Constrained Application Protocol (CoAP))'
|
9
|
+
s.description = 'Pure Ruby implementation of RFC 7252 (Constrained Application
|
10
|
+
Protocol (CoAP)). The Constrained Application Protocol (CoAP) is a
|
11
|
+
specialized web transfer protocol for use with constrained nodes and
|
12
|
+
constrained (e.g., low-power, lossy) networks. The nodes often have 8-bit
|
13
|
+
microcontrollers with small amounts of ROM and RAM, while constrained
|
14
|
+
networks such as IPv6 over Low-Power Wireless Personal Area Networks
|
15
|
+
(6LoWPANs) often have high packet error rates and a typical throughput of
|
16
|
+
10s of kbit/s. The protocol is designed for machine-to-machine (M2M)
|
17
|
+
applications such as smart energy and building automation.'
|
28
18
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
19
|
+
s.homepage = 'https://github.com/nning/coap'
|
20
|
+
s.license = 'MIT'
|
21
|
+
s.authors = ['Carsten Bormann', 'Simon Frerichs', 'henning mueller']
|
22
|
+
s.email = 'henning@orgizm.net'
|
23
|
+
|
24
|
+
s.files = `git ls-files`.split($/)
|
25
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
27
|
+
s.require_paths = ['lib']
|
28
|
+
|
29
|
+
s.add_development_dependency 'bundler', '~> 1.6'
|
30
|
+
s.add_development_dependency 'coveralls', '~> 0.7'
|
31
|
+
s.add_development_dependency 'faker', '~> 1.4'
|
32
|
+
s.add_development_dependency 'minitest', '~> 5.4'
|
33
|
+
s.add_development_dependency 'rake', '~> 10.3'
|
34
|
+
s.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
|
36
|
+
s.add_dependency 'celluloid-io', '~> 0.16', '>= 0.16.1'
|
37
|
+
s.add_dependency 'resolv-ipv6favor', '~> 0'
|
33
38
|
end
|
data/lib/coap.rb
CHANGED
@@ -1,34 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
def logger
|
6
|
-
if @logger.nil?
|
7
|
-
@logger = Logger.new(STDOUT)
|
8
|
-
@logger.level = Logger::WARN
|
9
|
-
end
|
10
|
-
|
11
|
-
@logger
|
12
|
-
end
|
13
|
-
def logger= logger
|
14
|
-
@logger.close unless @logger.nil?
|
15
|
-
|
16
|
-
@logger = logger
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
require 'logger'
|
21
|
-
require 'socket'
|
22
|
-
require 'resolv-ipv6favor'
|
23
|
-
require 'ipaddr'
|
24
|
-
require 'timeout'
|
25
|
-
#require 'CoDTLS'
|
26
|
-
|
27
|
-
require 'coap/coap.rb'
|
28
|
-
require 'coap/message.rb'
|
29
|
-
require 'coap/block.rb'
|
30
|
-
require 'coap/mysocket.rb'
|
31
|
-
require 'coap/observer.rb'
|
32
|
-
require 'coap/client.rb'
|
33
|
-
|
34
|
-
require 'misc/hexdump.rb'
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
require 'core'
|
3
|
+
include CoRE
|
data/lib/core.rb
ADDED
data/lib/core/coap.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module CoRE
|
2
|
+
module CoAP
|
3
|
+
module_function
|
4
|
+
|
5
|
+
def logger
|
6
|
+
if @logger.nil?
|
7
|
+
@logger = Logger.new(STDOUT)
|
8
|
+
@logger.level = Logger::WARN
|
9
|
+
end
|
10
|
+
|
11
|
+
@logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def logger=(logger)
|
15
|
+
@logger.close unless @logger.nil?
|
16
|
+
@logger = logger
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'celluloid/io'
|
22
|
+
require 'ipaddr'
|
23
|
+
require 'logger'
|
24
|
+
require 'resolv-ipv6favor'
|
25
|
+
require 'socket'
|
26
|
+
require 'timeout'
|
27
|
+
require 'yaml'
|
28
|
+
|
29
|
+
require 'core/coap/utility'
|
30
|
+
require 'core/coap/coding'
|
31
|
+
require 'core/coap/types'
|
32
|
+
require 'core/coap/options'
|
33
|
+
require 'core/coap/registry'
|
34
|
+
|
35
|
+
require 'core/coap/coap'
|
36
|
+
require 'core/coap/message'
|
37
|
+
require 'core/coap/version'
|
38
|
+
require 'core/coap/block'
|
39
|
+
require 'core/coap/resolver'
|
40
|
+
require 'core/coap/transmission'
|
41
|
+
require 'core/coap/observer'
|
42
|
+
require 'core/coap/client'
|