Merge lp:~chuck-bell/mysql-arduino/release-1.0.4-ga into lp:~chuck-bell/mysql-arduino/release-1.0.3-rc

Proposed by Alexy
Status: Needs review
Proposed branch: lp:~chuck-bell/mysql-arduino/release-1.0.4-ga
Merge into: lp:~chuck-bell/mysql-arduino/release-1.0.3-rc
Diff against target: 662 lines (+273/-303)
6 files modified
CHANGES.txt (+5/-0)
Readme.txt (+3/-37)
examples/mysql_connector/mysql_connector.ino (+258/-0)
mysql.cpp (+4/-6)
mysql.h (+3/-2)
mysql_connector.ino (+0/-258)
To merge this branch: bzr merge lp:~chuck-bell/mysql-arduino/release-1.0.4-ga
Reviewer Review Type Date Requested Status
Chuck Bell Pending
Review via email: mp+275301@code.launchpad.net

Description of the change

please check this https://github.com/esp8266/Arduino/issues/916

We want port your beautiful library to esp8266 arduino compatible system . Can you help us ?
I not find other method to communicate to you

To post a comment you must log in.

Unmerged revisions

6. By Chuck Bell

Adding latest updates.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CHANGES.txt'
--- CHANGES.txt 2015-03-04 15:33:05 +0000
+++ CHANGES.txt 2015-10-22 10:38:35 +0000
@@ -3,6 +3,11 @@
3This file contains a brief summary of changes made from previous versions of3This file contains a brief summary of changes made from previous versions of
4the connector.4the connector.
55
61.0.4ga - July 2015
7--------------------
8* Fixed a defect in the get_next_row() method.
9* Added the reference manual. Yippee!
10
61.0.3rc - March 2015111.0.3rc - March 2015
7--------------------12--------------------
8* Code has been changed slightly to help with long latency issues over13* Code has been changed slightly to help with long latency issues over
914
=== modified file 'Readme.txt'
--- Readme.txt 2013-10-23 19:56:58 +0000
+++ Readme.txt 2015-10-22 10:38:35 +0000
@@ -77,40 +77,6 @@
7777
78Documentation78Documentation
79-------------79-------------
80The documentation for the connector library is a work in progress. In the80The documentation for the connector library is included with the source
81meantime, I have written a couple of blogs about the connector that explain81files. I have also written a couple of blogs about the connector that explain
82how to use it. Please refer to the blogs until such time there is sufficient82how to use it.
83documentation available.
84
85
86Dependency: SHA1 library
87------------------------
88The Connector/Arduino requires the SHA1 library from the following link.
89
90Note: The single file download already has this library with the changes
91described below already applied so there is nothing for you to do. However, if
92you cloned the connector library instead of using the download, please download
93the SHA1 library, install it, and read on for modifications needed to this
94library.
95
96http://code.google.com/p/cryptosuite/downloads/list
97
98You must download and install that library first and include it in your
99project. The following shows all of the library header files you need to
100include.
101
102#include <SPI.h>
103#include <Ethernet.h>
104#include <sha1.h>
105#include <avr/pgmspace.h>
106#include "mysql.h"
107
108NOTICE: The SHA1 library may not compile correctly in your IDE. A change is
109needed to ensure it will compile correctly. See the sha1.diff file for
110details.
111
112We also do not need some of the features in the SHA1 library and since it takes
113up space, we can eliminate them. If you would like to remove the unneeded code
114from the SHA1 library, apply the sha1_no256.diff file to remove them and
115delete the sha1256.h and sh1256.cpp files. This will save you about 2k of
116program space.
11783
=== added directory 'examples/mysql_connector'
=== added file 'examples/mysql_connector/mysql_connector.ino'
--- examples/mysql_connector/mysql_connector.ino 1970-01-01 00:00:00 +0000
+++ examples/mysql_connector/mysql_connector.ino 2015-10-22 10:38:35 +0000
@@ -0,0 +1,258 @@
1/*
2 Example queries for using the Connector/Arduino library.
3
4 This file contains a number of examples as discussed in the Readme. It
5 also contains an example of how to use the library with the WiFi shield.
6
7 In order to run these examples, you must have the world sample database
8 installed (http://dev.mysql.com/doc/index-other.html) and the following
9 databases and tables created:
10
11 CREATE DATABASE test_arduino;
12 CREATE TABLE test_arduino.hello (msg char(50), msg_date timestamp);
13 CREATE TABLE temps (temp_c float, temp_date timestamp);
14
15 Take some time to read through the code before you load and run it.
16
17 NOTICE: There are a lot of queries in this file. Together they use a lot
18 of program space - especially the dtostrf() example. If you attempt
19 to run all of these at one time, depending on your board you may
20 run out of space or the sketch may run out of memory and hang.
21 Thus, if you want to run these tests, I recommend doing them
22 *one at a time*.
23
24 Because of this, all of the examples are commented out. To run one,
25 just uncomment it and its corresponding string constant at the
26 top of the file and off you go! :)
27*/
28#include <SPI.h>
29#include <Ethernet.h>
30#include <sha1.h>
31//#include <avr/dtostrf.h> // Add this for the Due if you need drostrf
32#include <stdlib.h>
33//#include <WiFi.h> // Use this for WiFi
34#include <mysql.h>
35
36byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
37IPAddress server_addr(10,0,1,13); // Supply the IP of the MySQL *server* here
38
39char user[] = "root"; // can be anything but the user must have
40char password[] = "secret"; // access rights to connect (host must permit it)
41
42// WiFi card example
43//char ssid[] = "my_lonely_ssid";
44//char pass[] = "horse_no_name";
45
46Connector my_conn; // The Connector/Arduino reference
47
48// String constants for examples. Uncomment those you need.
49
50//const char TEST_SELECT_QUERY[] = "SELECT * FROM world.city LIMIT 10";
51//const char QUERY_POP[] = "SELECT population FROM world.city WHERE name = 'New York'";
52//const char INSERT_TEXT[] = "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!', NULL)";
53//const char INSERT_DATA[] = "INSERT INTO test_arduino.temps VALUES (%s, NULL)";
54//const char HELLO_SQL[] = "SELECT * from test_arduino.hello";
55//const char HELLO_DATA[] = "SELECT * from test_arduino.temps";
56
57/**
58 * do_query - execute a query and display results
59 *
60 * This method demonstrates how to execute a query, get the column
61 * names and print them, then read rows printing the values. It
62 * is a mirror of the show_results() example in the connector class.
63 *
64 * You can use this method as a template for writing methods that
65 * must iterate over rows from a SELECT and operate on the values read.
66 *
67 */
68void do_query(const char *q) {
69 column_names *c; // pointer to column values
70 row_values *r; // pointer to row values
71
72 // First, execute query. If it returns a value pointer,
73 // we have a result set to process. If not, we exit.
74 if (!my_conn.cmd_query(q)) {
75 return;
76 }
77
78 // Next, we read the column names and display them.
79 //
80 // NOTICE: You must *always* read the column names even if
81 // you do not use them. This is so the connector can
82 // read the data out of the buffer. Row data follows the
83 // column data and thus must be read first.
84
85 c = my_conn.get_columns();
86 for (int i = 0; i < c->num_fields; i++) {
87 Serial.print(c->fields[i]->name);
88 if (i < c->num_fields - 1) {
89 Serial.print(",");
90 }
91 }
92 Serial.println();
93
94 // Next, we use the get_next_row() iterator and read rows printing
95 // the values returned until the get_next_row() returns NULL.
96
97 int num_cols = c->num_fields;
98 int rows = 0;
99 do {
100 r = my_conn.get_next_row();
101 if (r) {
102 rows++;
103 for (int i = 0; i < num_cols; i++) {
104 Serial.print(r->values[i]);
105 if (i < num_cols - 1) {
106 Serial.print(", ");
107 }
108 }
109 Serial.println();
110
111 // Note: we free the row read to free the memory allocated for it.
112 // You should do this after you've processed the row.
113
114 my_conn.free_row_buffer();
115 }
116 } while (r);
117 Serial.print(rows);
118 Serial.println(" rows in result.");
119
120 // Finally, we are done so we free the column buffers
121
122 my_conn.free_columns_buffer();
123}
124
125void setup() {
126 Serial.begin(115200);
127 while (!Serial); // wait for serial port to connect. Needed for Leonardo only
128
129 Ethernet.begin(mac_addr);
130
131 // WiFi section
132// int status = WiFi.begin(ssid, pass);
133// // if you're not connected, stop here:
134// if ( status != WL_CONNECTED) {
135// Serial.println("Couldn't get a wifi connection");
136// while(true);
137// }
138// // if you are connected, print out info about the connection:
139// else {
140// Serial.println("Connected to network");
141// IPAddress ip = WiFi.localIP();
142// Serial.print("My IP address is: ");
143// Serial.println(ip);
144// }
145
146 delay(1000);
147 Serial.println("Connecting...");
148 if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
149 delay(1000);
150 }
151 else
152 Serial.println("Connection failed.");
153
154 //
155 // SELECT Examples
156 //
157
158/*
159 // EXAMPLE 1
160
161 // SELECT query returning rows (built-in methods)
162 // Here we simply read the columns, print the names, then loop through
163 // the rows printing the values read. We set a limit to make this something
164 // that executes in a reasonable timeframe.
165
166 my_conn.cmd_query(TEST_SELECT_QUERY);
167 my_conn.show_results();
168*/
169/*
170 // EXAMPLE 2
171
172 // SELECT query returning rows (custom method)
173 // Here we execute the same query as above but use a custom method for reading
174 // and displaying the results. See the do_query() method above for more
175 // information about how it works.
176
177 do_query(TEST_SELECT_QUERY);
178*/
179/*
180 // EXAMPLE 3
181
182 // SELECT query for lookup value (1 row returned)
183 // Here we get a value from the database and use it.
184
185 long head_count = 0;
186 my_conn.cmd_query(QUERY_POP);
187
188 // We ignore the columns but we have to read them to get that data out of the queue
189
190 my_conn.get_columns();
191
192 // Now we read the rows.
193
194 row_values *row = NULL;
195 do {
196 row = my_conn.get_next_row();
197 // We use the first value returned in the row - population of NYC!
198 if (row != NULL) {
199 head_count = atol(row->values[0]);
200 }
201 } while (row != NULL);
202
203 // We're done with the buffers so Ok to clear them (and save precious memory).
204
205 my_conn.free_columns_buffer();
206 my_conn.free_row_buffer();
207
208 // Now, let's do something with the data.
209
210 Serial.print("NYC pop = ");
211 Serial.println(head_count);
212*/
213
214 //
215 // INSERT Examples
216 //
217
218/*
219 // EXAMPLE 4
220
221 // Inserting static text into a table.
222 // Here we simply insert text data into a table. No conversion needed.
223 // It also demonstrates the use of NULL to initiate a timestamp value.
224
225 my_conn.cmd_query(INSERT_TEXT);
226 // Now, let's check our results.
227 do_query(HELLO_SQL);
228*/
229/*
230 // EXAMPLE 5
231
232 // Inserting real time data into a table.
233 // Here we want to insert a row into a table but in this case we are
234 // simulating reading the data from a sensor or some other component.
235 // In this case, we 'simulate' reading temperature in celsius.
236
237 float value_read = 26.9;
238
239 // To use the value in an INSERT statement, we must construct a string
240 // that has the value inserted in it. For example, what we want is:
241 // 'INSERT INTO test_arduino.temps VALUES (26.9, NULL)' but the 26.9 is
242 // held in the variable 'value_read'. So, we use a character string
243 // formatting operation sprintf(). Notice here we must convert the float
244 // to a string first and we use the %s specifier in the INSERT_DATA
245 // string.
246
247 char query[64];
248 char temperature[10];
249 dtostrf(value_read, 1, 1, temperature);
250 sprintf(query, INSERT_DATA, temperature);
251 my_conn.cmd_query(query);
252 // Now, let's check our results.
253 do_query(HELLO_DATA);
254*/
255}
256
257void loop() {
258}
0259
=== modified file 'mysql.cpp'
--- mysql.cpp 2015-03-04 15:14:29 +0000
+++ mysql.cpp 2015-10-22 10:38:35 +0000
@@ -25,6 +25,7 @@
25 Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.25 Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.
26 Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.26 Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.
27 Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.27 Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.
28 Version 1.0.4ga Updated by Dr. Charles A. Bell, July 2015.
28*/29*/
29#include "Arduino.h"30#include "Arduino.h"
30#include "mysql.h"31#include "mysql.h"
@@ -1008,7 +1009,7 @@
1008 * in the class.1009 * in the class.
1009 *1010 *
1010*/1011*/
1011boolean Connector::get_row_values() {1012int Connector::get_row_values() {
1012 int res = 0;1013 int res = 0;
1013 int offset = 0;1014 int offset = 0;
10141015
@@ -1016,7 +1017,7 @@
1016 // are read.1017 // are read.
1017 if (!columns_read) {1018 if (!columns_read) {
1018 print_message(READ_COLS, true);1019 print_message(READ_COLS, true);
1019 return true;1020 return EOF_PACKET;
1020 }1021 }
1021 // Drop any row data already read1022 // Drop any row data already read
1022 free_row_buffer();1023 free_row_buffer();
@@ -1029,10 +1030,7 @@
1029 row.values[f] = read_string(&offset);1030 row.values[f] = read_string(&offset);
1030 }1031 }
1031 }1032 }
1032 else {1033 return res;
1033 return res;
1034 }
1035 return true;
1036}1034}
10371035
1038#endif1036#endif
10391037
=== modified file 'mysql.h'
--- mysql.h 2015-03-04 15:14:29 +0000
+++ mysql.h 2015-10-22 10:38:35 +0000
@@ -30,6 +30,7 @@
30 Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.30 Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.
31 Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.31 Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.
32 Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.32 Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.
33 Version 1.0.4ga Updated by Dr. Charles A. Bell, July 2015.
33*/34*/
34#ifndef mysql_h35#ifndef mysql_h
35#define mysql_h36#define mysql_h
@@ -50,7 +51,7 @@
50#define EOF_PACKET 0xfe51#define EOF_PACKET 0xfe
51#define ERROR_PACKET 0xff52#define ERROR_PACKET 0xff
52#define MAX_FIELDS 0x20 // Maximum number of fields. Reduce to save memory. Default=3253#define MAX_FIELDS 0x20 // Maximum number of fields. Reduce to save memory. Default=32
53#define VERSION_STR "1.0.3rc"54#define VERSION_STR "1.0.4ga"
5455
55#if defined WITH_SELECT56#if defined WITH_SELECT
5657
@@ -157,7 +158,7 @@
157 int get_field(field_struct *fs);158 int get_field(field_struct *fs);
158 int get_row();159 int get_row();
159 boolean get_fields();160 boolean get_fields();
160 boolean get_row_values();161 int get_row_values();
161 column_names *query_result();162 column_names *query_result();
162#endif163#endif
163164
164165
=== removed file 'mysql_connector.ino'
--- mysql_connector.ino 2013-10-23 19:56:58 +0000
+++ mysql_connector.ino 1970-01-01 00:00:00 +0000
@@ -1,258 +0,0 @@
1/*
2 Example queries for using the Connector/Arduino library.
3
4 This file contains a number of examples as discussed in the Readme. It
5 also contains an example of how to use the library with the WiFi shield.
6
7 In order to run these examples, you must have the world sample database
8 installed (http://dev.mysql.com/doc/index-other.html) and the following
9 databases and tables created:
10
11 CREATE DATABASE test_arduino;
12 CREATE TABLE test_arduino.hello (msg char(50), msg_date timestamp);
13 CREATE TABLE temps (temp_c float, temp_date timestamp);
14
15 Take some time to read through the code before you load and run it.
16
17 NOTICE: There are a lot of queries in this file. Together they use a lot
18 of program space - especially the dtostrf() example. If you attempt
19 to run all of these at one time, depending on your board you may
20 run out of space or the sketch may run out of memory and hang.
21 Thus, if you want to run these tests, I recommend doing them
22 *one at a time*.
23
24 Because of this, all of the examples are commented out. To run one,
25 just uncomment it and its corresponding string constant at the
26 top of the file and off you go! :)
27*/
28#include <SPI.h>
29#include <Ethernet.h>
30#include <sha1.h>
31//#include <avr/dtostrf.h> // Add this for the Due if you need drostrf
32#include <stdlib.h>
33//#include <WiFi.h> // Use this for WiFi
34#include <mysql.h>
35
36byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
37IPAddress server_addr(10,0,1,13); // Supply the IP of the MySQL *server* here
38
39char user[] = "root"; // can be anything but the user must have
40char password[] = "secret"; // access rights to connect (host must permit it)
41
42// WiFi card example
43//char ssid[] = "my_lonely_ssid";
44//char pass[] = "horse_no_name";
45
46Connector my_conn; // The Connector/Arduino reference
47
48// String constants for examples. Uncomment those you need.
49
50//const char TEST_SELECT_QUERY[] = "SELECT * FROM world.city LIMIT 10";
51//const char QUERY_POP[] = "SELECT population FROM world.city WHERE name = 'New York'";
52//const char INSERT_TEXT[] = "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!', NULL)";
53//const char INSERT_DATA[] = "INSERT INTO test_arduino.temps VALUES (%s, NULL)";
54//const char HELLO_SQL[] = "SELECT * from test_arduino.hello";
55//const char HELLO_DATA[] = "SELECT * from test_arduino.temps";
56
57/**
58 * do_query - execute a query and display results
59 *
60 * This method demonstrates how to execute a query, get the column
61 * names and print them, then read rows printing the values. It
62 * is a mirror of the show_results() example in the connector class.
63 *
64 * You can use this method as a template for writing methods that
65 * must iterate over rows from a SELECT and operate on the values read.
66 *
67 */
68void do_query(const char *q) {
69 column_names *c; // pointer to column values
70 row_values *r; // pointer to row values
71
72 // First, execute query. If it returns a value pointer,
73 // we have a result set to process. If not, we exit.
74 if (!my_conn.cmd_query(q)) {
75 return;
76 }
77
78 // Next, we read the column names and display them.
79 //
80 // NOTICE: You must *always* read the column names even if
81 // you do not use them. This is so the connector can
82 // read the data out of the buffer. Row data follows the
83 // column data and thus must be read first.
84
85 c = my_conn.get_columns();
86 for (int i = 0; i < c->num_fields; i++) {
87 Serial.print(c->fields[i]->name);
88 if (i < c->num_fields - 1) {
89 Serial.print(",");
90 }
91 }
92 Serial.println();
93
94 // Next, we use the get_next_row() iterator and read rows printing
95 // the values returned until the get_next_row() returns NULL.
96
97 int num_cols = c->num_fields;
98 int rows = 0;
99 do {
100 r = my_conn.get_next_row();
101 if (r) {
102 rows++;
103 for (int i = 0; i < num_cols; i++) {
104 Serial.print(r->values[i]);
105 if (i < num_cols - 1) {
106 Serial.print(", ");
107 }
108 }
109 Serial.println();
110
111 // Note: we free the row read to free the memory allocated for it.
112 // You should do this after you've processed the row.
113
114 my_conn.free_row_buffer();
115 }
116 } while (r);
117 Serial.print(rows);
118 Serial.println(" rows in result.");
119
120 // Finally, we are done so we free the column buffers
121
122 my_conn.free_columns_buffer();
123}
124
125void setup() {
126 Serial.begin(115200);
127 while (!Serial); // wait for serial port to connect. Needed for Leonardo only
128
129 Ethernet.begin(mac_addr);
130
131 // WiFi section
132// int status = WiFi.begin(ssid, pass);
133// // if you're not connected, stop here:
134// if ( status != WL_CONNECTED) {
135// Serial.println("Couldn't get a wifi connection");
136// while(true);
137// }
138// // if you are connected, print out info about the connection:
139// else {
140// Serial.println("Connected to network");
141// IPAddress ip = WiFi.localIP();
142// Serial.print("My IP address is: ");
143// Serial.println(ip);
144// }
145
146 delay(1000);
147 Serial.println("Connecting...");
148 if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
149 delay(1000);
150 }
151 else
152 Serial.println("Connection failed.");
153
154 //
155 // SELECT Examples
156 //
157
158/*
159 // EXAMPLE 1
160
161 // SELECT query returning rows (built-in methods)
162 // Here we simply read the columns, print the names, then loop through
163 // the rows printing the values read. We set a limit to make this something
164 // that executes in a reasonable timeframe.
165
166 my_conn.cmd_query(TEST_SELECT_QUERY);
167 my_conn.show_results();
168*/
169/*
170 // EXAMPLE 2
171
172 // SELECT query returning rows (custom method)
173 // Here we execute the same query as above but use a custom method for reading
174 // and displaying the results. See the do_query() method above for more
175 // information about how it works.
176
177 do_query(TEST_SELECT_QUERY);
178*/
179/*
180 // EXAMPLE 3
181
182 // SELECT query for lookup value (1 row returned)
183 // Here we get a value from the database and use it.
184
185 long head_count = 0;
186 my_conn.cmd_query(QUERY_POP);
187
188 // We ignore the columns but we have to read them to get that data out of the queue
189
190 my_conn.get_columns();
191
192 // Now we read the rows.
193
194 row_values *row = NULL;
195 do {
196 row = my_conn.get_next_row();
197 // We use the first value returned in the row - population of NYC!
198 if (row != NULL) {
199 head_count = atol(row->values[0]);
200 }
201 } while (row != NULL);
202
203 // We're done with the buffers so Ok to clear them (and save precious memory).
204
205 my_conn.free_columns_buffer();
206 my_conn.free_row_buffer();
207
208 // Now, let's do something with the data.
209
210 Serial.print("NYC pop = ");
211 Serial.println(head_count);
212*/
213
214 //
215 // INSERT Examples
216 //
217
218/*
219 // EXAMPLE 4
220
221 // Inserting static text into a table.
222 // Here we simply insert text data into a table. No conversion needed.
223 // It also demonstrates the use of NULL to initiate a timestamp value.
224
225 my_conn.cmd_query(INSERT_TEXT);
226 // Now, let's check our results.
227 do_query(HELLO_SQL);
228*/
229/*
230 // EXAMPLE 5
231
232 // Inserting real time data into a table.
233 // Here we want to insert a row into a table but in this case we are
234 // simulating reading the data from a sensor or some other component.
235 // In this case, we 'simulate' reading temperature in celsius.
236
237 float value_read = 26.9;
238
239 // To use the value in an INSERT statement, we must construct a string
240 // that has the value inserted in it. For example, what we want is:
241 // 'INSERT INTO test_arduino.temps VALUES (26.9, NULL)' but the 26.9 is
242 // held in the variable 'value_read'. So, we use a character string
243 // formatting operation sprintf(). Notice here we must convert the float
244 // to a string first and we use the %s specifier in the INSERT_DATA
245 // string.
246
247 char query[64];
248 char temperature[10];
249 dtostrf(value_read, 1, 1, temperature);
250 sprintf(query, INSERT_DATA, temperature);
251 my_conn.cmd_query(query);
252 // Now, let's check our results.
253 do_query(HELLO_DATA);
254*/
255}
256
257void loop() {
258}

Subscribers

People subscribed via source and target branches

to all changes: