5/20/2023 10:40 AM | |
Joined: 3/30/2023 Last visit: 5/20/2023 Posts: 1 Rating: (0) |
Hi everyone, recently I create IOTDatabase in MariaDB to store values from sensors. I follow the guide (link: I follow the guide in https://github.com/SIMATICmeetsLinux/IOT2050-NodeRed-DataCollector/blob/main/docs/README_IOT2050SETUP.md), everything is OK but when I try to use a Nodejs code to export the table from IOTDatatable (in IOTDatabase), it has error. Here is my code: const mysql=require('mysql'); // Create a connection to the MySQL server constconnection=mysql.createConnection({ host:"192.168.0.10", user:"iotuser", password:"1", database:"IOTDatabase", port:"3306" }); // Connect to the MySQL server connection.connect((error)=>{ if(error) { console.error('Error connecting to MySQL server: ',error); return; } console.log('Connected to MySQL server'); }); // Define the SQL query to read data from the database constquery='SELECT * FROM IOTDatatable'; // Execute the query connection.query(query, (error,results,fields)=>{ if(error) { console.error('Error executing query: ',error); return; } console.log('Result: ',results); }); // Close the connection to the MySQL server when done connection.end(); And this error occurs: Error executing query: Error: connect ECONNREFUSED 192.168.0.10:3306 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) -------------------- at Protocol._enqueue (C:\Users\AN515-57\Desktop\HK222\Thesis\IOT2050\Node_red\CodeNodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48) at Protocol.handshake (C:\Users\AN515-57\Desktop\HK222\Thesis\IOT2050\Node_red\CodeNodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23) at Connection.connect (C:\Users\AN515-57\Desktop\HK222\Thesis\IOT2050\Node_red\CodeNodejs\node_modules\mysql\lib\Connection.js:116:18) at Object.<anonymous> (C:\Users\AN515-57\Desktop\HK222\Thesis\IOT2050\Node_red\CodeNodejs\docBang.js:36:12) at Module._compile (node:internal/modules/cjs/loader:1254:14) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) at node:internal/main/run_main_module:23:47 { errno: -4078, code: 'ECONNREFUSED', syscall: 'connect', address: '192.168.0.10', port: 3306, fatal: true } No firewall at all in IoT2050. How can I fix that? I tried above code with IoT2040, and it worked well. |
Follow us on