I'm making a real time dashboard for wind and solar farms approximately around 100 devices, and I'm having trouble with the data coming from aws iot mqtt websocket connection using amplify pubsub library documentation . I'm able to connect to the broker using mqtt over websockets but the data logs several times in the console when i receive the data. This is the code I am using
import Amplify, { PubSub } from "aws-amplify";
import { AWSIoTProvider } from "@aws-amplify/pubsub";
import { useEffect } from "react";
import { useState } from "react";
const DemoConnection = () => {
Amplify.configure({
Auth: {
identityPoolId: "xxxxxx",
region: "us-east-1",
},
});
Amplify.addPluggable(
new AWSIoTProvider({
aws_pubsub_region: "us-east-1",
aws_pubsub_endpoint:
"wss://xxxxx.amazonaws.com/mqtt",
})
);
PubSub.subscribe("myTopic", { provider: "AWSIoTProvider" }).subscribe({
next: (data) => {
console.log("Message received", data);
},
error: (error) => console.error(error),
complete: () => console.log("Done"),
});
return null;
};
export default DemoConnection;
Please help me with the above problem