sps_mqtt_bridge 0.1.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data/lib/sps_mqtt_bridge.rb +56 -10
- data.tar.gz.sig +0 -0
- metadata +46 -43
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0747d4b4cef89b81c6d4797a08b9988c86c27ecc9617be127403ae8fa9cef606
|
4
|
+
data.tar.gz: 7ed7899e435ec8f2def042d604cefef3d3ff7837ea385a5959d011223a477db7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fb49b834a27f38aa89134b27d00ae4acba6e223641ab9e845cc66e8aade3a76f9a205be7b6fc0f33790d5303efad08e3774c0d944268ccf4ade078bd60b869d
|
7
|
+
data.tar.gz: 794bba6afae55bf49a648887747e377cf75dce4bdb6cc820b96383201e74c8796cdf630e9ec3e38ff007c5e0e943f60202d196ad017ca67ce7e2c4b1f8618921
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/sps_mqtt_bridge.rb
CHANGED
@@ -3,15 +3,19 @@
|
|
3
3
|
# file: sps_mqtt_bridge.rb
|
4
4
|
|
5
5
|
require 'mqtt'
|
6
|
-
require '
|
6
|
+
require 'sps-sub'
|
7
7
|
require 'sps-pub'
|
8
|
+
require 'open-uri' # used sps_to_http
|
9
|
+
require 'timeout' # used sps_to_http
|
10
|
+
|
8
11
|
|
9
12
|
|
10
13
|
class SpsMqttBridge
|
11
14
|
|
12
|
-
def initialize(mqtt: {address: 'mqtt', port: '1883'},
|
13
|
-
|
14
|
-
|
15
|
+
def initialize(mqtt: {address: 'mqtt', port: '1883'},
|
16
|
+
sps:{host: 'sps', address: host, port: '59000'},
|
17
|
+
sps2:{address: 'sps', port: '59000'})
|
18
|
+
@mqtt, @sps, @sps2 = mqtt, sps, sps2
|
15
19
|
end
|
16
20
|
|
17
21
|
def mqtt_to_sps(topic: '#')
|
@@ -19,7 +23,7 @@ class SpsMqttBridge
|
|
19
23
|
MQTT::Client.connect(@mqtt[:address], @mqtt[:port]) do |client|
|
20
24
|
|
21
25
|
client.get(topic) do |t, message|
|
22
|
-
SPSPub.notice [t, message].join(': '),
|
26
|
+
SPSPub.notice [t, message].join(': '),
|
23
27
|
address: @sps[:address], port: @sps[:port]
|
24
28
|
end
|
25
29
|
end
|
@@ -27,14 +31,56 @@ class SpsMqttBridge
|
|
27
31
|
|
28
32
|
def sps_to_mqtt(topic: '#')
|
29
33
|
|
30
|
-
|
34
|
+
SPSSub.new(host: @sps[:address], port: @sps[:port]).\
|
35
|
+
subscribe(topic: topic) do |message,t|
|
31
36
|
|
32
|
-
|
37
|
+
MQTT::Client.connect(@mqtt[:address], @mqtt[:port]) do |client|
|
38
|
+
client.publish(t, message)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def sps_to_sps(topic: '#')
|
45
|
+
|
46
|
+
SPSSub.new(host: @sps[:address], port: @sps[:port]).\
|
47
|
+
subscribe(topic: topic) do |message,t|
|
48
|
+
|
49
|
+
SPSPub.notice [t, message].join(': '),
|
50
|
+
address: @sps2[:address], port: @sps2[:port]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def sps_to_http(topic: '#', url: '', timeout: 5, \
|
55
|
+
http_auth: ["user", "password"])
|
56
|
+
|
57
|
+
sps = SPSSub.new(host: @sps[:address], port: @sps[:port])
|
58
|
+
|
59
|
+
sps.subscribe(topic: topic) do |message,t|
|
60
|
+
|
61
|
+
begin
|
62
|
+
|
63
|
+
Timeout::timeout(timeout){
|
64
|
+
|
65
|
+
ipaddr = url[/https?:\/\/([^\/]+)/,1]
|
66
|
+
ip_address = block_given? ? yield(ipaddr) || ipaddr : ipaddr
|
67
|
+
full_url = url.sub(/(https?:\/\/)([^\/]+)/,'\1' + ip_address).\
|
68
|
+
sub('$topic', t).sub('$msg', message)
|
69
|
+
|
70
|
+
buffer = URI.open(full_url, read_timeout: timeout,\
|
71
|
+
http_basic_authentication: http_auth).read
|
72
|
+
|
73
|
+
}
|
74
|
+
rescue Timeout::Error => e
|
75
|
+
|
76
|
+
puts 'connection timed out'
|
77
|
+
|
78
|
+
rescue OpenURI::HTTPError => e
|
79
|
+
|
80
|
+
puts '400 bad request'
|
33
81
|
|
34
|
-
MQTT::Client.connect(@mqtt[:address], @mqtt[:port]) do |client|
|
35
|
-
client.publish(t, message)
|
36
|
-
end
|
37
82
|
end
|
83
|
+
|
38
84
|
end
|
39
85
|
end
|
40
86
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sps_mqtt_bridge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -10,51 +10,55 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
13
|
+
MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
|
14
|
+
YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjExMTE4MjA0NjE2WhcN
|
15
|
+
MjIxMTE4MjA0NjE2WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFt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ki2waVZoI3c8CLSgSOcBDpDHcL7fgUe09uWWzfdrMBMeh
|
31
|
+
vwTdIO/n1KTmby4INpTHKqF4IMK85X67B8kwJ3kohnIDU1yeztmiICWtbwfyotB2
|
32
|
+
BXKNapPOfz9bBuwehAquXQgynTV9k+4rPWnLcmSsgceN4UzoMQXsoUvXXdmLscaV
|
33
|
+
cfm5RbVyjVIBDpqH8OHTTxjhtRZt6kSd/nDQTKed8NpCxSNu8SS2WQWs1noy/f7l
|
34
|
+
HX+swCcHIazEMrM1DzEdtOwEZnfK4eBGOYdmbh/HoxvhqIQJmjQS6kP90kDKmosj
|
35
|
+
okdUodn4ejgTAei7/kvAnfBUpBHEalVhTzh3FBjH6kJ39h+4TydJdq3IRQA/5EnY
|
36
|
+
oX//LQ2ozJLQqPJvDwZHjLYc
|
33
37
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
38
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
35
39
|
dependencies:
|
36
40
|
- !ruby/object:Gem::Dependency
|
37
|
-
name:
|
41
|
+
name: sps-pub
|
38
42
|
requirement: !ruby/object:Gem::Requirement
|
39
43
|
requirements:
|
40
44
|
- - "~>"
|
41
45
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
46
|
+
version: '0.5'
|
43
47
|
- - ">="
|
44
48
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
49
|
+
version: 0.5.5
|
46
50
|
type: :runtime
|
47
51
|
prerelease: false
|
48
52
|
version_requirements: !ruby/object:Gem::Requirement
|
49
53
|
requirements:
|
50
54
|
- - "~>"
|
51
55
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
56
|
+
version: '0.5'
|
53
57
|
- - ">="
|
54
58
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
59
|
+
version: 0.5.5
|
56
60
|
- !ruby/object:Gem::Dependency
|
57
|
-
name: sps-
|
61
|
+
name: sps-sub
|
58
62
|
requirement: !ruby/object:Gem::Requirement
|
59
63
|
requirements:
|
60
64
|
- - "~>"
|
@@ -62,7 +66,7 @@ dependencies:
|
|
62
66
|
version: '0.3'
|
63
67
|
- - ">="
|
64
68
|
- !ruby/object:Gem::Version
|
65
|
-
version: 0.3.
|
69
|
+
version: 0.3.7
|
66
70
|
type: :runtime
|
67
71
|
prerelease: false
|
68
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -72,29 +76,29 @@ dependencies:
|
|
72
76
|
version: '0.3'
|
73
77
|
- - ">="
|
74
78
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.3.
|
79
|
+
version: 0.3.7
|
76
80
|
- !ruby/object:Gem::Dependency
|
77
81
|
name: mqtt
|
78
82
|
requirement: !ruby/object:Gem::Requirement
|
79
83
|
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0.2'
|
83
84
|
- - ">="
|
84
85
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
86
|
+
version: 0.5.0
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.5'
|
86
90
|
type: :runtime
|
87
91
|
prerelease: false
|
88
92
|
version_requirements: !ruby/object:Gem::Requirement
|
89
93
|
requirements:
|
90
|
-
- - "~>"
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: '0.2'
|
93
94
|
- - ">="
|
94
95
|
- !ruby/object:Gem::Version
|
95
|
-
version: 0.
|
96
|
+
version: 0.5.0
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0.5'
|
96
100
|
description:
|
97
|
-
email:
|
101
|
+
email: digital.robertson@gmail.com
|
98
102
|
executables: []
|
99
103
|
extensions: []
|
100
104
|
extra_rdoc_files: []
|
@@ -120,10 +124,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
124
|
version: '0'
|
121
125
|
requirements: []
|
122
126
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.7.10
|
124
128
|
signing_key:
|
125
129
|
specification_version: 4
|
126
|
-
summary: Subscribes and re-publishes messages automatically from MQTT to SPS or
|
127
|
-
|
130
|
+
summary: Subscribes and re-publishes messages automatically from MQTT to SPS or to
|
131
|
+
HTTP.
|
128
132
|
test_files: []
|
129
|
-
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|