MySQL for the Internet of Things

(Steven Felgate) #1

Chapter 6 ■ Building low-Cost MysQl data nodes


Be sure to double-check the source code and the IP address of your MySQL server as well as
the username and password chosen. If you are still encountering problems connecting, see the
“Troubleshooting Connector/Arduino” section in the MySQL Connector Reference Manual^16 for a list of
things to test to ensure that your MySQL server is configured correctly.
Once you have double-checked the server installation and the information in the sketch, compile and
upload the sketch to your Arduino. Then start the serial monitor and observe the process of connecting to
the MySQL server. Figure 6-16 shows a completed and successful execution of the code.


■Note in the examples i am connecting to an older version of MysQl that was installed on my BeagleBone


Black board. the sketch will connect to any version of MysQl from 5.0 and later.


Wow, is that it? Not very interesting, is it? If you see the statements in your serial monitor as shown
in Figure 6-16, rest assured that the Arduino has connected to and issued a query to the MySQL server. To
check, simply return to the mysql client and issue a select on the table. But first, run the sketch a number of
times to issue several inserts in the table.


Figure 6-16. Correct serial monitor output


(^16) https://github.com/ChuckBell/MySQL_Connector_Arduino/blob/master/extras/MySQL_Connector_Arduino_
Reference_Manual.pdf
You can do this in two ways. First, you can press RESET on your Arduino. If you leave your serial monitor
running, the Arduino presents the messages in order, as shown in Figure 6-17. Second, you can upload the
sketch again. In this case, the serial monitor closes, and you have to reopen it. The advantage of this method
is you can change the query statement each time, thereby inserting different rows into the database. Go
ahead and try that now, and check your database for the changes.

Free download pdf