Skip to content

Troubleshooting

Dr. Charles Bell edited this page Mar 29, 2020 · 3 revisions

This section presents a short but proven practice for troubleshooting sketches that use the connector. Should you have a situation where your sketch fails or doesn't work when modified or moved to another network, deployed, etc., following this process can help isolate the problem.

  1. Verify the network. Try connecting another computer in place of the Arduino to ensure you can connect to the network and the database sever. Correct any network issues before moving on.
  2. Verify your user account. With the same computer, try logging into the database using the credentials in your sketch. Correct any issues with permissions and user accounts before moving on.
  3. Check permissions. If you restart your Arduino and still cannot connect, go back and verify your permissions again.
  4. Check network hardware. Make sure there are no firewalls, port scanners, etc. that are blocking access to the database server.
  5. Isolate your code. Once all connection problems are solved, check your code. Chances are you can comment out or remove most of the code to check only the bare minimum parts. I recommend breaking the code into sections and testing each until you encounter the section with the problem.
  6. Check your hardware. When all else fails, try another Arduino. I've seen cases where an Arduino breaks or has a short or some other failure where it can boot and run simple sketches but anything more than that it fails.

A Note About Testing Access to MySQL

Once your user account is setup and you have granted the correct permissions, you should check the connection. This is perhaps the one thing that most new users skip and assume everything will work. Furthermore, they make the mistake of testing the user account from the same host as the server. This will mask a number of potential pitfalls and is not the best test.

The best way to check if your user account and permissions is to use another computer to login to the MySQL server. Simply connect another computer to the same network and open the mysql client and attempt to connect. If you do not have another computer to use, you can force the mysql client to use the network to connect (as opposed to socket connections by default) by specifying the host and port as shown below. The host in this case is the hostname or IP of the MySQL server, not the Arduino.

mysql -ubob -psecret –h192.168.0.2 --port=3306

Once you have connected, try accessing the database and attempt any operations you want to include in your sketch. Now would be a good time to test the SQL statements you plan to include in your sketch. Simply type them in and run them. For example, try inserting some dummy data, creating objects, selecting rows – whatever you plan to do in your sketch. Not only will this verify your user account has the correct permissions; it will also verify your SQL statements are properly written and thus avoid strange errors when you run your script.

Once you can successfully connect and have verified you can access the correct database objects, reset the data and transfer the login information to your sketch or write it down for later reference.