MQTT and Node-RED

Hi! I’m trying to communicate Thinger and a PLC using MQTT. I already could connect them and store data in a bucket. My problem now is that I need to make changes on the data before storing it in the bucket. For that I’ve used the Function node with this code:

var p=msg.payload;
node.log(typeof p);

p.Ppaneles=p.Ppaneles/1000;
p.Epaneles=p.Epaneles/1000;
p.Pvivienda=p.Pvivienda/1000;
p.Evivienda=p.Evivienda/1000;
p.Pred=p.Pred/1000;
p.Ered=p.Ered/1000;
p.dioxido=p.Epaneles0.3111; //Kg de CO2 ahorrados con fotovoltaica*

msg.payload=p;
return msg;

I change JSON into an object, I do the mathematical operations I need and then I change it again to JSON (I have no experience using this programming language and Node-RED, so there may be errors in the code).
I also tried the same code in Function node but adding a JSON node too.

This is the node structure I am making tests with (part 1 of the picture) (when it works I will change the inject node to a mqtt-in node). I inject a JSON message, then the function node makes the mathematical operations, then it is converted to json with a json node and finally data are written in a bucket with the bucket write node.
The upper message is related to the flow that does not contain a JSON node. The lower one refers to the flow containing the json node.

When I went to the data bucket section (part 2 of the picture) to see if there are data being stored, I found that the data bucket did not “recognize” none of them (I tried storing both types of messages).

Do you know how can this be solved?
Thank you in advance! :smiley: