Read the statement by Michael Teeuw here.
Use of array within all module files
-
@bdeelman you would save the config value in a variable usable by all routines in the source file.
u do not need to save in the modulename.js, as it is provided as this.config
-
@sdetweil can you be more precise? I did not understand you.
The
subscriptions
is the generate json array with all kind of information to build an element / divs etc. That array is build at node_helper.js and globally needed within modulename.js.As I understand the way of working well…?
Regards,
Bert -
@bdeelman said in Use of array within all module files:
These payloads arrived within the function at the module file. But I can not use the payload outside of that specific function.
so in the receiving function, store the payload value somewhere that other functions can use it
this.subscriptions=payload
similar for the config info in the node_helper
-
@sdetweil Thanks for your reply. Much appreciated!
I think I need another approach to get the result that I need. The
subscriptions
array is (must be) part of thethis.config
. So I addsubscriptions: [];
to thedefaults:
at the modulename.jsThe thing now is add the generated JSON (csvtojson) to the
this.config
. :grinning_face_with_big_eyes: and I can usethis.config
as a payload.The array is something like this:
subscriptions = [{ topic: 'homey/light/keuken/dimmer-fibaro-1/onoff', // MQTT Topic name label: 'Licht keuken', type: 'device', display: { left: 50, top: 50 }, }, { topic: 'homey/sensor/washok/temp-hum-xiaomi-1/measure-temperature', label: 'Washok Temp', type: 'label', display: { left: 265, top: 0, prefix: "", suffix: "°C", decimals: 0 }, }
-
@bdeelman sorry I do not understand what you want
u can send anything with sendSocketNotification and you can store it anywhere, not just in this.config
-
@sdetweil I am sorry and lost. ;)
The
sendSocketNotification
from node_helper.jsself.sendSocketNotification('MQTT_PAYLOAD', { topic: topic, value: value, subs: self.subscriptions )};
So if I understand correctly…I should add
this.subscriptions = payload;
at the receiving functionsocketNotificationReceived
at modulename.jssocketNotificationReceived: function(notification, payload) { this.subscriptions = payload; if (notification === 'MQTT_PAYLOAD') { // // } },
I did that but it is not working. The array is not available at other functions within modulename.js.
At the node_helper part it is working.
this.subscriptions = (jsonObj);
and I can use the array at other functions. withvar self = this; var l = self.subscriptions.length; // as an example.
-
@bdeelman so, I would open the developers window., ctrl-shift-i on the pi MM window
select the sources tab, navigate the left nav modules/your module name, select the source file name modulename.jsscroll to the line for the socketNotificationReceived().
this.and click the number at the left edge of that line, should turn blue
then hit f5 to refresh the page, and MM will reload and you should stop at the line…
move your mouse over the word ‘this’, and it should expand a box describing what this points to , which should be THIS modules instance data…
if not, then THAT is the problem…