diff --git a/package-lock.json b/package-lock.json index 56369f93..0526aecf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "license": "MIT", "dependencies": { "async-mqtt": "^2.6.3", + "circular-json": "^0.5.9", "convert-units": "^2.3.4", "dotenv": "^16.3.1", "lodash": "^4.17.21", @@ -2669,6 +2670,12 @@ "node": ">= 6" } }, + "node_modules/circular-json": { + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.5.9.tgz", + "integrity": "sha512-4ivwqHpIFJZBuhN3g/pEcdbnGUywkBblloGbkglyloVjjR3uT6tieI89MVOfbP2tHX5sgb01FuLgAOzebNlJNQ==", + "deprecated": "CircularJSON is in maintenance only, flatted is its successor." + }, "node_modules/clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", @@ -8970,6 +8977,11 @@ } } }, + "circular-json": { + "version": "0.5.9", + "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.5.9.tgz", + "integrity": "sha512-4ivwqHpIFJZBuhN3g/pEcdbnGUywkBblloGbkglyloVjjR3uT6tieI89MVOfbP2tHX5sgb01FuLgAOzebNlJNQ==" + }, "clean-stack": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", diff --git a/package.json b/package.json index 51fab795..c1eaf014 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "homepage": "https://github.com/BigThunderSR/onstar2mqtt#readme", "dependencies": { "async-mqtt": "^2.6.3", + "circular-json": "^0.5.9", "convert-units": "^2.3.4", "dotenv": "^16.3.1", "lodash": "^4.17.21", diff --git a/src/index.js b/src/index.js index 56353c86..b3754303 100644 --- a/src/index.js +++ b/src/index.js @@ -7,6 +7,8 @@ const {Diagnostic} = require('./diagnostic'); const MQTT = require('./mqtt'); const Commands = require('./commands'); const logger = require('./logger'); +const CircularJSON = require('circular-json'); + const onstarConfig = { @@ -111,7 +113,7 @@ const configureMQTT = async (commands, client, mqttHA) => { }) .catch((err)=> {logger.error('Command error', {command, err}) logger.info(commandStatusTopic); - client.publish(commandStatusTopic, JSON.stringify({"Command": err}), {retain: true})}); + client.publish(commandStatusTopic, CircularJSON.stringify({"Command": err}), {retain: true})}); }); const topic = mqttHA.getCommandTopic(); logger.info('Subscribed to command topic', {topic});