I am desperately trying to interact with the Arduino IoT Cloud via a Web App from a Browser, and am defeated at every turn. I have another thread in the forums about CORS violations trying to access the REST API Client, and now I'm trying to use arduino-iot-js to receive and set Thing Property values in real time via an MQTT channel, and it fails at runtime.
It throws this error very early (before even calling any functions from the library) when it's imported and referenced, per the Chrome Dev Console:
constants.js:46 Uncaught ReferenceError: Buffer is not defined
at node_modules/mqtt-packet/constants.js (constants.js:46:34)
at __require (chunk-IEMOZLTW.js?v=27d7d660:40:50)
at node_modules/mqtt-packet/parser.js (parser.js:4:19)
at __require (chunk-IEMOZLTW.js?v=27d7d660:40:50)
at node_modules/mqtt-packet/mqtt.js (mqtt.js:1:18)
at __require (chunk-IEMOZLTW.js?v=27d7d660:40:50)
at node_modules/mqtt/lib/client.js (client.js:10:20)
at __require (chunk-IEMOZLTW.js?v=27d7d660:40:50)
at node_modules/mqtt/lib/connect/index.js (index.js:3:20)
at __require (chunk-IEMOZLTW.js?v=27d7d660:40:50)
The error is in this line:
protocol.SESSIONPRESENT_HEADER = Buffer.from([protocol.SESSIONPRESENT_MASK])
(Line 46 of node_modules/mqtt-packet/consstants.js)
Note that this doesn't appear to crash on any particular usage off the package. Simply importing the package and having a reference to to it, like "...await ArduinoIoTCloud.connect(...", causes the crash on startup. The call to "ArduinoIoTCloud.connect" never gets executed; the app doesn't get anywhere near that far before the exception. Just having the reference in the code, causing the package to be included, causes the crash at startup.
I've done an "npm update" to ensure the latest package versions, and the problem persists.
Any idea what's up here, and how to fix it?
ADDITIONAL INFO:
- This problem only appears to happen in the Browser. It does not occur in a Node app.
- Even though the crash doesn't happen in a Node app, the Node app exhibits these issues:
- "client.sendProperty(thingId, name, value);" isn't able to set Booleans to false.
- It can set Numbers to anything, and it can set Booleans to true, but it can not set Booleans to false. A True value remains True even after "sendProperty...." with 'false'. I've tried "false", false, and 0 - nothing works.
- Changes to Property values (via the Web Dashboard or via a Node app) are not being transmitted to the client, per this setup:
client.onPropertyValue(thingId, name, (value) => {
console.log(`RECEIVED ${name} value ${value}`);
});
-- Am I setting up that callback wrong?