Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"signalk-geofence-switch": "signalk-geofence-switch.js",
"signalk-delay": "signalk-delay.js",
"signalk-put-handler": "signalk-put-handler.js",
"signalk-put-error": "signalk-put-error.js",
"signalk-put-success": "signalk-put-success.js",
"signalk-input-handler-next": "signalk-input-handler-next.js",
"signalk-input-handler": "signalk-input-handler.js"
}
Expand Down
28 changes: 28 additions & 0 deletions signalk-put-error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script type="text/javascript">
RED.nodes.registerType('signalk-put-error',{
category: 'Signal K',
color: '#ffcc01',
defaults: {
name: {value:""}
},
inputs: 1,
outputs: 0,
icon: "bridge.png",
align: 'right',
label: function() {
return this.name||"signalk-put-error";
},
paletteLabel: 'put error'
});
</script>

<script type="text/x-red" data-template-name="signalk-put-error">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>

<script type="text/x-red" data-help-name="signalk-put-error">
<p>Respond to a pending PUT request with an error.</p>
</script>
20 changes: 20 additions & 0 deletions signalk-put-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

module.exports = function(RED) {
function SignalK(config) {
RED.nodes.createNode(this,config);
var node = this;

var app = node.context().global.get('app')

node.on('input', msg => {
let cb = msg.putCallBack
if ( cb ) {
cb({ state: 'COMPLETED', statusCode: msg.payload?.statusCode || 500, message: msg.payload?.message || 'Error'})
} else {
node.error('No callback provided for put response')
}
})
}
RED.nodes.registerType("signalk-put-error", SignalK);
}

8 changes: 7 additions & 1 deletion signalk-put-handler.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
color: '#ffcc01',
defaults: {
name: {value:""},
path: {value:""}
path: {value:""},
pending: {value: false},
},
inputs:0,
outputs:1,
Expand All @@ -25,8 +26,13 @@
<label for="node-input-path"><i class="icon-tag"></i> Path</label>
<input type="text" id="node-input-path" placeholder="Path">
</div>
<div class="form-row">
<label for="node-input-pending"><i class="icon-tag"></i> Use Put Response</label>
<input type="checkbox" id="node-input-pending">
</div>
</script>

<script type="text/x-red" data-help-name="signalk-put-handler">
<p>Input that sends messages when a PUT is sent to the server for the given path</p>
<p>If "Use Put Response" is checked, the node will respond with status PENDING, use the signalk-put-response node to handle the response.</p>
</script>
9 changes: 7 additions & 2 deletions signalk-put-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ module.exports = function(RED) {
var app = node.context().global.get('app')

function handlePut(context, path, value, cb) {
node.send({topic: path, payload: value})
return { state: 'SUCCESS' }
if ( config.pending ) {
node.send({topic: path, payload: value, putCallBack: cb})
return { state: 'PENDING' }
} else {
node.send({topic: path, payload: value})
return { state: 'SUCCESS' }
}
}

let deReg = app.registerActionHandler('vessels.self', config.path,
Expand Down
28 changes: 28 additions & 0 deletions signalk-put-success.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script type="text/javascript">
RED.nodes.registerType('signalk-put-success',{
category: 'Signal K',
color: '#ffcc01',
defaults: {
name: {value:""}
},
inputs: 1,
outputs: 0,
icon: "bridge.png",
align: 'right',
label: function() {
return this.name||"signalk-put-success";
},
paletteLabel: 'put success'
});
</script>

<script type="text/x-red" data-template-name="signalk-put-success">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>

<script type="text/x-red" data-help-name="signalk-put-success">
<p>Respond to a pending PUT request with success.</p>
</script>
20 changes: 20 additions & 0 deletions signalk-put-success.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

module.exports = function(RED) {
function SignalK(config) {
RED.nodes.createNode(this,config);
var node = this;

var app = node.context().global.get('app')

node.on('input', msg => {
let cb = msg.putCallBack
if ( cb ) {
cb({ state: 'COMPLETED', statusCode: msg.payload?.statusCode || 200, message: msg.payload?.message || 'OK'})
} else {
node.error('No callback provided for put response')
}
})
}
RED.nodes.registerType("signalk-put-success", SignalK);
}

4 changes: 2 additions & 2 deletions signalk-send-put.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ module.exports = function(RED) {
if ( reply.state === 'COMPLETED' ) {
if ( reply.statusCode === 200 ) {
node.status({fill:'green',shape:"dot",text:`value: ${msg.payload}`})
node.send([{ payload: reply}, null])
node.send([{ payload: reply, putCallBack: msg.putCallBack}, null])
} else if ( reply.state === 'PENDING' ) {
node.status({fill:'yellow',shape:"dot",text:'pending...'})
} else {
node.status({fill:'red',shape:"dot",text:`error`})
node.error(`put error ${reply.statusCode} ${reply.message || ''}`)
node.send([null, { payload: reply}])
node.send([null, { payload: reply, putCallBack: msg.putCallBack}])
}
}
}, config.source && config.source.length > 0 ? config.source : undefined)
Expand Down
Loading