mqttopia 0.1.20 → 0.2.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 +4 -4
- data/.gemrc +8 -0
- data/.rubocop.yml +5 -1
- data/MQTT_SUBSCRIPTIONS.md +7 -13
- data/lib/mqttopia/client.rb +106 -34
- data/lib/mqttopia/logger.rb +18 -6
- data/lib/mqttopia/serializers/trip_metric.rb +12 -12
- data/lib/mqttopia/serializers/trip_point.rb +40 -0
- data/lib/mqttopia/subscriptions/redirect.rb +11 -7
- data/lib/mqttopia/subscriptions/services/base.rb +2 -0
- data/lib/mqttopia/subscriptions/services/trip_metrics.rb +0 -1
- data/lib/mqttopia/subscriptions/services/trip_points.rb +45 -0
- data/lib/mqttopia/topics/services.rb +6 -0
- data/lib/mqttopia/version.rb +1 -1
- data/lib/mqttopia.rb +27 -1
- data/lib/tasks/initialize.rake +2 -6
- data/mqttopia.gemspec +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e187ae43b2ef47585aa3e90f989bf95e4b6a5a2ce5435050b6197b1de69d5867
|
4
|
+
data.tar.gz: f28d85e56435d9a70eff252b638c98d1506de4ca58678a09de79cf01bf6ed9e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38e1e64174271e7df513c72fd8f2475cb35de740407e93c5ecadb6552ccd435d9e1c9a6c79436b1b5b9d20525180c6138abfb2584b0e46334e3ac6a2fdecbdd4
|
7
|
+
data.tar.gz: 3052bd4fe4f365a2bc4e58894ef043df13f2ef43af3eb33ab110f72a4f1db2243bbd670eb9cafeafe2d658891e3c6076b0c98d2fd941af06cfaaf4ac4877ff52
|
data/.gemrc
ADDED
data/.rubocop.yml
CHANGED
@@ -28,7 +28,7 @@ Style/ClassVars:
|
|
28
28
|
Layout/LineLength:
|
29
29
|
Max: 120
|
30
30
|
Metrics/ClassLength:
|
31
|
-
Max:
|
31
|
+
Max: 180
|
32
32
|
Metrics/MethodLength:
|
33
33
|
Max: 30
|
34
34
|
Metrics/AbcSize:
|
@@ -38,4 +38,8 @@ Lint/MissingSuper:
|
|
38
38
|
Lint/RescueException:
|
39
39
|
Enabled: false
|
40
40
|
Style/RedundantFetchBlock:
|
41
|
+
Enabled: false
|
42
|
+
Metrics/CyclomaticComplexity:
|
43
|
+
Enabled: false
|
44
|
+
Metrics/PerceivedComplexity:
|
41
45
|
Enabled: false
|
data/MQTT_SUBSCRIPTIONS.md
CHANGED
@@ -17,7 +17,7 @@ This subscription handles trip metrics and serializes the data related to trips,
|
|
17
17
|
"l": 100,
|
18
18
|
"cs": "2"
|
19
19
|
},
|
20
|
-
"connt":
|
20
|
+
"connS":{"type":"Connected","connt":"MOBILE","subType":"LTE"},
|
21
21
|
"pws": -1,
|
22
22
|
"gps": -1,
|
23
23
|
"nlog": 585,
|
@@ -40,7 +40,11 @@ This subscription handles trip metrics and serializes the data related to trips,
|
|
40
40
|
trip_id: 123,
|
41
41
|
metrics: {
|
42
42
|
location_permission: "BACKGROUND_FINE",
|
43
|
-
|
43
|
+
connection: {
|
44
|
+
connection_type: "MOBILE",
|
45
|
+
connection_sub_type: "LTE",
|
46
|
+
connection_status: "Connected"
|
47
|
+
},
|
44
48
|
battery: {
|
45
49
|
battery_level: 100,
|
46
50
|
charging_status: "UNKNOWN",
|
@@ -84,16 +88,6 @@ This subscription handles trip metrics and serializes the data related to trips,
|
|
84
88
|
"-4": "DISABLED"
|
85
89
|
}
|
86
90
|
```
|
87
|
-
- **connection_type**
|
88
|
-
```json
|
89
|
-
{
|
90
|
-
"wf": "WIFI",
|
91
|
-
"cel": "CELLULAR",
|
92
|
-
"et": "ETHERNET",
|
93
|
-
"nc": "NO_CONNECTION",
|
94
|
-
"uk": "UNKNOWN"
|
95
|
-
}
|
96
|
-
```
|
97
91
|
- **charging_status**
|
98
92
|
```json
|
99
93
|
{
|
@@ -118,7 +112,7 @@ payload = {
|
|
118
112
|
"l": 100,
|
119
113
|
"cs": "2"
|
120
114
|
},
|
121
|
-
"connt":
|
115
|
+
"connS":{"type":"Connected","connt":"MOBILE","subType":"LTE"},
|
122
116
|
"pws": -1,
|
123
117
|
"gps": -1,
|
124
118
|
"nlog": 585,
|
data/lib/mqttopia/client.rb
CHANGED
@@ -7,11 +7,14 @@ require_relative "subscriptions/redirect"
|
|
7
7
|
|
8
8
|
module Mqttopia
|
9
9
|
class Client
|
10
|
-
@
|
10
|
+
@instance_mutex = Mutex.new
|
11
|
+
|
11
12
|
attr_reader :mqtt_client, :debugging, :debugging_topic
|
12
13
|
|
13
14
|
def self.instance
|
14
|
-
@
|
15
|
+
@instance_mutex.synchronize do
|
16
|
+
@instance ||= new
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
private_class_method :new
|
@@ -23,51 +26,84 @@ module Mqttopia
|
|
23
26
|
ssl: Mqttopia.ssl
|
24
27
|
)
|
25
28
|
@mqtt_client = MQTT::Client.new(
|
29
|
+
version: Mqttopia.version,
|
26
30
|
port: port,
|
27
31
|
username: username,
|
28
32
|
password: password,
|
29
33
|
ssl: ssl,
|
30
|
-
|
31
|
-
|
34
|
+
client_id: SecureRandom.hex(3) + "-#{Mqttopia.client_id}",
|
35
|
+
keep_alive: Mqttopia.keep_alive,
|
36
|
+
will_topic: Mqttopia.will_topic,
|
37
|
+
will_retain: Mqttopia.will_retain,
|
38
|
+
will_payload: Mqttopia.will_payload,
|
39
|
+
will_qos: Mqttopia.will_qos,
|
40
|
+
ack_timeout: Mqttopia.ack_timeout
|
32
41
|
)
|
42
|
+
@subscriptions = {}
|
43
|
+
@subscription_thread_mutex ||= Mutex.new
|
33
44
|
@debugging = Mqttopia.debugging
|
34
|
-
@debugging_topic =
|
35
|
-
rescue
|
45
|
+
@debugging_topic = Mqttopia.debugging_topic
|
46
|
+
rescue StandardError => e
|
36
47
|
log_error("initialize", e)
|
37
48
|
end
|
38
49
|
|
39
50
|
def connect
|
40
|
-
|
41
|
-
|
51
|
+
retry_count = 0
|
52
|
+
max_retries = 15
|
53
|
+
|
54
|
+
loop do
|
55
|
+
host = active_host(Mqttopia.hosts)
|
56
|
+
raise ArgumentError, "No hosts available" if host.nil?
|
57
|
+
|
58
|
+
mqtt_client.host = host
|
59
|
+
mqtt_client.connect
|
42
60
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
61
|
+
retry_count = 0 # Reset retry count on successful connection
|
62
|
+
break # Exit the loop once connected
|
63
|
+
rescue StandardError => e
|
64
|
+
retry_count += 1
|
65
|
+
disconnect_and_log("connect", e)
|
66
|
+
|
67
|
+
if retry_count >= max_retries
|
68
|
+
log_error("connect", "Terminating connection attempts after #{max_retries} failures")
|
69
|
+
break # Stop retrying after max retries
|
70
|
+
end
|
71
|
+
|
72
|
+
sleep(2 * retry_count) # Delay before retrying to prevent rapid retries
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def publish(topic, message = nil, qos = 0)
|
77
|
+
self.class.publish(topic, message, qos)
|
47
78
|
end
|
48
79
|
|
49
80
|
def self.publish(topic, message = nil, qos = 0)
|
81
|
+
# Publishes a message to a topic.
|
82
|
+
#
|
50
83
|
client = new
|
84
|
+
# @param message [String, NilClass] Message to publish, defaults to nil
|
85
|
+
# @param qos [Integer] Quality of service, defaults to 0
|
86
|
+
#
|
87
|
+
# @return [Boolean] True if publish succeeded, false otherwise
|
51
88
|
client.connect
|
52
89
|
|
53
|
-
# publish(topic, payload = '', retain = false, qos = 0)
|
54
90
|
client.mqtt_client.publish(topic, message, false, qos)
|
55
91
|
client.disconnect
|
56
92
|
|
57
93
|
Mqttopia::Logger.debug("\n#{message}\n") if client.debugging
|
58
94
|
true
|
59
|
-
rescue
|
95
|
+
rescue StandardError => e
|
60
96
|
Mqttopia::Logger.error("\nMqttopia::Client -> publish: #{e}\n")
|
61
97
|
false
|
62
98
|
end
|
63
99
|
|
64
|
-
def subscribe(topic, qos = 0, &block)
|
100
|
+
def subscribe(topic, listener_event = nil, qos = 0, &block)
|
65
101
|
return unless ensure_connection
|
66
102
|
raise StandardError, "Blocked Topic" if [debugging_topic].include?(topic)
|
67
103
|
|
68
104
|
mqtt_client.subscribe(topic => qos)
|
69
|
-
|
70
|
-
rescue
|
105
|
+
register_subscription(listener_event, &block)
|
106
|
+
rescue StandardError => e
|
71
107
|
disconnect_and_log("subscribe", e)
|
72
108
|
end
|
73
109
|
|
@@ -82,6 +118,8 @@ module Mqttopia
|
|
82
118
|
private
|
83
119
|
|
84
120
|
def active_host(hosts = Mqttopia.hosts, port = Mqttopia.port, timeout = 10)
|
121
|
+
return if hosts.nil? || hosts.empty?
|
122
|
+
|
85
123
|
hosts.each do |host|
|
86
124
|
Socket.tcp(host, port, connect_timeout: timeout) do |sock|
|
87
125
|
sock.close
|
@@ -93,30 +131,65 @@ module Mqttopia
|
|
93
131
|
nil # Return nil if no reachable host is found
|
94
132
|
end
|
95
133
|
|
96
|
-
def
|
97
|
-
|
98
|
-
mqtt_client.get do |topic, message|
|
99
|
-
log_debug("Received RAW message on topic #{topic}: #{message} with QOS #{qos}")
|
134
|
+
def register_subscription(listener_event = nil, &block)
|
135
|
+
return unless block_given?
|
100
136
|
|
101
|
-
|
137
|
+
@subscriptions[listener_event] = block # Store callback for this topic
|
102
138
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
139
|
+
start_subscription_thread unless @subscription_thread
|
140
|
+
end
|
141
|
+
|
142
|
+
def start_subscription_thread
|
143
|
+
@subscription_thread_mutex.synchronize do
|
144
|
+
return if @subscription_thread
|
145
|
+
|
146
|
+
@subscription_thread ||= Thread.new do
|
147
|
+
retry_count = 0
|
148
|
+
max_retries = 15
|
108
149
|
|
109
|
-
|
150
|
+
loop do
|
151
|
+
mqtt_client.get do |topic, message|
|
152
|
+
handle_subscription_message(topic, message)
|
153
|
+
end
|
154
|
+
|
155
|
+
retry_count = 0 # Reset retry count i
|
156
|
+
f successful
|
157
|
+
rescue StandardError => e
|
158
|
+
retry_count += 1
|
159
|
+
log_error("subscription_thread", e)
|
160
|
+
|
161
|
+
if retry_count >= max_retries
|
162
|
+
log_error("subscription_thread", "Terminating after #{max_retries} failed attempts")
|
163
|
+
break # Exit the loop and terminate the thread
|
164
|
+
end
|
165
|
+
|
166
|
+
sleep(2 * retry_count) # Delay before retrying
|
167
|
+
retry # Restart loop if under max retries
|
168
|
+
end
|
110
169
|
end
|
111
170
|
end
|
112
171
|
end
|
113
172
|
|
173
|
+
def handle_subscription_message(topic, message)
|
174
|
+
response = safe_mqtt_response(topic, message)
|
175
|
+
|
176
|
+
if debugging && topic.exclude?(debugging_topic)
|
177
|
+
Mqttopia::Client.publish(debugging_topic, { 'topic_name': topic, 'mqttopia_response': response })
|
178
|
+
end
|
179
|
+
|
180
|
+
return unless response.is_a?(Hash) && response[:event]
|
181
|
+
|
182
|
+
@subscriptions.each do |subscribed_topic, callback|
|
183
|
+
callback.call(response[:data]) if subscribed_topic.to_s == response[:event]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
114
187
|
def safe_mqtt_response(topic_name, raw_payload)
|
115
|
-
Mqttopia::Subscriptions::Redirect.new(
|
188
|
+
::Mqttopia::Subscriptions::Redirect.new(
|
116
189
|
topic_name: topic_name,
|
117
190
|
payload: parse_json(raw_payload)
|
118
191
|
).call
|
119
|
-
rescue
|
192
|
+
rescue StandardError => e
|
120
193
|
log_error("safe_mqtt_response", e) if debugging
|
121
194
|
nil
|
122
195
|
end
|
@@ -139,11 +212,10 @@ module Mqttopia
|
|
139
212
|
Mqttopia::Logger.error("\nMqttopia::Client -> #{method}: #{error_details(error)}\n")
|
140
213
|
end
|
141
214
|
|
142
|
-
def log_debug(message)
|
143
|
-
Mqttopia::Logger.debug("\n#{message}\n") if debugging
|
144
|
-
end
|
145
|
-
|
146
215
|
def disconnect_and_log(method, error)
|
216
|
+
@subscription_thread_mutex.synchronize do
|
217
|
+
Thread.kill(@subscription_thread) if @subscription_thread
|
218
|
+
end
|
147
219
|
disconnect
|
148
220
|
log_error(method, error)
|
149
221
|
end
|
data/lib/mqttopia/logger.rb
CHANGED
@@ -7,23 +7,35 @@ module Mqttopia
|
|
7
7
|
class << self
|
8
8
|
# Initialize the logger
|
9
9
|
def logger
|
10
|
-
@logger ||= Mqttopia.logger
|
10
|
+
@logger ||= Mqttopia.logger
|
11
|
+
end
|
12
|
+
|
13
|
+
def logger_level
|
14
|
+
@logger_level ||= Mqttopia.logger_level
|
11
15
|
end
|
12
16
|
|
13
17
|
# Allow users to set a custom logger (e.g., logging to a file)
|
14
|
-
attr_writer :logger
|
18
|
+
attr_writer :logger, :logger_level
|
15
19
|
|
16
20
|
# Simple wrapper for logging debug messages
|
17
|
-
|
21
|
+
def debug(msg)
|
22
|
+
logger.debug(msg) if %i[debug].include?(logger_level)
|
23
|
+
end
|
18
24
|
|
19
25
|
# Wrapper for logging info messages
|
20
|
-
|
26
|
+
def info(msg)
|
27
|
+
logger.info(msg) if %i[debug info].include?(logger_level)
|
28
|
+
end
|
21
29
|
|
22
30
|
# Wrapper for logging warn messages
|
23
|
-
|
31
|
+
def warn(msg)
|
32
|
+
logger.warn(msg) if %i[debug info warn].include?(logger_level)
|
33
|
+
end
|
24
34
|
|
25
35
|
# Wrapper for logging error messages
|
26
|
-
|
36
|
+
def error(msg)
|
37
|
+
logger.error(msg) if %i[debug info warn error].include?(logger_level)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
29
41
|
end
|
@@ -5,7 +5,7 @@ module Mqttopia
|
|
5
5
|
module TripMetric
|
6
6
|
module_function
|
7
7
|
|
8
|
-
KEYS = %i[ts locPerms
|
8
|
+
KEYS = %i[ts locPerms connS batt battPwOp pws notf gps nlog loc].freeze
|
9
9
|
|
10
10
|
def serialize(body)
|
11
11
|
return unless valid_metric?(body[:metrics])
|
@@ -21,7 +21,7 @@ module Mqttopia
|
|
21
21
|
def serialize_metrics(metrics)
|
22
22
|
{
|
23
23
|
location_permission: location_permission_mapper(metrics[:locPerms]),
|
24
|
-
|
24
|
+
connection: serialize_connection(metrics[:connS]),
|
25
25
|
battery: serialize_battery(metrics[:batt], metrics[:battPwOp], metrics[:pws]),
|
26
26
|
notification_permission: metrics[:notf]&.zero?,
|
27
27
|
gps: metrics[:gps]&.zero?,
|
@@ -30,6 +30,16 @@ module Mqttopia
|
|
30
30
|
}
|
31
31
|
end
|
32
32
|
|
33
|
+
def serialize_connection(connt_s)
|
34
|
+
return unless connt_s
|
35
|
+
|
36
|
+
{
|
37
|
+
connection_type: connt_s[:type],
|
38
|
+
connection_sub_type: connt_s[:subType],
|
39
|
+
connection_status: connt_s[:connt]
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
33
43
|
def serialize_battery(battery, optimization_status, power_saving_mode)
|
34
44
|
return unless battery
|
35
45
|
|
@@ -63,16 +73,6 @@ module Mqttopia
|
|
63
73
|
}.fetch(permission&.to_s) { "UNKNOWN" }
|
64
74
|
end
|
65
75
|
|
66
|
-
def connection_type_mapper(connection_type)
|
67
|
-
{
|
68
|
-
"wf" => "WIFI",
|
69
|
-
"cel" => "CELLULAR",
|
70
|
-
"et" => "ETHERNET",
|
71
|
-
"nc" => "NO_CONNECTION",
|
72
|
-
"uk" => "UNKNOWN"
|
73
|
-
}.fetch(connection_type) { "UNKNOWN" }
|
74
|
-
end
|
75
|
-
|
76
76
|
def charging_status_mapper(charging_status)
|
77
77
|
{
|
78
78
|
"0" => "UNKNOWN",
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Mqttopia
|
4
|
+
module Serializers
|
5
|
+
module TripPoint
|
6
|
+
module_function
|
7
|
+
|
8
|
+
KEYS = %i[lat lon ts ctp_id trip_id].freeze
|
9
|
+
|
10
|
+
def serialize(body)
|
11
|
+
return unless valid_point?(body[:point])
|
12
|
+
|
13
|
+
{
|
14
|
+
trip_id: body[:trip_id],
|
15
|
+
point: serialize_point(body[:point]),
|
16
|
+
logged_at: body.dig(:point, :ts)&.to_s,
|
17
|
+
received_at: current_timestamp
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def serialize_point(point)
|
22
|
+
{
|
23
|
+
latitude: point[:lat],
|
24
|
+
longitude: point[:lon],
|
25
|
+
accuracy: point[:acc],
|
26
|
+
altitude: point[:alt],
|
27
|
+
current_trip_point_id: point[:ctp_id]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def valid_point?(point)
|
32
|
+
point.is_a?(Hash) && KEYS.all? { |key| point.key?(key) }
|
33
|
+
end
|
34
|
+
|
35
|
+
def current_timestamp
|
36
|
+
DateTime.now.strftime("%Q")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "services/trip_metrics"
|
4
4
|
require_relative "services/test_debug"
|
5
|
+
require_relative "services/trip_points"
|
5
6
|
require_relative "../topics/services"
|
6
7
|
|
7
8
|
module Mqttopia
|
@@ -16,14 +17,17 @@ module Mqttopia
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def call
|
19
|
-
Mqttopia::Topics::Services::KEYS.
|
20
|
-
next unless topic_name.match(value[:regex])
|
20
|
+
Mqttopia::Topics::Services::KEYS.each do |key, value|
|
21
|
+
next unless topic_name.match?(value[:regex])
|
21
22
|
|
22
|
-
return
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
return {
|
24
|
+
event: key&.to_s,
|
25
|
+
data: value[:service].safe_constantize.call(
|
26
|
+
topic_name,
|
27
|
+
payload,
|
28
|
+
{ serializer: value[:serializer] }
|
29
|
+
)
|
30
|
+
}
|
27
31
|
end
|
28
32
|
|
29
33
|
Mqttopia::Logger.warn "No matching topic found for #{topic_name}" if debugging
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_model"
|
4
|
+
require_relative "../../serializers/trip_point"
|
5
|
+
require_relative "./base"
|
6
|
+
|
7
|
+
module Mqttopia
|
8
|
+
module Subscriptions
|
9
|
+
module Services
|
10
|
+
class TripPoints < Mqttopia::Subscriptions::Services::Base
|
11
|
+
class TripPointsInvalidError < ArgumentError
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :trip_id, :point, :options, :user_id
|
15
|
+
|
16
|
+
validates :trip_id, presence: true, numericality: { only_integer: true, greater_than: 0 }
|
17
|
+
validates :point, presence: true
|
18
|
+
# validate :point_json_format
|
19
|
+
|
20
|
+
def initialize(trip_id:, point:, options: {})
|
21
|
+
@trip_id = trip_id
|
22
|
+
@point = point
|
23
|
+
@options = options
|
24
|
+
@user_id = options[:user_id]
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.call(topic, payload, options = {})
|
28
|
+
trip_id = topic.include?("trips/") && topic.match(%r{trips/[^/]+}) && extract_trip_id(topic)
|
29
|
+
options[:user_id] = topic.include?("user/") && topic.match(%r{user/[^/]+}) && extract_user_id(topic)
|
30
|
+
|
31
|
+
new(trip_id: trip_id, point: payload, options: options).process
|
32
|
+
end
|
33
|
+
|
34
|
+
def process
|
35
|
+
raise TripPointsInvalidError, errors.full_messages.to_sentence unless valid?
|
36
|
+
|
37
|
+
Mqttopia::Serializers::TripPoint.serialize({
|
38
|
+
trip_id: trip_id,
|
39
|
+
point: point
|
40
|
+
})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -10,6 +10,12 @@ module Mqttopia
|
|
10
10
|
serializer: "Mqttopia::Serializers::TripMetric",
|
11
11
|
regex: %r{\Ailla/trips/(?<trip_id>\d+)/trip_metric/send(?:/user/(?<user_id>\d+))?\z}
|
12
12
|
},
|
13
|
+
trip_point: {
|
14
|
+
topic_name: "illa/trips/:trip_id/driver_trip_point/send/user/:user_id",
|
15
|
+
service: "Mqttopia::Subscriptions::Services::TripPoints",
|
16
|
+
serializer: "Mqttopia::Serializers::TripPoint",
|
17
|
+
regex: %r{\Ailla/trips/(?<trip_id>\d+)/driver_trip_point/send(?:/user/(?<user_id>\d+))?\z}
|
18
|
+
},
|
13
19
|
test_debug: {
|
14
20
|
topic_name: "test",
|
15
21
|
service: "Mqttopia::Subscriptions::Services::TestDebug",
|
data/lib/mqttopia/version.rb
CHANGED
data/lib/mqttopia.rb
CHANGED
@@ -13,12 +13,38 @@ Dir[File.expand_path("tasks/**/*.rake", __dir__)].each { |task| load task }
|
|
13
13
|
module Mqttopia
|
14
14
|
class Error < StandardError; end
|
15
15
|
|
16
|
-
mattr_accessor :
|
16
|
+
mattr_accessor :version,
|
17
|
+
:hosts,
|
18
|
+
:port,
|
19
|
+
:username,
|
20
|
+
:password,
|
21
|
+
:ssl,
|
22
|
+
:logger,
|
23
|
+
:logger_level,
|
24
|
+
:keep_alive,
|
25
|
+
:will_topic,
|
26
|
+
:will_retain,
|
27
|
+
:will_payload,
|
28
|
+
:will_qos,
|
29
|
+
:ack_timeout,
|
30
|
+
:client_id,
|
31
|
+
:debugging,
|
32
|
+
:debugging_topic
|
17
33
|
|
34
|
+
@@version = "3.1.1"
|
18
35
|
@@port = 1883
|
19
36
|
@@ssl = true
|
37
|
+
@@will_topic = nil
|
38
|
+
@@will_retain = false
|
39
|
+
@@will_payload = nil
|
40
|
+
@@will_qos = 0
|
41
|
+
@@keep_alive = 15
|
42
|
+
@@ack_timeout = 10
|
20
43
|
@@logger = ::Logger.new($stdout)
|
44
|
+
@@logger_level = :info
|
21
45
|
@@debugging = false
|
46
|
+
@@debugging_topic = "mqttopia/test/debugging"
|
47
|
+
@@client_id = "mqttopia-#{Mqttopia::VERSION}"
|
22
48
|
|
23
49
|
def self.configure
|
24
50
|
yield self
|
data/lib/tasks/initialize.rake
CHANGED
@@ -34,11 +34,7 @@ namespace :mqttopia do
|
|
34
34
|
# $client.publish('test/topic', 'Hello, MQTT')
|
35
35
|
RUBY
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
else
|
40
|
-
File.write(file_name, content)
|
41
|
-
puts "Created: #{file_name}"
|
42
|
-
end
|
37
|
+
|
38
|
+
File.write(file_name, content) unless File.exist?(file_name)
|
43
39
|
end
|
44
40
|
end
|
data/mqttopia.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
17
|
spec.metadata["source_code_uri"] = "https://github.com/go-illa/mqttopia"
|
18
18
|
spec.metadata["changelog_uri"] = "https://github.com/go-illa/mqttopia"
|
19
|
+
spec.metadata["github_repo"] = "https://github.com/go-illa/mqttopia"
|
19
20
|
|
20
21
|
# Specify which files should be added to the gem when it is released.
|
21
22
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mqttopia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Illa Tech
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -171,6 +171,7 @@ executables: []
|
|
171
171
|
extensions: []
|
172
172
|
extra_rdoc_files: []
|
173
173
|
files:
|
174
|
+
- ".gemrc"
|
174
175
|
- ".rubocop.yml"
|
175
176
|
- CHANGELOG.md
|
176
177
|
- MQTT_SUBSCRIPTIONS.md
|
@@ -185,10 +186,12 @@ files:
|
|
185
186
|
- lib/mqttopia/logger.rb
|
186
187
|
- lib/mqttopia/serializers/test_debug.rb
|
187
188
|
- lib/mqttopia/serializers/trip_metric.rb
|
189
|
+
- lib/mqttopia/serializers/trip_point.rb
|
188
190
|
- lib/mqttopia/subscriptions/redirect.rb
|
189
191
|
- lib/mqttopia/subscriptions/services/base.rb
|
190
192
|
- lib/mqttopia/subscriptions/services/test_debug.rb
|
191
193
|
- lib/mqttopia/subscriptions/services/trip_metrics.rb
|
194
|
+
- lib/mqttopia/subscriptions/services/trip_points.rb
|
192
195
|
- lib/mqttopia/topics/services.rb
|
193
196
|
- lib/mqttopia/version.rb
|
194
197
|
- lib/tasks/initialize.rake
|
@@ -200,6 +203,7 @@ metadata:
|
|
200
203
|
homepage_uri: https://github.com/go-illa
|
201
204
|
source_code_uri: https://github.com/go-illa/mqttopia
|
202
205
|
changelog_uri: https://github.com/go-illa/mqttopia
|
206
|
+
github_repo: https://github.com/go-illa/mqttopia
|
203
207
|
post_install_message: "\n [MQTTOPIA] Please make sure to run `rails generate
|
204
208
|
mqttopia:install`\n "
|
205
209
|
rdoc_options: []
|