2 Replies Latest reply on Nov 28, 2018 8:51 AM by RMMorti

    Intel Galileo - Send MySQL Querys from sketch, both running on Galileo

    RMMorti

      Hi everyone, i'm strugling with my project.

       

      I need to connect the skecth running on the galileo with the MySQL server, also running in the same Galileo board.

       

      I could install both Apache and MySQL on the board, and i can connect to MySQL from another client perfeclty, even use some php files stored in the board to execute MySQL queries, but i can't reach the MySQL server, with a skecth, i was testing the examples with library MySQL Connector Arduino, which its compatible with Galileo (acording the last update)

       

      The code stops working at Serial.println("Connecting..."); and nothing happens after that print.

       

      my main goal, is to store data collected by sensors on MySQL running on my Galileo

       

      when using SSH, or simple web brosing, i use the ip: 192.168.0.113 , and it works, i get the index.php i made.

      but, in the MySQL connection on my php files, i need to use 127.0.0.1, as host.

       

      This is the IP config i get from galileo

      Ip galileo.jpg

       

      This is the code:

       

      #include <Ethernet.h>

      #include <MySQL_Connection.h>

      #include <MySQL_Cursor.h>

       

      byte mac_addr[] = {0x98, 0x4F, 0xEE, 0x00, 0x3F, 0x90 };;

      //IPAdress server_addr (192,168,0,1); // IP of the MySQL *server* here

      IPAddress server_addr(127,0,0,1);  // IP of the MySQL *server* here

      char user[] = "root";              // MySQL user login username

      char password[] = "root";        // MySQL user login password

       

      // Sample query

      char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";

       

      EthernetClient client;

      MySQL_Connection conn((Client *)&client);

       

      void setup() {

        Serial.begin(115200);

        while (!Serial); // wait for serial port to connect

        Ethernet.begin(mac_addr);

        Serial.println("Connecting...");

        if (conn.connect(server_addr, 3306, user, password)) {

          delay(1000);

        }

        else

          Serial.println("Connection failed.");

      }

       

      void loop() {

        delay(2000);

       

        Serial.println("Recording data.");

       

        // Initiate the query class instance

        MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);

        // Execute the query

        cur_mem->execute(INSERT_SQL);

        // Note: since there are no results, we do not need to read any data

        // Deleting the cursor also frees up memory used

        delete cur_mem;

      }

       

       

      Sorry for my english, thanks in advance

        • 1. Re: Intel Galileo - Send MySQL Querys from sketch, both running on Galileo
          Intel Corporation
          This message was posted on behalf of Intel Corporation

          Hello RMMorti,

          Thank you for your interest in the Intel Galileo board. 

          Could you please confirm that you are able to access the SQL database from another computer to verify if your user account and permissions used in your sketch can connect to the database server? 

          Both, the Galileo and the MySQL server must be in the same network. You must setup the MySQL server to permit network connections also be sure there are not firewalls or port blocking software to prohibit access to the server (MySQL default port is 3306). 

          Thank you and best regards,
          Eliza

          • 2. Re: Intel Galileo - Send MySQL Querys from sketch, both running on Galileo
            RMMorti

            Hi Eliza, thanks for your reply

             

            i forgot to mention that i'm using AlexT's repo

             

            i did some changes to the skecth, changed the lines

             

            IPAddress server_addr(127,0,0,1);

            to

            byte server_addr[] = {127,0,0,1};

             

            (also tested with 192,168,0,113, both failed)

             

            and now, its doesn't stop on "Connecting..." , but tills, fails to connect, now it show the  "Conection Failed" message, and the MySQL error aswell.

             

            I tested and tried the suggestion you posted

             

            1) Acces from remote computer: i don't know , i can acces with SSH with PuTTY or SCP with WinSCP from my windows PC, i made a php file, wich it connects to MySQL, but the sketch doesn't.
            How can i test it from windows if its possible to access?

             

            2)User, Password: My php files uses root, as user and password and somehow is working. this is the php file

             

            <?php

            $conexion=mysqli_connect("127.0.0.1","root","root","tempt_humd") or die ("Couldn't connect!<br>Error: ".mysqli_connect_error());

            if($conexion){

            echo "Success!";

            }

             

            mysql_close($conexion);

            ?>

             

            I tested some querys, insert, and select, and both working, i guess the user/pass, is fine, btw this is my user tables on mysql, i made a galileo user, but i thought using root was better.

            usertables.jpg

             

             

             

            3) Same Network: Mysql server is running on the Galileo, so i thought, both share the same network, doesn't? by the way, ton my LAN, the galileo have this IP: 192.168.0.113, but i used the 127.0.0.1 (localhost for galileo, i guess) to connect from the php files, LAN ip works, for apache, SSH, and SCP,

             

            4)FireWall: i was trying to get this command to work: iptables -L  , but it give this error:

             

             

            modprobe: module ip_tables not found in modules.dep

            iptables v1.4.17: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)

            Perhaps iptables or your kernel needs to be upgraded.

             

            nmap, its not working on this repo, i duno, how to intalls it, how i can check the firewall?

             

            5)Ports: i got this with netstat -tln , its well congifured? if not, how i can configure the ports?

            puertosgalileo.jpg

             

             

            6) MySQL config file: i did this changes to the my.cf file ,this changes worked with the php files,

             

            [client]

            password = root

            port = 3306

            socket = /var/lib/mysql/mysql.sock

             

            [mysqld_safe]

            err-log = /var/log/mysql.err

             

            [mysqld]

            user = mysql

            port = 3306

            socket = /var/lib/mysql/mysql.sock

            pid-file = /var/lib/mysql/mysqld.pid

            log-error = /var/log/mysqld.err

            basedir = /usr

            datadir = /var/mysql

            skip-locking

            loose-skip-innodb

            #skip-networking

            #bind-address = 0.0.0.0