Achronite / node-red-contrib-energenie-ener314rt

Node Red nodes for Energenie ENER314-RT Raspberry Pi board
MIT License
12 stars 3 forks source link

TypeError: Cannot read property 'log' of undefined #49

Closed crushedbits closed 3 years ago

crushedbits commented 3 years ago

Hi I have recently bought the energenie ENER314rt board for the raspberry pi. I am just trying to control a blue socket with the module and node-red but I seem unable to get it to work. I am using a newly installed pi, with node-red v1.3.3 I loaded your module using npm and can see all the blocks. I can double click into the OOK blue block, learn and use the button in it to turn the socket on and off, but if I deploy a flow I receive the following error TypeError: Cannot read property 'log' of undefined Now I may be new to node-red but I thought I could connect your OOK block to an inject block and just pass a boolean true to turn it on, have also tried a number 1 and a string 1. Am I just doing something wrong. I would be really grateful for some pointers. I am trying to use the whole home energy monitor to monitor my solar panels and then using an OOK socket to turn on a washing machine.

Achronite commented 3 years ago

Hi,

Sending a boolean type of true/false or a 1/0 into the node should be the same and both work equally.

Can you confirm the version of node-red-contrib-energenie-ener314rt that you are using and also send me the console log file?

A test flow would be good too; just select the nodes in question and chose 'export'.

EDIT: I'm wondering if you have hit some bug with the 'Control & Monitor' node introduced in version 0.4. Can you please delete this node, redeploy and then restart node-red to eliminate this as a possible cause?

crushedbits commented 3 years ago

Thanks for getting back to me so quickly. The version of node-red-contrib-energenie-ener314rt is 0.4.0 I captured a log file and have attached it as node-red.log I have also attached the exported JSON. Was not sure how to delete the Control&Monitor node, so what I did was disable it. Deleted the flow, restarted node-red, then remade the flow and ran it. Unfortunately the problem persists. I included the log of this in the same node-red.log file under the asterisks.

node-red.log.txt

Exported flow.

[{"id":"2fd4015e.729f5e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"96ecf18e.9f994","type":"energenie-board","name":"ENER314-RT","timeout":"5000"},{"id":"fdab43dc.8d32e","type":"ook-switch","z":"2fd4015e.729f5e","name":"Control","zone":0,"switchNum":1,"board":"96ecf18e.9f994","x":600,"y":200,"wires":[[]],"inputLabels":["switch#1"]},{"id":"d2c65190.578d1","type":"inject","z":"2fd4015e.729f5e","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":140,"y":180,"wires":[["fdab43dc.8d32e"]]},{"id":"e53ce858.945958","type":"inject","z":"2fd4015e.729f5e","name":"Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":140,"y":240,"wires":[["fdab43dc.8d32e"]]}]

Achronite commented 3 years ago

OK I have a possible fix in my develop branch, that I would like you to test.

Assuming you are running this on rPi using standard install:

1) Download ener314-rt.js

2) node-red-stop

3) Replace the file ~/.node-red/node_modules/node-red-contrib-energenie-ener314rt/red/ener314-rt.js with the one downloaded

4) node-red-start

Please let me know how you get on.

crushedbits commented 3 years ago

Hi, Have tried replacing the ener314-rt.js file, unfortunately it is still displaying the same problem. I have included a picture of the node-red work area showing that the control node still shows not configured and the console gives the same error. Have also included another log file and flow export.

Yes it is running on a rPi with a standard lite install.

JSON [{"id":"2fd4015e.729f5e","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"e03e56f3.188558","type":"energenie-board","name":"ENER314-RT","timeout":"5000"},{"id":"12425b63.79c235","type":"ook-switch","z":"2fd4015e.729f5e","name":"Control","zone":0,"switchNum":1,"board":"e03e56f3.188558","x":510,"y":240,"wires":[[]]},{"id":"c577dceb.a1357","type":"inject","z":"2fd4015e.729f5e","name":"on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":180,"y":160,"wires":[["12425b63.79c235"]]},{"id":"65b196f0.988268","type":"inject","z":"2fd4015e.729f5e","name":"off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":160,"y":300,"wires":[["12425b63.79c235"]]}] node-red.log.txt not_configured

Achronite commented 3 years ago

The 'Not Configured' error occurs when you have not added an energenie board that it is associated with. This is stored as a config node in the palette. It could explain the TypeError too; the config node is somehow getting confused.

Check your 'Configuration Nodes' using the burger menu. You should have one of type 'energenie-board', by default it is called 'ENER314-RT', and this should be selected within the Control Node under 'Board'. If you have multiple config nodes, delete all but one.

If you still have issues, delete all energenie nodes and the config node; redeploy to ensure everything is clean and then add the control node back, it should then only show 'Add new energenie board...' in the control node board dropdown, click on the pencil and add a board, then deploy. You can do any teaching later.

In the log file you should then see a line that says '[info] ener314rt: radio initialised' when starting node-red.

crushedbits commented 3 years ago

1_all_nodes_deleted 2_nodes_in_palette 3_add_new_energenie_board 4_add_new_board 5_done 6_control_node_in_workspace 7_deployed_says_success_but_says_not_configured 8_ENER314-RT_under_configuration_node

crushedbits commented 3 years ago

Tried again.

  1. deleted all nodes
  2. Selected control node
  3. Double clicked it, pressed pencil
  4. Pressed Add excepting all defaults
  5. pressed done
  6. deployed
  7. Says successful but still gives not configured error
  8. checked configuration node menu.

list relates to pictures above.

Could not find the info comment in the log but I am still getting this: 29 Apr 18:41:22 - [error] [energenie-board:1f07aa02.7ea0d6] TypeError: Cannot read property 'log' of undefined

It does kind of feel as if the board config is missing. I do leave it all as default. I know your driver behind node-red is working as using the learn button turns it on and the off button turns the socket off.

Achronite commented 3 years ago

The TypeError bug is caused by a log statement in energenie-board aka ener314-rt.js, by trying to access a variable 'out of scope', For example using 'this.log' within a function. You are not seeing the radio inititalised message in the log file, so it is probably that statement causing the issue.

I suspect it is some weird bug that only occurs when only OOK switches are added at initial config (which was how i started too), I'll need to do some further testing on an old pi; as I don't want to mess with my home server setup with many devices.

In the meantime, can you comment out the line "use strict" within ener314-rt.js, this can sometimes be used to ignore these types of errors. You could also try adding one of the pink/purple devices first to try and unblock this; these devices work differently using the radio receive mode to 'discover' them. (I have a mix of both types).

Can you also let me know your node-red and node $ node -v versions too pls?

Achronite commented 3 years ago

OK - I've done a bit more digging, it looks like the config node may not be created properly if there is an issue with the call to initialise the board; which could cause the 'Not Configured' message; I've moved the node creation further up the code, please try the updated ener314-rt.js file.

Also, what model of rPi are you using?

crushedbits commented 3 years ago

Hi You have cracked it. All now working well. Have managed to switch OOK switches and retrieve payload from whole house monitor. If you are still interested I am using a rPi3. Thanks for sticking with it, you are a star. I noticed that github allows BAT tipping. (Small triangle at top right of comment box) But you have not verified yourself as a content provider. If you are interested try reading this https://chrisruppel.com/blog/brave-rewards-github-pages/ Or going to Braves website and searching content creators. I think it would be worth doing because it makes tipping people like yourself really easy. If you do verify yourself let me know on this thread and I will bung you a few BAT. (At present 1 BAT = $1.18) Again Thanks for your time.