meshtastic 0.0.10 → 0.0.11

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +34 -9
  3. data/.rubocop_todo.yml +21 -54
  4. data/lib/meshtastic/admin.rb +24 -0
  5. data/lib/meshtastic/apponly.rb +24 -0
  6. data/lib/meshtastic/atak.rb +24 -0
  7. data/lib/meshtastic/cannedmessages.rb +24 -0
  8. data/lib/meshtastic/channel.rb +24 -0
  9. data/lib/meshtastic/clientonly.rb +24 -0
  10. data/lib/meshtastic/config.rb +24 -0
  11. data/lib/meshtastic/connection_status.rb +24 -0
  12. data/lib/meshtastic/deviceonly.rb +24 -0
  13. data/lib/meshtastic/localonly.rb +24 -0
  14. data/lib/meshtastic/mesh.rb +24 -0
  15. data/lib/meshtastic/module_config.rb +24 -0
  16. data/lib/meshtastic/mqtt.rb +2 -3
  17. data/lib/meshtastic/paxcount.rb +24 -0
  18. data/lib/meshtastic/portnums.rb +24 -0
  19. data/lib/meshtastic/remote_hardware.rb +24 -0
  20. data/lib/meshtastic/rtttl.rb +24 -0
  21. data/lib/meshtastic/storeforward.rb +24 -0
  22. data/lib/meshtastic/telemetry.rb +24 -0
  23. data/lib/meshtastic/version.rb +1 -1
  24. data/lib/meshtastic/xmodem.rb +24 -0
  25. data/lib/meshtastic.rb +21 -1
  26. data/spec/lib/meshtastic/admin_spec.rb +6 -0
  27. data/spec/lib/meshtastic/apponly_pb_spec.rb +1 -1
  28. data/spec/lib/meshtastic/apponly_spec.rb +6 -0
  29. data/spec/lib/meshtastic/atak_pb_spec.rb +1 -1
  30. data/spec/lib/meshtastic/atak_spec.rb +6 -0
  31. data/spec/lib/meshtastic/cannedmessages_pb_spec.rb +1 -1
  32. data/spec/lib/meshtastic/cannedmessages_spec.rb +6 -0
  33. data/spec/lib/meshtastic/channel_pb_spec.rb +1 -1
  34. data/spec/lib/meshtastic/channel_spec.rb +6 -0
  35. data/spec/lib/meshtastic/clientonly_pb_spec.rb +1 -1
  36. data/spec/lib/meshtastic/clientonly_spec.rb +6 -0
  37. data/spec/lib/meshtastic/config_pb_spec.rb +1 -1
  38. data/spec/lib/meshtastic/config_spec.rb +6 -0
  39. data/spec/lib/meshtastic/connection_status_pb_spec.rb +1 -1
  40. data/spec/lib/meshtastic/connection_status_spec.rb +6 -0
  41. data/spec/lib/meshtastic/deviceonly_pb_spec.rb +1 -1
  42. data/spec/lib/meshtastic/deviceonly_spec.rb +6 -0
  43. data/spec/lib/meshtastic/localonly_pb_spec.rb +1 -1
  44. data/spec/lib/meshtastic/localonly_spec.rb +6 -0
  45. data/spec/lib/meshtastic/mesh_pb_spec.rb +1 -1
  46. data/spec/lib/meshtastic/mesh_spec.rb +6 -0
  47. data/spec/lib/meshtastic/module_config_pb_spec.rb +1 -1
  48. data/spec/lib/meshtastic/module_config_spec.rb +6 -0
  49. data/spec/lib/meshtastic/mqtt_pb_spec.rb +1 -1
  50. data/spec/lib/meshtastic/mqtt_spec.rb +1 -1
  51. data/spec/lib/meshtastic/paxcount_pb_spec.rb +1 -1
  52. data/spec/lib/meshtastic/paxcount_spec.rb +6 -0
  53. data/spec/lib/meshtastic/portnums_pb_spec.rb +1 -1
  54. data/spec/lib/meshtastic/portnums_spec.rb +6 -0
  55. data/spec/lib/meshtastic/remote_hardware_pb_spec.rb +1 -1
  56. data/spec/lib/meshtastic/remote_hardware_spec.rb +6 -0
  57. data/spec/lib/meshtastic/rtttl_pb_spec.rb +1 -1
  58. data/spec/lib/meshtastic/rtttl_spec.rb +6 -0
  59. data/spec/lib/meshtastic/storeforward_pb_spec.rb +1 -1
  60. data/spec/lib/meshtastic/storeforward_spec.rb +6 -0
  61. data/spec/lib/meshtastic/telemetry_pb_spec.rb +1 -1
  62. data/spec/lib/meshtastic/telemetry_spec.rb +6 -0
  63. data/spec/lib/meshtastic/xmodem_pb_spec.rb +1 -1
  64. data/spec/lib/meshtastic/xmodem_spec.rb +6 -0
  65. metadata +39 -2
  66. data/lib/meshtastic/mqtt.rb.BAKq! +0 -214
data/lib/meshtastic.rb CHANGED
@@ -1,6 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'meshtastic/admin_pb'
4
+ require 'meshtastic/apponly_pb'
5
+ require 'meshtastic/atak_pb'
6
+ require 'meshtastic/cannedmessages_pb'
7
+ require 'meshtastic/channel_pb'
8
+ require 'meshtastic/clientonly_pb'
9
+ require 'meshtastic/config_pb'
10
+ require 'meshtastic/connection_status_pb'
11
+ require 'meshtastic/deviceonly_pb'
12
+ require 'meshtastic/localonly_pb'
13
+ require 'meshtastic/mesh_pb'
14
+ require 'meshtastic/module_config_pb'
15
+ require 'meshtastic/mqtt_pb'
16
+ require 'meshtastic/paxcount_pb'
17
+ require 'meshtastic/portnums_pb'
18
+ require 'meshtastic/remote_hardware_pb'
19
+ require 'meshtastic/rtttl_pb'
20
+ require 'meshtastic/storeforward_pb'
21
+ require 'meshtastic/telemetry_pb'
3
22
  require 'meshtastic/version'
23
+ require 'meshtastic/xmodem_pb'
4
24
 
5
25
  # Plugin used to interact with Meshtastic nodes
6
26
  module Meshtastic
@@ -21,7 +41,7 @@ module Meshtastic
21
41
  autoload :Paxcount, 'meshtastic/paxcount'
22
42
  autoload :Portnums, 'meshtastic/portnums'
23
43
  autoload :RemoteHardware, 'meshtastic/remote_hardware'
24
- autoload :Rtttl, 'meshtastic/rtttl'
44
+ autoload :RTTTL, 'meshtastic/rtttl'
25
45
  autoload :Storeforward, 'meshtastic/storeforward'
26
46
  autoload :Telemetry, 'meshtastic/telemetry'
27
47
  autoload :Xmodem, 'meshtastic/xmodem'
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Admin do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ApponlyPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Apponly do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ATAKPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::ATAK do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::CannedmessagesPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Cannedmessages do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ChannelPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Channel do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ClientonlyPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Clientonly do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ClientonlyPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Clientonly do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ConnectionStatusPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::ConnectionStatus do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::DeviceonlyPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Deviceonly do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::LocalonlyPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Localonly do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::MeshPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Mesh do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::ModuleConfigPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::ModuleConfig do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::MQTTPB do
6
6
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::MQTT do
6
6
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::PaxcountPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Paxcount do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::PortnumsPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Portnums do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::RemoteHardwarePB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::RemoteHardware do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::RTTTLPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::RTTTL do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::StoreforwardPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Storeforward do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::TelemetryPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::Telemetry do
6
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Meshtastic::AdminPB do
5
+ describe Meshtastic::XModemPB do
6
6
  end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Meshtastic::XModem do
6
+ 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.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.
@@ -221,54 +221,91 @@ files:
221
221
  - build_meshtastic_gem.sh
222
222
  - git_commit.sh
223
223
  - lib/meshtastic.rb
224
+ - lib/meshtastic/admin.rb
224
225
  - lib/meshtastic/admin_pb.rb
226
+ - lib/meshtastic/apponly.rb
225
227
  - lib/meshtastic/apponly_pb.rb
228
+ - lib/meshtastic/atak.rb
226
229
  - lib/meshtastic/atak_pb.rb
230
+ - lib/meshtastic/cannedmessages.rb
227
231
  - lib/meshtastic/cannedmessages_pb.rb
232
+ - lib/meshtastic/channel.rb
228
233
  - lib/meshtastic/channel_pb.rb
234
+ - lib/meshtastic/clientonly.rb
229
235
  - lib/meshtastic/clientonly_pb.rb
236
+ - lib/meshtastic/config.rb
230
237
  - lib/meshtastic/config_pb.rb
238
+ - lib/meshtastic/connection_status.rb
231
239
  - lib/meshtastic/connection_status_pb.rb
240
+ - lib/meshtastic/deviceonly.rb
232
241
  - lib/meshtastic/deviceonly_pb.rb
242
+ - lib/meshtastic/localonly.rb
233
243
  - lib/meshtastic/localonly_pb.rb
244
+ - lib/meshtastic/mesh.rb
234
245
  - lib/meshtastic/mesh_pb.rb
246
+ - lib/meshtastic/module_config.rb
235
247
  - lib/meshtastic/module_config_pb.rb
236
248
  - lib/meshtastic/mqtt.rb
237
- - lib/meshtastic/mqtt.rb.BAKq!
238
249
  - lib/meshtastic/mqtt_pb.rb
250
+ - lib/meshtastic/paxcount.rb
239
251
  - lib/meshtastic/paxcount_pb.rb
252
+ - lib/meshtastic/portnums.rb
240
253
  - lib/meshtastic/portnums_pb.rb
254
+ - lib/meshtastic/remote_hardware.rb
241
255
  - lib/meshtastic/remote_hardware_pb.rb
256
+ - lib/meshtastic/rtttl.rb
242
257
  - lib/meshtastic/rtttl_pb.rb
258
+ - lib/meshtastic/storeforward.rb
243
259
  - lib/meshtastic/storeforward_pb.rb
260
+ - lib/meshtastic/telemetry.rb
244
261
  - lib/meshtastic/telemetry_pb.rb
245
262
  - lib/meshtastic/version.rb
263
+ - lib/meshtastic/xmodem.rb
246
264
  - lib/meshtastic/xmodem_pb.rb
247
265
  - meshtastic.gemspec
248
266
  - reinstall_meshtastic_gemset.sh
249
267
  - sig/meshtastic.rbs
250
268
  - spec/lib/meshtastic/admin_pb_spec.rb
269
+ - spec/lib/meshtastic/admin_spec.rb
251
270
  - spec/lib/meshtastic/apponly_pb_spec.rb
271
+ - spec/lib/meshtastic/apponly_spec.rb
252
272
  - spec/lib/meshtastic/atak_pb_spec.rb
273
+ - spec/lib/meshtastic/atak_spec.rb
253
274
  - spec/lib/meshtastic/cannedmessages_pb_spec.rb
275
+ - spec/lib/meshtastic/cannedmessages_spec.rb
254
276
  - spec/lib/meshtastic/channel_pb_spec.rb
277
+ - spec/lib/meshtastic/channel_spec.rb
255
278
  - spec/lib/meshtastic/clientonly_pb_spec.rb
279
+ - spec/lib/meshtastic/clientonly_spec.rb
256
280
  - spec/lib/meshtastic/config_pb_spec.rb
281
+ - spec/lib/meshtastic/config_spec.rb
257
282
  - spec/lib/meshtastic/connection_status_pb_spec.rb
283
+ - spec/lib/meshtastic/connection_status_spec.rb
258
284
  - spec/lib/meshtastic/deviceonly_pb_spec.rb
285
+ - spec/lib/meshtastic/deviceonly_spec.rb
259
286
  - spec/lib/meshtastic/localonly_pb_spec.rb
287
+ - spec/lib/meshtastic/localonly_spec.rb
260
288
  - spec/lib/meshtastic/mesh_pb_spec.rb
289
+ - spec/lib/meshtastic/mesh_spec.rb
261
290
  - spec/lib/meshtastic/module_config_pb_spec.rb
291
+ - spec/lib/meshtastic/module_config_spec.rb
262
292
  - spec/lib/meshtastic/mqtt_pb_spec.rb
263
293
  - spec/lib/meshtastic/mqtt_spec.rb
264
294
  - spec/lib/meshtastic/paxcount_pb_spec.rb
295
+ - spec/lib/meshtastic/paxcount_spec.rb
265
296
  - spec/lib/meshtastic/portnums_pb_spec.rb
297
+ - spec/lib/meshtastic/portnums_spec.rb
266
298
  - spec/lib/meshtastic/remote_hardware_pb_spec.rb
299
+ - spec/lib/meshtastic/remote_hardware_spec.rb
267
300
  - spec/lib/meshtastic/rtttl_pb_spec.rb
301
+ - spec/lib/meshtastic/rtttl_spec.rb
268
302
  - spec/lib/meshtastic/storeforward_pb_spec.rb
303
+ - spec/lib/meshtastic/storeforward_spec.rb
269
304
  - spec/lib/meshtastic/telemetry_pb_spec.rb
305
+ - spec/lib/meshtastic/telemetry_spec.rb
270
306
  - spec/lib/meshtastic/version_spec.rb
271
307
  - spec/lib/meshtastic/xmodem_pb_spec.rb
308
+ - spec/lib/meshtastic/xmodem_spec.rb
272
309
  - spec/lib/meshtastic_spec.rb
273
310
  - spec/spec_helper.rb
274
311
  - upgrade_Gemfile_gems.sh
@@ -1,214 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'base64'
4
- require 'geocoder'
5
- require 'json'
6
- require 'mqtt'
7
- require 'openssl'
8
- require 'securerandom'
9
- require 'meshtastic/mqtt_pb'
10
-
11
- # Avoiding Namespace Collisions
12
- MQTTClient = MQTT::Client
13
-
14
- # Plugin used to interact with Meshtastic nodes
15
- module Meshtastic
16
- module MQTT
17
- # Supported Method Parameters::
18
- # mqtt_obj = Meshtastic::MQQT.connect(
19
- # host: 'optional - mqtt host (default: mqtt.meshtastic.org)',
20
- # port: 'optional - mqtt port (defaults: 1883)',
21
- # username: 'optional - mqtt username (default: meshdev)',
22
- # password: 'optional - (default: large4cats)'
23
- # )
24
-
25
- public_class_method def self.connect(opts = {})
26
- # Publicly available MQTT server / credentials by default
27
- host = opts[:host] ||= 'mqtt.meshtastic.org'
28
- port = opts[:port] ||= 1883
29
- username = opts[:username] ||= 'meshdev'
30
- password = opts[:password] ||= 'large4cats'
31
-
32
- mqtt_obj = MQTTClient.connect(
33
- host: host,
34
- port: port,
35
- username: username,
36
- password: password
37
- )
38
-
39
- mqtt_obj.client_id = SecureRandom.random_bytes(8).unpack1('H*')
40
-
41
- mqtt_obj
42
- rescue StandardError => e
43
- raise e
44
- end
45
-
46
- # Supported Method Parameters::
47
- # Meshtastic::MQQT.subscribe(
48
- # mqtt_obj: 'required - mqtt_obj returned from #connect method'
49
- # region: 'optional - region (default: US)',
50
- # channel: 'optional - channel name (default: LongFast)',
51
- # psk: 'optional - channel pre-shared key (default: AQ==)',
52
- # qos: 'optional - quality of service (default: 0)',
53
- # json: 'optional - JSON output (default: false)'
54
- # )
55
-
56
- public_class_method def self.subscribe(opts = {})
57
- mqtt_obj = opts[:mqtt_obj]
58
- region = opts[:region] ||= 'US'
59
- channel = opts[:channel] ||= 'LongFast'
60
- psk = opts[:psk] ||= 'AQ=='
61
- qos = opts[:qos] ||= 0
62
- json = opts[:json] ||= false
63
-
64
- # TODO: Find JSON URI for this
65
- root_topic = "msh/#{region}/2/json" if json
66
- # root_topic = "msh/#{region}/2/e" unless json
67
- root_topic = "msh/#{region}/2/c" unless json
68
- mqtt_obj.subscribe("#{root_topic}/#{channel}/#", qos)
69
-
70
- # Decrypt the message
71
- # Our AES key is 128 or 256 bits, shared as part of the 'Channel' specification.
72
-
73
- # Actual pre-shared key for LongFast channel
74
- psk = '1PG7OiApB1nwvP+rz05pAQ==' if channel == 'LongFast'
75
- padded_psk = psk.ljust(psk.length + ((4 - (psk.length % 4)) % 4), '=')
76
- replaced_psk = padded_psk.gsub('-', '+').gsub('_', '/')
77
- psk = replaced_psk
78
- dec_psk = Base64.strict_decode64(psk)
79
-
80
- # cipher = OpenSSL::Cipher.new('AES-256-CTR')
81
- cipher = OpenSSL::Cipher.new('AES-128-CTR')
82
- mqtt_obj.get_packet do |packet|
83
- begin
84
- puts '-' * 80
85
-
86
- if json
87
- raw_payload = JSON.parse(packet.payload, symbolize_names: true)
88
- payload = Meshtastic::ServiceEnvelope.json_decode(raw_payload)
89
- map_report = Meshtastic::MapReport.json_decode(raw_payload)
90
- else
91
- raw_payload = packet.payload.to_s
92
- payload = Meshtastic::ServiceEnvelope.decode(raw_payload)
93
- map_report = Meshtastic::MapReport.decode(raw_payload)
94
- end
95
-
96
- puts "Payload: #{payload.inspect}"
97
- puts "Payload Length: #{payload.length}"
98
- puts "Map Report: #{map_report.inspect}"
99
- puts "Map Report Length: #{map_report.length}"
100
-
101
- packet_from = packet_from_hex.to_i(16)
102
- packet_to = packet_to_hex.to_i(16)
103
- msg_len = msg_len_hex.to_i(16)
104
- channel = channel_hex.to_i(16)
105
- packet_id = pid_hex.to_i(16)
106
- topic = packet.topic
107
- puts "\nTopic: #{topic}"
108
-
109
-
110
- nonce_packet_id = [packet_id].pack('V').ljust(8, "\x00")
111
- nonce_from_node = [packet_from].pack('V').ljust(8, "\x00")
112
- nonce = "#{nonce_packet_id}#{nonce_from_node}".b
113
- puts "Nonce: #{nonce.inspect} | Length: #{nonce.length}"
114
-
115
- # Decrypt the message
116
- # Key must be 32 bytes
117
- # IV mustr be 16 bytes
118
- cipher.decrypt
119
- cipher.key = dec_psk
120
- cipher.iv = nonce
121
- first_byte = 16
122
- last_byte = first_byte + msg_len - 1
123
- encrypted_payload = payload[first_byte..last_byte]
124
- puts "\nEncrypted Payload:\n#{encrypted_payload.inspect}"
125
- puts "Length: #{encrypted_payload.length}" if encrypted_payload
126
-
127
- decrypted = cipher.update(encrypted_payload) + cipher.final
128
- puts "\nDecrypted Payload:\n#{decrypted.inspect}"
129
- puts "Length: #{decrypted.length}" if decrypted
130
-
131
- raw_packet = packet.to_s.b
132
- raw_packet_len = raw_packet.length
133
- puts "\nRaw Packet: #{raw_packet.inspect}"
134
- puts "Length: #{raw_packet_len}"
135
- rescue Google::Protobuf::ParseError => e
136
- puts "Error parsing message: #{e}"
137
- next
138
- end
139
- end
140
- rescue Interrupt
141
- puts "\nCTRL+C detected. Exiting..."
142
- rescue StandardError => e
143
- raise e
144
- ensure
145
- mqtt_obj.disconnect if mqtt_obj
146
- end
147
-
148
- # Supported Method Parameters::
149
- # mqtt_obj = Meshtastic.gps_search(
150
- # lat: 'required - latitude float (e.g. 37.7749)',
151
- # lon: 'required - longitude float (e.g. -122.4194)',
152
- # )
153
- public_class_method def self.gps_search(opts = {})
154
- lat = opts[:lat]
155
- lon = opts[:lon]
156
-
157
- raise 'ERROR: Latitude and Longitude are required' unless lat && lon
158
-
159
- gps_arr = [lat.to_f, lon.to_f]
160
-
161
- Geocoder.search(gps_arr)
162
- rescue StandardError => e
163
- raise e
164
- end
165
-
166
- # Supported Method Parameters::
167
- # mqtt_obj = Meshtastic.disconnect(
168
- # mqtt_obj: 'required - mqtt_obj returned from #connect method'
169
- # )
170
- public_class_method def self.disconnect(opts = {})
171
- mqtt_obj = opts[:mqtt_obj]
172
-
173
- mqtt_obj.disconnect if mqtt_obj
174
- nil
175
- rescue StandardError => e
176
- raise e
177
- end
178
-
179
- # Author(s):: 0day Inc. <request.pentest@0dayinc.com>
180
-
181
- public_class_method def self.authors
182
- "AUTHOR(S):
183
- 0day Inc. <request.pentest@0dayinc.com>
184
- "
185
- end
186
-
187
- # Display Usage for this Module
188
-
189
- public_class_method def self.help
190
- puts "USAGE:
191
- mqtt_obj = #{self}.connect(
192
- host: 'optional - mqtt host (default: mqtt.meshtastic.org)',
193
- port: 'optional - mqtt port (defaults: 1883)',
194
- username: 'optional - mqtt username (default: meshdev)',
195
- password: 'optional - (default: large4cats)'
196
- )
197
-
198
- #{self}.subscribe(
199
- mqtt_obj: 'required - mqtt_obj object returned from #connect method',
200
- region: 'optional - region (default: US)',
201
- channel: 'optional - channel name (default: LongFast)',
202
- psk: 'optional - channel pre-shared key (default: AQ==)',
203
- qos: 'optional - quality of service (default: 0)'
204
- )
205
-
206
- mqtt_obj = #{self}.disconnect(
207
- mqtt_obj: 'required - mqtt_obj object returned from #connect method'
208
- )
209
-
210
- #{self}.authors
211
- "
212
- end
213
- end
214
- end