function sendDeviceTelemetry(node, client, message, properties) {
        if (validateMessage(message)){
            if (message.timestamp && isNaN(Date.parse(message.timestamp))) {
                node.error(node.deviceid + ' -> Invalid format: if present, timestamp must be in ISO format (e.g., YYYY-MM-DDTHH:mm:ss.sssZ)');
            } else {
                // Create message and set encoding and type
                var msg = new Message(JSON.stringify(message));
                // Check if properties set and add if so
                if (properties){
                    for (let property in properties) {
                        msg.properties.add(properties[property].key, properties[property].value);
                    }
                }
                msg.contentEncoding = 'utf-8';
                msg.contentType = 'application/json';
                // Send the message
                client.sendEvent(msg, function(err,res) {
                    if(err) {
                        node.error(node.deviceid + ' -> An error ocurred when sending telemetry: ' + err);
                    } else {
                        node.log(node.deviceid + ' -> Telemetry sent: ' + JSON.stringify(message));
                    }
                });
                
            }            
        } else {
            node.error(node.deviceid + ' -> Invalid message format.');
        }
    }
// Send messages to IoT platform (Transparant Edge, IoT Hub, IoT Central)
Send messages to IoT platform (Transparant Edge, IoT Hub, IoT Central)
Send messages to IoT platform ( Transparant Edge IoT Hub IoT Central )
function sendDeviceTelemetry(node, client, message, properties) {
        if (validateMessage(message)){
            if (message.timestamp && isNaN(Date.parse(message.timestamp))) {
                node.error(node.deviceid + ' -> Invalid format: if present, timestamp must be in ISO format (e.g., YYYY-MM-DDTHH:mm:ss.sssZ)');
            } else {
                var msg = new Message(JSON.stringify(message));
                if (properties){
                    for (let property in properties) {
                        msg.properties.add(properties[property].key, properties[property].value);
                    }
                }
                msg.contentEncoding = 'utf-8';
                msg.contentType = 'application/json';
                client.sendEvent(msg, function(err,res) {
                    if(err) {
                        node.error(node.deviceid + ' -> An error ocurred when sending telemetry: ' + err);
                    } else {
                        node.log(node.deviceid + ' -> Telemetry sent: ' + JSON.stringify(message));
                    }
                });
            }            
        } else {
            node.error(node.deviceid + ' -> Invalid message format.');
        }
    }
function sendDeviceTelemetry ( node , client , message , properties ) { if ( validateMessage ( message ) ) { if ( message . timestamp && isNaN ( Date . parse ( message . timestamp ) ) ) { node . error ( node . deviceid + ' -> Invalid format: if present, timestamp must be in ISO format (e.g., YYYY-MM-DDTHH:mm:ss.sssZ)' ) ; } else { var msg = new Message ( JSON . stringify ( message ) ) ; if ( properties ) { for ( let property in properties ) { msg . properties . add ( properties [ property ] . key , properties [ property ] . value ) ; } } msg . contentEncoding = 'utf-8' ; msg . contentType = 'application/json' ; client . sendEvent ( msg , function ( err , res ) { if ( err ) { node . error ( node . deviceid + ' -> An error ocurred when sending telemetry: ' + err ) ; } else { node . log ( node . deviceid + ' -> Telemetry sent: ' + JSON . stringify ( message ) ) ; } } ) ; } } else { node . error ( node . deviceid + ' -> Invalid message format.' ) ; } }
Send messages to IoT platform (Transparant Edge, IoT Hub, IoT Central)
Send messages to IoT platform ( Transparant Edge IoT Hub IoT Central )
// Create message and set encoding and type // Check if properties set and add if so // Send the message