meshtastic 0.0.22 → 0.0.24
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/README.md +2 -1
- data/lib/meshtastic/mqtt.rb +95 -18
- data/lib/meshtastic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b24b299642029b92a222cd725fc4fcc7cc16f65456e9e7ed14a19ba961370126
|
4
|
+
data.tar.gz: f311791bced3690a4e7072cd0c71c0d7521eec9a14c93425a70a8d46f6a1e198
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 356940728257de2c144fdd3614e20b0ef7e03fba208d2e97b13822a8bf1e732bb2e338da814d06303147c756b9e60f34068723e43f774070136e123bb8dea955
|
7
|
+
data.tar.gz: eb0bd43a244d7bad3dd49ee52ecc4f07a4ecbd079781065a0fd64723e4aeb60bb1e8292f2402558c7d920ba373f0cecb5064c72dd750078668049604073162cd
|
data/README.md
CHANGED
@@ -37,10 +37,11 @@ Meshtastic::MQTT.subscribe(
|
|
37
37
|
```
|
38
38
|
|
39
39
|
This code will print the `from` value of each message received:
|
40
|
+
|
40
41
|
```ruby
|
41
42
|
require 'meshtastic'
|
42
43
|
mqtt_obj = Meshastic::MQTT.connect
|
43
|
-
Meshtastic::MQTT.subscribe(
|
44
|
+
Meshtastic::MQTT.subscribe(mqtt_obj: mqtt_obj) do |message|
|
44
45
|
puts message[:from]
|
45
46
|
end
|
46
47
|
```
|
data/lib/meshtastic/mqtt.rb
CHANGED
@@ -45,6 +45,7 @@ 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==)',
|
@@ -55,6 +56,7 @@ module Meshtastic
|
|
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
|
+
full_topic = "#{root_topic}/#{region}/2/json/#{channel}/#" if json
|
69
|
+
full_topic = "#{root_topic}/#{region}/2/c/#{channel}/#" unless json
|
70
|
+
puts "Subscribing to: #{full_topic}"
|
71
|
+
mqtt_obj.subscribe(full_topic, 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.
|
@@ -82,20 +85,19 @@ module Meshtastic
|
|
82
85
|
filter_arr = filter.to_s.split(',').map(&:strip)
|
83
86
|
mqtt_obj.get_packet do |packet_bytes|
|
84
87
|
raw_packet = packet_bytes.to_s.b
|
85
|
-
raw_packet_len = raw_packet.to_s.b.length
|
86
88
|
raw_topic = packet_bytes.topic ||= ''
|
87
89
|
raw_message = packet_bytes.payload
|
88
90
|
|
89
91
|
begin
|
90
92
|
disp = false
|
91
93
|
message = {}
|
94
|
+
stdout_message = ''
|
92
95
|
|
93
96
|
if json
|
94
97
|
message = JSON.parse(raw_message, symbolize_names: true)
|
95
98
|
else
|
96
|
-
|
97
|
-
|
98
|
-
message = svc_envl.to_h[:packet]
|
99
|
+
decoded_packet = Meshtastic::ServiceEnvelope.decode(raw_message)
|
100
|
+
message = decoded_packet.to_h[:packet]
|
99
101
|
end
|
100
102
|
message[:topic] = raw_topic
|
101
103
|
message[:node_id_from] = "!#{message[:from].to_i.to_s(16)}"
|
@@ -119,6 +121,75 @@ module Meshtastic
|
|
119
121
|
|
120
122
|
decrypted = cipher.update(encrypted_message) + cipher.final
|
121
123
|
message[:decrypted] = decrypted
|
124
|
+
# Vvv Decode the decrypted message vvV
|
125
|
+
end
|
126
|
+
|
127
|
+
if message[:decoded]
|
128
|
+
payload = message[:decoded][:payload]
|
129
|
+
|
130
|
+
msg_type = message[:decoded][:portnum]
|
131
|
+
case msg_type
|
132
|
+
when :ADMIN_APP
|
133
|
+
pb_obj = Meshtastic::Admin.decode(payload)
|
134
|
+
when :ATAK_FORWARDER
|
135
|
+
pb_obj = Meshtastic::AtakForwarder.decode(payload)
|
136
|
+
when :ATAK_PLUGIN
|
137
|
+
pb_obj = Meshtastic::AtakPlugin.decode(payload)
|
138
|
+
when :AUDIO_APP
|
139
|
+
pb_obj = Meshtastic::Audio.decode(payload)
|
140
|
+
when :DETECTION_SENSOR_APP
|
141
|
+
pb_obj = Meshtastic::DetectionSensor.decode(payload)
|
142
|
+
when :IP_TUNNEL_APP
|
143
|
+
pb_obj = Meshtastic::IpTunnel.decode(payload)
|
144
|
+
when :MAP_REPORT_APP
|
145
|
+
pb_obj = Meshtastic::MapReport.decode(payload)
|
146
|
+
when :MAX
|
147
|
+
pb_obj = Meshtastic::Max.decode(payload)
|
148
|
+
when :NEIGHBORINFO_APP
|
149
|
+
pb_obj = Meshtastic::NeighborInfo.decode(payload)
|
150
|
+
when :NODEINFO_APP
|
151
|
+
pb_obj = Meshtastic::NodeInfo.decode(payload)
|
152
|
+
when :PAXCOUNTER_APP
|
153
|
+
pb_obj = Meshtastic::Paxcounter.decode(payload)
|
154
|
+
when :POSITION_APP
|
155
|
+
pb_obj = Meshtastic::Position.decode(payload)
|
156
|
+
when :PRIVATE_APP
|
157
|
+
pb_obj = Meshtastic::Private.decode(payload)
|
158
|
+
when :RANGE_TEST_APP
|
159
|
+
pb_obj = Meshtastic::RangeTest.decode(payload)
|
160
|
+
when :REMOTE_HARDWARE_APP
|
161
|
+
pb_obj = Meshtastic::RemoteHardware.decode(payload)
|
162
|
+
when :REPLY_APP
|
163
|
+
pb_obj = Meshtastic::Reply.decode(payload)
|
164
|
+
when :ROUTING_APP
|
165
|
+
pb_obj = Meshtastic::Routing.decode(payload)
|
166
|
+
when :SERIAL_APP
|
167
|
+
pb_obj = Meshtastic::Serial.decode(payload)
|
168
|
+
when :SIMULATOR_APP
|
169
|
+
pb_obj = Meshtastic::Simulator.decode(payload)
|
170
|
+
when :STORE_FORWARD_APP
|
171
|
+
pb_obj = Meshtastic::StoreForward.decode(payload)
|
172
|
+
when :TEXT_MESSAGE_APP
|
173
|
+
pb_obj = Meshtastic::TextMessage.decode(payload)
|
174
|
+
when :TEXT_MESSAGE_COMPRESSED_APP
|
175
|
+
pb_obj = Meshtastic::TextMessageCompressed.decode(payload)
|
176
|
+
when :TELEMETRY_APP
|
177
|
+
pb_obj = Meshtastic::Telemetry.decode(payload)
|
178
|
+
when :TRACEROUTE_APP
|
179
|
+
pb_obj = Meshtastic::Traceroute.decode(payload)
|
180
|
+
when :UNKNOWN_APP
|
181
|
+
pb_obj = Meshtastic.Unknown.decode(payload)
|
182
|
+
when :WAYPOINT_APP
|
183
|
+
pb_obj = Meshtastic::Waypoint.decode(payload)
|
184
|
+
when :ZPS_APP
|
185
|
+
pb_obj = Meshtastic::Zps.decode(payload)
|
186
|
+
else
|
187
|
+
puts "WARNING: Unknown message type: #{msg_type}"
|
188
|
+
end
|
189
|
+
# Overwrite the payload with the decoded protobuf object
|
190
|
+
message[:decoded][:payload] = pb_obj.to_h
|
191
|
+
# puts pb_obj.public_methods
|
192
|
+
# message[:decoded][:pb_obj] = pb_obj
|
122
193
|
end
|
123
194
|
|
124
195
|
filter_arr = [message[:id].to_s] if filter.nil?
|
@@ -127,20 +198,25 @@ module Meshtastic
|
|
127
198
|
disp = true if filter_arr.first == message[:id] ||
|
128
199
|
filter_arr.all? { |filter| flat_message.include?(filter) }
|
129
200
|
|
130
|
-
|
201
|
+
message[:raw_packet] = raw_packet if block_given?
|
202
|
+
stdout_message = JSON.pretty_generate(message) unless block_given?
|
203
|
+
rescue Google::Protobuf::ParseError,
|
204
|
+
JSON::GeneratorError
|
205
|
+
|
206
|
+
stdout_message = message.to_s.b.inspect unless block_given?
|
131
207
|
next
|
132
208
|
ensure
|
133
209
|
if disp
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
210
|
+
if block_given?
|
211
|
+
yield message
|
212
|
+
else
|
213
|
+
puts "\n"
|
214
|
+
puts '-' * 80
|
215
|
+
puts 'MSG:'
|
216
|
+
puts stdout_message
|
217
|
+
puts '-' * 80
|
218
|
+
puts "\n\n\n"
|
219
|
+
end
|
144
220
|
else
|
145
221
|
print '.'
|
146
222
|
end
|
@@ -206,6 +282,7 @@ module Meshtastic
|
|
206
282
|
|
207
283
|
#{self}.subscribe(
|
208
284
|
mqtt_obj: 'required - mqtt_obj object returned from #connect method',
|
285
|
+
root_topic: 'optional - root topic (default: msh)',
|
209
286
|
region: 'optional - region (default: US)',
|
210
287
|
channel: 'optional - channel name (default: LongFast)',
|
211
288
|
psk: 'optional - channel pre-shared key (default: AQ==)',
|
data/lib/meshtastic/version.rb
CHANGED