meshtastic 0.0.35 → 0.0.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bca28989f9cdb4c958571d59ea70d035154bb4c796017bbd948dea5987dfbc8d
4
- data.tar.gz: 4dd3be1a0ccde5cab5711fe2e31c8d9dd869a4f4f204b2af5916ee6b731b47aa
3
+ metadata.gz: 41d11712815ee1680ff3929084cbe63bc0500d400bbdf7d2f087709a9ded258f
4
+ data.tar.gz: 817138fd986e7a7f7267e69861f866dedad4ac95de8194e7a6e3edcdd6b028ac
5
5
  SHA512:
6
- metadata.gz: 34639b023c2ae75cb76f627fb0af84c08703f112a4da326fd14ef2103a8667dc376260617ba905275f047a78e3086e6d62586f65b84848caa92b816951dcca8d
7
- data.tar.gz: 83b59c484395c04983c6ca4c20624e14101369345c5ae09db8e2d7879410556e21615aadeb2865959c37bf851b147424c3970e71ff6ea29d690dfae006b260c8
6
+ metadata.gz: 31ce0114b3ad6e1a03ad185b2706f44ee303c7d8ed1f5fa258ad96b5b6422bdde6d62352fcb7ea71005aa242d99a50eaa2917ef94c063c4a4d6c5f2f04a129e2
7
+ data.tar.gz: 2caacc5276cb34442c07af78fd8539620b613a3021b84893be243299c0ebd2bdbbdd303a2c65edd3286128c26792fa8e02b2d2be8e51e250b11323307817d6cb
@@ -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}/2/json/#{channel}/#" if json
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 == 'LongFast'
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
- raw_message = packet_bytes.payload
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
- message = JSON.parse(raw_message, symbolize_names: true)
98
+ decoded_payload_hash = JSON.parse(raw_payload, symbolize_names: true)
100
99
  else
101
- decoded_packet = Meshtastic::ServiceEnvelope.decode(raw_message)
102
- message = decoded_packet.to_h[:packet]
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(message)
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 = message.inspect
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 message
248
+ yield decoded_payload_hash
242
249
  else
243
250
  puts "\n"
244
251
  puts '-' * 80
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.35'
4
+ VERSION = '0.0.37'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meshtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.35
4
+ version: 0.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.