var topicDevicesRoot = '$aws/things/kenta-upnp-gateway/devices' mqttClient.on('connect', function () { mqttClient.subscribe(topicDevicesRoot + '/#'); }); mqttClient.on('message', function (topic, buffer) { if (topic.indexOf(topicDevicesRoot) === 0){ executeAction(getContextFromTopic(topic), JSON.parse(buffer.toString())); } else { console.error('MQTT: Unknown message received on topic ' + topic); console.error(buffer.toString()); } });