un petit probleme lors de la compilation maintenant
voici le code
/*
Example queries for using the Connector/Arduino library.
This file contains a number of examples as discussed in the Readme. It
also contains an example of how to use the library with the WiFi shield.
In order to run these examples, you must have the world sample database
installed (http://dev.mysql.com/doc/index-other.html) and the following
databases and tables created:
CREATE DATABASE test_arduino;
CREATE TABLE test_arduino.hello (msg char(50), msg_date timestamp);
CREATE TABLE temps (temp_c float, temp_date timestamp);
Take some time to read through the code before you load and run it.
NOTICE: There are a lot of queries in this file. Together they use a lot
of program space - especially the dtostrf() example. If you attempt
to run all of these at one time, depending on your board you may
run out of space or the sketch may run out of memory and hang.
Thus, if you want to run these tests, I recommend doing them
*one at a time*.
Because of this, all of the examples are commented out. To run one,
just uncomment it and its corresponding string constant at the
top of the file and off you go! :)
*/
#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[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x52, 0x20 };
IPAddress server_addr(192,168,1,4); // 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)
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);
delay(1000);
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
//
// SELECT Examples
//
/*
// EXAMPLE 1
// SELECT query returning rows (built-in methods)
// Here we simply read the columns, print the names, then loop through
// the rows printing the values read. We set a limit to make this something
// that executes in a reasonable timeframe.
my_conn.cmd_query(TEST_SELECT_QUERY);
my_conn.show_results();
*/
/*
// EXAMPLE 2
// SELECT query returning rows (custom method)
// Here we execute the same query as above but use a custom method for reading
// and displaying the results. See the do_query() method above for more
// information about how it works.
do_query(TEST_SELECT_QUERY);
*/
/*
// EXAMPLE 3
// SELECT query for lookup value (1 row returned)
// Here we get a value from the database and use it.
long head_count = 0;
my_conn.cmd_query(QUERY_POP);
// We ignore the columns but we have to read them to get that data out of the queue
my_conn.get_columns();
// Now we read the rows.
row_values *row = NULL;
do {
row = my_conn.get_next_row();
// We use the first value returned in the row - population of NYC!
if (row != NULL) {
head_count = atol(row->values[0]);
}
} while (row != NULL);
// We're done with the buffers so Ok to clear them (and save precious memory).
my_conn.free_columns_buffer();
my_conn.free_row_buffer();
// Now, let's do something with the data.
Serial.print("NYC pop = ");
Serial.println(head_count);
*/
//
// INSERT Examples
//
/*
// EXAMPLE 4
// Inserting static text into a table.
// Here we simply insert text data into a table. No conversion needed.
// It also demonstrates the use of NULL to initiate a timestamp value.
my_conn.cmd_query(INSERT_TEXT);
// Now, let's check our results.
do_query(HELLO_SQL);
*/
/*
// EXAMPLE 5
// Inserting real time data into a table.
// Here we want to insert a row into a table but in this case we are
// simulating reading the data from a sensor or some other component.
// In this case, we 'simulate' reading temperature in celsius.
float value_read = 26.9;
// To use the value in an INSERT statement, we must construct a string
// that has the value inserted in it. For example, what we want is:
// 'INSERT INTO test_arduino.temps VALUES (26.9, NULL)' but the 26.9 is
// held in the variable 'value_read'. So, we use a character string
// formatting operation sprintf(). Notice here we must convert the float
// to a string first and we use the %s specifier in the INSERT_DATA
// string.
char query[64];
char temperature[10];
dtostrf(value_read, 1, 1, temperature);
sprintf(query, INSERT_DATA, temperature);
my_conn.cmd_query(query);
// Now, let's check our results.
do_query(HELLO_DATA);
*/
}
void loop() {
}
On ne voit pas les premières erreurs c'est dommage car cela peut masquer la cause racine des erreurs.
Celles-ci pourraient être causées par une librairie mal installée.
fdufnews:
On ne voit pas les premières erreurs c'est dommage car cela peut masquer la cause racine des erreurs.
Celles-ci pourraient être causées par une librairie mal installée.
mysql_connector.ino: In function 'void do_query(const char*)':
mysql_connector:69: error: 'column_names' was not declared in this scope
mysql_connector:69: error: 'c' was not declared in this scope
mysql_connector:70: error: 'row_values' was not declared in this scope
mysql_connector:70: error: 'r' was not declared in this scope
mysql_connector:85: error: 'class Connector' has no member named 'get_columns'
mysql_connector:100: error: 'class Connector' has no member named 'get_next_row'
mysql_connector:114: error: 'class Connector' has no member named 'free_row_buffer'
mysql_connector:122: error: 'class Connector' has no member named 'free_columns_buffer'
Dans le fichier mysql.h de la librairie il y a des lignes à dé-commenter pour activer certaines fonctionnalités.
//#define WITH_SELECT // Uncomment this for use without SELECT capability
// to save space.
//#define WITH_DEBUG // Uncomment this for enabling debugging of messages
//#define WIFI // Uncomment this for use with the WiFi shield
//#include <WiFi.h> // Uncomment this for use with the WiFi shield
Dans ton cas, il faudrait de-commenter la ligne WITH-SELECT qui conditionne la compilation des definitions qui manquent pour compiler ton code.
fdufnews:
Dans le fichier mysql.h de la librairie il y a des lignes à dé-commenter pour activer certaines fonctionnalités.
//#define WITH_SELECT // Uncomment this for use without SELECT capability
// to save space.
//#define WITH_DEBUG // Uncomment this for enabling debugging of messages
//#define WIFI // Uncomment this for use with the WiFi shield
//#include <WiFi.h> // Uncomment this for use with the WiFi shield
Dans ton cas, il faudrait de-commenter la ligne WITH-SELECT qui conditionne la compilation des definitions qui manquent pour compiler ton code.
je ne suis pas un spécialiste des fichier .H
mais je viens d’éditer le mien et je trouve étrange a comparé des autres
/*
Copyright (c) 2012, 2014 Oracle and/or its affiliates.
All rights reserved.
This program is free software;
you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;
without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program;
if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
mysql.h - Library for communicating with a MySQL Server over Ethernet.
This header file defines the Connector class for connecting to and
issuing queries against a MySQL database. You can issue any command
using SQL statements for inserting or retrieving data.
Dependencies:
- requires the SHA1 code from google code repository. See README.txt
for more details.
Version 1.0.0a Created by Dr. Charles A. Bell, April 2012.
Version 1.0.0b Updated by Dr. Charles A. Bell, October 2013.
Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.
Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.
*/
#ifndef mysql_h
#define mysql_h
#include "Arduino.h"
#include <SPI.h>
#include <Ethernet.h>
//#define WITH_SELECT
// Uncomment this for use without SELECT capability
// to save space.
//#define WITH_DEBUG
// Uncomment this for enabling debugging of messages
//#define WIFI
// Uncomment this for use with the WiFi shield
//#include <WiFi.h>
// Uncomment this for use with the WiFi shield
#define OK_PACKET 0x00
#define EOF_PACKET 0xfe
#define ERROR_PACKET 0xff
#define MAX_FIELDS 0x20
// Maximum number of fields. Reduce to save memory. Default=32
#define VERSION_STR "1.0.2b"
#if defined WITH_SELECT
// Structure for retrieving a field (minimal implementation).
typedef struct {
char *db;
char *table;
char *name;
} field_struct;
// Structure for storing result set metadata.
typedef struct {
int num_fields;
// actual number of fields
field_struct *fields[MAX_FIELDS];
} column_names;
// Structure for storing row data.
typedef struct {
char *values[MAX_FIELDS];
} row_values;
#endif
/**
* Connector class
*
* The connector class permits users to connect to and issue queries
*
against a MySQL database. It is a lightweight connector with the
* following features.
*
*
- Connect and authenticate with a MySQL server (using 'new' 4.1+
* protocol).
*
- Issue simple commands like INSERT, UPDATE, DELETE, SHOW, etc.
*
- Run queries that return result sets.
*
* There are some strict limitations:
*
*
- Queries must fit into memory. This is because the class uses an
* internal buffer for building data packets to send to the server.
*
It is suggested long strings be stored in program memory using
* P
ROGMEM (see cmd_query_P).
* - Result sets are read one row-at-a-time.
*
- The combined length of a row in a result set must fit into
* memory. The connector reads one packet-at-a-time and since the
*
Arduino has a limited data size, the combined length of all fields
* must be less than available memory.
* -
Server error responses are processed immediately with the error
* code and text written via Serial.print.
*/
class Connector
{
public:
Connector();
boolean mysql_connect(IPAddress server, int port,
char *user, char *password);
void disconnect();
boolean cmd_query(const char *query);
boolean cmd_query_P(const char *query);
int is_connected () { return client.connected();
}
const char *version() { return VERSION_STR; }
#if defined WITH_SELECT
column_names *get_columns();
row_values *get_next_row();
void free_columns_buffer();
void free_row_buffer();
void show_results();
#endif
private:
byte *buffer;
char *server_version;
byte seed[20];
int packet_len;
#if defined WITH_SELECT
column_names columns;
boolean columns_read;
int num_cols;
row_values row;
#endif
// Determine if WiFi shield is used
#if defined WIFI
WiFi
Client client;
#else
EthernetClient client;
#endif
// Methods for handling packets
int wait_for_client();
void send_authentication_packet(char *user, char *password);
void read_packet();
void parse_handshake_packet();
int check_ok_packet();
void parse_error_packet();
boolean run_query(int query_len);
// Utility methods
boolean scramble_password(char *password, byte *pwd_hash);
int get_lcb_len(int offset);
int read_int(int offset, int size=0);
void store_int(byte *buff, long value, int size);
#if defined WITH_SELECT
char *read_string(int *offset);
int get_field(field_struct *fs);
int get_row();
boolean get_fields();
boolean get_row_values();
column_names *query_result();
#endif
// diagnostic methods
#if defined WITH_DEBUG
void print_packet();
#endif
void print_message(const char *msg, bool EOL = false) {
char pos;
while ((pos = pgm_read_byte(msg))) {
Serial.print(pos);
msg++;
}
if (EOL)
Serial.println();
}
};
#endif
quelqu'un pourrai donc me renvoyer sont fichier .h qui fonctionne
fdufnews:
Il n'y a pas besoin d'être spécialiste pour enlever // devant une ligne.
//#define WITH_SELECT // Uncomment this for use without SELECT capability
// to save space.
devient ça
#define WITH_SELECT // Uncomment this for use without SELECT capability
// to save space.
C'est quand même pas très complexe
Cette manip a deja ete faite mais aucun changement ... voila pourquoi je voulais un autre fichier .H
mysql_connector.ino: In function 'void do_query(const char*)':
mysql_connector:69: error: 'column_names' was not declared in this scope
mysql_connector:69: error: 'c' was not declared in this scope
mysql_connector:70: error: 'row_values' was not declared in this scope
mysql_connector:70: error: 'r' was not declared in this scope
mysql_connector:85: error: 'class Connector' has no member named 'get_columns'
mysql_connector:100: error: 'class Connector' has no member named 'get_next_row'
mysql_connector:114: error: 'class Connector' has no member named 'free_row_buffer'
mysql_connector:122: error: 'class Connector' has no member named 'free_columns_buffer'