• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
Leonardo + ENC28j60 bezpośrednie połączenie z mysql
#1
Cześć,
posiadam taki zestaw jak wyżej.

Wcześniej skonfigurowałem bibliotekę EtherCard.h (musiałem w bibliotece inaczej zdefiniować PIN żeby było połączenie(może to jest jakaś istotna wiadomość do tego wpisu)) i bez problemu byłem podłączony z siecią. Teraz chciałem połączyć się bezpośrednio przez arduino leonardo z bazą danych mysql używając biblioteki MySQL_Connection, lecz po prawidłowym wpisaniu danych logowania i IP nie mam połączenia z bazą. W tym przykładowym sketchu tej biblioteki używana jest też biblioteka Ethernet.h i chyba w tym miejscu leży problem, gdyż Ethernet.h nie jest kompatybilne z ENC28J60? Gdy miałbym ethernet shield'a to raczej nie byłoby problemu? Czy się mylę? 


SKETCH MYSQL CONNECTOR:
Kod:
#include <SPI.h>
#include <Ethernet.h>
#include <sha1.h>
//#include <avr/dtostrf.h>  // Add this for the Due if you need drostrf
#include <stdlib.h>
//#include <WiFi.h>  // Use this for WiFi
#include <mysql.h>

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(10,0,1,13);  // Supply the IP of the MySQL *server* here

char user[] = "root";         // can be anything but the user must have
char password[] = "secret";   // access rights to connect (host must permit it)

// WiFi card example
//char ssid[] = "my_lonely_ssid";
//char pass[] = "horse_no_name";

Connector my_conn;        // The Connector/Arduino reference

// String constants for examples. Uncomment those you need.

//const char TEST_SELECT_QUERY[] = "SELECT * FROM world.city LIMIT 10";
//const char QUERY_POP[] = "SELECT population FROM world.city WHERE name = 'New York'";
//const char INSERT_TEXT[] = "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!', NULL)";
//const char INSERT_DATA[] = "INSERT INTO test_arduino.temps VALUES (%s, NULL)";
//const char HELLO_SQL[] = "SELECT * from test_arduino.hello";
//const char HELLO_DATA[] = "SELECT * from test_arduino.temps";

/**
* do_query - execute a query and display results
*
* This method demonstrates how to execute a query, get the column
* names and print them, then read rows printing the values. It
* is a mirror of the show_results() example in the connector class.
*
* You can use this method as a template for writing methods that
* must iterate over rows from a SELECT and operate on the values read.
*
*/
void do_query(const char *q) {
 column_names *c; // pointer to column values
 row_values *r;   // pointer to row values

 // First, execute query. If it returns a value pointer,
 // we have a result set to process. If not, we exit.
 if (!my_conn.cmd_query(q)) {
   return;
 }

 // Next, we read the column names and display them.
 //
 // NOTICE: You must *always* read the column names even if
 //         you do not use them. This is so the connector can
 //         read the data out of the buffer. Row data follows the
 //         column data and thus must be read first.

 c = my_conn.get_columns();
 for (int i = 0; i < c->num_fields; i++) {
   Serial.print(c->fields[i]->name);
   if (i < c->num_fields - 1) {
     Serial.print(",");
   }
 }
 Serial.println();

 // Next, we use the get_next_row() iterator and read rows printing
 // the values returned until the get_next_row() returns NULL.

 int num_cols = c->num_fields;
 int rows = 0;
 do {
   r = my_conn.get_next_row();
   if (r) {
     rows++;
     for (int i = 0; i < num_cols; i++) {
       Serial.print(r->values[i]);
       if (i < num_cols - 1) {
         Serial.print(", ");
       }
     }
     Serial.println();

     // Note: we free the row read to free the memory allocated for it.
     // You should do this after you've processed the row.

     my_conn.free_row_buffer();
   }
 } while (r);
 Serial.print(rows);
 Serial.println(" rows in result.");

 // Finally, we are done so we free the column buffers

 my_conn.free_columns_buffer();
}

void setup() {
 Serial.begin(115200);
 while (!Serial); // wait for serial port to connect. Needed for Leonardo only

 Ethernet.begin(mac_addr);

 // WiFi section
//  int status = WiFi.begin(ssid, pass);
//  // if you're not connected, stop here:
//  if ( status != WL_CONNECTED) {
//    Serial.println("Couldn't get a wifi connection");
//    while(true);
//  }
//  // if you are connected, print out info about the connection:
//  else {
//    Serial.println("Connected to network");
//    IPAddress ip = WiFi.localIP();
//    Serial.print("My IP address is: ");
//    Serial.println(ip);
//  }

 delay(1000);
 Serial.println("Connecting...");
 if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
   delay(1000);
 }
 else
   Serial.println("Connection failed.");


}

void loop() {
}



Może ma ktoś pomysł jak można rozwiązać ten problem? Z góry dziękuję za odpowiedź.
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości