Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disconnect AWS IoT device after it's connected

Tags:

I'm working on a web application where the user can login with AWS Cognito. After login with the AWS credentials I'm connecting to AWS IoT device like

var device = AwsIot.device({ 
    clientId: clientID, 
    host: host, 
    accessKeyId: credentials.accessKeyId, 
    secretKey: credentials.secretAccessKey, 
    protocol: 'wss', 
    sessionToken: credentials.sessionToken, 
    offlineQueueing: 'false' 
}); 

Then once the user logout from the app using AWS Cognito using

cognitoUser.signOut(); 

Then after logout I want to disconnect the the AWS IoT device as well. Right now I'm seeing even after the logout the device is listening to the events like

device.on('close', function() {}) 
device.on('error', function() {}) 
device.on('offline', function() {}) 

Can someone please specify which function should I call to disconnect the device as well so that it don't listen to these events as well.

I was going through the doc https://github.com/aws/aws-iot-device-sdk-js But I didn't got any specific function for this.

Moreover I used the AWS credential to connect the AWS IoT device, and once I logout from Cognito then the device should have been automatically disconnected as well I think. Please let me know what should be the approach here.

like image 507
Indranil Mondal Avatar asked Feb 16 '18 13:02

Indranil Mondal


People also ask

How do I know if my AWS is connected to IoT?

Check device connection status using the console To check the connection status using the console, navigate to the Devices page of the AWS IoT console and choose the device you've added. In the Details section of the Wireless devices details page, you'll see the date and time the last uplink was received.

Can a device connected to AWS IoT receive messages back from cloud?

Finally, AWS IoT Core accelerates IoT application development. It serves as an easy to use interface for applications running in the cloud and on mobile devices to access data sent from connected devices, and send data and commands back to the devices.

Where is endpoint in IoT AWS?

The AWS IoT device service endpoints support device-centric access to security and management services. To learn your account's device data endpoint, you can find it in the Settings page of your AWS IoT Core console.

How do I communicate with an IoT device?

The communication of IoT devices can be unidirectional (send data) or bidirectional (send and receive data). If it is a remote communication then the data has to be transferred via a gateway. The network protocol used can be Wi-Fi, Bluetooth, Satellite, or directly connecting to the internet via ethernet port.


1 Answers

I got the answer from AWS IOT support team on this.

The AwsIot.device class is a wrapper for the MQTT class with helpers to assist with connecting to AWS endpoints To disconnect your device, you can call device.end(); This will close your connection and invoke device.on('close'). As for Cognito Sign-out. This will not invalidate the session credentials already provided by Cognito which were used to establish the connection. They will continue to be valid until their assume role time expires.

like image 178
Indranil Mondal Avatar answered Sep 29 '22 02:09

Indranil Mondal