meshtastic 0.0.21 → 0.0.22

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 749b55978ad13d4e2d04290919cef8522f7133e77f500a4ea2ecbdc15a0f232b
4
- data.tar.gz: 753d6a0b90e582fd9e6d0a6e7c97e89a768dfa9c74af06f643f61e5f5cd7cf09
3
+ metadata.gz: bbd76d5eb5caa289b389949f752dcdcbe9185dd55db794ceeaa7aeff86342eb9
4
+ data.tar.gz: 9a941303697050de11c04c2fbcc64ef6cffebd16b1959a3b1e5359b904c7628d
5
5
  SHA512:
6
- metadata.gz: c8d80c61a3175e099d1266de3617050363ce6263fc31481f685210f675faa19951ef2e580a7ccc6c391a6294216f0ae9ed53f7c4e6f9587e88a44e76ad0527d4
7
- data.tar.gz: fed2e497a7376aa133b4e4a929eef84353f94eca60940fa959e02075217fa272490402feb2522b8695a7417f7ab80c377e79cc668ca5aca50efd0e223cd82d1b
6
+ metadata.gz: 3af0be5f4930d87b7a4f536417de6429302bd65da11f19ccf843241de0d32b1c72077ab6a4ce2231f237b75669514ee4a237b618e65534884da6f0db619f5f0a
7
+ data.tar.gz: d560584669d17490e6da18e4169164dce4077f2cbcb8619bca0f5d816b46e4526d2334acaeaeba3cd32b4a5e0494250dbd34fe6994a0baf4e2b066d60289722e
data/Gemfile CHANGED
@@ -19,7 +19,7 @@ gem 'mqtt', '0.6.0'
19
19
  gem 'rake', '13.2.1'
20
20
  gem 'rdoc', '6.6.3.1'
21
21
  gem 'rspec', '3.13.0'
22
- gem 'rubocop', '1.63.3'
22
+ gem 'rubocop', '1.63.4'
23
23
  gem 'rubocop-rake', '0.6.0'
24
24
  gem 'rubocop-rspec', '2.29.1'
25
25
  gem 'rvm', '1.11.3.9'
data/README.md CHANGED
@@ -36,6 +36,15 @@ Meshtastic::MQTT.subscribe(
36
36
  )
37
37
  ```
38
38
 
39
+ This code will print the `from` value of each message received:
40
+ ```ruby
41
+ require 'meshtastic'
42
+ mqtt_obj = Meshastic::MQTT.connect
43
+ Meshtastic::MQTT.subscribe( mqtt_obj: mqtt_obj) do |message|
44
+ puts message[:from]
45
+ end
46
+ ```
47
+
39
48
  ## Contributing
40
49
 
41
50
  Bug reports and pull requests are welcome on GitHub at https://github.com/0dayinc/meshtastic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/0dayinc/meshtastic/blob/master/CODE_OF_CONDUCT.md).
@@ -50,7 +50,7 @@ module Meshtastic
50
50
  # psk: 'optional - channel pre-shared key (default: AQ==)',
51
51
  # qos: 'optional - quality of service (default: 0)',
52
52
  # json: 'optional - JSON output (default: false)',
53
- # filter: 'optional - comma-delimited string(s) to filter on in payload (default: nil)'
53
+ # filter: 'optional - comma-delimited string(s) to filter on in message (default: nil)'
54
54
  # )
55
55
 
56
56
  public_class_method def self.subscribe(opts = {})
@@ -84,26 +84,28 @@ module Meshtastic
84
84
  raw_packet = packet_bytes.to_s.b
85
85
  raw_packet_len = raw_packet.to_s.b.length
86
86
  raw_topic = packet_bytes.topic ||= ''
87
- raw_payload = packet_bytes.payload
87
+ raw_message = packet_bytes.payload
88
88
 
89
89
  begin
90
- payload = {}
90
+ disp = false
91
+ message = {}
92
+
91
93
  if json
92
- payload = JSON.parse(raw_payload, symbolize_names: true)
94
+ message = JSON.parse(raw_message, symbolize_names: true)
93
95
  else
94
- svc_envl = Meshtastic::ServiceEnvelope.decode(raw_payload)
95
- # map_report = Meshtastic::MapReport.decode(raw_payload)
96
- payload = svc_envl.to_h[:packet]
96
+ svc_envl = Meshtastic::ServiceEnvelope.decode(raw_message)
97
+ # map_report = Meshtastic::MapReport.decode(raw_message)
98
+ message = svc_envl.to_h[:packet]
97
99
  end
98
- payload[:topic] = raw_topic
99
- payload[:node_id_from] = "!#{payload[:from].to_i.to_s(16)}"
100
- payload[:node_id_to] = "!#{payload[:to].to_i.to_s(16)}"
101
-
102
- encrypted_payload = payload[:encrypted]
103
- # If encrypted_payload is not nil, then decrypt the message
104
- if encrypted_payload.to_s.length.positive?
105
- packet_id = payload[:id]
106
- packet_from = payload[:from]
100
+ message[:topic] = raw_topic
101
+ message[:node_id_from] = "!#{message[:from].to_i.to_s(16)}"
102
+ message[:node_id_to] = "!#{message[:to].to_i.to_s(16)}"
103
+
104
+ encrypted_message = message[:encrypted]
105
+ # If encrypted_message is not nil, then decrypt the message
106
+ if encrypted_message.to_s.length.positive?
107
+ packet_id = message[:id]
108
+ packet_from = message[:from]
107
109
  nonce_packet_id = [packet_id].pack('V').ljust(8, "\x00")
108
110
  nonce_from_node = [packet_from].pack('V').ljust(8, "\x00")
109
111
  nonce = "#{nonce_packet_id}#{nonce_from_node}".b
@@ -115,41 +117,33 @@ module Meshtastic
115
117
  cipher.key = dec_psk
116
118
  cipher.iv = nonce
117
119
 
118
- decrypted = cipher.update(encrypted_payload) + cipher.final
119
- payload[:decrypted] = decrypted
120
+ decrypted = cipher.update(encrypted_message) + cipher.final
121
+ message[:decrypted] = decrypted
120
122
  end
121
123
 
122
- filter_arr = [payload[:id].to_s] if filter.nil?
123
- disp = false
124
- flat_payload = payload.values.join(' ')
124
+ filter_arr = [message[:id].to_s] if filter.nil?
125
+ flat_message = message.values.join(' ')
125
126
 
126
- disp = true if filter_arr.first == payload[:id] ||
127
- filter_arr.all? { |filter| flat_payload.include?(filter) }
127
+ disp = true if filter_arr.first == message[:id] ||
128
+ filter_arr.all? { |filter| flat_message.include?(filter) }
128
129
 
130
+ rescue Google::Protobuf::ParseError
131
+ next
132
+ ensure
129
133
  if disp
130
134
  puts "\n"
131
135
  puts '-' * 80
132
136
  puts "*** DEBUGGING ***"
133
- puts "Payload:\n#{payload}"
137
+ puts "MSG:\n#{message.inspect}"
134
138
  # puts "\nMap Report: #{map_report.inspect}"
135
139
  puts "\nRaw Packet: #{raw_packet.inspect}"
136
140
  puts "Length: #{raw_packet_len}"
137
141
  puts '-' * 80
138
142
  puts "\n\n\n"
143
+ yield message if block_given?
139
144
  else
140
145
  print '.'
141
146
  end
142
- rescue Google::Protobuf::ParseError
143
- puts "\n"
144
- puts '-' * 80
145
- puts "*** DEBUGGING ***"
146
- puts "Payload:\n#{payload}"
147
- # puts "\nMap Report: #{map_report.inspect}"
148
- puts "\nRaw Packet: #{raw_packet.inspect}"
149
- puts "Length: #{raw_packet_len}"
150
- puts '-' * 80
151
- puts "\n\n\n"
152
- next
153
147
  end
154
148
  end
155
149
  rescue Interrupt
@@ -217,7 +211,7 @@ module Meshtastic
217
211
  psk: 'optional - channel pre-shared key (default: AQ==)',
218
212
  qos: 'optional - quality of service (default: 0)',
219
213
  json: 'optional - JSON output (default: false)',
220
- filter: 'optional - comma-delimited string(s) to filter on in payload (default: nil)'
214
+ filter: 'optional - comma-delimited string(s) to filter on in message (default: nil)'
221
215
  )
222
216
 
223
217
  #{self}.gps_search(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.21'
4
+ VERSION = '0.0.22'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meshtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-27 00:00:00.000000000 Z
11
+ date: 2024-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 1.63.3
131
+ version: 1.63.4
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 1.63.3
138
+ version: 1.63.4
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-rake
141
141
  requirement: !ruby/object:Gem::Requirement