Sorry for the confusion. ;D
What I was trying to get across is that when I use the web interface to create a reset request for a node everything works correctly. I see the reset request come through in the logs only once and the node does respond with the RST string like it should. When I create a request using an event the reset request is continually sent by the Pi Gateway sketch and the node does respond with the proper RST response. But like I said the request is sent in every ack by the Pi Gateway sketch.
Here is the code for the event I created:
exports.events = {
resetDaily : {
label: 'Schedule reset request on a node.',
icon: 'clock',
descr: 'Make a request to a node to reset daily values at midnight.',
nextSchedule:function(node) {
return timeoutOffset(08, 44); },
scheduledExecute:function(node) {
var reqValue = null;
// Void out any outstanding requests before sending new reset request.
requestString = node._id + ':VOID:' + reqName + (reqValue?':'+reqValue.tri
m():'') + '\n';;
requestString += 'RQ:' + node._id + ':' + 'RST' + (reqValue?':'+reqValue.t
rim():'') + '\n';
sendMessageToGateway(requestString);
console.info('REQUEST SENT: ' + requestString.replaceNewlines());
}
}
};
When I look at the the Pi Gateway sketch it looks like it relies on the Gateway app to send out a Void command to clean up the request. Is that correct?
I was able to successfully schedule a reset event and upon successful receipt of the request the node sends a Void command. I still need to test things a bit more. Here is the code for anyone who might be interested:
exports.events = {
resetDaily : {
label: 'Schedule reset request on a node.',
icon: 'clock',
descr: 'Ask a node to reset daily values at midnight.',
nextSchedule:function(node) {
return timeoutOffset(00, 00);
},
scheduledExecute:function(node) {
var dbNode = node;
if (dbNode.requests == undefined) dbNode.requests = {};
isNew = false;
if (dbNode.requests[reqName] == null) {
dbNode.requests[reqName] = {};
isNew = true;
}
dbNode.requests[reqName].name = reqName;
dbNode.requests[reqName].value = null;
dbNode.requests[reqName].updated = Date.now();
dbNode.requests[reqName].status = 'PENDING';
dbNode.requests[reqName].timeout = requestTimeout;
requestString='';
if (!isNew) //VOID previous request value before queuing adding latest value
requestString += node._id + ':VOID:' + reqName + (reqValue?':'+reqValue.trim():'') + '\n';
requestString += 'RQ:' + node._id + ':' + reqName + (reqValue?':'+reqValue.trim():'') + '\n';
sendMessageToGateway(requestString);
console.info('REQUEST SENT: ' + requestString.replaceNewlines());
db.update({ _id: dbNode._id }, { $set : dbNode}, {}, function (err, numReplaced) { console.info('SUBMITNODEREQUEST DB
-Replaced:' + numReplaced); });
console.info(` [${node._id}] ${(isNew?'Added':'Updated')} request:${reqName}`);
io.sockets.emit('UPDATENODE', dbNode);
}
}
};