Thursday, December 6, 2012

Remove cc2420 software CRC check

1*. Modify CC2420TinyosNetworkP.nc in /opt/tinyos/tos/chips/CC2420/lowpan

line 160 -163:

//if(!(call CC2420PacketBody.getMetadata(msg))->crc) {
// return msg;
//}

2. Modify CC2420ReceiveP.nc in /opt/tinyos/tos/chips/CC2420/receive

line 644 -652:

// We may have received an ack that should be processed by Transmit
// buf[rxFrameLength] >> 7 checks the CRC
if (rx_buf ) {
uint8_t type = ( header->fcf >> IEEE154_FCF_FRAME_TYPE ) & 7;
signal CC2420Receive.receive( type, m_p_rx_buf );
post receiveDone_task();
return;
}

3. 2. Modify CC2420ReceiveP.nc in /opt/tinyos/tos/chips/CC2420/receive

line 381:

if( (header.fcf & (1 << IEEE154_FCF_SECURITY_ENABLED)) && (crc << 7) ){

to

if( header.fcf & (1 << IEEE154_FCF_SECURITY_ENABLED) ){

Friday, August 17, 2012

Fix ImportError: No module named dateutil.rrule error in MAC 10.8 with Python 2.7.3


When I try to execute python code with import matplotlib, I received following errors:


Traceback (most recent call last):
  File "plotPRREachNode.py", line 6, in
    import matplotlib.pyplot as pl
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/pyplot.py", line 26, in
    from matplotlib.figure import Figure, figaspect
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/figure.py", line 19, in
    from axes import Axes, SubplotBase, subplot_class_factory
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/axes.py", line 19, in
    import matplotlib.dates as mdates
  File "/Library/Python/2.7/site-packages/matplotlib-1.2.x-py2.7-macosx-10.8-intel.egg/matplotlib/dates.py", line 122, in
    from dateutil.rrule import rrule, MO, TU, WE, TH, FR, SA, SU, YEARLY, \
ImportError: No module named dateutil.rrule


The method to solve this error is go to http://labix.org/python-dateutil/#head-2f49784d6b27bae60cde1cff6a535663cf87497b and download the python-dateutil-1.5.tar.gz 

Then untar the file and type in command line:
python setup.py install



That's it, wish this could help.


Tuesday, August 14, 2012

EASY Install matplotlib on mac ox 10.8



  1. Get Xcode 4.3.2, it's required for some of the later steps.
  2. Download the latest version of python for OSX from python.org
  3. Grab the Scipy superpack.
  4. Uninstall any previous versions of numpy/matplotlib/scipy that you currently have. That includes doing cd /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ and moving any numpy/matplotlib/scipy directories or eggs into a temp directory.
  5. cd ~/Downloads(or wherever you downloaded the superpack script to) and run sh install_superpack.shAnswer no to the question are you installing from a repository cloned to this machine or you'll be confused about why the script keeps failing.
That should be it! You should now be able to boot up the python console and import numpy, scipy, matplotlib.
share|improve this answer




source:  http://fonnesbeck.github.com/ScipySuperpack/


Alternately, if you have curl installed, you can get the script via:
$ curl -o install_superpack.sh 
https://raw.github.com/fonnesbeck/ScipySuperpack/master/install_superpack.sh
To install, open a terminal in the directory that the script is located and call:
$ sh install_superpack.sh
You will be prompted for your administrator password. If you have already installed the current gFortran, you can bypass that package during the install process. Similarly, the installation requires Git, so you will be prompted to install it if you are installing remotely.

Sunday, April 29, 2012

How to resync MySQL Replication after updated master database

After update the table structure in master database, the slave stopping replication. After update the mysqldump with -d  for the new database to slave machine, it report duplicate entry error.

You can using following commands to fix it: (source: http://forums.mysql.com/read.php?26,24736,24884#msg-24884)

mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; 
mysql> START SLAVE; 

Use the value 1 for any SQL statement that does not use AUTO_INCREMENT or LAST_INSERT_ID(), otherwise you will need to use the value 2. Statements that use AUTO_INCREMENT or LAST_INSERT_ID() take up 2 events in the binary log.

Friday, February 24, 2012

Setup connection to MySQL in VS 2010

Author: 
Source: http://arunasujith.blogspot.com/2012/02/mysql-c-connection-example-in-visual_10.html


Creating a MySQL database connection using C++ is  really easy. But for a beginner it can be really hard to find the correct procedure cause it will gave really troubles. At the first time when I'm doing it it took me quite some time to make it work. So I'm going to explain how to make a connection to the MySQL database using C++ code. We use the library called boost to make the connection. 

Step 1 (Download the boost library)
First step is to download the boost library. You can download it from here from the official download page Or you can download the one I've compressed and uploaded which is smaller in size from here.

Step 2 (Create the project using Visual Studio 2008)
First go  to File --> New --> Project and you'll get a screen like this. 

mysql c++ connection example

Select Visual C++ --> Win 32 --> Win 32 Console Application  and give a name to the project and press OK. 
Then set Application Type to Console Application and remember to tick the empty project. and click finish.

Then Right Click the project and add new Item a cpp source file called Connect.cpp.

// Standard includes
#include 
#include 
#include 
using namespace std;

// Connector Includes

#include "cppconnection/driver.h"
#include "cppconnection/exception.h"
#include "cppconnection/resultset.h"
#include "cppconnection/statement.h"


// Link to the Connector/C++ library
#pragma comment(lib, "mysqlcppconn.lib")

// Connection details
string server   = "localhost";
string username = "root";
string password = "123"; //

int main(){
    sql::Driver     *driver; // MySQL Driver Object
    sql::Connection *connection; // MySQL connection Object
    sql::Statement  *statement;   // Statement which holds SQL commands
    sql::ResultSet  *resultSet;    // ResultSet to hold the results
    //Here is the connection
    try{
        driver = get_driver_instance();
        connection = driver->connect(server, username, password);
        statement = connection->createStatement();
        statement->execute("USE performance_schema");
        resultSet = statement->executeQuery("show tables");
        while (resultSet->next()){
            // Iterating the result set
            cout << resultSet->getString(1) << endl;               
        }
    }
    catch (sql::Exception e){
        cout << "Error message: " << e.what() << endl;
        system("pause");
        exit(1);
    }

    //Clear resources
    delete res;
    delete statement;
    delete connection;

    system("pause");
    return 0;
}

Copy the boost folder into the project folder. In this example the folder is Visual Studio 2008\Projects\MySQLConnection\MySQLConnection folder.

Then download this header and dll files and extract them into the same folder Visual Studio 2008\Projects\MySQLConnection\MySQLConnection folder.

Then the final step is right cilck on the Project and go to 
Properties --> Configuration Properties --> C/C++ --> General . 
On the right hand side set the "Additional Include Directories" value to ".\" value. (with out the quotes)

That's it build your project and run the project. And one more final thing when you run the project set the  "Solution Configuration" to Release mode. In the Debug Mode I had some error which I still don't no why.

So that's it now I think you got a clear idea about creating a connection for MySQL using C++ in Visual Studio 2008. See you around with another exciting post... :)

Tuesday, January 31, 2012

get ForwardingTable size in tinyos


entry = call ForwardingTable.getTable(&n);
while(entry[cur_entry].valid)
cur_entry++;
    printf("\t\tthe length of ForwardingTable is %i\n", cur_entry);

Monday, January 30, 2012

Printf in tinyos


To see the output generated by the Printf tutorial application you need to start the PrintfClient by running
the following command:


java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSBXXX:telosb


A few points are worthy of note before jumping in and writing your own applications that use the functionality
provided by the printf library.
1. In order to use the printf library, the tos/lib/printf directory must be in your include path. The
easiest way to include it is by adding the following line directly within the Makefile of your top level
application:
CFLAGS += -I$(TOSDIR)/lib/printf
2. Remember that changing the printf buffer size is done similarly:
CFLAGS += -DPRINTF_BUFFER_SIZE=XXX3. You MUST be sure to #include "printf.h" header file in every component in which you would like to
call the printf() command. Failure to do so will result in obscure error messages making it difficult to
identify the problem

Monday, January 16, 2012

Allow user to access mysql database from anywhere

GRANT ALL ON *.* TO USERNAME@'%' IDENTIFIED BY 'PASSWORD';

Thursday, January 5, 2012

Connect to MySQL using C++ on Ubuntu

Source:  http://blog.trilabs.co.tz/2011/09/connect-to-mysql-using-c-on-ubuntu.html


Someone asked on Facebook how to connect to a MySQL Database Using C++. So I thought it will be cool to just share it here for everyone.

Ground Work

Here is how things look like on my computer.
  • OS:  Ubuntu 11.04  ( Linux legacy 2.6.38-11-generic #48-Ubuntu SMP Fri Jul 29 19:05:14 UTC 2011 i686 i686 i386 GNU/Linux)
  • DB: MySQL 5.1 ( mysql Ver 14.14 Distrib 5.1.54, for debian-linux-gnu (i686) using readline 6.2)
  • Compiler:  GCC 4.5 (g++ (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2)
I had to install some C++ MySQL Connector and other helpers, actually after trying the textbook way and it did not work, I did a bit of googling and asking dev here and there.
?View Code SHELL
sudo apt-get install libmysqlcppconn4 libmysqlcppconn-dev libmysqlclient-dev

Code

To illustrate this, I am going to connect to the development database of one of the project I am working on show a list of products against store they can be bought. I am assuming your database knowledge in order. I have also added as much details as I could on the code itself.
?View Code CPP
#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
 
/**
 * This structure will be used to store all cessary inforamtion to connect to the database
 */
struct connection_details
{
    char *server;
    char *user;
    char *password;
    char *database;
};
 
/**
 * Sets up connection to the database, this depends on the functions from mysql.h.
 * This function will connect and return a MYSQL pointer to the new connection using the
 * structure above connection_details.
 */
MYSQL* mysql_connection_setup(struct connection_details mysql_details)
{
     // first of all create a mysql instance and initialize the variables within
    MYSQL *connection = mysql_init(NULL);
 
    // connect to the database with the details attached.
    if (!mysql_real_connect(connection,mysql_details.server, mysql_details.user, mysql_details.password, mysql_details.database, 0, NULL, 0)) {
      printf("Conection error : %s\n", mysql_error(connection));
      exit(1);
    }
    return connection;
}
 
/**
 * Performs the query.
 * This function perform the SQL quert and returns a pointer of MYSQL_RES
 */
MYSQL_RES* mysql_perform_query(MYSQL *connection, char *sql_query)
{
   // send the query to the database
   if (mysql_query(connection, sql_query))
   {
      printf("MySQL query error : %s\n", mysql_error(connection));
      exit(1);
   }
 
   return mysql_use_result(connection);
}
 
/**
 * Main function
 */
int main()
{
  MYSQL *conn;  // the connection
  MYSQL_RES *res; // the results
  MYSQL_ROW row; // the results row (line by line)
 
  struct connection_details mysqlD;
  mysqlD.server = "localhost";  // where the mysql database is
  mysqlD.user = "jikoni";  // the root user of mysql
  mysqlD.password = "ugalinakuku"; // the password of the root user in mysql
  mysqlD.database = "discounts"; // the databse to pick
 
  // connect to the mysql database
  conn = mysql_connection_setup(mysqlD);
 
  // assign the results return to the MYSQL_RES pointer
  res = mysql_perform_query(conn, "SELECT products.product,stores.name  FROM products, stores WHERE products.sto_id = stores.id");
 
  printf("\n\t Product -> Store:\n\n\n");
 
  //To traverse the results we use a while loop in C++ and use the mysql_fetch_row function from within the mysql library set
  //where a row is a type of MYSQL_ROW.
 
  while ((row = mysql_fetch_row(res)) !=NULL)
      printf("\t-> %s -> %s \n", row[0],row[1]);
 
  /* clean up the database result set */
  mysql_free_result(res);
  /* clean up the database link */
  mysql_close(conn);
 
  return 0;
}

Compiling the code

Compile this program is a bit tricky as we need to link to the mysql libraries and headers that we have  used within the program, in our case the  mysql.h.  Luckly for us we can make use of the mysql_config, you may need to install it via your package manager system if you do not have it already. I already had it installed.
mysql_config provides you with useful information for compiling your MySQL client and connecting it to MySQL.
See what information it has by simply running it.
?View Code SHELL
# mysql_config
Usage: /usr/bin/mysql_config [OPTIONS]
Options:
        --cflags         [-I/usr/include/mysql  -DBIG_JOINS=1  -fno-strict-aliasing   -DUNIV_LINUX -DUNIV_LINUX]
        --include        [-I/usr/include/mysql]
        --libs           [-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient]
        --libs_r         [-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient_r]
        --plugindir      [/usr/lib/mysql/plugin]
        --socket         [/var/run/mysqld/mysqld.sock]
        --port           [0]
        --version        [5.1.54]
        --libmysqld-libs [-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqld -ldl -lwrap -lrt]
So to compile it run
?View Code SHELL
# g++ -o cmysql $(mysql_config --cflags) cmysql.cpp $(mysql_config --libs)
cmysql.cpp: In function ‘int main()’:
cmysql.cpp:60:19: warning: deprecated conversion from string constant to ‘char*’
cmysql.cpp:61:17: warning: deprecated conversion from string constant to ‘char*’
cmysql.cpp:62:21: warning: deprecated conversion from string constant to ‘char*’
cmysql.cpp:63:21: warning: deprecated conversion from string constant to ‘char*’
cmysql.cpp:69:129: warning: deprecated conversion from string constant to ‘char*’
Ignore the warring for now,  if there errors then fix them and run the executable, cmysql, that would have been generated. I will look into the warnings in time.
?View Code SHELL
# ./cmysql 
 
  Product -> Store:
 
 -> USB Flash Disk -> Brand Computers Ltd
 -> Dell 65-Watt 3-Prong Slim AC Adapter -> Brand Computers Ltd
 -> Dell Streak 7 Android Tablet -> Brand Computers Ltd
 -> Nokia 701 -> Brand Computers Ltd
 -> Dell Inspron 1240 -> Just Computers
 -> HP Photosmart D110A -> Just Computers
 -> Web Hosting -> Tri Labs Limited
 -> Bulk SMS -> Tri Labs Limited
 -> EVDO USB Modem -> Tri Labs Limited
 -> EVDO USB Modem -> Tri Labs Limited
 -> Joomla We Template -> Tri Labs Limited
 -> Night Gear -> Viatuzi
 -> Tech Sports Bra -> Viatuzi
 -> Women's Fiona Bra -> Viatuzi
 -> VRV Color Tank -> Viatuzi
I hope this help someone out there.