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
1=== modified file 'CHANGES.txt'
2--- CHANGES.txt 2015-03-04 15:33:05 +0000
3+++ CHANGES.txt 2015-10-22 10:38:35 +0000
4@@ -3,6 +3,11 @@
5 This file contains a brief summary of changes made from previous versions of
6 the connector.
7
8+1.0.4ga - July 2015
9+--------------------
10+* Fixed a defect in the get_next_row() method.
11+* Added the reference manual. Yippee!
12+
13 1.0.3rc - March 2015
14 --------------------
15 * Code has been changed slightly to help with long latency issues over
16
17=== modified file 'Readme.txt'
18--- Readme.txt 2013-10-23 19:56:58 +0000
19+++ Readme.txt 2015-10-22 10:38:35 +0000
20@@ -77,40 +77,6 @@
21
22 Documentation
23 -------------
24-The documentation for the connector library is a work in progress. In the
25-meantime, I have written a couple of blogs about the connector that explain
26-how to use it. Please refer to the blogs until such time there is sufficient
27-documentation available.
28-
29-
30-Dependency: SHA1 library
31-------------------------
32-The Connector/Arduino requires the SHA1 library from the following link.
33-
34-Note: The single file download already has this library with the changes
35-described below already applied so there is nothing for you to do. However, if
36-you cloned the connector library instead of using the download, please download
37-the SHA1 library, install it, and read on for modifications needed to this
38-library.
39-
40-http://code.google.com/p/cryptosuite/downloads/list
41-
42-You must download and install that library first and include it in your
43-project. The following shows all of the library header files you need to
44-include.
45-
46-#include <SPI.h>
47-#include <Ethernet.h>
48-#include <sha1.h>
49-#include <avr/pgmspace.h>
50-#include "mysql.h"
51-
52-NOTICE: The SHA1 library may not compile correctly in your IDE. A change is
53-needed to ensure it will compile correctly. See the sha1.diff file for
54-details.
55-
56-We also do not need some of the features in the SHA1 library and since it takes
57-up space, we can eliminate them. If you would like to remove the unneeded code
58-from the SHA1 library, apply the sha1_no256.diff file to remove them and
59-delete the sha1256.h and sh1256.cpp files. This will save you about 2k of
60-program space.
61+The documentation for the connector library is included with the source
62+files. I have also written a couple of blogs about the connector that explain
63+how to use it.
64
65=== added directory 'examples/mysql_connector'
66=== added file 'examples/mysql_connector/mysql_connector.ino'
67--- examples/mysql_connector/mysql_connector.ino 1970-01-01 00:00:00 +0000
68+++ examples/mysql_connector/mysql_connector.ino 2015-10-22 10:38:35 +0000
69@@ -0,0 +1,258 @@
70+/*
71+ Example queries for using the Connector/Arduino library.
72+
73+ This file contains a number of examples as discussed in the Readme. It
74+ also contains an example of how to use the library with the WiFi shield.
75+
76+ In order to run these examples, you must have the world sample database
77+ installed (http://dev.mysql.com/doc/index-other.html) and the following
78+ databases and tables created:
79+
80+ CREATE DATABASE test_arduino;
81+ CREATE TABLE test_arduino.hello (msg char(50), msg_date timestamp);
82+ CREATE TABLE temps (temp_c float, temp_date timestamp);
83+
84+ Take some time to read through the code before you load and run it.
85+
86+ NOTICE: There are a lot of queries in this file. Together they use a lot
87+ of program space - especially the dtostrf() example. If you attempt
88+ to run all of these at one time, depending on your board you may
89+ run out of space or the sketch may run out of memory and hang.
90+ Thus, if you want to run these tests, I recommend doing them
91+ *one at a time*.
92+
93+ Because of this, all of the examples are commented out. To run one,
94+ just uncomment it and its corresponding string constant at the
95+ top of the file and off you go! :)
96+*/
97+#include <SPI.h>
98+#include <Ethernet.h>
99+#include <sha1.h>
100+//#include <avr/dtostrf.h> // Add this for the Due if you need drostrf
101+#include <stdlib.h>
102+//#include <WiFi.h> // Use this for WiFi
103+#include <mysql.h>
104+
105+byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
106+IPAddress server_addr(10,0,1,13); // Supply the IP of the MySQL *server* here
107+
108+char user[] = "root"; // can be anything but the user must have
109+char password[] = "secret"; // access rights to connect (host must permit it)
110+
111+// WiFi card example
112+//char ssid[] = "my_lonely_ssid";
113+//char pass[] = "horse_no_name";
114+
115+Connector my_conn; // The Connector/Arduino reference
116+
117+// String constants for examples. Uncomment those you need.
118+
119+//const char TEST_SELECT_QUERY[] = "SELECT * FROM world.city LIMIT 10";
120+//const char QUERY_POP[] = "SELECT population FROM world.city WHERE name = 'New York'";
121+//const char INSERT_TEXT[] = "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!', NULL)";
122+//const char INSERT_DATA[] = "INSERT INTO test_arduino.temps VALUES (%s, NULL)";
123+//const char HELLO_SQL[] = "SELECT * from test_arduino.hello";
124+//const char HELLO_DATA[] = "SELECT * from test_arduino.temps";
125+
126+/**
127+ * do_query - execute a query and display results
128+ *
129+ * This method demonstrates how to execute a query, get the column
130+ * names and print them, then read rows printing the values. It
131+ * is a mirror of the show_results() example in the connector class.
132+ *
133+ * You can use this method as a template for writing methods that
134+ * must iterate over rows from a SELECT and operate on the values read.
135+ *
136+ */
137+void do_query(const char *q) {
138+ column_names *c; // pointer to column values
139+ row_values *r; // pointer to row values
140+
141+ // First, execute query. If it returns a value pointer,
142+ // we have a result set to process. If not, we exit.
143+ if (!my_conn.cmd_query(q)) {
144+ return;
145+ }
146+
147+ // Next, we read the column names and display them.
148+ //
149+ // NOTICE: You must *always* read the column names even if
150+ // you do not use them. This is so the connector can
151+ // read the data out of the buffer. Row data follows the
152+ // column data and thus must be read first.
153+
154+ c = my_conn.get_columns();
155+ for (int i = 0; i < c->num_fields; i++) {
156+ Serial.print(c->fields[i]->name);
157+ if (i < c->num_fields - 1) {
158+ Serial.print(",");
159+ }
160+ }
161+ Serial.println();
162+
163+ // Next, we use the get_next_row() iterator and read rows printing
164+ // the values returned until the get_next_row() returns NULL.
165+
166+ int num_cols = c->num_fields;
167+ int rows = 0;
168+ do {
169+ r = my_conn.get_next_row();
170+ if (r) {
171+ rows++;
172+ for (int i = 0; i < num_cols; i++) {
173+ Serial.print(r->values[i]);
174+ if (i < num_cols - 1) {
175+ Serial.print(", ");
176+ }
177+ }
178+ Serial.println();
179+
180+ // Note: we free the row read to free the memory allocated for it.
181+ // You should do this after you've processed the row.
182+
183+ my_conn.free_row_buffer();
184+ }
185+ } while (r);
186+ Serial.print(rows);
187+ Serial.println(" rows in result.");
188+
189+ // Finally, we are done so we free the column buffers
190+
191+ my_conn.free_columns_buffer();
192+}
193+
194+void setup() {
195+ Serial.begin(115200);
196+ while (!Serial); // wait for serial port to connect. Needed for Leonardo only
197+
198+ Ethernet.begin(mac_addr);
199+
200+ // WiFi section
201+// int status = WiFi.begin(ssid, pass);
202+// // if you're not connected, stop here:
203+// if ( status != WL_CONNECTED) {
204+// Serial.println("Couldn't get a wifi connection");
205+// while(true);
206+// }
207+// // if you are connected, print out info about the connection:
208+// else {
209+// Serial.println("Connected to network");
210+// IPAddress ip = WiFi.localIP();
211+// Serial.print("My IP address is: ");
212+// Serial.println(ip);
213+// }
214+
215+ delay(1000);
216+ Serial.println("Connecting...");
217+ if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
218+ delay(1000);
219+ }
220+ else
221+ Serial.println("Connection failed.");
222+
223+ //
224+ // SELECT Examples
225+ //
226+
227+/*
228+ // EXAMPLE 1
229+
230+ // SELECT query returning rows (built-in methods)
231+ // Here we simply read the columns, print the names, then loop through
232+ // the rows printing the values read. We set a limit to make this something
233+ // that executes in a reasonable timeframe.
234+
235+ my_conn.cmd_query(TEST_SELECT_QUERY);
236+ my_conn.show_results();
237+*/
238+/*
239+ // EXAMPLE 2
240+
241+ // SELECT query returning rows (custom method)
242+ // Here we execute the same query as above but use a custom method for reading
243+ // and displaying the results. See the do_query() method above for more
244+ // information about how it works.
245+
246+ do_query(TEST_SELECT_QUERY);
247+*/
248+/*
249+ // EXAMPLE 3
250+
251+ // SELECT query for lookup value (1 row returned)
252+ // Here we get a value from the database and use it.
253+
254+ long head_count = 0;
255+ my_conn.cmd_query(QUERY_POP);
256+
257+ // We ignore the columns but we have to read them to get that data out of the queue
258+
259+ my_conn.get_columns();
260+
261+ // Now we read the rows.
262+
263+ row_values *row = NULL;
264+ do {
265+ row = my_conn.get_next_row();
266+ // We use the first value returned in the row - population of NYC!
267+ if (row != NULL) {
268+ head_count = atol(row->values[0]);
269+ }
270+ } while (row != NULL);
271+
272+ // We're done with the buffers so Ok to clear them (and save precious memory).
273+
274+ my_conn.free_columns_buffer();
275+ my_conn.free_row_buffer();
276+
277+ // Now, let's do something with the data.
278+
279+ Serial.print("NYC pop = ");
280+ Serial.println(head_count);
281+*/
282+
283+ //
284+ // INSERT Examples
285+ //
286+
287+/*
288+ // EXAMPLE 4
289+
290+ // Inserting static text into a table.
291+ // Here we simply insert text data into a table. No conversion needed.
292+ // It also demonstrates the use of NULL to initiate a timestamp value.
293+
294+ my_conn.cmd_query(INSERT_TEXT);
295+ // Now, let's check our results.
296+ do_query(HELLO_SQL);
297+*/
298+/*
299+ // EXAMPLE 5
300+
301+ // Inserting real time data into a table.
302+ // Here we want to insert a row into a table but in this case we are
303+ // simulating reading the data from a sensor or some other component.
304+ // In this case, we 'simulate' reading temperature in celsius.
305+
306+ float value_read = 26.9;
307+
308+ // To use the value in an INSERT statement, we must construct a string
309+ // that has the value inserted in it. For example, what we want is:
310+ // 'INSERT INTO test_arduino.temps VALUES (26.9, NULL)' but the 26.9 is
311+ // held in the variable 'value_read'. So, we use a character string
312+ // formatting operation sprintf(). Notice here we must convert the float
313+ // to a string first and we use the %s specifier in the INSERT_DATA
314+ // string.
315+
316+ char query[64];
317+ char temperature[10];
318+ dtostrf(value_read, 1, 1, temperature);
319+ sprintf(query, INSERT_DATA, temperature);
320+ my_conn.cmd_query(query);
321+ // Now, let's check our results.
322+ do_query(HELLO_DATA);
323+*/
324+}
325+
326+void loop() {
327+}
328
329=== modified file 'mysql.cpp'
330--- mysql.cpp 2015-03-04 15:14:29 +0000
331+++ mysql.cpp 2015-10-22 10:38:35 +0000
332@@ -25,6 +25,7 @@
333 Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.
334 Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.
335 Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.
336+ Version 1.0.4ga Updated by Dr. Charles A. Bell, July 2015.
337 */
338 #include "Arduino.h"
339 #include "mysql.h"
340@@ -1008,7 +1009,7 @@
341 * in the class.
342 *
343 */
344-boolean Connector::get_row_values() {
345+int Connector::get_row_values() {
346 int res = 0;
347 int offset = 0;
348
349@@ -1016,7 +1017,7 @@
350 // are read.
351 if (!columns_read) {
352 print_message(READ_COLS, true);
353- return true;
354+ return EOF_PACKET;
355 }
356 // Drop any row data already read
357 free_row_buffer();
358@@ -1029,10 +1030,7 @@
359 row.values[f] = read_string(&offset);
360 }
361 }
362- else {
363- return res;
364- }
365- return true;
366+ return res;
367 }
368
369 #endif
370
371=== modified file 'mysql.h'
372--- mysql.h 2015-03-04 15:14:29 +0000
373+++ mysql.h 2015-10-22 10:38:35 +0000
374@@ -30,6 +30,7 @@
375 Version 1.0.1b Updated by Dr. Charles A. Bell, February 2014.
376 Version 1.0.2b Updated by Dr. Charles A. Bell, April 2014.
377 Version 1.0.3rc Updated by Dr. Charles A. Bell, March 2015.
378+ Version 1.0.4ga Updated by Dr. Charles A. Bell, July 2015.
379 */
380 #ifndef mysql_h
381 #define mysql_h
382@@ -50,7 +51,7 @@
383 #define EOF_PACKET 0xfe
384 #define ERROR_PACKET 0xff
385 #define MAX_FIELDS 0x20 // Maximum number of fields. Reduce to save memory. Default=32
386-#define VERSION_STR "1.0.3rc"
387+#define VERSION_STR "1.0.4ga"
388
389 #if defined WITH_SELECT
390
391@@ -157,7 +158,7 @@
392 int get_field(field_struct *fs);
393 int get_row();
394 boolean get_fields();
395- boolean get_row_values();
396+ int get_row_values();
397 column_names *query_result();
398 #endif
399
400
401=== removed file 'mysql_connector.ino'
402--- mysql_connector.ino 2013-10-23 19:56:58 +0000
403+++ mysql_connector.ino 1970-01-01 00:00:00 +0000
404@@ -1,258 +0,0 @@
405-/*
406- Example queries for using the Connector/Arduino library.
407-
408- This file contains a number of examples as discussed in the Readme. It
409- also contains an example of how to use the library with the WiFi shield.
410-
411- In order to run these examples, you must have the world sample database
412- installed (http://dev.mysql.com/doc/index-other.html) and the following
413- databases and tables created:
414-
415- CREATE DATABASE test_arduino;
416- CREATE TABLE test_arduino.hello (msg char(50), msg_date timestamp);
417- CREATE TABLE temps (temp_c float, temp_date timestamp);
418-
419- Take some time to read through the code before you load and run it.
420-
421- NOTICE: There are a lot of queries in this file. Together they use a lot
422- of program space - especially the dtostrf() example. If you attempt
423- to run all of these at one time, depending on your board you may
424- run out of space or the sketch may run out of memory and hang.
425- Thus, if you want to run these tests, I recommend doing them
426- *one at a time*.
427-
428- Because of this, all of the examples are commented out. To run one,
429- just uncomment it and its corresponding string constant at the
430- top of the file and off you go! :)
431-*/
432-#include <SPI.h>
433-#include <Ethernet.h>
434-#include <sha1.h>
435-//#include <avr/dtostrf.h> // Add this for the Due if you need drostrf
436-#include <stdlib.h>
437-//#include <WiFi.h> // Use this for WiFi
438-#include <mysql.h>
439-
440-byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
441-IPAddress server_addr(10,0,1,13); // Supply the IP of the MySQL *server* here
442-
443-char user[] = "root"; // can be anything but the user must have
444-char password[] = "secret"; // access rights to connect (host must permit it)
445-
446-// WiFi card example
447-//char ssid[] = "my_lonely_ssid";
448-//char pass[] = "horse_no_name";
449-
450-Connector my_conn; // The Connector/Arduino reference
451-
452-// String constants for examples. Uncomment those you need.
453-
454-//const char TEST_SELECT_QUERY[] = "SELECT * FROM world.city LIMIT 10";
455-//const char QUERY_POP[] = "SELECT population FROM world.city WHERE name = 'New York'";
456-//const char INSERT_TEXT[] = "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!', NULL)";
457-//const char INSERT_DATA[] = "INSERT INTO test_arduino.temps VALUES (%s, NULL)";
458-//const char HELLO_SQL[] = "SELECT * from test_arduino.hello";
459-//const char HELLO_DATA[] = "SELECT * from test_arduino.temps";
460-
461-/**
462- * do_query - execute a query and display results
463- *
464- * This method demonstrates how to execute a query, get the column
465- * names and print them, then read rows printing the values. It
466- * is a mirror of the show_results() example in the connector class.
467- *
468- * You can use this method as a template for writing methods that
469- * must iterate over rows from a SELECT and operate on the values read.
470- *
471- */
472-void do_query(const char *q) {
473- column_names *c; // pointer to column values
474- row_values *r; // pointer to row values
475-
476- // First, execute query. If it returns a value pointer,
477- // we have a result set to process. If not, we exit.
478- if (!my_conn.cmd_query(q)) {
479- return;
480- }
481-
482- // Next, we read the column names and display them.
483- //
484- // NOTICE: You must *always* read the column names even if
485- // you do not use them. This is so the connector can
486- // read the data out of the buffer. Row data follows the
487- // column data and thus must be read first.
488-
489- c = my_conn.get_columns();
490- for (int i = 0; i < c->num_fields; i++) {
491- Serial.print(c->fields[i]->name);
492- if (i < c->num_fields - 1) {
493- Serial.print(",");
494- }
495- }
496- Serial.println();
497-
498- // Next, we use the get_next_row() iterator and read rows printing
499- // the values returned until the get_next_row() returns NULL.
500-
501- int num_cols = c->num_fields;
502- int rows = 0;
503- do {
504- r = my_conn.get_next_row();
505- if (r) {
506- rows++;
507- for (int i = 0; i < num_cols; i++) {
508- Serial.print(r->values[i]);
509- if (i < num_cols - 1) {
510- Serial.print(", ");
511- }
512- }
513- Serial.println();
514-
515- // Note: we free the row read to free the memory allocated for it.
516- // You should do this after you've processed the row.
517-
518- my_conn.free_row_buffer();
519- }
520- } while (r);
521- Serial.print(rows);
522- Serial.println(" rows in result.");
523-
524- // Finally, we are done so we free the column buffers
525-
526- my_conn.free_columns_buffer();
527-}
528-
529-void setup() {
530- Serial.begin(115200);
531- while (!Serial); // wait for serial port to connect. Needed for Leonardo only
532-
533- Ethernet.begin(mac_addr);
534-
535- // WiFi section
536-// int status = WiFi.begin(ssid, pass);
537-// // if you're not connected, stop here:
538-// if ( status != WL_CONNECTED) {
539-// Serial.println("Couldn't get a wifi connection");
540-// while(true);
541-// }
542-// // if you are connected, print out info about the connection:
543-// else {
544-// Serial.println("Connected to network");
545-// IPAddress ip = WiFi.localIP();
546-// Serial.print("My IP address is: ");
547-// Serial.println(ip);
548-// }
549-
550- delay(1000);
551- Serial.println("Connecting...");
552- if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
553- delay(1000);
554- }
555- else
556- Serial.println("Connection failed.");
557-
558- //
559- // SELECT Examples
560- //
561-
562-/*
563- // EXAMPLE 1
564-
565- // SELECT query returning rows (built-in methods)
566- // Here we simply read the columns, print the names, then loop through
567- // the rows printing the values read. We set a limit to make this something
568- // that executes in a reasonable timeframe.
569-
570- my_conn.cmd_query(TEST_SELECT_QUERY);
571- my_conn.show_results();
572-*/
573-/*
574- // EXAMPLE 2
575-
576- // SELECT query returning rows (custom method)
577- // Here we execute the same query as above but use a custom method for reading
578- // and displaying the results. See the do_query() method above for more
579- // information about how it works.
580-
581- do_query(TEST_SELECT_QUERY);
582-*/
583-/*
584- // EXAMPLE 3
585-
586- // SELECT query for lookup value (1 row returned)
587- // Here we get a value from the database and use it.
588-
589- long head_count = 0;
590- my_conn.cmd_query(QUERY_POP);
591-
592- // We ignore the columns but we have to read them to get that data out of the queue
593-
594- my_conn.get_columns();
595-
596- // Now we read the rows.
597-
598- row_values *row = NULL;
599- do {
600- row = my_conn.get_next_row();
601- // We use the first value returned in the row - population of NYC!
602- if (row != NULL) {
603- head_count = atol(row->values[0]);
604- }
605- } while (row != NULL);
606-
607- // We're done with the buffers so Ok to clear them (and save precious memory).
608-
609- my_conn.free_columns_buffer();
610- my_conn.free_row_buffer();
611-
612- // Now, let's do something with the data.
613-
614- Serial.print("NYC pop = ");
615- Serial.println(head_count);
616-*/
617-
618- //
619- // INSERT Examples
620- //
621-
622-/*
623- // EXAMPLE 4
624-
625- // Inserting static text into a table.
626- // Here we simply insert text data into a table. No conversion needed.
627- // It also demonstrates the use of NULL to initiate a timestamp value.
628-
629- my_conn.cmd_query(INSERT_TEXT);
630- // Now, let's check our results.
631- do_query(HELLO_SQL);
632-*/
633-/*
634- // EXAMPLE 5
635-
636- // Inserting real time data into a table.
637- // Here we want to insert a row into a table but in this case we are
638- // simulating reading the data from a sensor or some other component.
639- // In this case, we 'simulate' reading temperature in celsius.
640-
641- float value_read = 26.9;
642-
643- // To use the value in an INSERT statement, we must construct a string
644- // that has the value inserted in it. For example, what we want is:
645- // 'INSERT INTO test_arduino.temps VALUES (26.9, NULL)' but the 26.9 is
646- // held in the variable 'value_read'. So, we use a character string
647- // formatting operation sprintf(). Notice here we must convert the float
648- // to a string first and we use the %s specifier in the INSERT_DATA
649- // string.
650-
651- char query[64];
652- char temperature[10];
653- dtostrf(value_read, 1, 1, temperature);
654- sprintf(query, INSERT_DATA, temperature);
655- my_conn.cmd_query(query);
656- // Now, let's check our results.
657- do_query(HELLO_DATA);
658-*/
659-}
660-
661-void loop() {
662-}

Subscribers

People subscribed via source and target branches

to all changes: