mchenier / tplink-hs110-pump-monitor

Monitor a HS110 power so you can get notification on multiple use cases.
Apache License 2.0
4 stars 4 forks source link

improvement to log and inactivity notice #2

Closed gantonel closed 4 years ago

gantonel commented 4 years ago

I suggest the following potential improvement for consideration:- 1) Every time the node is restarted it should be reported in the log 2) The .env file may benefit from having two variables so that one decides the critical time of inactivity, before being notified & the other decides how often one should be notified if inactivity continues 3) Maybe there should be two logs one as in the original & another for all the output that is currently going to the terminal window 4) Maybe if the pump is stuck on for more than a certain number of minutes an alert should be emanated, similar to the excessive inactivity. Likewise one could chose how often to be alerted.

gantonel commented 4 years ago

Given that the cloud is unreliable it can be removed

I have no opinion or knowledge about the LAN discovery feature, so I will rely on your good judgement

I may not get a chance to look at what you have done in the next few days. I hope to make constructive comments then

Regards

Giorgio

Sent from my iPhone

On 15 Apr 2020, at 1:37 am, mchenier notifications@github.com wrote:

 Ok I did some changes.

Docker option is now possible check the README There is new config param: enableIdleAlert enableRunningAlert enableStartAlert enableStopAlert deviceIP Device IP is to solve problem I had with the discovery of the api that stop working for no reason. I strongly recommend fixing the IP of your device with the DHCP of your router and using this feature to solve discovery problem. I still support discovery but I can't test it since it was not working when I tested it.

Again I will gladly take your feedback to improve the app. The app.js is starting to get a little convoluted a refactor may come if we have to make more changes or add more features.

I'm thinking of removing some feature tell me your opinion about:

The cloudAPI LAN discovery feature — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

gantonel commented 4 years ago

I have had a look but it will not work now. I am pasting the error log below. Any suggestions?

0 info it worked if it ends with ok 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] 2 info using npm@6.14.4 3 info using node@v12.16.1 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info lifecycle tplink-hs110-pump-monitor@1.0.0~prestart: tplink-hs110-pump-monitor@1.0.0 6 info lifecycle tplink-hs110-pump-monitor@1.0.0~start: tplink-hs110-pump-monitor@1.0.0 7 verbose lifecycle tplink-hs110-pump-monitor@1.0.0~start: unsafe-perm in lifecycle true 8 verbose lifecycle tplink-hs110-pump-monitor@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/giorgioantonelli/tplink/tplink-hs110-pump-monitor/node_modules/.bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin 9 verbose lifecycle tplink-hs110-pump-monitor@1.0.0~start: CWD: /Users/giorgioantonelli/tplink/tplink-hs110-pump-monitor 10 silly lifecycle tplink-hs110-pump-monitor@1.0.0~start: Args: [ '-c', 'node ./app.js' ] 11 silly lifecycle tplink-hs110-pump-monitor@1.0.0~start: Returned: code: 1 signal: null 12 info lifecycle tplink-hs110-pump-monitor@1.0.0~start: Failed to exec start script 13 verbose stack Error: tplink-hs110-pump-monitor@1.0.0 start: node ./app.js 13 verbose stack Exit status 1 13 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:311:20) 13 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:311:20) 13 verbose stack at maybeClose (internal/child_process.js:1021:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) 14 verbose pkgid tplink-hs110-pump-monitor@1.0.0 15 verbose cwd /Users/giorgioantonelli/tplink/tplink-hs110-pump-monitor 16 verbose Darwin 16.7.0 17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" 18 verbose node v12.16.1 19 verbose npm v6.14.4 20 error code ELIFECYCLE 21 error errno 1 22 error tplink-hs110-pump-monitor@1.0.0 start: node ./app.js 22 error Exit status 1 23 error Failed at the tplink-hs110-pump-monitor@1.0.0 start script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ]

mchenier commented 4 years ago

Did you update your config.json? Try using the ip adresse of your HS110 instead of 0.0.0.0.

Like I said I couldn't test the discovery since it wasn't working for me anymore.

gantonel commented 4 years ago

How would I find the address? Where do I look?

On 15 Apr 2020, at 6:12 am, mchenier notifications@github.com wrote:

Did you update your config.json? Try using the ip adresse of your HS110 instead of 0.0.0.0.

Like I said I couldn't test the discovery since it wasn't working for me anymore.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mchenier/tplink-hs110-pump-monitor/issues/2#issuecomment-613657126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7U7MPDBOQIXSB4NRX6CWLRMS7TZANCNFSM4LXDCQFA.

gantonel commented 4 years ago

By the way. There is no hurry to get it working immediately. Take your time. I can revert back to previous version for now

On 15 Apr 2020, at 6:12 am, mchenier notifications@github.com wrote:

Did you update your config.json? Try using the ip adresse of your HS110 instead of 0.0.0.0.

Like I said I couldn't test the discovery since it wasn't working for me anymore.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mchenier/tplink-hs110-pump-monitor/issues/2#issuecomment-613657126, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7U7MPDBOQIXSB4NRX6CWLRMS7TZANCNFSM4LXDCQFA.

mchenier commented 4 years ago

You don't get this output at start at all ?

[2020-04-14T16:15:34.312] [INFO] debug - Acceptable Inactivity : 480.00 minutes console.js:6 [2020-04-14T16:15:34.312] [INFO] debug - Alert for Inactivity every : 30.00 minutes console.js:6 [2020-04-14T16:15:34.313] [INFO] debug - Acceptable Activity : 6.00 minutes console.js:6 [2020-04-14T16:15:34.313] [INFO] debug - Alert for Excessive activity every: 30.00 minutes

Maybe try npm install again. I don't think I added dependency but it could be the problem.

For the IP you have to go in your router and find the DHCP menu. You will find a list of client. If you don't see HS110 you may have to look at the MAC adress that is writen on the back of your HS110.

But I have tested the discovery and it seams to work now and there was no bug so that is not really the problem.

I found this solution if nothing worked:

Step 1: $ npm cache clean --force

Step 2: Delete node_modules by $ rm -rf node_modules package-lock.json folder or delete it manually by going into the directory and right-click > delete / move to trash. Also, delete package-lock.json file too.

Step 3: npm install

To start again, $ npm start

gantonel commented 4 years ago

Correct. I do not get that input. I had just got the IP address…

I will try the install again. Could it be related to the fact that after the instal I moved the folder?

On 15 Apr 2020, at 6:21 am, mchenier notifications@github.com wrote:

You don't get this output at start at all ?

[2020-04-14T16:15:34.312] [INFO] debug - Acceptable Inactivity : 480.00 minutes console.js:6 [2020-04-14T16:15:34.312] [INFO] debug - Alert for Inactivity every : 30.00 minutes console.js:6 [2020-04-14T16:15:34.313] [INFO] debug - Acceptable Activity : 6.00 minutes console.js:6 [2020-04-14T16:15:34.313] [INFO] debug - Alert for Excessive activity every: 30.00 minutes

Maybe try npm install again. I don't think I added dependency but it could be the problem.

For the IP you have to go in your router and find the DHCP menu. You will find a list of client. If you don't see HS110 you may have to look at the MAC adress that is writen on the back of your HS110.

But I have tested the discovery and it seams to work now and there was no bug so that is not really the problem.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mchenier/tplink-hs110-pump-monitor/issues/2#issuecomment-613661008, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7U7MMTT7JQXSK24SMEEC3RMTATZANCNFSM4LXDCQFA.

mchenier commented 4 years ago

Maybe Im not in expert with Node.js but I definetly had problem with the dependencies.

I did the steps mention in my last comment and it made a lot of changes to the node directory. I pushed the fix tell me if it works for you. You can also try the executable see if you have the same problem

gantonel commented 4 years ago

I did re-install the whole thing.

Would you believe that it may have been due to a frustrating problem I had noticed a while back?

Using TextEdit the STRAIGHT quotes become curvy on the line being edited. Do you know why that might happen?

Anyway, we are back up and running.

How would I insure that the address of that plug stays as

Device name HS110 LAN IPv4 192.168.0.5 LAN IPv6

Mac Address 74:DA:88:52:AB:BD Vendor Name Unknown

Apparently it is listed with the wired devices, rather than WiFi. Strange

Thanks again.

What time of the day is it up there?

On 15 Apr 2020, at 6:30 am, mchenier notifications@github.com wrote:

Maybe Im not in expert with Node.js but I definetly had problem with the dependencies.

I did the steps mention in my last comment and it made a lot of changes to the node directory. I pushed the fix tell me if it works for you. You can also try the executable see if you have the same problem

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mchenier/tplink-hs110-pump-monitor/issues/2#issuecomment-613665452, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7U7MJLTSQ7XQPM4VCJOOLRMTBWZANCNFSM4LXDCQFA.

mchenier commented 4 years ago

To ensure the ip stays the same you have to add a DHCP client with a fix IP. So basicaly you enter the MAC adress and ip adress in pair in your router in a menu somewhere.

Should be near the DHCP client list.

It's 17h21 right now.

gantonel commented 4 years ago

Thanks I will do it later. I will also attempt to check that it works with the 0.0.0.0

On 15 Apr 2020, at 7:22 am, mchenier notifications@github.com wrote:

To ensure the ip stays the same you have to add a DHCP client with a fix IP. So basicaly you enter the MAC adress and ip adress in pair in your router in a menu somewhere.

Should be near the DHCP client list.

It's 17h21 right now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mchenier/tplink-hs110-pump-monitor/issues/2#issuecomment-613688152, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7U7MLVPFTLX5CC3CLREMDRMTHZDANCNFSM4LXDCQFA.

vdasilva commented 4 years ago

Good work fellas! I'll test tonight and post any issues from my end.

mchenier commented 4 years ago

I did a big refactor. Now the app has 3 files. utils.js for email and log stuff tplinkAPI.js for the api stuff app.js for the main application

I didn't like how big the app.js was so there it is. I also added some function to clarify. Because of all that refactor I don't see the need of removing the cloudAPI since it's not in the way anymore and maybe someone will find it usefull for whatever reason.

Hope you like it.

mchenier commented 4 years ago

I have added some stats in the alert email. I didn't know where to put them honestly but I wanted to show you if you needed those stats. It was part of the api and it could be usefull. So if you have any idea for those data let me know.

Looks like that:

Global energy consumption for this month and this year

{"year":2020,"month":4,"day":1,"energy":0.185} {"year":2020,"month":4,"day":2,"energy":0.28} {"year":2020,"month":4,"day":3,"energy":0.694} {"year":2020,"month":4,"day":4,"energy":0.41} {"year":2020,"month":4,"day":5,"energy":0.272} {"year":2020,"month":4,"day":6,"energy":0.32} {"year":2020,"month":4,"day":7,"energy":0.194} {"year":2020,"month":4,"day":8,"energy":0.211} {"year":2020,"month":4,"day":9,"energy":0.112} {"year":2020,"month":4,"day":10,"energy":0.128} {"year":2020,"month":4,"day":11,"energy":0.135} {"year":2020,"month":4,"day":12,"energy":0.246} {"year":2020,"month":4,"day":13,"energy":0.528} {"year":2020,"month":4,"day":14,"energy":0.286} {"year":2020,"month":4,"day":15,"energy":0.061}

{"year":2020,"month":1,"energy":0.396} {"year":2020,"month":2,"energy":0.007} {"year":2020,"month":3,"energy":2.542} {"year":2020,"month":4,"energy":4.062}

gantonel commented 4 years ago

I think you are going from strength to strength. I have not seen the new version yet, but I like it already. Well done

mchenier commented 4 years ago

I will close that issue since it's more of a good conversation. Feel free to open an issue to talk again :)