Splitting msg.payload from serial device

Dear all,

i was able to set up serial communication between my arduino (Wemos D1) and my RBP that runs node red.
sow i am able to read out the values that are sent by the arduino into my node red.
but i dont know how to split the msg.payload(s) from each other sow i can show the value on my dashboard.
can somebody tell me how to do this?

image


#include <DHTesp.h>
DHTesp dht;


// DHT Sensor 
const int DHTPin = 12;

// S1 
const int s1 = 5;
int  switch1last = 0;
// S2 
const int s2 = 4;
int  switch2last = 0;
// S3 
const int s3 = 0;
int  switch3last = 0;

// Lamp1 
const int lamp1 = 16;
// Lamp2 
const int lamp2 = 14;
// Lamp3 
const int lamp3 = 13;

// Analog output pin dimmer1 
const int analogOutPinDimmer1 = 2; 
int outputValueDimmer1 = 0;        // value output to the PWM (analog out)
// relais Dimmer 1
const int rd1 = 15;


String hum;
String temp;


// Timers auxiliar variables
long now = millis();
long lastMeasure = 0;


void setup() {
  pinMode(lamp1, OUTPUT);
  pinMode(lamp2, OUTPUT);
  pinMode(lamp3, OUTPUT);
  pinMode(rd1, OUTPUT);
  pinMode(s1, INPUT_PULLUP);
  pinMode(s2, INPUT_PULLUP);
  pinMode(s3, INPUT_PULLUP);

   Serial.begin(115200);
   dht.setup(D6, DHTesp::DHT22);
}

void loop() {

  now = millis();
  // Publishes new temperature and humidity every 10 seconds
  if (now - lastMeasure > 10000) {
    lastMeasure = now;
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.getHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.getTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
   // float f = dht.readTemperature(true);

    // Check if any reads failed and exit early (to try again).
   // if (isnan(h) || isnan(t) || isnan(f)) {
  // if (isnan(h) || isnan(t)) {
   //   Serial.println("Failed to read from DHT sensor!");
    //  return;
   // }

    // Computes temperature values in Celsius
    float hic = dht.computeHeatIndex(t, h, false);
    static char temperatureTemp[7];
    dtostrf(hic, 6, 2, temperatureTemp);
    
    // Uncomment to compute temperature values in Fahrenheit 
    // float hif = dht.computeHeatIndex(f, h);
    // static char temperatureTemp[7];
    // dtostrf(hic, 6, 2, temperatureTemp);
    
    static char humidityTemp[7];
    dtostrf(h, 6, 2, humidityTemp);

    // Publishes Temperature and Humidity values
    //temperatureTemp = t;
    //humidityTemp = h;
//    client.publish("room/temperature", temperatureTemp);
//    client.publish("room/humidity", humidityTemp);


    hum = String(h);
    temp = String(t);
    
   // Serial.println("Humidity: ");
    Serial.println(hum);
  //  Serial.println(" %\t Temperature: ");
    Serial.println(temp);
  //  Serial.println(" *C ");
   // Serial.print(f);
   // Serial.print(" *F\t Heat index: ");
   // Serial.print(hic);
   // Serial.println(" *C ");
    // Serial.print(hif);
    // Serial.println(" *F");


  //switch 1
int  switch1 = digitalRead(s1);
Serial.println(switch1);

    
  }

delay (100);
}


 

Send the data as a JSON string, then you can just feed it through a JSON node to decode it.

thank you for your respond.
i was able to do it by the join node to join them all in a array.
and was able to separate them with the change node.

but now i am struggling to send a string value on the serial out node to the arduino.
for the arduino i use the Serial.readString() statement.
does anybody have experience with this?

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