FrontlineSMS to Website

Posted on February 19, 2012

0


Various technologies were explored with the intention of finding a suitable technology for communicating between FrontlineSMS and a webpage.

The early prototyping stage involved setting up a local web server. It was decided to use a local web server rather than an online server in the early stages of development, as the types of technologies that would be necessary were uncertain.

FrontlineSMS allows for the forwarding of messages to a web server through the use of its Keyword function, and also can be set to listen for a message from a web server through its HTTP Trigger function.  More on the use of these functions are available on the help section of the FrontlineSMS website.

Javascript, PHP and Python are known languages that have been used to construct scripts for communicating between a webpage and FrontlineSMS (based on post in FrontlineSMS forums).

PYTHON

The library for connecting Python to a MYSQL database mysql-Python (download from: http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.2/)also proved difficult to install on Mac OSX through MAMP.  Various tutorial were found online for installing the Python package, however, almost all the support was for the Linux Ubuntu operating system. The tutorial for installing mysql_python was followed online at: http://birdhouse.org/blog/2009/02/21/python-mysql-connections-on-mac-os/, to install the package. However, it was discovered that an additional problem was the use of the MAMP software as a web server, as the software only seemed to work with MacPort. http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/. It appeared that the problem exist with GCC compilers version 3.0 and 4.0 (http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/), based on the error message received when trying to build the package: error: command ‘gcc-4.0’ failed with exit status 1.

Although this option might be considered in the future, it was decided to use WebSockets in PHP (see post on Web Technologies). The API for WebSockets is available online: http://www.php.net/manual/en/ref.sockets.php. A tutorial on WebSocket is available online: http://devzone.zend.com/209/writing-socket-servers-in-php/.

PHP WEBSOCKETS

Example code for a TCP server: https://wiki.sihnon.net/index.php/Multi-Client_TCP_Server_Example.

PHP WebSocket on google code: http://code.google.com/p/phpwebsocket/.

PHP group chat using WebSockets: http://vinayvgsr.posterous.com/group-chat-via-phpwebsocket

PHP SMS Gateway

Similar software to frontlineSMS connecting to PHP webpage.

http://www.ozekisms.com/index.php?owpn=324

Receiving a message using a protocol

http://www.developershome.com/sms/howToReceiveSMSUsingPC4.asp

FRONTLINESMS

FrontlineSMS Tutorial on external commands part 1:

http://frontlinesms.ning.com/profiles/blogs/create-awesome-app-with-external-command-tutorial

FrontlineSMS Tutorial on external commands part 2:

http://frontlinesms.ning.com/profiles/blogs/create-awesome-sms-app-with-external-command-tutorial-part-2?xg_source=activity

External commands with database query:

http://frontlinesms.ning.com/forum/topics/2052630:Topic:8063?id=2052630%3ATopic%3A8063&page=3#comments 

FrontlineSMS Wiki

https://github.com/frontlinesms/frontlinesms-super-project/wiki

16-02-2012

Was able to send a message from webpage to FrontlineSMS.  However, unable to send message from FrontlineSMS to webpage.  Further research would have to be conducted in this area.

28-02-2012

Installed NodeJS and Socket.IO plugins.  These technologies allow for full duplex communication between client and server.  Socket.IO specification available: https://github.com/LearnBoost/socket.io-spec.  NodeJS Manual and Documentation available: http://nodejs.org/docs/latest/api/http.html. Message successfully sent from webpage to FrontlineSMS to server, and received default server message on FrontlineSMS.

Other projects using Socket.IO

https://github.com/LearnBoost/Socket.IO/wiki/Projects-using-Socket.IO

29-02-2012

Created a function that split up message received by server from FrontlineSMS into parts.  Set up a default function for a FrontlineSMS keyword.  Next step will be to insert the message received from FrontlineSMS into a database, so it can be posted on website.  Also noticed a problem with FrontlineSMS not forwarding the message from server to mobile phone.  The message says pending, but does not get sent.

The library used to connect from nodejs to MYSQL database is db-mysql. The drivers and instructions for installing db-mysql drivers available: http://nodejsdb.org/db-mysql/.

NodeJS database connection with authentification

http://davidwalsh.name/websocket

01-03-2012

Received error messages when trying to install the db-mysql module.

npm http GET https://registry.npmjs.org/db-mysql
npm http 304 https://registry.npmjs.org/db-mysql

> db-mysql@0.7.6 install /Applications/MAMP/htdocs/node_modules/db-mysql
> node-waf configure build

Checking for program g++ or c++ : /usr/bin/g++
Checking for program cpp : /usr/bin/cpp
Checking for program ar : /usr/bin/ar
Checking for program ranlib : /usr/bin/ranlib
Checking for g++ : ok
Checking for node path : not found
Checking for node prefix : ok /usr/local
Checking for program mysql_config : /Applications/MAMP//Library/bin/mysql_config
Checking for library mysqlclient_r : Missing libmysqlclient_r
‘configure’ finished successfully (0.449s)
Waf: Entering directory `/Applications/MAMP/htdocs/node_modules/db-mysql/build’
[ 1/12] cxx: lib/node-db/binding.cc -> build/Release/lib/node-db/binding_1.o
[ 2/12] cxx: lib/node-db/connection.cc -> build/Release/lib/node-db/connection_1.o
[ 3/12] cxx: lib/node-db/events.cc -> build/Release/lib/node-db/events_1.o
[ 4/12] cxx: lib/node-db/exception.cc -> build/Release/lib/node-db/exception_1.o
[ 5/12] cxx: lib/node-db/query.cc -> build/Release/lib/node-db/query_1.o
[ 6/12] cxx: lib/node-db/result.cc -> build/Release/lib/node-db/result_1.o
[ 7/12] cxx: src/connection.cc -> build/Release/src/connection_1.o
In file included from ../src/connection.cc:2:
../src/./connection.h:5:19: error: mysql.h: No such file or directory
In file included from ../src/./connection.h:8,
from ../src/connection.cc:2:
../src/././result.h:16: error: expected ‘,’ or ‘…’ before ‘&’ token
../src/././result.h:16: error: ISO C++ forbids declaration of ‘MYSQL_FIELD’ with no type
../src/././result.h:28: error: expected `)’ before ‘*’ token
../src/././result.h:54: error: ISO C++ forbids declaration of ‘MYSQL’ with no type
../src/././result.h:54: error: expected ‘;’ before ‘*’ token
../src/././result.h:55: error: ISO C++ forbids declaration of ‘MYSQL_RES’ with no type
../src/././result.h:55: error: expected ‘;’ before ‘*’ token
In file included from ../src/connection.cc:2:
../src/./connection.h:43: error: ISO C++ forbids declaration of ‘MYSQL’ with no type
../src/./connection.h:43: error: expected ‘;’ before ‘*’ token
../src/connection.cc: In constructor ‘node_db_mysql::Connection::Connection()’:
../src/connection.cc:11: error: class ‘node_db_mysql::Connection’ does not have any field named ‘connection’
../src/connection.cc: In member function ‘virtual bool node_db_mysql::Connection::isAlive(bool)’:
../src/connection.cc:57: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:57: error: ‘mysql_ping’ was not declared in this scope
../src/connection.cc: In member function ‘virtual void node_db_mysql::Connection::open()’:
../src/connection.cc:65: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:65: error: ‘mysql_init’ was not declared in this scope
../src/connection.cc:66: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:71: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:71: error: ‘MYSQL_SET_CHARSET_NAME’ was not declared in this scope
../src/connection.cc:71: error: ‘mysql_options’ was not declared in this scope
../src/connection.cc:75: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:75: error: ‘MYSQL_OPT_COMPRESS’ was not declared in this scope
../src/connection.cc:75: error: ‘mysql_options’ was not declared in this scope
../src/connection.cc:79: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:79: error: ‘MYSQL_INIT_COMMAND’ was not declared in this scope
../src/connection.cc:79: error: ‘mysql_options’ was not declared in this scope
../src/connection.cc:83: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:83: error: ‘MYSQL_OPT_READ_TIMEOUT’ was not declared in this scope
../src/connection.cc:83: error: ‘mysql_options’ was not declared in this scope
../src/connection.cc:90: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:90: error: ‘MYSQL_OPT_SSL_VERIFY_SERVER_CERT’ was not declared in this scope
../src/connection.cc:90: error: ‘mysql_options’ was not declared in this scope
../src/connection.cc:93: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:93: error: ‘MYSQL_OPT_CONNECT_TIMEOUT’ was not declared in this scope
../src/connection.cc:97: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:97: error: ‘MYSQL_OPT_WRITE_TIMEOUT’ was not declared in this scope
../src/connection.cc:101: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:108: error: ‘mysql_real_connect’ was not declared in this scope
../src/connection.cc:116: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:116: error: ‘mysql_error’ was not declared in this scope
../src/connection.cc: In member function ‘virtual void node_db_mysql::Connection::close()’:
../src/connection.cc:122: error: ‘class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:122: error: ‘mysql_close’ was not declared in this scope
../src/connection.cc: In member function ‘virtual std::string node_db_mysql::Connection::escape(const std::string&) const’:
../src/connection.cc:133: error: ‘const class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:133: error: ‘mysql_real_escape_string’ was not declared in this scope
../src/connection.cc: In member function ‘virtual std::string node_db_mysql::Connection::version() const’:
../src/connection.cc:141: error: ‘const class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:141: error: ‘mysql_get_server_info’ was not declared in this scope
../src/connection.cc: In member function ‘virtual node_db::Result* node_db_mysql::Connection::query(const std::string&) const’:
../src/connection.cc:150: error: ‘const class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:150: error: ‘mysql_real_query’ was not declared in this scope
../src/connection.cc:151: error: ‘const class node_db_mysql::Connection’ has no member named ‘connection’
../src/connection.cc:151: error: ‘mysql_error’ was not declared in this scope
../src/connection.cc:154: error: ‘const class node_db_mysql::Connection’ has no member named ‘connection’
Waf: Leaving directory `/Applications/MAMP/htdocs/node_modules/db-mysql/build’
Build failed: -> task failed (err #1):
{task: cxx connection.cc -> connection_1.o}
npm ERR! error installing db-mysql@0.7.6

> db-mysql@0.7.6 preuninstall /Applications/MAMP/htdocs/node_modules/db-mysql
> rm -rf build/*
npm ERR! db-mysql@0.7.6 install: `node-waf configure build`
npm ERR! `sh “-c” “node-waf configure build”` failed with 1
npm ERR!
npm ERR! Failed at the db-mysql@0.7.6 install script.
npm ERR! This is most likely a problem with the db-mysql package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-waf configure build
npm ERR! You can get their info via:
npm ERR! npm owner ls db-mysql
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Darwin 10.8.0
npm ERR! command “node” “/usr/local/bin/npm” “install” “db-mysql”
npm ERR! cwd /Applications/MAMP/htdocs
npm ERR! node -v v0.6.11
npm ERR! npm -v 1.1.1
npm ERR! code ELIFECYCLE
npm ERR! message db-mysql@0.7.6 install: `node-waf configure build`
npm ERR! message `sh “-c” “node-waf configure build”` failed with 1
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Applications/MAMP/htdocs/npm-debug.log
npm not ok

It was discovered that the Node.JS db-mysql module is platform dependent (http://stackoverflow.com/questions/3878818/node-js-and-mysql-drivers).  Therefore, an alternative would have to be used.

02-03-2012

Installed the Node-Mysql module available: https://github.com/felixge/node-mysql/blob/master/Readme.md.

Server throws error message :

node.js:201
throw e; // process.nextTick error, or ‘error’ event on first tick
^
Error: connect ECONNREFUSED
at errnoException (net.js:646:11)
at Object.afterConnect [as oncomplete] (net.js:637:18)

Error was resolved by changing the MYSQL server to run on port 3306 instead of port 8889. Message written successfully to database and posted on website.  The next step would be to insert the message received from FrontlineSMS into database.

13-03-2012
Blog post by Ryan Raffa on connecting FrontlineSMS to database. http://www.ryanraffa.com/parsons/blog/1448/frontlinesms-saving-to-a-database/

FrontlineSMS substitution variables, which can be used with keywords, to replace sms content – http://frontlinesms.ning.com/profiles/blogs/2052630:BlogPost:9729

Advertisements