Adding function to node

Good morning,
I am modifying the ocpp node for personal use.
I have added a function that makes it reconnect if it loses the connection (this only did it if you did a deploy).
The author of the module that makes the reconnection.

Indicates that a ws.reconnect () call can be made for the module to reconnect.

What I would like to know is how can I add the option that if it receives by the msg.payload the word "car", execute the ws.reconnect ().

I have tried adding this to the module js.
if (msg.payload == 'car'){
ws.reconnect();
}
but it does not work...
Could someone guide me?

Thank you!

Hey,
I think you should add it here:

image

Because that is where the input message (msg) arrives ...

1 Like

It works perfect!

Thank you very much for your help!!!

1 Like

One question more.

In this part of my code:

    ws.addEventListener('close', function(){
      logger.log('info', `Closing websocket connectio to ${csUrl}`);
      node.status({fill: 'red', shape: 'dot', text: 'Cerrado...'});
      node.wsconnected = false;

I would like you to take a text out of the payload, for example, 'Dog'.
I have tried adding
msg.payload = 'Dog';

But it shouldn't work that way.

Any ideas?

Thank you very much!!

Based on only one function of your code it is not easy to see what you are doing.
Is that the same function as this original function?

image

I don't think you can access there your input message, at least like the code is structured like it is now.

Not sure what you mean. How do you want it to work then?
Please show a complete code snippet with the msg handling code included. And explain what you expect, and which result you currently get instead...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.