I have Tagocore installed and running inside a Raspberry pi3.
The Integration with Tago-IO is running smoothly.
I need to work with the data inside Tagocore and for that I'm using a script invoked by the "Action" function, and this "Action" is also working.
At the moment I use the following support to access tagocore data through the script (
https://tagocore.com/docs/analysis/code)
This document points in its script an example of accessing the TAGOCORE_DATA environment.
My data array follows the proper model suggested by Tagocore/Tago-IO.
---------------------------------------------------------------------------------------------------------
PROBLEM: Executing the script returns an error in the Analysis console.
---------------------------------------------------------------------------------------------------------
This is the Scope data which is being sent by the device, the token of this device was place in the environment variable of Analysis
----------------------------------------------------------------------------------------------------------
[
{
"variable": "temperature",
"value": 16.5
},
{
"variable": "humidity",
"value": 74
}
]
----------------------------------------------------------------------------------------------------------
This is the suggested script:
----------------------------------------------------------------------------------------------------------
const data = process.env.TAGOCORE_DATA;
const temperatureItem = data.find((i) => i.variable === 'temperature');
console.log("Temperature is at:", temperatureItem.value);
---------------------------------------------------------------------------------------------------------
The error returned is:
---------------------------------------------------------------------------------------------------------
[2022-09-30 16:27:01.564]: Finishing script execution with code 1
[2022-09-30 16:27:01.552]: /home/pi/Users/tagocore/project-code/calculo_01_edit1.js:2
const temperatureItem = data.find((i) => i.variable === 'temperature');
^
TypeError: Cannot read property 'find' of undefined
at Object.<anonymous> (/home/pi/Users/tagocore/project-code/calculo_01_edit1.js:2:30)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
[2022-09-30 16:27:01.062]: Starting analysis 6140e438ed59eb1f99dc68f0
---------------------------------------------------------------------------------------------------------------------------------------
Finally:
.
If I run the script separately elsewhere without the line (const data = process.env.TAGOCORE_DATA;) it works correctly and returns the following: ("Temperature is at:" 16.5)
--------------------------------------------------------------------------------------------------------------------------------------
I would really appreciate your help from the community.