Read the statement by Michael Teeuw here.
read csv-data and put it in an array
-
that’s not what i wanted (writing code for me). my big problem is, not to know how i can start, how i can test code-snippets and so on …
i read some articles, but when i want to test some lines of code, i don’t know what to do. in my magicmirror module i can’t do that => error messages … i hope that i have expressed myself clearly and understandably …
if i have a code-snoppet, go to terminal and put innode xxx.jspath not found, module not found, and many other error messages … maybe i soon despair …
-
@Perlchamp is the xxx.js in the current folder? if not u need to give path to the file
you can do in MM module, with messages… there are two parts… the server side (node_helper) whose messages (console.log) come out on the same terminal window
the browser side (modulename.js) uses Log.log. and displays only in the developer windowI have modified a logging module that will display them together on the terminal window
https://github.com/sdetweil/MMM-Logging
install this as the FIRST module in the list
use this definition in config.js{ module: 'MMM-Logging', disabled: false, config: { // Module functions out of the box with nothing set here. // See below for configurable options. echoLocal: true, echoRemote: true, overwriteBrowserMethods: true, format: "{{message}} ({{folder}}/{{file}}:{{line}} {{method}})", } }, -
thanks a lot, i will try to “play” with it. can take some time …
-
@Perlchamp ok, if you are trying to use the csv-> somethign libraries and installed them in you module folder, then u want to be IN that folder to run your sample node xxx.js tests so the module folder path is right for require()
-
@sdetweil said in read csv-data and put it in an array:
u want to be IN that folder
you mean in my module folder? it’s called “MMM-birthdaylist” …
-
@Perlchamp correct
cd ~/MagicMirror/modules/MMM-birthdaylist node xxx.jsnote xxx.js can’t do anything specifically MagicMirror related no module register no sendSocketNotification
-
ok, thanks a lot sam :-)
no i will try to play with it. -
Log.log("hello Log");=> Log.log(“hello Log”);
^ReferenceError: Log is not defined
at Object. (/home/thomas/MagicMirror/modules/MMM-birthdaylist/test.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)console.log("hello console");=> hello console
-
another question:
what can i do with MMM-logging. if i start npm start in the MagicMirror folder nothing will displayed. and to test, etc. i have to close MagicMirror because it fill the hole screen … -
@Perlchamp log.log only works in the modulename.js (the part loaded in the browser)
we call it that cause its filename matches the module name -
ok, thanks again :-)
-
@Perlchamp u can redirect the output of npm start to a file, npm start >somefile
u can minimize the window with alt-spacebar, n
u can open the developers window ( for the modulename,js debugging) npm start dev
or if mirror already running use f12 or ctrl-shift-i on the keyboardI debug from my PC, ssh connected to pi, or I run MM on my PC… and debug there
-
what do you use for debugging on pc ?
do you have x64 or arm-based pc ? -
@Perlchamp x64, run linux or windows (today on linux), doesn’t matter… same debug process… look at console or browser window
if I need to debug modulename.js on pi, I open browser from PC to the mirror URL and do it there -
AND:
thanks a lot for YOUR time. i hope it will not been wasted … i will working hard to get some results … -
@sdetweil said in read csv-data and put it in an array:
I open browser from PC to the mirror URL and do it there
I debug from my PC, ssh connected to pi, or I run MM on my PC… and debug therehow ?
-
@Perlchamp on MagicMirror, in config, set address:“0.0.0.0”,
And ipWhitelist:[],Then u can connect to the mm url from anywhere in your house/office.
http://ipaddress:portThen f12 or ctrl-shift-i on the browser keyboard to open the developers window.
-
ok thank.
if i want to testreadCSV: fs.readFile('birthdaylist.csv', 'utf8', function (err, data) { var dataArray = data.split(/\r?\n/); Log.log(dataArray);or
readList: function() { var JFile=require('jfile'); var myF=new JFile("MMM-birthday.txt"); myF.lines // ["first line","second line"]i have to do this in node_helper right? and first i have to require them and of course to install them … something i forgot ?
-
@Perlchamp Log.log is ONLY in the browser, but fs. Is not usable in browser
U can test it w node to make sure it works. Then for mm it has to be in node_helper
Install library, so that you CAN require
-
hallo sam :-)
i have now this in my node_helper.js:var NodeHelper = require("node_helper"); // add require of other javascripot components here // var xxx = require('yyy'); here const csv = require("csvtojson"); const csvFilePath = this.path + 'birthdaylist.csv'; module.exports = NodeHelper.create({ init(){ console.log("init module helper perlchamp"); }, start() { console.log("Starting module helper: ${this.name}"); console.log("dieser Pfad: ${this.path}"); csv() .fromFile(csvFilePath) .then((jsonObj)=>{ console.log(jsonObj); }) }, /* stop(){ console.log(`Stopping module helper: ${this.name}`); }, */ // handle messages from our module// each notification indicates a different messages // payload is a data structure that is different per message.. up to you to design this socketNotificationReceived(notification, payload) { console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); // if config message from module if (notification === "CONFIG") { // save payload config info this.config=payload // wait 15 seconds, send a message back to module setTimeout(()=> { this.sendSocketNotification("message_from_helper"," this is a test_message")}, 15000) } else if(notification === "????2") { } }, });terminal says:
Unhandled rejection Error: File does not exist. Check to make sure the file path to your csv is correct. at /home/dirk/MagicMirror/node_modules/csvtojson/v2/Converter.js:81:37 at suppressedCallback (fs.js:209:5) at FSReqCallback.oncomplete (fs.js:153:23)it’s from your SampleModule …
- how can i see the console.log statements in the browser, starting MM ?
- did i enter the code in the right place?
- if I enter the following into the terminal window:
node console.log (‘path: $ {this.path}’)
i got an error message:
bash: Syntaxerror unexpected word `(’
what am I doing wrong ?
many thanks in advance
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login