Help Using Other Library Js

Hi All,

I've read some threads about adding library js, but didn't get work. I want to use library from this site:
http://praytimes.org/manual
and library is
praytimes

I've add to my function global

And try to using it as a function. But still not working.
image

[{"id":"de86cd8d.e98f7","type":"function","z":"8f3ffe88.a77cf","name":"","func":" var prayTimes = global.get('prayTimes')\n var times = prayTimes.getTimes(new Date(), [43, -80], -5);\nmsg.payload = times;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":740,"wires":[["9f6c8586.20b888"]]},{"id":"ad6e6ab9.e346f8","type":"inject","z":"8f3ffe88.a77cf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":390,"y":740,"wires":[["de86cd8d.e98f7"]]},{"id":"9f6c8586.20b888","type":"debug","z":"8f3ffe88.a77cf","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":760,"wires":[]}]

Many thanks for your advise, Sir!

var PT = new PrayTimes('ISNA');
var times = PT.getTimes(new Date(), [43, -80], -5);

So you better create a new instance first?

Hi @aderici ,

Thank you for advise. I've try like you said:


But, still not get the output message

First get the PrayTimes from global context at the top of the page please

Hi, Sir
After add global.get context:
var PrayTimes = global.get('prayTimes');
var PT = new PrayTimes('ISNA');
var times = PT.getTimes(new Date(), [43, -80], -5);
msg.payload = times.sunrise;
return msg;

Here is the output
image

Hi @mrizkywiguna

The file you are trying to use is not packaged as a node.js module - so you cannot require it in your settings file.

If you edit PrayTimes.js and add the following line to the end of it:

module.exports = PrayTimes;

Then restart Node-RED, your Function should work.

You're The Best Nick!
Thank you very much, Sir!
image

Hi Sir,

Another questions, how to put this code into function?

prayTimes.tune( {sunrise: -1, sunset: 3.5} );

You'll have to explain a bit more about what you mean. I don't know anything about the library you are using, I have never seen it before today.

So when you ask how to put that code into a function, all I can say is just copy and paste it in... but I assume that isn't the sort of answer you are looking for.

I'm sorry, Sir.

Actually the code is working now. But the "time" results need some tune, because it's different from the actual. Based on the manual, this function is for tune the minutes:

Hi Nick,
Now i'm using this code for some adjusting. Maybe not the best way, but now I can tune it.

[{"id":"afd685b1.ab3298","type":"ui_text","z":"8f3ffe88.a77cf","group":"7394d5c4.292edc","order":0,"width":"5","height":"3","name":"Isya","label":"Isya","format":"{{msg.payload}}","layout":"col-center","x":990,"y":360,"wires":[]},{"id":"8f5fcb1b.e30bd8","type":"function","z":"8f3ffe88.a77cf","name":"isha","func":"var hms = msg.payload.isha;\n\nvar a = hms.split(':'); // split it at the colons\nvar tune = 4; //tuning\n// minutes are worth 60 seconds. Hours are worth 60 minutes.\nvar seconds = (+a[0]) * 60 * 60 + (+a[1]+tune) * 60; \nmsg.payload = seconds;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":360,"wires":[["ce39452a.02d7b8"]]},{"id":"ce39452a.02d7b8","type":"change","z":"8f3ffe88.a77cf","name":"To millisecs","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload*1000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":360,"wires":[["e6b1f8b5.ac6328"]]},{"id":"e6b1f8b5.ac6328","type":"moment","z":"8f3ffe88.a77cf","name":"","topic":"","input":"payload","inputType":"msg","inTz":"ETC/GMT","adjAmount":"0","adjType":"hours","adjDir":"add","format":"HH:mm","locale":"ID","output":"payload","outputType":"msg","outTz":"ETC/GMT","x":780,"y":360,"wires":[["afd685b1.ab3298"]]},{"id":"7394d5c4.292edc","type":"ui_group","name":"Isya","tab":"10aa04cd.61297b","order":6,"disp":false,"width":"5","collapse":false},{"id":"10aa04cd.61297b","type":"ui_tab","name":"smartprayer","icon":"dashboard","disabled":false,"hidden":false}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.