I've been dealing with the following problem for a while now, but somehow I can't solve it.
I have an influx DB that I fill with data. Previously this was done from a different system, but now I want to switch to node red.
Basically it works, but now I have a payload with "-"
--> WW-Storage_Temperature_above: msg.payload
And the "-" leads to a failure. But the expression exists in the database and so I want to keep it.
What can I do?
You can use that as a property name in JavaScript but it isn't recommended. It means that you will always have to reference it using bracket notation instead of dot notation.
// This does not work
msg.payload.WW-Storage_Temperature_above
// This DOES work
msg.payload['WW-Storage_Temperature_above']
So I tried some variants now. And with your suggestion "" in s slightly different way seems to work.
This is the expression:
[WW-Speicher_Temperatur_oben]: msg.payload
Which is why you should have shared your code because then we could have avoided the confusion. I now know that what you wanted was a reference inside an object as in:
{
[some-thing]: 42
}
That wasn't clear in your original post. When asking for help, please try to be clear and comprehensive about what you are asking and do not make assumptions that other people will recognise what you are saying.
yes I missed to copy the hole code, sorry.
For me it was not clear that the code around has impact in this case.
For the next time I know and will post the hole code.
Just want to add the final solution that works for me.
Jesterday with the expression [WW-Speicher_Temperatur_oben]: msg.payload
Node red "accepted" the expression. But today when I made the final cutover to node red no entries in influx DB.
With the following modification it works fine: ['WW-Speicher_Temperatur_oben']: msg.payload
And the hole code is:
msg.payload = [
{
['WW-Speicher_Temperatur_oben']: msg.payload