meshtastic 0.0.53 → 0.0.56
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/lib/meshtastic/version.rb +1 -1
- data/lib/meshtastic.rb +48 -8
- 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: 587ec9cf838d9bc00fb0881bfb06e5baaf32b76cf92be0f1687dee8397cc372e
|
4
|
+
data.tar.gz: 4bf94458eae35a86738318fff4931094f943bd3afcacb967e2022809c0e211ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cb23efe67552373a15b746b6553951f6694fe64fd03a68f4db730b2c477a769999dba92146b8a40d85cd3c29ea71c931a5406b1d081367a3699eaf8358af8b2
|
7
|
+
data.tar.gz: 9c2733116cfaebcfa388a4211d519e0216ca1709d2752d197bc7175cb92e4a1246c4e5ff7baea6fcd5314ff69af458b90b24094eb5ff749861ad2d116aae1844
|
data/lib/meshtastic/version.rb
CHANGED
data/lib/meshtastic.rb
CHANGED
@@ -53,6 +53,7 @@ module Meshtastic
|
|
53
53
|
# Meshtastic.send_text(
|
54
54
|
# from: 'required - From ID (String or Integer)',
|
55
55
|
# to: 'optional - Destination ID (Default: 0xFFFFFFFF)',
|
56
|
+
# via: 'optional - :radio || :mqtt (Default: :radio)',
|
56
57
|
# channel: 'optional - Channel ID (Default: 0)',
|
57
58
|
# text: 'optional - Text Message (Default: SYN)',
|
58
59
|
# want_ack: 'optional - Want Acknowledgement (Default: false)',
|
@@ -72,6 +73,7 @@ module Meshtastic
|
|
72
73
|
to_hex = to.delete('!').bytes.map { |b| b.to_s(16).rjust(2, '0') }.join if to.is_a?(String)
|
73
74
|
to = to_hex.to_i(16) if to_hex
|
74
75
|
|
76
|
+
via = opts[:via] ||= :radio
|
75
77
|
channel = opts[:channel] ||= 0
|
76
78
|
text = opts[:text] ||= 'SYN'
|
77
79
|
want_ack = opts[:want_ack] ||= false
|
@@ -100,6 +102,7 @@ module Meshtastic
|
|
100
102
|
send_data(
|
101
103
|
from: from,
|
102
104
|
to: to,
|
105
|
+
via: via,
|
103
106
|
channel: channel,
|
104
107
|
data: data,
|
105
108
|
want_ack: want_ack,
|
@@ -117,6 +120,7 @@ module Meshtastic
|
|
117
120
|
# Meshtastic.send_data(
|
118
121
|
# from: 'required - From ID (String or Integer)',
|
119
122
|
# to: 'optional - Destination ID (Default: 0xFFFFFFFF)',
|
123
|
+
# via: 'optional - :radio || :mqtt (Default: :radio)',
|
120
124
|
# channel: 'optional - Channel ID (Default: 0)',
|
121
125
|
# data: 'required - Data to Send',
|
122
126
|
# want_ack: 'optional - Want Acknowledgement (Default: false)',
|
@@ -135,6 +139,7 @@ module Meshtastic
|
|
135
139
|
to_hex = to.delete('!').bytes.map { |b| b.to_s(16).rjust(2, '0') }.join if to.is_a?(String)
|
136
140
|
to = to_hex.to_i(16) if to_hex
|
137
141
|
|
142
|
+
via = opts[:via] ||= :radio
|
138
143
|
channel = opts[:channel] ||= 0
|
139
144
|
data = opts[:data]
|
140
145
|
want_ack = opts[:want_ack] ||= false
|
@@ -160,6 +165,7 @@ module Meshtastic
|
|
160
165
|
mesh_packet: mesh_packet,
|
161
166
|
from: from,
|
162
167
|
to: to,
|
168
|
+
via: via,
|
163
169
|
channel: channel,
|
164
170
|
want_ack: want_ack,
|
165
171
|
hop_limit: hop_limit,
|
@@ -174,6 +180,7 @@ module Meshtastic
|
|
174
180
|
# mesh_packet: 'required - Mesh Packet to Send',
|
175
181
|
# from: 'required - From ID (String or Integer)',
|
176
182
|
# to: 'optional - Destination ID (Default: 0xFFFFFFFF)',
|
183
|
+
# via: 'optional - :radio || :mqtt (Default: :radio)',
|
177
184
|
# channel: 'optional - Channel ID (Default: 0)',
|
178
185
|
# want_ack: 'optional - Want Acknowledgement (Default: false)',
|
179
186
|
# hop_limit: 'optional - Hop Limit (Default: 3)',
|
@@ -190,6 +197,7 @@ module Meshtastic
|
|
190
197
|
to_hex = to.delete('!').bytes.map { |b| b.to_s(16).rjust(2, '0') }.join if to.is_a?(String)
|
191
198
|
to = to_hex.to_i(16) if to_hex
|
192
199
|
|
200
|
+
via = opts[:via] ||= :radio
|
193
201
|
channel = opts[:channel] ||= 0
|
194
202
|
want_ack = opts[:want_ack] ||= false
|
195
203
|
hop_limit = opts[:hop_limit] ||= 3
|
@@ -208,9 +216,15 @@ module Meshtastic
|
|
208
216
|
mesh_packet.channel = channel
|
209
217
|
mesh_packet.want_ack = want_ack
|
210
218
|
mesh_packet.hop_limit = hop_limit
|
211
|
-
|
212
|
-
#
|
213
|
-
|
219
|
+
|
220
|
+
# TODO: Implement strategy for obtaining last packet id
|
221
|
+
packet_id = 0
|
222
|
+
if mesh_packet.id.zero?
|
223
|
+
packet_id = generate_packet_id(
|
224
|
+
last_packet_id: packet_id
|
225
|
+
)
|
226
|
+
end
|
227
|
+
mesh_packet.id = packet_id
|
214
228
|
|
215
229
|
if psks
|
216
230
|
nonce_packet_id = [mesh_packet.id].pack('V').ljust(8, "\x00")
|
@@ -232,10 +246,21 @@ module Meshtastic
|
|
232
246
|
end
|
233
247
|
# puts mesh_packet.to_h
|
234
248
|
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
249
|
+
# puts "Sending Packet via: #{via}"
|
250
|
+
case via
|
251
|
+
when :radio
|
252
|
+
to_radio = Meshtastic::ToRadio.new
|
253
|
+
to_radio.packet = mesh_packet
|
254
|
+
send_to_radio(to_radio: to_radio)
|
255
|
+
when :mqtt
|
256
|
+
service_envelope = Meshtastic::ServiceEnvelope.new
|
257
|
+
service_envelope.packet = mesh_packet
|
258
|
+
service_envelope.channel_id = psks.keys.first
|
259
|
+
service_envelope.gateway_id = "!#{from.to_s(16).downcase}"
|
260
|
+
send_to_mqtt(service_envelope: service_envelope)
|
261
|
+
else
|
262
|
+
raise "ERROR: Invalid via parameter: #{via}"
|
263
|
+
end
|
239
264
|
rescue StandardError => e
|
240
265
|
raise e
|
241
266
|
end
|
@@ -248,7 +273,8 @@ module Meshtastic
|
|
248
273
|
last_packet_id = opts[:last_packet_id] ||= 0
|
249
274
|
last_packet_id = 0 if last_packet_id.negative?
|
250
275
|
|
251
|
-
(
|
276
|
+
Random.rand(0xffffffff) if last_packet_id.zero?
|
277
|
+
(last_packet_id + 1) & 0xffffffff if last_packet_id.positive?
|
252
278
|
end
|
253
279
|
|
254
280
|
# Supported Method Parameters::
|
@@ -265,6 +291,20 @@ module Meshtastic
|
|
265
291
|
raise e
|
266
292
|
end
|
267
293
|
|
294
|
+
# Supported Method Parameters::
|
295
|
+
# Meshtastic.send_to_mqtt(
|
296
|
+
# service_envelope: 'required - ServiceEnvelope Message to Send'
|
297
|
+
# )
|
298
|
+
public_class_method def self.send_to_mqtt(opts = {})
|
299
|
+
service_envelope = opts[:service_envelope]
|
300
|
+
|
301
|
+
raise 'ERROR: Invalid ServiceEnvelope Message' unless service_envelope.is_a?(Meshtastic::ServiceEnvelope)
|
302
|
+
|
303
|
+
service_envelope.to_proto
|
304
|
+
rescue StandardError => e
|
305
|
+
raise e
|
306
|
+
end
|
307
|
+
|
268
308
|
# Author(s):: 0day Inc. <support@0dayinc.com>
|
269
309
|
|
270
310
|
public_class_method def self.authors
|