meshtastic 0.0.131 → 0.0.133

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: 7d5c8125b93a40c6bf9c026e9772c358780efccd8c726429374f236dde76ee3e
4
- data.tar.gz: dddc89b1ff453d5f1d632c08b829c423ae37d4da2eefbe73e486404abc7ba1bb
3
+ metadata.gz: dd7da546fac5be533cc4420c830da4514bf10c5dd48577abfd54cf912d0af58e
4
+ data.tar.gz: 583508248f892029b83b21663e3666dff7bae1a034c085eaa67616c6834d4ef1
5
5
  SHA512:
6
- metadata.gz: e5c6a5f73853b09707850e2d3f33bfd9cd93f35dc5db352589f384d5c246640b6bdd377ff054096bd94d5c5896953a47a2fa05ec03e10057ad075cd051d675ce
7
- data.tar.gz: 186455cdf4cefe78b9d4711515675ee06f8664e4cb431e0865103a1ad6a6663484e754aa1358dd8442239e3ce74b9d57e7385b152ed6ef65d15518cd01a2b9ce
6
+ metadata.gz: e689b2141774914914ef4895867a5cc7e197cdf63ee0f282fbbcf5b1fcabf917167de1a81fccbbb865e4c35082f154dd4b3957769d0d601dd8388925f4b85ea7
7
+ data.tar.gz: af9a806f6fdf54668c1391ad46865a8590bfe4d8bb47829fafc7232eae7413dd470f506c1deffd25f4f08fa9dede9cd298d97a9a963c3e76cc5e031c6ca1c309
data/README.md CHANGED
@@ -30,6 +30,7 @@ At the moment the only module available is `Meshtastic::MQTT`. To view MQTT mes
30
30
  require 'meshtastic'
31
31
  Meshtastic::MQTT.help
32
32
  mqtt_obj = Meshastic::MQTT.connect
33
+ puts mqtt_obj.inspect
33
34
  Meshtastic::MQTT.subscribe(
34
35
  mqtt_obj: mqtt_obj,
35
36
  include: '_APP, LongFast'
@@ -43,6 +44,7 @@ require 'meshtastic'
43
44
  mqtt_obj = Meshastic::MQTT.connect
44
45
  Meshtastic::MQTT.subscribe(
45
46
  mqtt_obj: mqtt_obj,
47
+ root_topic: 'msh',
46
48
  region: 'US',
47
49
  topic: '2/e/LongFast/#',
48
50
  psks: { LongFast: 'AQ==' }
@@ -61,7 +63,9 @@ Meshtastic::MQTT.send_text(
61
63
  mqtt_obj: mqtt_obj,
62
64
  from: client_id,
63
65
  to: '!ffffffff',
64
- topic: "msh/US/2/e/LongFast/#{client_id}",
66
+ root_topic: 'msh',
67
+ region: 'US',
68
+ topic: '2/e/LongFast/#',
65
69
  channel: 93,
66
70
  text: 'Hello, World!',
67
71
  psks: { LongFast: 'AQ==' }
@@ -75,6 +79,7 @@ require 'meshtastic'
75
79
  mqtt_obj = Meshastic::MQTT.connect
76
80
  Meshtastic::MQTT.subscribe(
77
81
  mqtt_obj: mqtt_obj,
82
+ root_topic: 'msh',
78
83
  region: 'US',
79
84
  topic: '2/e/LongFast/#',
80
85
  psks: { LongFast: 'AQ==' },
@@ -255,7 +255,7 @@ module Meshtastic
255
255
  # to: 'optional - Destination ID (Default: "!ffffffff")',
256
256
  # root_topic: 'optional - root topic (default: msh)',
257
257
  # region: 'optional - region e.g. "US/VA", etc (default: US)',
258
- # topic: 'optional - topic to publish to (default: "2/e/LongFast")',
258
+ # topic: 'optional - topic to publish to (default: "2/e/LongFast/#")',
259
259
  # channel: 'optional - channel (Default: 6)',
260
260
  # text: 'optional - Text Message (Default: SYN)',
261
261
  # want_ack: 'optional - Want Acknowledgement (Default: false)',
@@ -270,16 +270,42 @@ module Meshtastic
270
270
  opts[:to] ||= '!ffffffff'
271
271
  opts[:root_topic] ||= 'msh'
272
272
  opts[:region] ||= 'US'
273
- opts[:topic] ||= '2/e/LongFast'
273
+ opts[:topic] ||= '2/e/LongFast/#'
274
+ opts[:topic] = opts[:topic].to_s.gsub('/#', '')
274
275
  opts[:channel] ||= 6
275
276
  absolute_topic = "#{opts[:root_topic]}/#{opts[:region]}/#{opts[:topic]}/#{opts[:from]}"
277
+ opts[:topic] = absolute_topic
276
278
  opts[:via] = :mqtt
277
279
 
278
280
  # TODO: Implement chunked message to deal with large messages
281
+ raw_text = opts[:text].to_s
282
+ max_bytes = 233
279
283
  mui = Meshtastic::MeshInterface.new
280
- protobuf_text = mui.send_text(opts)
281
284
 
282
- mqtt_obj.publish(absolute_topic, protobuf_text)
285
+ if raw_text.bytesize > max_bytes
286
+ chunks = []
287
+ current_chunk = ''
288
+ raw_text.each_char do |char|
289
+ if (current_chunk + char).bytesize > max_bytes
290
+ chunks.push(current_chunk)
291
+ current_chunk = char
292
+ else
293
+ current_chunk += char
294
+ end
295
+ end
296
+ chunks.push(current_chunk) unless current_chunk.empty?
297
+
298
+ total_chunks = chunks.length
299
+ chunks.each_with_index do |chunk, index|
300
+ opts[:text] = chunk
301
+ opts[:text] = "[#{index + 1}/#{total_chunks}] #{chunk}"
302
+ protobuf_chunk = mui.send_text(opts)
303
+ push(mqtt_obj.publish(absolute_topic, protobuf_chunk))
304
+ end
305
+ else
306
+ protobuf_text = mui.send_text(opts)
307
+ mqtt_obj.publish(absolute_topic, protobuf_text)
308
+ end
283
309
  rescue StandardError => e
284
310
  raise e
285
311
  end
@@ -339,7 +365,7 @@ module Meshtastic
339
365
  to: 'optional - Destination ID (Default: \"!ffffffff\")',
340
366
  root_topic: 'optional - root topic (default: msh)',
341
367
  region: 'optional - region e.g. 'US/VA', etc (default: US)',
342
- topic: 'optional - topic to publish to (default: '2/e/LongFast')',
368
+ topic: 'optional - topic to publish to (default: '2/e/LongFast/#')',
343
369
  channel: 'optional - channel (Default: 6)',
344
370
  text: 'optional - Text Message (Default: SYN)',
345
371
  want_ack: 'optional - Want Acknowledgement (Default: false)',
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meshtastic
4
- VERSION = '0.0.131'
4
+ VERSION = '0.0.133'
5
5
  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.131
4
+ version: 0.0.133
5
5
  platform: ruby
6
6
  authors:
7
7
  - 0day Inc.