meshtastic 0.0.21 → 0.0.23
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/Gemfile +1 -1
- data/README.md +10 -0
- data/lib/meshtastic/mqtt.rb +48 -47
- data/lib/meshtastic/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 92ee92f4c1356fc60440b101723abac1c35e33ef757bb74266e8d32a982df2b5
|
|
4
|
+
data.tar.gz: 3917587b0080996105d5f0c73fee9208f2c89ddf067a13a661d95f58a5fb5f43
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 678c08feb284f83a56bdc43824074621b1a0835de6ecf56757f2129f5ac26277940b4c1cc48b636947dbd8974bc94f872f7169429872c86c9f04f33161cc47c4
|
|
7
|
+
data.tar.gz: d581f878f32669d5a93a57dc849468669c21939d98b20915cce1c432bb76f1984b6bf9005690c9d581741fbe40a068bd06c5d3e0c7c9356853b6e5808eeccdef
|
data/Gemfile
CHANGED
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).
|
data/lib/meshtastic/mqtt.rb
CHANGED
|
@@ -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
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
90
|
+
raw_message = packet_bytes.payload
|
|
88
91
|
|
|
89
92
|
begin
|
|
90
|
-
|
|
93
|
+
disp = false
|
|
94
|
+
message = {}
|
|
95
|
+
|
|
91
96
|
if json
|
|
92
|
-
|
|
97
|
+
message = JSON.parse(raw_message, symbolize_names: true)
|
|
93
98
|
else
|
|
94
|
-
svc_envl = Meshtastic::ServiceEnvelope.decode(
|
|
95
|
-
# map_report = Meshtastic::MapReport.decode(
|
|
96
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
# If
|
|
104
|
-
if
|
|
105
|
-
packet_id =
|
|
106
|
-
packet_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(
|
|
119
|
-
|
|
123
|
+
decrypted = cipher.update(encrypted_message) + cipher.final
|
|
124
|
+
message[:decrypted] = decrypted
|
|
120
125
|
end
|
|
121
126
|
|
|
122
|
-
filter_arr = [
|
|
123
|
-
|
|
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 ==
|
|
127
|
-
filter_arr.all? { |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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
|
221
|
+
filter: 'optional - comma-delimited string(s) to filter on in message (default: nil)'
|
|
221
222
|
)
|
|
222
223
|
|
|
223
224
|
#{self}.gps_search(
|
data/lib/meshtastic/version.rb
CHANGED
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.
|
|
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-
|
|
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.
|
|
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.
|
|
138
|
+
version: 1.63.4
|
|
139
139
|
- !ruby/object:Gem::Dependency
|
|
140
140
|
name: rubocop-rake
|
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|