aws_iot_device 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +51 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE +201 -0
- data/README.md +175 -0
- data/Rakefile +6 -0
- data/aws_iot_device.gemspec +39 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/lib/aws_iot_device.rb +7 -0
- data/lib/aws_iot_device/mqtt_adapter.rb +32 -0
- data/lib/aws_iot_device/mqtt_adapter/client.rb +139 -0
- data/lib/aws_iot_device/mqtt_adapter/mqtt_adapter.rb +139 -0
- data/lib/aws_iot_device/mqtt_adapter/ruby_mqtt_adapter.rb +176 -0
- data/lib/aws_iot_device/mqtt_shadow_client.rb +6 -0
- data/lib/aws_iot_device/mqtt_shadow_client/json_payload_parser.rb +34 -0
- data/lib/aws_iot_device/mqtt_shadow_client/mqtt_manager.rb +135 -0
- data/lib/aws_iot_device/mqtt_shadow_client/shadow_action_manager.rb +235 -0
- data/lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb +60 -0
- data/lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb +50 -0
- data/lib/aws_iot_device/mqtt_shadow_client/token_creator.rb +32 -0
- data/lib/aws_iot_device/mqtt_shadow_client/topic_builder.rb +50 -0
- data/lib/aws_iot_device/version.rb +3 -0
- data/samples/mqtt_client_samples/mqtt_client_samples.rb +90 -0
- data/samples/shadow_action_samples/sample_shadow_action_update.rb +79 -0
- data/samples/shadow_client_samples/samples_shadow_client_delete.rb +73 -0
- data/samples/shadow_client_samples/samples_shadow_client_get.rb +74 -0
- data/samples/shadow_client_samples/samples_shadow_client_update.rb +81 -0
- data/samples/shadow_topic_samples/sample_topic_manager.rb +77 -0
- metadata +186 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'aws_iot_device'
|
2
|
+
require 'optparse'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Basic usage basic_greeting.rb -c \"YOUR_CERTIFICATE_PATH\" -k \"YOUR_KEY_FILE_PATH\" -ca \"YOUR_ROOT_CA_PATH -H \"YOUR_ENDPOINT\" -p 8883\n"
|
9
|
+
|
10
|
+
opts.separator ""
|
11
|
+
opts.separator "Common options"
|
12
|
+
opts.on_tail("-h", "--help", "--usage", "Show this message") do
|
13
|
+
puts opts
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on("-H", "--host [END_POINT]", "The endpoint where you want to connect") do |host|
|
18
|
+
options[:host] = host
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-p", "--port [MQTT_PORT]", "The port used for the connection Default is 8883") do |port|
|
22
|
+
options[:port] = port
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-c", "--cert [CERT_FILE_PATH]", "The path to the certificate file of the private key.") do |cert|
|
26
|
+
options[:cert] = cert
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-k", "--key [KEY_FILE_PATH]", "The path to private key file that would be used for encryption") do |key|
|
30
|
+
options[:key] = key
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on("-a", "--root_ca [ROOT_CA_PATH]", "The path to the authority certification file") do |root_ca|
|
34
|
+
options[:root_ca] = root_ca
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("-t", "--thing [THING_NAME]", "The Thing name on which the action would be done") do |thing|
|
38
|
+
options[:things] = thing
|
39
|
+
end
|
40
|
+
end.parse!(ARGV)
|
41
|
+
|
42
|
+
|
43
|
+
host = options[:host]
|
44
|
+
port = options[:port] || 8883
|
45
|
+
certificate_path = options[:cert]
|
46
|
+
private_key_path = options[:key]
|
47
|
+
root_ca_path = options[:root_ca]
|
48
|
+
thing = options[:things]
|
49
|
+
|
50
|
+
my_shadow_client = AwsIotDevice::MqttShadowClient::ShadowClient.new
|
51
|
+
my_shadow_client.configure_endpoint(host, port)
|
52
|
+
my_shadow_client.configure_credentials(root_ca_path, private_key_path, certificate_path)
|
53
|
+
|
54
|
+
my_shadow_client.connect
|
55
|
+
|
56
|
+
my_shadow_client.create_shadow_handler_with_name(thing, true)
|
57
|
+
|
58
|
+
filter_callback = Proc.new do |message|
|
59
|
+
puts "Executing the specific callback for topic: #{message.topic}\n##########################################\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
delta_callback = Proc.new do |delta|
|
63
|
+
message = JSON.parse(delta.payload)
|
64
|
+
puts "Catching a new message : #{message["state"]["message"]}\n##########################################\n"
|
65
|
+
end
|
66
|
+
|
67
|
+
my_shadow_client.register_delta_callback(delta_callback)
|
68
|
+
|
69
|
+
n = 1
|
70
|
+
3.times do
|
71
|
+
puts "Type the message that you want to register in the thing [#{thing}]:"
|
72
|
+
entry = $stdin.readline()
|
73
|
+
json_payload = "{\"state\":{\"desired\":{\"message\":\"#{entry.delete!("\n")}\"}}}"
|
74
|
+
my_shadow_client.update_shadow(json_payload, filter_callback, 5)
|
75
|
+
puts "#{3 - n} Message(s) left"
|
76
|
+
sleep 2
|
77
|
+
n += 1
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
my_shadow_client.disconnect
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require "aws_iot_device"
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
options = {}
|
5
|
+
|
6
|
+
OptionParser.new do |opts|
|
7
|
+
opts.banner = "Basic usage basic_greeting.rb -c \"YOUR_CERTIFICATE_PATH\" -k \"YOUR_KEY_FILE_PATH\" -ca \"YOUR_ROOT_CA_PATH -H \"YOUR_ENDPOINT\" -p 8883\n"
|
8
|
+
|
9
|
+
opts.separator ""
|
10
|
+
opts.separator "Common options"
|
11
|
+
opts.on_tail("-h", "--help", "--usage", "Show this message") do
|
12
|
+
puts opts
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on("-H", "--host [END_POINT]", "The endpoint where you want to connect") do |host|
|
17
|
+
options[:host] = host
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-p", "--port [MQTT_PORT]", "The port used for the connection Default is 8883") do |port|
|
21
|
+
options[:port] = port
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-c", "--cert [CERT_FILE_PATH]", "The path to the certificate file of the private key.") do |cert|
|
25
|
+
options[:cert] = cert
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-k", "--key [KEY_FILE_PATH]", "The path to private key file that would be used for encryption") do |key|
|
29
|
+
options[:key] = key
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("-a", "--root_ca [ROOT_CA_PATH]", "The path to the authority certification file") do |root_ca|
|
33
|
+
options[:root_ca] = root_ca
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-t", "--thing [THING_NAME]", "The Thing name on which the action would be done") do |thing|
|
37
|
+
options[:things] = thing
|
38
|
+
end
|
39
|
+
end.parse!(ARGV)
|
40
|
+
|
41
|
+
|
42
|
+
host = options[:host]
|
43
|
+
port = options[:port] || 8883
|
44
|
+
certificate_path = options[:cert]
|
45
|
+
private_key_path = options[:key]
|
46
|
+
root_ca_path = options[:root_ca]
|
47
|
+
thing = options[:things]
|
48
|
+
|
49
|
+
manager = AwsIotDevice::MqttShadowClient::MqttManager.new(host: host,
|
50
|
+
port: port,
|
51
|
+
ssl: true,
|
52
|
+
cert_file: certificate_path,
|
53
|
+
key_file: private_key_path,
|
54
|
+
ca_file: root_ca_path)
|
55
|
+
|
56
|
+
manager.connect
|
57
|
+
|
58
|
+
cli = AwsIotDevice::MqttShadowClient::ShadowTopicManager.new(manager)
|
59
|
+
|
60
|
+
filter_callback = Proc.new do |message|
|
61
|
+
puts "Received (through filtered callback) : "
|
62
|
+
puts "------------------- Topic: #{message.topic}"
|
63
|
+
puts "------------------- Payload: #{message.payload}"
|
64
|
+
puts "###################"
|
65
|
+
end
|
66
|
+
|
67
|
+
cli.shadow_topic_subscribe(thing, "get", filter_callback)
|
68
|
+
|
69
|
+
sleep 1
|
70
|
+
|
71
|
+
4.times do
|
72
|
+
cli.shadow_topic_publish(thing, "get", "")
|
73
|
+
sleep 1
|
74
|
+
end
|
75
|
+
|
76
|
+
manager.disconnect
|
77
|
+
|
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_iot_device
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pierre Goudet
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: facets
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.8.3
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.8.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mqtt
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.4.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.4.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timers
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 4.1.1
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 4.1.1
|
125
|
+
description: A gem use to communicates with the Aws Iot platform through the MQTT
|
126
|
+
protocol
|
127
|
+
email:
|
128
|
+
- p-goudet@ruby-dev.jp
|
129
|
+
executables: []
|
130
|
+
extensions: []
|
131
|
+
extra_rdoc_files: []
|
132
|
+
files:
|
133
|
+
- ".gitignore"
|
134
|
+
- CODE_OF_CONDUCT.md
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- aws_iot_device.gemspec
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- lib/aws_iot_device.rb
|
143
|
+
- lib/aws_iot_device/mqtt_adapter.rb
|
144
|
+
- lib/aws_iot_device/mqtt_adapter/client.rb
|
145
|
+
- lib/aws_iot_device/mqtt_adapter/mqtt_adapter.rb
|
146
|
+
- lib/aws_iot_device/mqtt_adapter/ruby_mqtt_adapter.rb
|
147
|
+
- lib/aws_iot_device/mqtt_shadow_client.rb
|
148
|
+
- lib/aws_iot_device/mqtt_shadow_client/json_payload_parser.rb
|
149
|
+
- lib/aws_iot_device/mqtt_shadow_client/mqtt_manager.rb
|
150
|
+
- lib/aws_iot_device/mqtt_shadow_client/shadow_action_manager.rb
|
151
|
+
- lib/aws_iot_device/mqtt_shadow_client/shadow_client.rb
|
152
|
+
- lib/aws_iot_device/mqtt_shadow_client/shadow_topic_manager.rb
|
153
|
+
- lib/aws_iot_device/mqtt_shadow_client/token_creator.rb
|
154
|
+
- lib/aws_iot_device/mqtt_shadow_client/topic_builder.rb
|
155
|
+
- lib/aws_iot_device/version.rb
|
156
|
+
- samples/mqtt_client_samples/mqtt_client_samples.rb
|
157
|
+
- samples/shadow_action_samples/sample_shadow_action_update.rb
|
158
|
+
- samples/shadow_client_samples/samples_shadow_client_delete.rb
|
159
|
+
- samples/shadow_client_samples/samples_shadow_client_get.rb
|
160
|
+
- samples/shadow_client_samples/samples_shadow_client_update.rb
|
161
|
+
- samples/shadow_topic_samples/sample_topic_manager.rb
|
162
|
+
homepage: https://github.com/RubyDevInc/aws-iot-device-sdk-ruby
|
163
|
+
licenses:
|
164
|
+
- Apache 2.0
|
165
|
+
metadata: {}
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - ">="
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
176
|
+
requirements:
|
177
|
+
- - ">="
|
178
|
+
- !ruby/object:Gem::Version
|
179
|
+
version: '0'
|
180
|
+
requirements: []
|
181
|
+
rubyforge_project:
|
182
|
+
rubygems_version: 2.4.5.1
|
183
|
+
signing_key:
|
184
|
+
specification_version: 4
|
185
|
+
summary: A gem use to communicates with the Aws Iot platform through the MQTT protocol
|
186
|
+
test_files: []
|