Main Menu

Events error

Started by sparky, March 17, 2017, 12:58:54 PM

sparky

Felix,

Would the following error have something to do with the new gateway version?

/home/pi/gateway/userMetrics/sprinkler.js:39
  sprinklersOddDays : { label:'Odd days @ 6:30AM', icon:'clock', descr:'Run this sprinkler program on odd days at 6:30AM', nextSchedule:function(node) { return exports.timeoutOffset(6,30); }, scheduledExecute:function(node) { if ((new Date().getDate()%2)==1) sendMessageToNode({nodeId:node._id, action:'PRG 2:300 3:300 1:300 4:300 5:300' /*runs stations 1-5 (300sec each))*/}); } },
                                                                                                                                                                        ^

TypeError: exports.timeoutOffset is not a function
    at Object.exports.events.sprinklersOddDays.nextSchedule (/home/pi/gateway/userMetrics/sprinkler.js:39:169)
    at schedule (/home/pi/gateway/gateway.js:594:52)
    at /home/pi/gateway/gateway.js:275:17
    at newArguments.(anonymous function) (/home/pi/gateway/node_modules/nedb/lib/executor.js:29:17)
    at Cursor.execFn (/home/pi/gateway/node_modules/nedb/lib/datastore.js:484:12)
    at callback (/home/pi/gateway/node_modules/nedb/lib/cursor.js:126:19)
    at /home/pi/gateway/node_modules/nedb/lib/cursor.js:193:12
    at /home/pi/gateway/node_modules/nedb/lib/datastore.js:329:14
    at Object.async.eachSeries (/home/pi/gateway/node_modules/nedb/node_modules/async/lib/async.js:130:20)
    at /home/pi/gateway/node_modules/nedb/lib/datastore.js:323:11

Thanks

ssmall

Look in the Metrics.js file and you will find a function called timeoutOffset toward the bottom of metrics.js.  Copy the function from metrics.js to your metrics file and that should take care of the issue.

Felix

Quote from: sparky on March 17, 2017, 12:58:54 PM
Would the following error have something to do with the new gateway version?

No.

Can you show the whole sprinkler.js content pls?

sparky

Quote from: ssmall on March 17, 2017, 04:19:28 PM
Look in the Metrics.js file and you will find a function called timeoutOffset toward the bottom of metrics.js.  Copy the function from metrics.js to your metrics file and that should take care of the issue.

Perfect!

Very much appreciated

Quote from: Felix on March 17, 2017, 04:24:27 PM
No.

Can you show the whole sprinkler.js content pls?

Got it, thanks

Felix

sparky,

You should not have to copy the function if you scope your user metrics correctly. I think your user metrics file was probably not in the right format.

sparky

Morning Felix,

Everything was working fine with the sprinkler metric up until I tried to add an event (Run this sprinkler program on odd days at 6:30AM) which then gave me the errors.  It was only after small's response that I added the helper functions.

See attached metric.

Thanks

Felix

Looks good.... i still don't think the core functions need to be duplicated, at least based on something I just tried.
I will keep in mind to try to look into this further.

ssmall

Felix, I have my own sprinkler definition setup in my user metrics.  The only way I could get it to run was to copy the missing functions.  Is there something I can try out so that I can use the functions defined in metrics.js?  I would prefer that to copying them.

sparky

Quote from: ssmall on March 22, 2017, 12:14:15 PM
Felix, I have my own sprinkler definition setup in my user metrics.  The only way I could get it to run was to copy the missing functions.  Is there something I can try out so that I can use the functions defined in metrics.js?  I would prefer that to copying them.

Do you happen to have a wifi thermostat that you communicate with?  If so, did you try your own metric in the UserMetric folder?

I tried and that will not work without getting the error below, even when the missing functions were copied.

[03-18-17_19:36:46.629] [LOG]   **** RUNNING SCHEDULED EVENT - nodeId:99 event:thermostatPoll...
[03-18-17_19:36:46.636] [ERROR] Event thermostatPoll execution failed: request is not defined
[03-18-17_19:36:46.652] [LOG]   **** SCHEDULING EVENT - nodeId:99 event:thermostatPoll to run in ~30s

Felix

I may need to revisit that part of the application. I've only used simple metrics in the user file so far.