New user event causes disconnect (v8.10)

Started by sparky, April 29, 2018, 01:57:09 PM

sparky

Felix,

Having an issue when creating a switch.js file in the userMetrics folder.  It appears that whenever selecting an event such as yours from metrics.js;

switchMoteOFF_AM : { label:'SwitchMote OFF at sunrise!', icon:'clock', descr:'Turn this switch OFF at sunrise', nextSchedule:function(node) { return exports.millisToFutureDate(exports.nextSunriseOrSunset(1), exports.ONEDAY*2); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BTN1:0'}); } },
  switchMote0ON_PM : { label:'SwitchMote0 ON at sunset!', icon:'clock', descr:'Turn this switch ON at sunset', nextSchedule:function(node) { return exports.millisToFutureDate(exports.nextSunriseOrSunset(0), exports.ONEDAY*2); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BTN0:1'}); } },


and clicking "add" the Gateway Dashboard instantly disconnects before re-connecting, see attached

but when I add an event such as;

switchMote0ON_PM : { label:'SwitchMote0 ON at 5:38PM!', icon:'clock', descr:'Turn this switch ON every evening', nextSchedule:function(node) { return exports.timeoutOffset(17,38); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BTN0:1'}); } },
  switchMote0OFF_AM : { label:'SwitchMote0 OFF at 7:56AM!', icon:'clock', descr:'Turn this switch OFF every morning', nextSchedule:function(node) { return exports.timeoutOffset(7,56); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BTN0:0'}); } },


everything is fine.

It appears it has something to do with suncalc

Thanks

Felix

Sparky,

Thanks for the report. Let's keep it separate as a bug/report thread.
So it sounds like this happens only for events you add in your userMetrics folder ?
I think your event has the same name, which I think should be fine, but what else has changed? (sorry I didn't go into comparing or degugging this myself yet).

Any additional errors from logs or console would be helpful.

sparky

I originally put this new topic here but then thought Felix is going to move it to Gateway v8.10.0 released! so I moved it.. lol, I just can't win lately with my posts. 

QuoteSo it sounds like this happens only for events you add in your userMetrics folder ?

Only events I add to the userMetrics folder having to do with suncalc

QuoteI think your event has the same name, which I think should be fine, but what else has changed?

I can't think of anything that has changed.  This morning I created the following event for the BellMote to see what happens;

doorbellOff_SS : { label:'Doorbell OFF at sunset!', icon:'clock', descr:'Turn doorbell OFF at sunset', nextSchedule:function(node) { return exports.millisToFutureDate(exports.nextSunriseOrSunset(0), exports.ONEDAY*2); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BELL:0'}); } },
  doorbellOn_SR : { label:'Doorbell ON at sunrise!', icon:'clock', descr:'Turn doorbell ON at sunrise', nextSchedule:function(node) { return exports.millisToFutureDate(exports.nextSunriseOrSunset(1), exports.ONEDAY*2); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BELL:1'}); } },


and I got the same results.  userMetrics folder isn't playing nice with suncalc

QuoteAny additional errors from logs or console would be helpful.

I could post a log if needed but nothing unusual that I can see.  I'm not getting any errors in db


Felix

It can get long so starting in the 8.10 release is OK but I might separate such topics just to avoid the noise in the original release thread.
Can you please check the gateway.sys.log and see what's in there. Any error should bubble up in that log.

sparky

QuoteCan you please check the gateway.sys.log and see what's in there.

I just simulated adding an event with suncalc.  Other than removing my IP, here is that part of the gateway.sys;

[04-30-18_10:45:01.786] [LOG]   **** RUNNING SCHEDULED EVENT - nodeId:99 event:thermostatPoll...
[04-30-18_10:45:01.788] [LOG]   **** SCHEDULING EVENT - nodeId:99 event:thermostatPoll to run in ~30s
[04-30-18_10:45:01.815] [LOG]      [99] DB-Updates:1
/home/pi/gateway/userMetrics/switch.js:73
  switchMote0ON_PM : { label:'SwitchMote0 ON at sunset!', icon:'clock', descr:'Turn this switch ON at sunset', nextSchedule:function(node) { return exports.millisToFutureDate(exports.nextSunriseOrSunset(0), exports.ONEDAY*2); }, scheduledExecute:function(node) { sendMessageToNode({nodeId:node._id, action:'BTN0:1'}); } },
                                                                                                                                                                                       ^

TypeError: exports.nextSunriseOrSunset is not a function
    at Object.exports.events.switchMote0ON_PM.nextSchedule (/home/pi/gateway/userMetrics/switch.js:73:184)
    at schedule (/home/pi/gateway/gateway.js:607:52)
    at /home/pi/gateway/gateway.js:273: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
[04-30-18_10:45:13.002] [INFO]  LOADING USER METRICS...
[04-30-18_10:45:13.018] [INFO]  LOADING USER METRICS MODULE [_example.js]
[04-30-18_10:45:13.055] [INFO]  LOADING USER METRICS MODULE [doorbell.js]
[04-30-18_10:45:13.071] [INFO]  LOADING USER METRICS MODULE [garage.js]
[04-30-18_10:45:13.101] [INFO]  LOADING USER METRICS MODULE [sonar.js]
[04-30-18_10:45:13.123] [INFO]  LOADING USER METRICS MODULE [sprinkler.js]
[04-30-18_10:45:13.141] [INFO]  LOADING USER METRICS MODULE [switch.js]
[04-30-18_10:45:13.658] [LOG]   **** SCHEDULING EVENT - nodeId:4 event:doorbellON_AM to run in ~19h44m
[04-30-18_10:45:13.664] [LOG]   **** SCHEDULING EVENT - nodeId:4 event:doorbellOFF_PM to run in ~9h14m
[04-30-18_10:45:13.666] [LOG]   **** SCHEDULING EVENT - nodeId:99 event:thermostatPoll to run in ~30s
[04-30-18_10:45:13.702] [LOG]      [4] DB-Updates:1
[04-30-18_10:45:13.707] [LOG]      [4] DB-Updates:1
[04-30-18_10:45:13.713] [LOG]      [99] DB-Updates:1
[04-30-18_10:45:14.572] [LOG]   >: 
[04-30-18_10:45:14.575] [LOG]   >: Transmitting at 915 Mhz...
[04-30-18_10:45:14.576] [LOG]   >: SPI Flash Init OK!
[04-30-18_10:45:16.579] [LOG]   >: [3] F:67.4 H:30 P:30.10   [RSSI:-53]
[04-30-18_10:45:16.607] [LOG]   post: /home/pi/gateway/data/db/0003_F.bin[1525099516,67.4]
[04-30-18_10:45:16.619] [LOG]   post: /home/pi/gateway/data/db/0003_H.bin[1525099516,30]
[04-30-18_10:45:16.622] [LOG]   post: /home/pi/gateway/data/db/0003_P.bin[1525099516,30.1]
[04-30-18_10:45:16.630] [LOG]   post: /home/pi/gateway/data/db/0003_RSSI.bin[1525099516,-53]
[04-30-18_10:45:16.645] [LOG]      [3] DB-Updates:1
[04-30-18_10:45:17.475] [INFO]  AUTHORIZING CONNECTION FROM ::1:60550
[04-30-18_10:45:17.492] [INFO]  NEW CONNECTION FROM (my IP)

Felix

Ok so it's a code visibility problem, I will look into it when I get a chance.