meshtastic 0.0.35 → 0.0.37
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/lib/meshtastic/mqtt.rb +24 -17
- data/lib/meshtastic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41d11712815ee1680ff3929084cbe63bc0500d400bbdf7d2f087709a9ded258f
|
4
|
+
data.tar.gz: 817138fd986e7a7f7267e69861f866dedad4ac95de8194e7a6e3edcdd6b028ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31ce0114b3ad6e1a03ad185b2706f44ee303c7d8ed1f5fa258ad96b5b6422bdde6d62352fcb7ea71005aa242d99a50eaa2917ef94c063c4a4d6c5f2f04a129e2
|
7
|
+
data.tar.gz: 2caacc5276cb34442c07af78fd8539620b613a3021b84893be243299c0ebd2bdbbdd303a2c65edd3286128c26792fa8e02b2d2be8e51e250b11323307817d6cb
|
data/lib/meshtastic/mqtt.rb
CHANGED
@@ -46,11 +46,10 @@ module Meshtastic
|
|
46
46
|
# Meshtastic::MQQT.subscribe(
|
47
47
|
# mqtt_obj: 'required - mqtt_obj returned from #connect method'
|
48
48
|
# root_topic: 'optional - root topic (default: msh)',
|
49
|
-
# region: 'optional - region (default: US)',
|
50
|
-
# channel: 'optional - channel name (default: LongFast)',
|
49
|
+
# region: 'optional - region e.g. 'US/VA', etc (default: US)',
|
50
|
+
# channel: 'optional - channel name (default: "2/c/LongFast/#")',
|
51
51
|
# psk: 'optional - channel pre-shared key (default: AQ==)',
|
52
52
|
# qos: 'optional - quality of service (default: 0)',
|
53
|
-
# json: 'optional - JSON output (default: false)',
|
54
53
|
# filter: 'optional - comma-delimited string(s) to filter on in message (default: nil)',
|
55
54
|
# gps_metadata: 'optional - include GPS metadata in output (default: false)'
|
56
55
|
# )
|
@@ -59,7 +58,7 @@ module Meshtastic
|
|
59
58
|
mqtt_obj = opts[:mqtt_obj]
|
60
59
|
root_topic = opts[:root_topic] ||= 'msh'
|
61
60
|
region = opts[:region] ||= 'US'
|
62
|
-
channel = opts[:channel] ||= 'LongFast'
|
61
|
+
channel = opts[:channel] ||= '2/e/LongFast/#'
|
63
62
|
psk = opts[:psk] ||= 'AQ=='
|
64
63
|
qos = opts[:qos] ||= 0
|
65
64
|
json = opts[:json] ||= false
|
@@ -67,8 +66,7 @@ module Meshtastic
|
|
67
66
|
gps_metadata = opts[:gps_metadata] ||= false
|
68
67
|
|
69
68
|
# TODO: Find JSON URI for this
|
70
|
-
full_topic = "#{root_topic}/#{region}
|
71
|
-
full_topic = "#{root_topic}/#{region}/2/c/#{channel}/#" unless json
|
69
|
+
full_topic = "#{root_topic}/#{region}/#{channel}"
|
72
70
|
puts "Subscribing to: #{full_topic}"
|
73
71
|
mqtt_obj.subscribe(full_topic, qos)
|
74
72
|
|
@@ -76,7 +74,7 @@ module Meshtastic
|
|
76
74
|
# Our AES key is 128 or 256 bits, shared as part of the 'Channel' specification.
|
77
75
|
|
78
76
|
# Actual pre-shared key for LongFast channel
|
79
|
-
psk = '1PG7OiApB1nwvP+rz05pAQ==' if channel
|
77
|
+
psk = '1PG7OiApB1nwvP+rz05pAQ==' if channel.include?('LongFast')
|
80
78
|
padded_psk = psk.ljust(psk.length + ((4 - (psk.length % 4)) % 4), '=')
|
81
79
|
replaced_psk = padded_psk.gsub('-', '+').gsub('_', '/')
|
82
80
|
psk = replaced_psk
|
@@ -86,21 +84,24 @@ module Meshtastic
|
|
86
84
|
cipher = OpenSSL::Cipher.new('AES-128-CTR')
|
87
85
|
filter_arr = filter.to_s.split(',').map(&:strip)
|
88
86
|
mqtt_obj.get_packet do |packet_bytes|
|
89
|
-
raw_packet = packet_bytes.to_s.b
|
87
|
+
# raw_packet = packet_bytes.to_s.b
|
90
88
|
raw_topic = packet_bytes.topic ||= ''
|
91
|
-
|
89
|
+
raw_payload = packet_bytes.payload
|
92
90
|
|
93
91
|
begin
|
94
92
|
disp = false
|
93
|
+
decoded_payload_hash = {}
|
95
94
|
message = {}
|
96
95
|
stdout_message = ''
|
97
96
|
|
98
97
|
if json
|
99
|
-
|
98
|
+
decoded_payload_hash = JSON.parse(raw_payload, symbolize_names: true)
|
100
99
|
else
|
101
|
-
|
102
|
-
|
100
|
+
decoded_payload = Meshtastic::ServiceEnvelope.decode(raw_payload)
|
101
|
+
decoded_payload_hash = decoded_payload.to_h
|
103
102
|
end
|
103
|
+
|
104
|
+
message = decoded_payload_hash[:packet] if decoded_payload_hash.keys.include?(:packet)
|
104
105
|
message[:topic] = raw_topic
|
105
106
|
message[:node_id_from] = "!#{message[:from].to_i.to_s(16)}"
|
106
107
|
message[:node_id_to] = "!#{message[:to].to_i.to_s(16)}"
|
@@ -123,6 +124,8 @@ module Meshtastic
|
|
123
124
|
|
124
125
|
decrypted = cipher.update(encrypted_message) + cipher.final
|
125
126
|
message[:decrypted] = decrypted
|
127
|
+
# decoded_packet = Meshtastic::ServiceEnvelope.decode(decrypted)
|
128
|
+
# puts "Decoded Decrypted Packet: #{decoded_packet.display.to_h}"
|
126
129
|
# Vvv Decode the decrypted message vvV
|
127
130
|
end
|
128
131
|
|
@@ -215,17 +218,21 @@ module Meshtastic
|
|
215
218
|
# message[:decoded][:pb_obj] = pb_obj
|
216
219
|
end
|
217
220
|
|
218
|
-
message[:raw_packet] = raw_packet if block_given?
|
221
|
+
# message[:raw_packet] = raw_packet if block_given?
|
222
|
+
decoded_payload_hash[:packet] = message
|
219
223
|
unless block_given?
|
220
224
|
message[:stdout] = 'pretty'
|
221
|
-
stdout_message = JSON.pretty_generate(
|
225
|
+
stdout_message = JSON.pretty_generate(decoded_payload_hash)
|
222
226
|
end
|
223
227
|
rescue Google::Protobuf::ParseError,
|
224
|
-
JSON::GeneratorError
|
228
|
+
JSON::GeneratorError,
|
229
|
+
ArgumentError => e
|
225
230
|
|
231
|
+
message[:decrypted] = e.message if ArgumentError
|
232
|
+
decoded_payload_hash[:packet] = message
|
226
233
|
unless block_given?
|
227
234
|
message[:stdout] = 'inspect'
|
228
|
-
stdout_message =
|
235
|
+
stdout_message = decoded_payload_hash.inspect
|
229
236
|
end
|
230
237
|
|
231
238
|
next
|
@@ -238,7 +245,7 @@ module Meshtastic
|
|
238
245
|
|
239
246
|
if disp
|
240
247
|
if block_given?
|
241
|
-
yield
|
248
|
+
yield decoded_payload_hash
|
242
249
|
else
|
243
250
|
puts "\n"
|
244
251
|
puts '-' * 80
|
data/lib/meshtastic/version.rb
CHANGED