Wednesday, December 24, 2014

Configuring smsd gammu 1.33.0 with MySQL and ODBC on Mac OS X Mavericks 10.9.5


2 days ago i got frustated why i CAN'T connecting gammu to mysql, after so many research then I have find solution about how to configure SMSD gammu 1.33.0 with MySQL using ODBC MySQL Connector on Mac OS X Mavericks 10.9.5

this is what I'm trying to configure on below step:
- Gammu 1.33.0
- MySQL 5.6
- MySQL ODBC Connector
- unixodbc

so if you have one of this installed before, please remove/backup it first.

and here's how I solved this problem:

1. configure modem first with gammu, if you don't know how, you can read my other post here about Step by step to easy install gammu on Mac OS X 10.9 Mavericks

2. install MySQL using homebrew. but before install this if you have MySQL installed before WITHOUT USING HOMEBREW please remove/backup it first,  especially MAMP, I got serious [ERROR] No database Selected problem occured that keep me puzzled for 2 days because ODBC MySQL Connector installing MySQL as their depedency, but if you have installed MySQL using homebrew in the first, i think you won't have problem like mine.  to install MySQL with homebrew type this command:

$ brew install mysql

3. install ODBC MySQL Connector using homebrew

$ brew install mysql-connector-odbc

4. check unixodbc on /usr/local/Cellar/ is there or not, if yes then you can go to step 5, if not, you must install it with:

$ brew install unixodbc

5. make sure your MySQL is up and running correctly

6. create database with name smsdb or whatever you want on your MySQL, and import mysql.sql file from gammu you've install before usually located on 
/usr/local/Cellar/gammu/1.33.0/share/doc/gammu/examples/sql/mysql.sql to your database

7. open your favorite text editor, and input this configuration and change to your need, then save with whatever name and wherever path you want, example: ~/smsdrc (saved on root like me)

[gammu]
device = /dev/tty.HUAWEIMobile-Modem
connection = at115200

[smsd]
logfile = smsd.log
phoneid = SMSServer1
PIN = 12345

Service = SQL
Driver = odbc
SQL = mysql

Host = my_local_odbc_mysql
User = root
Password = 
Database = smsdb


8. create/or open file .odbc.ini on ~/ folder

$ mate ~/.odbc.ini --> I'm using TextMate command line syntax here

9. input this configuration to .odbc.ini files and change to your need

[ODBC]
Trace         = 1
TraceAutoStop = 0
TraceFile     = ~/odbc_log.txt
TraceLibrary  = 

[my_local_odbc_mysql] # this must be same as on Host setting on smsdrc file
Driver      = /usr/local/Cellar/mysql-connector-odbc/5.3.2_1/lib/libmyodbc5a.so # path to ODBC Driver you installed, version maybe different from mine, 5a.so for ANSI 5w.so for Unicode, choose one to your need
SERVER      = localhost
PORT        = 3306
USER        = root
PASSWORD    =
DATABASE    = smsdb


10. test unixodbc config you just create

$ isql my_local_odbc_mysql

11. if you have this console, then you success connect to your mysql server, try some mysql command

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+

SQL>

SQL> show databases;
+-----------------------------------------------------------------+
| Database                                                        |
+-----------------------------------------------------------------+
| information_schema                                              |
| mysql                                                           |
| performance_schema                                              |
| phpmyadmin                                                      |
| test                                                            |
| smsdb                                                         |
+-----------------------------------------------------------------+
SQLRowCount returns 6
6 rows fetched
SQL>

12. type control + C to exit

13. it's time to test our gammu-smsd

$ gammu-smsd -c ~/smsdrc 
Log filename is "smsdlog"

if you have that message, then you success on configuring smsd gammu 1.33.0 with MySQL and ODBC on Mac OS X Mavericks 10.9.5

Congratulation !!! 

if your have an error like this

$ gammu-smsd -c smsdrc 
Log filename is "smsdlog"
gammu-smsd[78488]: SQLExecDirect failed, Code = -1, ODBC diagnostics:
gammu-smsd[78488]: 3D000:1:1046:[MySQL][ODBC 5.3(a) Driver][mysqld-5.6.22]No database selected

I think you install MySQL manually or not from homebrew, and the odbc is connected to that MySQL one, to see if you have MySQL running type this command:


$ ps ax | grep mysql

next time I will try share some simple web base sms management using PHP, MySQL and Gammu on Mac OS X.

thanks for reading, don't hestitate to comment here, if you have some problem.

No comments:

Post a Comment