ralberth / MMM-MysqlQuery

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

Combining modules (Temperature data --> MySQL server) #3

Closed qLience closed 5 years ago

qLience commented 5 years ago

Hello there, First of all i am trying to combine yours and https://github.com/Thlb/MMM-temp-ds18b20 because i want to sent my temperature data to a MySQL server. Im new in Javascript so i would like to know where to start with this problem.

Best regards Søren Koch

ralberth commented 5 years ago

Sorry for delay, I missed the automated email letting me know this was posted.

Would you please give more information on how temperature data should move? I think https://github.com/Thlb/MMM-temp-ds18b20 will get temperature data and display it via the server code https://github.com/Thlb/MMM-temp-ds18b20/blob/master/node_helper.js

This doesn't store data anywhere. It only uses MagicMirror library to communicate from the MagicMirror server (running on the same machine) to the browser display.

Would you like temperature data to be stored in MySQL, display it with MMM-MysqlQuery, and then use the MySQL data elsewhere? This would be a good use for MySQL in between the modules.

If you are interested in using MMM-temp-ds10b20 to get temperature data, and then display it in MagicMirror just like MMM-MysqlQuery does, there may be a simpler way: https://github.com/Thlb/MMM-temp-ds18b20/blob/master/MMM-temp-ds18b20.css is the CSS file that controls how MMM-temp-ds18b20 displays the temperature. You may be able to supply your own CSS file that moves each value around so the display is what you want. This is less modules to configure, but the CSS will be ugly and complex.

Another idea is to take the JavaScript code from https://github.com/Thlb/MMM-temp-ds18b20/blob/master/node_helper.js and put it in your own, separate file. This file would get the temperature from all your devices and insert them into a MySQL database table. Use a scheduler to run this file outside of MagicMirror entirely. On a Linux machine you could use cron. On a Windows machine, Task Scheduler.

Then, you can use MMM-MysqlQuery to simply "select device_name, current_temp from mytemps order by device_name".

var Sensor = require('ds18x20');
var mysql = require("mysql");

var con = mysql.createConnection(/* parameters to connect to mysql */);
con.connect(function(err) {
   ...
   for (/*loop over a config file?*/) {
      value = Sensor.get(sensor_id);
      con.query("delete from temperatures where sensor_name = '" + sensor_id + "'",
                   function(err, result) {
                      ...
                      con.query("insert into temperatures (sensor_name, value) values ('" + 
sensor_id + "', '" + value + "')", ...);
...

You might also want to borrow the formatTempValue method there too.

ralberth commented 5 years ago

Checking back in, it's been a few weeks. Are you still in trouble or did you find a way forward?

NewLoewe commented 5 years ago

Hi, this is a great Module for the MagicMirror. Exists this Module also for a Conecction to Microsoft SQL Database, because i work with a MS SQL Database. Thanks

ralberth commented 5 years ago

Closed for now, it's been since February without any action. If you are still seeing problems, PLEASE reopen this and we'll do more work on it!