mqtt_api_client 0.1.2 → 0.2.1
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 +4 -4
- data/.env.local.example +8 -0
- data/lib/mqtt_api_client/{command.rb → device.rb} +19 -16
- data/lib/mqtt_api_client/version.rb +1 -1
- data/lib/mqtt_api_client.rb +1 -2
- metadata +5 -5
- data/log/.keep +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a240564b318c55966a38d19bf82e3889f42913e95d6d0b55ca4029ef3e29a38e
|
4
|
+
data.tar.gz: a1882e0fb51e34be57b2cf9ae4daa6c2d80a09eb8a6a198cf3e384442132f043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 828d9958263be605c6c1ad5f4a10b7aeeac4508e5131ef6bb6399113786e8f8fcf6ed0bb1bda7ecf4f3cffe9757cdc5880d602f10a46b35efec610115c774e2a
|
7
|
+
data.tar.gz: 2ae4cd4206a80f4740b562bb80535584c97dbece54c064da133a5b0660a8f07605a576e62a13e5ada794b5d31a053193616c1b5c3fc7422b828f9eab1d245bd9
|
data/.env.local.example
ADDED
@@ -1,21 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "logger"
|
4
|
-
|
4
|
+
require "fileutils"
|
5
5
|
module MqttApiClient
|
6
|
-
class
|
6
|
+
class Device
|
7
7
|
TIMEOUT_SECONDS = 2
|
8
8
|
|
9
|
-
attr_reader :mqtt_client, :device_identifier
|
9
|
+
attr_reader :mqtt_client, :device_identifier, :logger
|
10
10
|
|
11
11
|
#
|
12
12
|
# @param mqtt_client [MQTT::Client]
|
13
13
|
# @param device_identifier [String]
|
14
|
-
def initialize(mqtt_client
|
14
|
+
def initialize(mqtt_client:, device_identifier:, logger: default_logger(device_identifier))
|
15
15
|
@mqtt_client = mqtt_client
|
16
16
|
@device_identifier = device_identifier
|
17
|
+
@logger = logger
|
17
18
|
|
18
|
-
logger
|
19
|
+
logger&.info "Command logger initialized at #{Time.now}"
|
19
20
|
|
20
21
|
subscribe_to_all(
|
21
22
|
"device/#{device_identifier}/file_list",
|
@@ -29,10 +30,10 @@ module MqttApiClient
|
|
29
30
|
begin
|
30
31
|
process_get(
|
31
32
|
"device/#{device_identifier}/file_list",
|
32
|
-
"
|
33
|
+
"file_list"
|
33
34
|
)
|
34
35
|
rescue Timeout::Error => e
|
35
|
-
logger
|
36
|
+
logger&.error "file_list timeout: #{e}"
|
36
37
|
|
37
38
|
Timeout::Error.new(e)
|
38
39
|
end
|
@@ -44,37 +45,39 @@ module MqttApiClient
|
|
44
45
|
begin
|
45
46
|
process_get(
|
46
47
|
"device/#{device_identifier}/health_status",
|
47
|
-
"
|
48
|
+
"health_status"
|
48
49
|
)
|
49
50
|
rescue Timeout::Error => e
|
50
|
-
logger
|
51
|
+
logger&.error "health_status timeout: #{e}"
|
51
52
|
|
52
53
|
Timeout::Error.new(e)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
57
|
+
def disconnect
|
58
|
+
mqtt_client.disconnect
|
59
|
+
end
|
60
|
+
|
56
61
|
private
|
57
62
|
|
58
63
|
def process_get(subscribed_topic, logger_key)
|
59
64
|
@_process_get ||= Timeout.timeout(TIMEOUT_SECONDS) do
|
60
65
|
mqtt_client.get do |topic, message|
|
61
66
|
if topic == subscribed_topic
|
62
|
-
logger
|
67
|
+
logger&.info "#{logger_key}: #{message}"
|
63
68
|
|
64
69
|
# do any logic with a message there, if you need to
|
65
70
|
|
66
71
|
return message
|
67
|
-
else
|
68
|
-
# I don't want to raise exception here because we are
|
69
|
-
# getting messages from the whole mqtt queue, one by one,
|
70
|
-
# and the next message could be that what we need
|
71
72
|
end
|
72
73
|
end
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
|
-
def
|
77
|
-
|
77
|
+
def default_logger(device_identifier)
|
78
|
+
FileUtils.mkdir_p("log")
|
79
|
+
|
80
|
+
Logger.new("log/device_#{device_identifier}.log", "daily")
|
78
81
|
end
|
79
82
|
|
80
83
|
#
|
data/lib/mqtt_api_client.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqtt_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladyslav Sumskyi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|
@@ -31,6 +31,7 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- ".env.local.example"
|
34
35
|
- ".rspec"
|
35
36
|
- ".rubocop.yml"
|
36
37
|
- CHANGELOG.md
|
@@ -40,9 +41,8 @@ files:
|
|
40
41
|
- Rakefile
|
41
42
|
- bitbucket-pipelines.yml
|
42
43
|
- lib/mqtt_api_client.rb
|
43
|
-
- lib/mqtt_api_client/
|
44
|
+
- lib/mqtt_api_client/device.rb
|
44
45
|
- lib/mqtt_api_client/version.rb
|
45
|
-
- log/.keep
|
46
46
|
homepage: https://bitbucket.org/macklabsinc/mqtt_api_client/src/master/
|
47
47
|
licenses:
|
48
48
|
- MIT
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
requirements: []
|
70
|
-
rubygems_version: 3.4.
|
70
|
+
rubygems_version: 3.4.19
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: MQTT API Client
|
data/log/.keep
DELETED
File without changes
|