I am building a React application that connects to AWS IoT Core via Amplify and Cognito. I have successfully connected the backend to AWS IoT. I wish to retrieve the device online/offline status from AWS using the events topic like so:
var device_name
var device_state
var device_mode
Amplify.PubSub.subscribe('$aws/events/presence/connected/device_name').subscribe({
next: data => table_data_online(data),
error: error => console.log(error),
close: () => console.log('Done'),
});
const table_data_online = (data) => {
device_name = data.value.clientId
device_state = 'Online'
}
const rows = [
{ id: device_name, status: device_state, mode: device_mode}
];
However, I cannot seem to set the device_name and device_state like this... How do I make it such that I can set the device_state and device_name strings for rows when an update is received from AWS IoT? Btw, rows is used in a MUI DataGrid table and is currently set to hold just 1 device.