tahu icon indicating copy to clipboard operation
tahu copied to clipboard

"TypeError: sparkplugPayload.timestamp.toNumber is not a function"

Open guaicaiboshi opened this issue 3 years ago • 0 comments

I am having a problem using the JavaScript Sparkplug Payload, as described on README, encoded = sparkplug.encodePayload(payload);Normal, but Decoding a payload below. var decoded = sparkplug.decodePayload(encoded); Start an error:

chunk-vendors.js:3874 [Vue warn]: Error in v-on handler: "TypeError: sparkplugPayload.timestamp.toNumber is not a function"

found in

---> <Root>

[system] TypeError: sparkplugPayload.timestamp.toNumber is not a function at Object.push.D:\MyTestStorage\Vuejs\HBuilderProjects\sparkplug-client-test\node_modules\sparkplug-payload\lib\sparkplugbpayload.js.exports.decodePayload (pages-index-index.js:10486) at VueComponent.test (VM441 index.js!D:\MyTestStorage\Vuejs\HBuilderProjects\sparkplug-client-test\pages\index\index.vue:37) at click (pages-index-index.js:63) at invokeWithErrorHandling (chunk-vendors.js:5117) at invoker (chunk-vendors.js:5442) at invokeWithErrorHandling (chunk-vendors.js:5117) at HTMLElement.invoker (chunk-vendors.js:5438) at HTMLElement.original._wrapper (chunk-vendors.js:10320)

sparkplugbpayload.js

image

My code: `

                        test() {

			var sparkplug = require('sparkplug-payload').get("spBv1.0"),
				payload = {
					"timestamp": new Date().getTime(),
					"metrics": [{
						"name": "intMetric",
						"value": 1,
						"type": "Int32"
					}]
				},
				encoded = sparkplug.encodePayload(payload);

			console.log(encoded);
			var decoded = sparkplug.decodePayload(encoded);
			console.log(decoded);
		}

`

guaicaiboshi avatar May 21 '21 08:05 guaicaiboshi