We recently attempt to use tuya cloud in Node-red, and we have found out that tuya's SDK is base on C--tuya SDK.
After following the instructions, we do compliled and got the executable bin file "subdevice_basic_demo". It dose work in command line like this, and links to the tuya cloud well.
croot@PN6400:~# cd /home/tuya/tuya-iot-core-sdk-main/build/bin
root@PN6400:/home/tuya/tuya-iot-core-sdk-main/build/bin# ./subdevice_basic_demo
But when we call the bin file in js file like this:
var fs = require("fs");
var exec = require('child_process').exec;
module.exports = function(RED) {
function PN6400_tuyaInit(config) {
RED.nodes.createNode(this,config);
var node = this;
this.key = RED.nodes.getNode(config.key);
node.on('input', function(msg) {
//run ('export PATH="/home/tuya/tuya-iot-core-sdk-main/build/bin/:$PATH"') ahead of time
exec('subdevice_basic_demo'+' ',function(error,stdout,stderr){
if(error) {
console.info('stderr : '+stderr);
}
});
});
}
RED.nodes.registerType("PN6400_tuyaInit",PN6400_tuyaInit);
}
Then nothing happened, aka the executable file "subdevice_basic_demo" never executed.
So anyone can help us?
Is the problem that it is not calling your code or that the code does not work when called like that? You can check by adding some logging to your C code so that it, for example, logs what is happening to file.
If it does work outside of Node-RED from the command line, then you proabably either need the full path to the command when you call it - or the environment that you are running Node-RED is not the same as the user you are using to run from command line.
Is the executable available in the cwd? Node-red current working directory will NOT be /home/tuya/tuya-iot-core-sdk-main/build/bin (i.e. try using full path) and check the account running node-red can access and execute the binary)