ralberth / MMM-MysqlQuery

MagicMirror plug-in module that displays a table of MySQL SELECT results
MIT License
8 stars 3 forks source link

Blank table / mirror doesn't load at all #5

Closed ralberth closed 5 years ago

ralberth commented 5 years ago

Bringing an email conversation from Jack G. over here so we track it at the project repo

I would like to start off by saying your Magic Mirror Module for Displaying MySQL data is exactly what I am looking for! However when trying to use it I get a blank table, or my Mirror Doesn't load at all.

The data base that I am trying to pull from is local to my network. So for host config I am using the local ip address of my database. I am using the standard weather module, Calendar, Date and Time, as well as the last FM scrobbler module. Am I able to pull from a local database? Please let me know if you can.

ralberth commented 5 years ago

Issue https://github.com/ralberth/MMM-MysqlQuery/issues/1 might have what you are looking for, or it might at least give you some ideas for troubleshooting.

Ideas:

  1. Comment out all other modules in your config/config.js file (this eliminates problems between modules and makes sure all logging applies only to MMM-MySql module)
  2. Type npm start dev to startup and log to the terminal, see if you see any error messages
  3. Copy what you see into this issue
  4. Paste in here what your configuration is in config/config.js for this module, so we can see the actual SQL SELECT or other SQL work you're sending to the server.
  5. Depending on your browser, right-click, select "Inspect element", click "Console" and paste any error messages here (be brief!) if they look telling. Other browsers keep it under a developer menu or other top-line menu.
jgamble49 commented 5 years ago

Rich, Iv'e since deleted that database as well as the Web pages used to POST to it. I will recreate it in the future because I would love to get your module working, however I do not have the time. Once I recreate the environment can I contact you? If it is easier we can close this issue and maybe reopen one in the future. Thanks, Jack

ralberth commented 5 years ago

No prob, sorry it wasn't working "out of the box" for you. I'll close it for now. Whenever you're ready, please re-open https://github.com/ralberth/MMM-MysqlQuery/issues/5 and we'll pick up where we left off!

Cheers,

On Fri, Feb 15, 2019 at 9:09 PM jgamble49 notifications@github.com wrote:

Rich, Iv'e since deleted that database as well as the Web pages used to POST to it. I will recreate it in the future because I would love to get your module working, however I do not have the time. Once I recreate the environment can I contact you? If it is easier we can close this issue and maybe reopen one in the future. Thanks, Jack

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ralberth/MMM-MysqlQuery/issues/5#issuecomment-464273715, or mute the thread https://github.com/notifications/unsubscribe-auth/AAChNdTWFc8CMcvyLOXH2KoN7UCV_oSEks5vN2hlgaJpZM4anX-8 .

ralberth commented 5 years ago

I talked with Jack over email...resolving for now until he gets time to get back to MagicMirror.

jgamble49 commented 5 years ago

Hey Rich,

Sorry about the delay! I am having an issue where the table populates, but with no data.

Here is the error I receive after commenting out all other modules, running the mirror, and running "npm start dev". The following is what was contained in the log file:

0 info it worked if it ends with ok 1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start', 'dev' ] 2 info using npm@5.6.0 3 info using node@v9.11.2 4 verbose stack Error: missing script: start 4 verbose stack at run (/usr/lib/node_modules/npm/lib/run-script.js:151:19) 4 verbose stack at /usr/lib/node_modules/npm/lib/run-script.js:61:5 4 verbose stack at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:115:5 4 verbose stack at /usr/lib/node_modules/npm/nodemodules/read-package-json/read-json.js:402:5 4 verbose stack at checkBinReferences (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:357:45) 4 verbose stack at final (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:400:3) 4 verbose stack at then (/usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:160:5) 4 verbose stack at /usr/lib/node_modules/npm/node_modules/read-package-json/read-json.js:348:12 4 verbose stack at /usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:525:3) 5 verbose cwd /home/pi/MagicMirror/modules/MMM-MysqlQuery 6 verbose Linux 4.14.79-v7+ 7 verbose argv "/usr/bin/node" "/usr/bin/npm" "start" "dev" 8 verbose node v9.11.2 9 verbose npm v5.6.0 10 error missing script: start 11 verbose exit [ 1, true ]

ralberth commented 5 years ago

Bummer!

This is what I see on my MagicMirror:

% npm start dev

> magicmirror@2.4.1 start
> sh run-start.sh "dev"

Starting MagicMirror: v2.4.1
Loading config ...
Loading module helpers ...
Initializing new module helper ...
Module helper loaded: MMM-MysqlQuery
All module helpers loaded.
Starting server on port 8089 ...
Server started ...
Connecting socket for: MMM-MysqlQuery
Starting module helper: MMM-MysqlQuery
Sockets connected & modules started ...
Launching application.

You're seeing a stack dump from MM, specifically the Error: missing script: start catches my eye. This is npm complaining that it can't find a start to execute, I think. Frankly, I'm not sure, it's kind of a guess.

There aren't any MagicMirror files in the execution stack, so let's just blame npm and move on. How about node server as another try? That'll get MagicMirror up and running and we'll have a log to look at.

jgamble49 commented 5 years ago

Honestly dude I'm a huge novice at this kinda stuff, so thank you for the help so far. I ran the npm start dev with out the MysqlQuery Module and the mirror started up normally.

I was able to get "npm start dev" to launch the application with just the MysqlQuery Module. In the console there are no errors, just two security warnings in reference to electron.

Here is my config for the module:

{
    module: 'MMM-MysqlQuery',
    position: "bottom_bar",
    config: {
        connection: {
            host: "local ip of database",
            port: 3306,
            user: "username for database",
            password: "password for data base",
            database: "data base name"
        },
        query: "SELECT * FROM `comments`",
        intervalSeconds: 1 * 60,
        emptyMessage: "No data",
        columns: [
            { name: "id" },
            { name: "name" },
            { name: "comment" }
        ]
    }
}

Here is what is returned when I run "node server"

internal/modules/cjs/loader.js:550
    throw err;
    ^

Error: Cannot find module '/home/pi/server'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:548:15)
    at Function.Module._load (internal/modules/cjs/loader.js:475:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)
ralberth commented 5 years ago

My bad, and thanks for the error...running it on Raspberry Pi is different.

Here's where we are so far:

Starting module helper: MMM-MysqlQuery saw in the log when running the module, so the server-side is up and running. This listens for requests from Electron/browser/whatever for queries to run.

You mentioned that there are rows in the database so we're good there. If you want to double-check your settings in the config.js file, run the cmdline_test.js file under modules/MMM-MysqlQuery. There's a sample invocation inside the file. Running this with the values you put in your config.js file will validate that MagicMirror can reach the database and the settings are correct. you'll see results from your database.

Next is to find out why your browser (Electron likely) isn't sending db queries to the MMM-MysqlQuery server code. In Electron, select "Toggle Developer Tools" on the menu (I'm a Mac, not sure where it is if you're a PC). This brings up a separate panel of all the low-level guts of the app. Click the Network tab. Select "Reload" from the menu. The Network panel will fill up with requests. These are HTTP things sent from Electron to your MM server, one of which is the MMM-MysqlQuery thing. Look in the Status column. Anything between 100 and 399 is good. Anything 400+ is bad.

Let me know if anything there is bad.

Next, click the Console tab on the developer tools pane. Hopefully you at least see "All modules started!" on a line. This is an important milestone where MMM has started all the code that needs to run in Electron, including MMM-MysqlQuery. Let me know if you see anything red/pink, or anything with "error" or something that stands-out.

jgamble49 commented 5 years ago

After running the cmdline_test.js with the same credentials that the mirror was using I got a connection error. I researched the error and my database was only allowing local connections. After editing the config file to allow outside connections it worked! Sorry to bother you with an issue that was of my own doing, but I really appreciate all the help! You can consider this issue resolved, once again, thanks for all the help!

ralberth commented 5 years ago

Woo hoo! Glad you have it working! That makes me happy to know it was solved and you didn't have to waste a lot more time sorting out problems. Congrats.