Problem to display serial in data to gauge

Hi good evening , im currently having a problem with my project. my project is to display the humidity and temperature value in gauge node by using a serial in. but when i connect the serial port it didnt show the value that i want. here is my node setting image and the debug show

please help me to solved this problem. in function node i have wrote msg.payload = {temperature: msg.payload.toString('utf8')}
return msg

You need to add a change node before the ui-gauge and move msg.payload.temperature to msg.payload and the same for humidity

i have put the change node like you said. but it display undefined. does the code in arduino ide can be the cause? here is my code in my ide

#include <dht11.h>



 const int dht11pin= 6;
 int value;
 
dht11 DHT;




void setup(){
  
  Serial.begin(9600);
  
  
  delay(1000);//Wait before accessing Sensor
  pinMode(dht11pin, OUTPUT);


}//end "setup()"

    
void loop(){
  //Start of Program 
 
    DHT.read(dht11pin);

    float h = (DHT.humidity) ;  //Stores humidity value
    float t = (DHT.temperature) ;

    String temp = String(t);
    String hum = String(h);
     //Stores temperature value
    

  

    value= analogRead(dht11pin);
    Serial.print("Current humidity = ");
    Serial.print(hum);
    Serial.println("%");
    
    
    Serial.print("Current temperature = ");
     Serial.print(temp);
    Serial.println("C");
    
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop(
[{"id":"91d97567.046a58","type":"tab","label":"DHT11 sensor","disabled":false,"info":""},{"id":"6637330a.c7435c","type":"serial in","z":"91d97567.046a58","name":"Arduino","serial":"99a4d77a.f152f8","x":210,"y":260,"wires":[["ac3e2a6f.3f75b8","6bdf444d.cd239c"]]},{"id":"13df06f3.d70369","type":"debug","z":"91d97567.046a58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.temperature","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":200,"wires":[]},{"id":"cd3f8475.069fa8","type":"debug","z":"91d97567.046a58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.humidity","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":280,"wires":[]},{"id":"ac3e2a6f.3f75b8","type":"function","z":"91d97567.046a58","name":"Temperature","func":"msg.payload = {temperature: msg.payload.temperature}\nreturn msg\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":220,"wires":[["d3c3f729.439d68"]],"info":"Node-RED receives Humidity and Temperature values in ASCII code format from serial monitor. To display these values on Node-RED Dashboard, we need to convert ASCII code into real values. So to do this above java program is used. In this program every ASCII code is subtracted by 48 except the decimal point and comma."},{"id":"501065f3.a445fc","type":"ui_gauge","z":"91d97567.046a58","name":"Humid Gauge","group":"e9247148.a4936","order":1,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":900,"y":320,"wires":[]},{"id":"f80bca47.194a48","type":"ui_gauge","z":"91d97567.046a58","name":"Temp Gauge","group":"90603af8.41fe78","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"Celcius","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":890,"y":240,"wires":[]},{"id":"6bdf444d.cd239c","type":"function","z":"91d97567.046a58","name":"Humidity","func":"msg.payload = {humidity: msg.payload.humidity}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":300,"wires":[["b13f0b9a.5c2ff8"]],"info":"Node-RED receives Humidity and Temperature values in ASCII code format from serial monitor. To display these values on Node-RED Dashboard, we need to convert ASCII code into real values. So to do this above java program is used. In this program every ASCII code is subtracted by 48 except the decimal point and comma."},{"id":"7f385305.5d1bcc","type":"debug","z":"91d97567.046a58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":400,"wires":[]},{"id":"d3c3f729.439d68","type":"change","z":"91d97567.046a58","name":"","rules":[{"t":"move","p":"payload.temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":220,"wires":[["13df06f3.d70369","f80bca47.194a48"]]},{"id":"b13f0b9a.5c2ff8","type":"change","z":"91d97567.046a58","name":"","rules":[{"t":"move","p":"payload.humidity","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":300,"wires":[["cd3f8475.069fa8","501065f3.a445fc"]]},{"id":"99a4d77a.f152f8","type":"serial-port","serialport":"COM8","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"0","bin":"false","out":"time","addchar":"false","responsetimeout":""},{"id":"e9247148.a4936","type":"ui_group","name":"humidity","tab":"4fca59d3.f1ef38","order":4,"disp":true,"width":"6","collapse":false},{"id":"90603af8.41fe78","type":"ui_group","name":"temperature","tab":"4fca59d3.f1ef38","order":9,"disp":true,"width":"6","collapse":false},{"id":"4fca59d3.f1ef38","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Since you have control of the Arduino software I think it would be better if you sent the data as JSON strings so that it can be passed through a JSON node and then be available as a JavaScript Object contains the values.

hi colin, im new in this. can you teach me how to do that?

Which bit don't you know how to do?
Build a JSON string in the Arduino?
Convert it to a javascript object in node red? If this is the bit you don't know how to do then you just have to feed it through a JSON node.

If you mean you don't know what the JSON string should look like then it depends on exactly what you are trying to send, which isn't clear to me, but possibly something like
{"temperature": 23.0, "humidity": 38}

actually both of them , can you ? here is my coding in arduino



#include <dht11.h>



 const int dht11pin= 6;
 int value;
 
dht11 DHT;




void setup(){
  
  Serial.begin(9600);
  
  
  delay(1000);//Wait before accessing Sensor
  pinMode(dht11pin, OUTPUT);


}//end "setup()"

    
void loop(){
  //Start of Program 
 
    DHT.read(dht11pin);

    float h = (DHT.humidity) ;  //Stores humidity value
    float t = (DHT.temperature) ;

    String temp = String(t);
    String hum = String(h);
     //Stores temperature value
    
  

    value= analogRead(dht11pin);
    Serial.print("Current humidity = ");
    Serial.print(hum);
    Serial.println("%");
    
    
    
    Serial.print("Current temperature = ");
    Serial.print(temp);
    Serial.println("C");
    
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop(

how can i get the value from the arduino dht11 sensor and display it on the json string below?

msg.payload = {"temperature": , "humidity": }
return msg;

Modify your Arduino code to actually send the string {"temperature": 23.0, "humidity": 38}. Job done.

which part should i change? the serial print?

Yes. Something like...

    char s[100];
    sprintf(s, "{\"humidity\": %f, \"temperature\": %f}", hum, temp);
    Serial.print(s);

↑ untested - but should get you on the right track

... then feed the payload into a JSON node & you will have a JS object

then, the docs will explain how to use the debug panel to find the right path to any data item.

https://nodered.org/docs/user-guide/messages

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