Taking a user centred approach in implementation involves catering for the needs of a novice user, it was deemed necessary to design a graphical user interface for the NodeJS SocketIO server.
Currently to run the nodeJS server the user manually types in the command in the terminal to start or stop the server.
Messages from server are also logged in the terminal.
This method is prone to errors (in this case error thrown because server could not connect to the database)
Resolved by starting mamp servers and restarting NodeJs server
This method is also susceptible to errors when typing in the commands, and it does not cater for a novice user that needs to learn the system, or an occasional user that needs to remember how to use the system.
The software is available on github – https://github.com/satoruhiga/ofxNodejs. Download the folder and copy it to your openFrameworks addons directory and rename to ofxNodejs. Navigate to ../…/openFrameworks-location/addons/ofxNodejs/simple-server-example and the example should run ( nodejs required). For mac users Nodejs can be obtained by downloading from NodeJS website, or by building Libnode. (Also see post NodeJS _ https://agnetpro.wordpress.com/2012/03/09/nodejs/)
To add the library to the project folder simply copy the example into your apps directory or add the ofxnodejs reference to project file (see readme file). You can also add your node_modules by calling the ofxNodejs:: appendNodePath function.
It was decided to use the copy line by line method of code into openFrameworks. The proposed reason being it would be simpler to use nodejs variables from within openFrameworks, which can then be displayed on the interface. The problem encountered at this stage was openFrameworks throwing an error “cannot find module ‘mysql’ “, that is, the ‘node-mysql’ module, which is being used to query database.
Screenshot showing error message in console:
There is a mysql bridge for openFrameworks – ofxMysql written by Elliot Woods. The addon was downloaded from github and added to project. When trying to connect to database, openFrameworks threw the errors-
“OF: OF_LOG_ERROR: mycontroller: Connection failed to database ‘products’ on host production ”
“OF: OF_LOG_ERROR: ofxMysql: Unknown Mysql server host ‘production’ (2)”
This was resolved by following instructions on the openFrameworks forum. Instead of passing the parameter ‘localhost’ to the ofxMysql function, the parameter ‘127.0.0.1’ was passed , which enabled connection to the database.
The requirements of the Agricultural Network Project include returning results from a query to an SMS, therefore, the results from the c/c++ query had to be returned to nodejs. Using the ofxMysql library also requires rewriting query functions that has already been written for nodejs – nodemsyql. Hence, it would be better to try to get the node-mysql module working.
The node-mysql module was verified to work with ofxNodejs by Satoru Higa under the environment: MacOSX 10.7.3 + XAMPP + node(macports) + npm(macports), and the recommendation was to verify that nodejs was properly installed through npm and the node_modules PATH was set in the Global Environment. It was discovered that there was a new version of nodejs available, and also, installing nodejs from the package available on the nodejs website did not install all the required libraries. (To view hidden files in Mac OSX please see – http://gigaom.com/apple/quick-tip-showhide-hidden-files/)
Screenshot showing version of nodejs installed and errors when nodejs is installed using the mac osx package file:
To resolve this problem macports (macports guide)was downloaded from – http://www.macports.org/install.php, and the package was installed on system. Nodejs was then installed through the terminal using the command : $ sudo port install nodejs – and entering root/administrator password. Npm was then installed using the command: $ sudo port install npm. Node-mysql was then installed using the command: $ npm install mysql.
Screenshot shows the results from reinstalling nodejs through macports, npm through macports, and mysql through npm:
Nodejs with node-mysql is now verified to work in openFrameworks using the ofxNodejs bridge under the environment: Mac osx 10.6.8 + MAMP + node(macports) + npm(macports).
Problem encountered when trying to update/delete records with nodejs.
Problem was due to incorrect statement. A similar post was found in node-mysql google group mailing list – http://groups.google.com/group/nodejs/browse_thread/thread/155f6faf6361b292. This was used as a guideline to rectify existing problem of updating records. System can now update existing records in database.
(Google search node-mysql update record – http://www.google.co.uk/search?q=node-mysql+update+record&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a)
C++ OpenFrameworks tutorial on creative computation – http://doc.gold.ac.uk/CreativeComputing/creativecomputation/?page_id=760
OpenFrameworks writing to screen – http://www.openframeworks.cc/documentation/graphics/ofTrueTypeFont.html