NNH Noob need help ;)

#1

I am using node red with iobroker. I have a problem with passing a flow to iobroker. [error] [function:extractData] Function tried to send a message of type string

function:extractData:
    /*
returns:
1. travelDurationTraffic in min
2. travelDuration in min
3. traveDelay in min
4. trafficJam boolean
5. trafficCongestion string
6. travelDistance in km
7. msg object (for debugging and return to the loop)
*/
var travelDurationTraffic = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDurationTraffic / 60);
var travelDuration = Math.ceil(msg.payload.resourceSets[0].resources[0].travelDuration / 60);

var shortname = msg.name+":"+msg.payload.resourceSets[0].resources[0].routeLegs[0].description+"/"+msg.payload.resourceSets[0].resources[0].travelDistance+" km";

var msgTraffic = [
    {
        topic: msg.topic_prefix + ".name",
        payload: msg.name
    },
    {
        topic: msg.topic_prefix + ".travelDurationTraffic",
        payload: travelDurationTraffic
    },
    {    
        topic: msg.topic_prefix + ".travelDuration",
        payload: travelDuration
    },
    {    
        topic: msg.topic_prefix + ".travelDelay",
        payload: travelDurationTraffic - travelDuration
    },
    {    
        topic: msg.topic_prefix + ".trafficJam",
        payload: (travelDurationTraffic - travelDuration >= msg.threshold)
    },
    {    
        topic: msg.topic_prefix + ".trafficCongestion",
        payload: msg.payload.resourceSets[0].resources[0].trafficCongestion
    },
    {    
        topic: msg.topic_prefix + ".travelDistance",
        payload: msg.payload.resourceSets[0].resources[0].travelDistance
    },
    {    
        topic: msg.topic_prefix + ".travelDescription",
        payload: msg.payload.resourceSets[0].resources[0].routeLegs[0].description
    }
];

return [shortname,msgTraffic,msg.payload.resourceSets[0].resources[0].routeLegs,msg];

can also post the complete flow if necessary.
the flow isn't from me
I am total beginner so please tell for beginner :slight_smile:

0 Likes

#2

Function nodes must always pass complete messages not just values such as strings (hence the error message). Therefore the return at the end must either return a message or an array of messages. Some of your values returned are not messages.

0 Likes

#3

you can’t return variables, you need to return javascript objects

0 Likes