aws / aws-iot-device-sdk-js-v2

Next generation AWS IoT Client SDK for Node.js using the AWS Common Runtime
Apache License 2.0
222 stars 100 forks source link

How to make correct migration from aws-iot-device-sdk to aws-iot-device-sdk-v2 #203

Closed baliand closed 2 years ago

baliand commented 2 years ago

Confirm by changing [ ] to [x] below:

Known Issue

Platform/OS/Hardware/Device AWS Lambda arm and x86

Describe the question Please help me. I can'd find how to correct make migration

I have this connection

const awsIot = require('aws-iot-device-sdk'); 

let client = awsIot.device({
        clientId: utils.uuidv1(),
        protocol: 'wss',
        host: MYHOST,
        keepalive: 1000,
});

client.on('error', (err) => {
    console.error(err);
});
client.on('connect', () => {
    console.info('MQTT connected');
});

client.on('message', async (messageTopic, payload) => {
/// some my actions
});

client.subscribe(mysubTopic, async (error, granted) => {
 // some my actions
})

// i need make unsubscripbe for some case
client.unsubscribe(mysubTopic);

How can I do it now with aws-iot-device-sdk-v2?

Thanks

KaibaLopez commented 2 years ago

Hi @baliand , So first let me ask, have you taken a look at our samples for v2? specifically the pub_sub one might help you I believe. If you have then could you be a bit more specific on what you are having problems with?

baliand commented 2 years ago

@KaibaLopez I saw pub_sub and it not understandable for me. I need send command to device and wait response from device. My code running on AWS lambda.

I try to do next:

 try {
        const clientBootstrap = new io.ClientBootstrap();

        const config = iot.AwsIotMqttConnectionConfigBuilder.new_websocket_builder()
            .with_endpoint('<SECRET>.iot.<REGION_SECRET>.amazonaws.com')
            .with_keep_alive_seconds(1000)
            .with_client_id(uuidv4())
            .build();

        console.log(config);

        const client = new mqtt.MqttClient(clientBootstrap);

        const clientConnection = client.new_connection(config);

        clientConnection.on('error', (err) => {
            console.error(err);
        });
        clientConnection.on('connect', () => {
            console.log('MQTT connected');
        });

        clientConnection.on('message', function (topic, payload) {
            console.log('message', topic, payload.toString());
        });

        await clientConnection.connect()
    } catch (e) {
        console.log(e);
    }

I;m getting Failed to connect: aws-c-io: AWS_IO_TLS_ERROR_NEGOTIATION_FAILURE, TLS (SSL) negotiation failed

What kind of difference between new_websocket_builder and new_with_websockets?

Many thanks!

jmklix commented 2 years ago

I highly recommend that you start with getting the pubsub working and go from there. There is even a new example in javascript(vs the original example in typescript). What exactly do you not understand about the pubsub example?

The difference between new_websocket_builder and new_with_websockets is that there really is none. As seen here one just returns the other.

github-actions[bot] commented 2 years ago

Greetings! It looks like this issue hasn’t been active in longer than a week. We encourage you to check if this is still an issue in the latest release. Because it has been longer than a week since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.