Using the MySQL C client API on the FOX Board it is possible to build a powerful gateway between external devices like lights, switches, display, etc. and the values stored in a SQL database.
An example is to generate an SQL "INSERT" every time a switch is pressed or show the results of a complex SQL "SELECT" directly on a LCD display to see the live values of total sales amounts from your ecommerce site.
$ source init_env
$ tar zxvf mysql-5.0.21.tar.gz $ cd mysql-5.0.21
$ patch -p1 < mysql-5.0.21-fox.patch
$ autoconf $ sh configure.fox $ makeIf autoconf doesn't run, check if the autotools are already installed on your Linux box.
$ gcc-cris -mlinux -isystem /sdk_path/target/cris-axis-linux-gnu/ -lm -o mysqltest1 mysqltest1.c /sdk_path/mysql-5.0.21/libmysql/.libs/libmysqlclient.a /sdk_path/mysql-5.0.21/zlib/.libs/libz.a $ cris-strip mysqltest1You will obtain a file of about 400Kb because the mysql library are linked statically.
$ scp mysqltest1root@192.168.0.90:/var
[root@axis-00408c012220 /var]97# ./mysqltest1 5.0.21If it works, you are ready to try a connection to a MySQL server.
In this example we'll generate on the MySQL server one record each time we push an external switch. The record will have a timestamp to know when the switch was pressed.
A led will indicate if the new log record has generated on the MySQL server with a single blink. More blinks indicate an error condition.
The external switch is connected to the FOX Board as shown on the following schematic diagram:
Schematic to connect an external switch |
Schematic to connect an external LED |
To create all of them you can use directly this SQL commands file: @source='logger.sql'
Be shure that your MySQL server is enabled to receive external transactions. To do that modify this line on /etc&msql/my.cnf:
#skip-external-lockingin
skip-external-lockingBe shure also that you server can accept connection on default MySQL port 3306.
This is the source of logger.c: @source='logger.c'
This is the result thet we obtain in the switch table:
mysql> select * from switch; +----+----------------+----------+----------------+ | id | time | switchid | description | +----+----------------+----------+----------------+ | 1 | 20060530074807 | IOG16 | Switch pressed | | 2 | 20060530074809 | IOG16 | Switch pressed | | 3 | 20060530074811 | IOG16 | Switch pressed | | 4 | 20060530074812 | IOG16 | Switch pressed | | 5 | 20060530074813 | IOG16 | Switch pressed | | 6 | 20060530074813 | IOG16 | Switch pressed | | 7 | 20060530074814 | IOG16 | Switch pressed | | 8 | 20060530074815 | IOG16 | Switch pressed | | 9 | 20060530074815 | IOG16 | Switch pressed | +----+----------------+----------+----------------+ 9 rows in set (0.00 sec)