Ask : two node to one function?

Dear All :

  1. The switch has topic is no2_pn, but hv error...why?
  2. In the code Line 20 that is correct?
  3. Or in the code has another error?

Thank u.

The error is because no2_pn is a String value so it needs to have " around it. The same is true for "no2_cali_val" and "no2_array".

if (msg.topic == "no2_pn")

Dear Sir :

I hope the output is no2_array, not "no2_array".
So how to do?

Thank u.

I'm sorry - I did not spot that no2_array was a locally defined variable.

So "no2_pn" and "no2_cali_val" are String types and need quotes.

no2_array is a local variable so does not need quotes.

Dear Sir :

Thank u.

  1. But if no "no2_array" that it still has error...
  2. How can I output value that is no2_array's vaule.
  3. Cause the value is numberic.

Thanks again.

Please share your code (not a screenshot, paste it in and format it as a code block using by wrapping it with ```.

What error are you now getting?

Dear Sir :

  1. The code is below:
//var i;
//var j;
var no2_array=[];
if(msg.topic=="no2_pn") 
{
    if(msg.payload==true)
        no2_array[0]=0;  //+
    else
        no2_array[0]=1;  //-
    
}
//
if(msg.topic=="no2_cali_val")
{
    //1j=msg.payload;
    no2_array[1]=(msg.payload<<8);
    no2_array[2]=msg.payload&0xFF;
}
//
msg.payload="no2_array";
return msg;
  1. So msg.payload's value is always string?

Thank u.

I have edited your last post, but next time that you post any code, please use three back ticks and not quotations.
Like this ```
and not """

No, no2_array is a variable and not a string, so you don't need string quotes around it.
So instead of msg.payload="no2_array"; you need msg.payload=no2_array;

Dear Sir :

  1. I will use ''' next time.
  2. its right : msg.payload=no2_array;

Thank u.

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