serbotec
Posts: 7
Joined: Wed Aug 12, 2015 11:02 am

Sending data from Gertboard to database

Sun Nov 22, 2015 3:52 pm

Hello everyone,
Im using Raspberry Pi 2 with gertboard rev 2 +ATMega 328p
I have a project for my college to record, measure wind and to visualization the recorded data with the LAMP(Linux Apache as Webserver, Mysql database and PHP) system.

I would like to send my data directly to my mysql database. I have found some solution with minicom (.txt) but is there another way to send the recorded data from the gertboard ?

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: Sending data from Gertboard to database

Sun Nov 22, 2015 4:00 pm

If the MySQL server is running on the same raspberry pi it's pretty easy to so with python.
If not, you'll need the MySQL to be accessible trough network. ;)

Laurens

serbotec
Posts: 7
Joined: Wed Aug 12, 2015 11:02 am

Re: Sending data from Gertboard to database

Sun Nov 22, 2015 6:57 pm

Laurens-wuyts wrote:If the MySQL server is running on the same raspberry pi it's pretty easy to so with python.
If not, you'll need the MySQL to be accessible trough network. ;)

Laurens
Hey Laurens thanks for the fast response,

The input is coming from my circuite board it goes over the ADC, than my Atmega Chip is transforming floting number voltage into the wind speed. The only way to see my recorded data from my gertboard is minicom (.txt).
I don't know, how i get the numbers from my microcontroller to raspberry/mysql.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: Sending data from Gertboard to database

Sun Nov 22, 2015 9:43 pm

For python you have the python serial library, which handles uart (serial) communication (like minicom).
I think you should be able to receive the data in python and write it to a database.
P.S. could you post the command that you are using for minicom?

Laurens

serbotec
Posts: 7
Joined: Wed Aug 12, 2015 11:02 am

Re: Sending data from Gertboard to database

Sun Dec 06, 2015 4:25 pm

Laurens-wuyts wrote:For python you have the python serial library, which handles uart (serial) communication (like minicom).
I think you should be able to receive the data in python and write it to a database.
P.S. could you post the command that you are using for minicom?
Laurens
I used the makefile from wiringpi/examples/gertboard and added some lines with #c for mysql to compile it:
LDFLAGS = -L/usr/local/lib -L/usr/include/
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm `mysql_config --cflags` `mysql_config --libs`

So far its compiling and i don't have any issues with that, but my access to the database gets denied. I don't know why? I installed the sudo apt-get install libmysqlclient-dev before for the mysql header. Here is my code for the connection:

Code: Select all

#include <stdio.h>
//gertboard includes:
#include <wiringPi.h>
#include <gertboard.h>
//mysql includes;
#include <mysql/mysql.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

//parameters:
#define DATABASE_NAME  "test"
#define DATABASE_USERNAME "root"
#define DATABASE_PASSWORD "xxxxxxxxxxxx"

//MYSQL objekt
MYSQL *mysql1;

void mysql_connect (void)
{
     //initialize MYSQL object for connections
 mysql1 = mysql_init(NULL);

     if(mysql1 == NULL)
     {
         fprintf(stderr, "ABB : %s\n", mysql_error(mysql1));
         return;
     }

     //Connect to the database
     if(mysql_real_connect(mysql1, "192.168.2.120", DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, 0, NULL, 0) == NULL)
     {
      fprintf(stderr, "%s\n", mysql_error(mysql1));
     }
     else
     {
         printf("Database connection successful.\r\n");
     }
}
Thank you for the help so far.

User avatar
Laurens-wuyts
Posts: 716
Joined: Wed Aug 21, 2013 7:35 pm
Location: Belgium
Contact: Website

Re: Sending data from Gertboard to database

Mon Dec 07, 2015 5:04 am

The problem probably is that you try to connect to the database, but you didn't allow external access to the database. ;)
Try this and see if it works then.

Laurens

serbotec
Posts: 7
Joined: Wed Aug 12, 2015 11:02 am

Re: Sending data from Gertboard to database

Mon Dec 07, 2015 1:33 pm

Laurens-wuyts wrote:The problem probably is that you try to connect to the database, but you didn't allow external access to the database. ;)
Laurens
You were right Laurens, I did this Configuring MySQL for Network access it was a bit easier than your link :D .

I added in phpmyadmin a new USER "pi_insert" in the privileges with all ALL PRIVILEGES and Database-specific privileges for my database that im using for my measurement. Now everything is working with the connection and i get a

Code: Select all

Database connection successful.
Thank you,
Milo

Return to “HATs and other add-ons”