meshtastic 0.0.52 → 0.0.55

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5656d74b5db708a5326543863dcbedc9fa101d7a61e8fd3d0136f095ab108ab4
4
- data.tar.gz: f18672f97ef7721d575ab07bd5e7cf019c38b11bf6486a132b35264ab8fdc978
3
+ metadata.gz: 6e5fa2b876003694039c7b9e869e3ae165f4f9c89023ef9936e059d55fb88f77
4
+ data.tar.gz: 7b7b7a348051bb55b232e0dc974d9dbb182a85a6680fa9575f19832dbc48685f
5
5
  SHA512:
6
- metadata.gz: c3eb1b0c0484564d25a9eafba5ab9a281bbab340e09472d9e3e9a173f9bea7d3d1cd65f173af5397cb54e6705b2d576638f80c3c96d5b95e958317e4ec5b751b
7
- data.tar.gz: 5a8f975dd695e868569daa7d45c954f422d970becbfd42ed2ebc96b038b3056d9638c4c14f56ea1db2f72e7bea22d589026b17973027816f6b212a1a4526f7f0
6
+ metadata.gz: 99bd471d591581d107dcb38ea258d48b468cc3c124b276d7d1b6e935b1a78d12d4e555d15f6e426a93f372f97576482a15fb2bcd39b05f5873c0958c51da5110
7
+ data.tar.gz: 0a0e1c273cad423c52a1e4d00fab66e59936951e35d0be5cf37fd4677ea971d56ea57dfd9ab2c41d1c62e3393101730d86286443602c54728d101ef09849337b
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.52'
4
+ VERSION = '0.0.55'
5
5
  end
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
@@ -95,11 +97,12 @@ module Meshtastic
95
97
  data.payload = text
96
98
  data.portnum = port_num
97
99
  data.want_response = want_response
98
- puts data.to_h
100
+ # puts data.to_h
99
101
 
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
@@ -230,12 +238,23 @@ module Meshtastic
230
238
 
231
239
  mesh_packet.encrypted = encrypted_payload
232
240
  end
233
- puts mesh_packet.to_h
234
-
235
- to_radio = Meshtastic::ToRadio.new
236
- to_radio.packet = mesh_packet
237
-
238
- send_to_radio(to_radio: to_radio)
241
+ # puts mesh_packet.to_h
242
+
243
+ # puts "Sending Packet via: #{via}"
244
+ case via
245
+ when :radio
246
+ to_radio = Meshtastic::ToRadio.new
247
+ to_radio.packet = mesh_packet
248
+ send_to_radio(to_radio: to_radio)
249
+ when :mqtt
250
+ service_envelope = Meshtastic::ServiceEnvelope.new
251
+ service_envelope.packet = mesh_packet
252
+ service_envelope.channel_id = psks.keys.first
253
+ service_envelope.gateway_id = "!#{from.to_s(16).downcase}"
254
+ send_to_mqtt(service_envelope: service_envelope)
255
+ else
256
+ raise "ERROR: Invalid via parameter: #{via}"
257
+ end
239
258
  rescue StandardError => e
240
259
  raise e
241
260
  end
@@ -265,6 +284,20 @@ module Meshtastic
265
284
  raise e
266
285
  end
267
286
 
287
+ # Supported Method Parameters::
288
+ # Meshtastic.send_to_mqtt(
289
+ # service_envelope: 'required - ServiceEnvelope Message to Send'
290
+ # )
291
+ public_class_method def self.send_to_mqtt(opts = {})
292
+ service_envelope = opts[:service_envelope]
293
+
294
+ raise 'ERROR: Invalid ServiceEnvelope Message' unless service_envelope.is_a?(Meshtastic::ServiceEnvelope)
295
+
296
+ service_envelope.to_proto
297
+ rescue StandardError => e
298
+ raise e
299
+ end
300
+
268
301
  # Author(s):: 0day Inc. <support@0dayinc.com>
269
302
 
270
303
  public_class_method def self.authors
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.52
4
+ version: 0.0.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.