From ca28ea8d85472a84750a3a34e574b83728455b0e Mon Sep 17 00:00:00 2001 From: Ryan Kelley Date: Mon, 24 May 2021 07:48:25 -0700 Subject: [PATCH] Add unique ID to mqtt client id, remove exhut dep check Signed-off-by: Ryan Kelley --- web/api/datasources/mqtt.js | 12 +++++++++++- web/client/src/components/SensorsMap/index.js | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/web/api/datasources/mqtt.js b/web/api/datasources/mqtt.js index 6a960c0..5078136 100644 --- a/web/api/datasources/mqtt.js +++ b/web/api/datasources/mqtt.js @@ -1,4 +1,5 @@ const { DataSource } = require('apollo-datasource'); +const generator = require('generate-password'); const mqtt = require('mqtt'); @@ -30,10 +31,19 @@ if ( mqttPort = mqtt.port; } +// Generates a ID to add to end of Mqtt clientId +const clientUnique = generator.generate({ + length: 8, + numbers: true, + symbols: false, +}); + +console.log('MQTT Unique ID:', clientUnique); + const client = mqtt.connect( `mqtt://${brokerId}.messaging.internetofthings.ibmcloud.com`, { - clientId: mqttClientId, + clientId: `${mqttClientId}:${clientUnique}`, username: mqttUsername, password: mqttPassword, port: mqttPort, diff --git a/web/client/src/components/SensorsMap/index.js b/web/client/src/components/SensorsMap/index.js index 9bf4898..b519b1e 100644 --- a/web/client/src/components/SensorsMap/index.js +++ b/web/client/src/components/SensorsMap/index.js @@ -162,6 +162,7 @@ const SensorsMap = ({ sensors, setDisplayedSensor, setShouldShowSideMenu }) => { }) }) } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [sensors]) const zoomIn = () => {