meshtastic 0.0.21 → 0.0.23

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: 749b55978ad13d4e2d04290919cef8522f7133e77f500a4ea2ecbdc15a0f232b
4
- data.tar.gz: 753d6a0b90e582fd9e6d0a6e7c97e89a768dfa9c74af06f643f61e5f5cd7cf09
3
+ metadata.gz: 92ee92f4c1356fc60440b101723abac1c35e33ef757bb74266e8d32a982df2b5
4
+ data.tar.gz: 3917587b0080996105d5f0c73fee9208f2c89ddf067a13a661d95f58a5fb5f43
5
5
  SHA512:
6
- metadata.gz: c8d80c61a3175e099d1266de3617050363ce6263fc31481f685210f675faa19951ef2e580a7ccc6c391a6294216f0ae9ed53f7c4e6f9587e88a44e76ad0527d4
7
- data.tar.gz: fed2e497a7376aa133b4e4a929eef84353f94eca60940fa959e02075217fa272490402feb2522b8695a7417f7ab80c377e79cc668ca5aca50efd0e223cd82d1b
6
+ metadata.gz: 678c08feb284f83a56bdc43824074621b1a0835de6ecf56757f2129f5ac26277940b4c1cc48b636947dbd8974bc94f872f7169429872c86c9f04f33161cc47c4
7
+ data.tar.gz: d581f878f32669d5a93a57dc849468669c21939d98b20915cce1c432bb76f1984b6bf9005690c9d581741fbe40a068bd06c5d3e0c7c9356853b6e5808eeccdef
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,16 @@ Meshtastic::MQTT.subscribe(
36
36
  )
37
37
  ```
38
38
 
39
+ This code will print the `from` value of each message received:
40
+
41
+ ```ruby
42
+ require 'meshtastic'
43
+ mqtt_obj = Meshastic::MQTT.connect
44
+ Meshtastic::MQTT.subscribe(mqtt_obj: mqtt_obj) do |message|
45
+ puts message[:from]
46
+ end
47
+ ```
48
+
39
49
  ## Contributing
40
50
 
41
51
  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).
@@ -45,16 +45,18 @@ module Meshtastic
45
45
  # Supported Method Parameters::
46
46
  # Meshtastic::MQQT.subscribe(
47
47
  # mqtt_obj: 'required - mqtt_obj returned from #connect method'
48
+ # root_topic: 'optional - root topic (default: msh)',
48
49
  # region: 'optional - region (default: US)',
49
50
  # channel: 'optional - channel name (default: LongFast)',
50
51
  # psk: 'optional - channel pre-shared key (default: AQ==)',
51
52
  # qos: 'optional - quality of service (default: 0)',
52
53
  # json: 'optional - JSON output (default: false)',
53
- # filter: 'optional - comma-delimited string(s) to filter on in payload (default: nil)'
54
+ # filter: 'optional - comma-delimited string(s) to filter on in message (default: nil)'
54
55
  # )
55
56
 
56
57
  public_class_method def self.subscribe(opts = {})
57
58
  mqtt_obj = opts[:mqtt_obj]
59
+ root_topic = opts[:root_topic] ||= 'msh'
58
60
  region = opts[:region] ||= 'US'
59
61
  channel = opts[:channel] ||= 'LongFast'
60
62
  psk = opts[:psk] ||= 'AQ=='
@@ -63,9 +65,10 @@ module Meshtastic
63
65
  filter = opts[:filter]
64
66
 
65
67
  # TODO: Find JSON URI for this
66
- root_topic = "msh/#{region}/2/json" if json
67
- root_topic = "msh/#{region}/2/c" unless json
68
- mqtt_obj.subscribe("#{root_topic}/#{channel}/#", qos)
68
+ mqtt_path = "#{root_topic}/#{region}/2/json/#{channel}/#" if json
69
+ mqtt_path = "#{root_topic}/#{region}/2/c/#{channel}/#" unless json
70
+ puts "Subscribing to: #{mqtt_path}"
71
+ mqtt_obj.subscribe(mqtt_path, qos)
69
72
 
70
73
  # Decrypt the message
71
74
  # Our AES key is 128 or 256 bits, shared as part of the 'Channel' specification.
@@ -84,26 +87,28 @@ module Meshtastic
84
87
  raw_packet = packet_bytes.to_s.b
85
88
  raw_packet_len = raw_packet.to_s.b.length
86
89
  raw_topic = packet_bytes.topic ||= ''
87
- raw_payload = packet_bytes.payload
90
+ raw_message = packet_bytes.payload
88
91
 
89
92
  begin
90
- payload = {}
93
+ disp = false
94
+ message = {}
95
+
91
96
  if json
92
- payload = JSON.parse(raw_payload, symbolize_names: true)
97
+ message = JSON.parse(raw_message, symbolize_names: true)
93
98
  else
94
- svc_envl = Meshtastic::ServiceEnvelope.decode(raw_payload)
95
- # map_report = Meshtastic::MapReport.decode(raw_payload)
96
- payload = svc_envl.to_h[:packet]
99
+ svc_envl = Meshtastic::ServiceEnvelope.decode(raw_message)
100
+ # map_report = Meshtastic::MapReport.decode(raw_message)
101
+ message = svc_envl.to_h[:packet]
97
102
  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]
103
+ message[:topic] = raw_topic
104
+ message[:node_id_from] = "!#{message[:from].to_i.to_s(16)}"
105
+ message[:node_id_to] = "!#{message[:to].to_i.to_s(16)}"
106
+
107
+ encrypted_message = message[:encrypted]
108
+ # If encrypted_message is not nil, then decrypt the message
109
+ if encrypted_message.to_s.length.positive?
110
+ packet_id = message[:id]
111
+ packet_from = message[:from]
107
112
  nonce_packet_id = [packet_id].pack('V').ljust(8, "\x00")
108
113
  nonce_from_node = [packet_from].pack('V').ljust(8, "\x00")
109
114
  nonce = "#{nonce_packet_id}#{nonce_from_node}".b
@@ -115,41 +120,36 @@ module Meshtastic
115
120
  cipher.key = dec_psk
116
121
  cipher.iv = nonce
117
122
 
118
- decrypted = cipher.update(encrypted_payload) + cipher.final
119
- payload[:decrypted] = decrypted
123
+ decrypted = cipher.update(encrypted_message) + cipher.final
124
+ message[:decrypted] = decrypted
120
125
  end
121
126
 
122
- filter_arr = [payload[:id].to_s] if filter.nil?
123
- disp = false
124
- flat_payload = payload.values.join(' ')
127
+ filter_arr = [message[:id].to_s] if filter.nil?
128
+ flat_message = message.values.join(' ')
125
129
 
126
- disp = true if filter_arr.first == payload[:id] ||
127
- filter_arr.all? { |filter| flat_payload.include?(filter) }
130
+ disp = true if filter_arr.first == message[:id] ||
131
+ filter_arr.all? { |filter| flat_message.include?(filter) }
128
132
 
133
+ rescue Google::Protobuf::ParseError
134
+ next
135
+ ensure
129
136
  if disp
130
- puts "\n"
131
- puts '-' * 80
132
- puts "*** DEBUGGING ***"
133
- puts "Payload:\n#{payload}"
134
- # puts "\nMap Report: #{map_report.inspect}"
135
- puts "\nRaw Packet: #{raw_packet.inspect}"
136
- puts "Length: #{raw_packet_len}"
137
- puts '-' * 80
138
- puts "\n\n\n"
137
+ if block_given?
138
+ yield message
139
+ else
140
+ puts "\n"
141
+ puts '-' * 80
142
+ puts "*** DEBUGGING ***"
143
+ puts "MSG:\n#{message.inspect}"
144
+ # puts "\nMap Report: #{map_report.inspect}"
145
+ puts "\nRaw Packet: #{raw_packet.inspect}"
146
+ puts "Length: #{raw_packet_len}"
147
+ puts '-' * 80
148
+ puts "\n\n\n"
149
+ end
139
150
  else
140
151
  print '.'
141
152
  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
153
  end
154
154
  end
155
155
  rescue Interrupt
@@ -212,12 +212,13 @@ module Meshtastic
212
212
 
213
213
  #{self}.subscribe(
214
214
  mqtt_obj: 'required - mqtt_obj object returned from #connect method',
215
+ root_topic: 'optional - root topic (default: msh)',
215
216
  region: 'optional - region (default: US)',
216
217
  channel: 'optional - channel name (default: LongFast)',
217
218
  psk: 'optional - channel pre-shared key (default: AQ==)',
218
219
  qos: 'optional - quality of service (default: 0)',
219
220
  json: 'optional - JSON output (default: false)',
220
- filter: 'optional - comma-delimited string(s) to filter on in payload (default: nil)'
221
+ filter: 'optional - comma-delimited string(s) to filter on in message (default: nil)'
221
222
  )
222
223
 
223
224
  #{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.23'
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.23
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