From a PIC to a mySQL data base? How do do that?

General discussion on mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
DingbatCA
Posts: 6
Joined: 28 Dec 2005 06:32
Location: Livermore CA
Contact:

From a PIC to a mySQL data base? How do do that?

#1 Post by DingbatCA » 05 Jan 2009 06:51

How in the heck do I do this?
On one side I have a dsPIC30F4013. On the other side, a Linux server with a mySQL data base. The server is hosting web pages so I can input data from a web interface.

I have a DS1812 hooked up to the pic and can pull tempture from it. I would like to get that data into the mySQL data base.

Lets make it a bit harder. The pic is in the middle of nowhere and is solar powered. Yes, that area does have cell covarage, so I am guessing a GSM modem will be needed.
How do I pull this off?

jcdarden
Posts: 41
Joined: 03 Aug 2008 07:42
Location: California USA
Contact:

#2 Post by jcdarden » 05 Jan 2009 09:31

The home alarm companies do this with GSM -- or with whoever's cell system they are using.

If they are doing it inside a small monthly alarm fee ... it can not be too expensive.

We have this on a house in Arizona ... which has no wire line phone. I don't recall the price but it is a standard alarm rate. No too much.

You may find some commercial re-seller of this service (other than the cellphone companies) who will put you on their sub-net for a reasonable fee. Perhaps even the alarm companies provide this service as an adjunct .. it would not surprise me.

There are also some 2-way radio communications companies who provide data relay -- including internet interface. Check Motorola in the area of interest. Not sure of the price..

One can, of course, do it themselves if a base station location is possible.
Thousand Oaks, CA
Skype Address is: "PatDarden"

DingbatCA
Posts: 6
Joined: 28 Dec 2005 06:32
Location: Livermore CA
Contact:

#3 Post by DingbatCA » 05 Jan 2009 17:50

I have AT&T as my current provider, and for basic testing, I will just steal the SIM out of my cell phone.

I was more trying to figure out the PIC side. How do I get the temperature value out to the server? Do I need to code a full TCP stack? Do I need to write a simple e-mail protocol?

anton
Posts: 807
Joined: 23 Sep 2004 09:16
Location: South-Africa
Contact:

#4 Post by anton » 06 Jan 2009 05:40

Hi DingbatCA,

I made use of a PHP script file on my server that receives data and then passes it to the mySQL database.

A simple script will look something like this

Code: Select all

<?php
$db_host = "www.yourhost.com";
$db_user = "your_mysql_username";
$db_pwd = "your_mysql_password";
$db_name = "the_database";

	$vdata = $_REQUEST['data'];

  mysql_connect($db_host, $db_user, $db_pwd)  or die("Unable to connect to database");
  mysql_select_db($db_name)  or die("Unable to select database");
  mysql_query("INSERT INTO YOUR_TABLE (DataID, Data) VALUES ('NULL', '.$vdata.')");

mysql_close();
?>
Now when you go to your internet explorer or firefox and type

Code: Select all

http://www.yoursite.com/write2.php?data=Hello
It will write Hello into the Data field. To do this on the PIC, you will need a GPRS modem such as the Telit GM862, make a simple GPRS connection and then send the following code to the module

Code: Select all

GET write2.php?data=Hello HTTP/1.1
Host: www.yoursite.com
Connection: close
Hope this help

Anton
Another proud user of LV 24-33A Development System and mikroPascal PRO for dsPIC :)
PortA not working? Add CMCON := 7; PortD not working? Add ADCON1 := 6;
To paste code on the forum, please use the [b] Code [/b] button !! ;)

DingbatCA
Posts: 6
Joined: 28 Dec 2005 06:32
Location: Livermore CA
Contact:

#5 Post by DingbatCA » 06 Jan 2009 17:13

That was what I was looking for. Thanks.

deploser
Posts: 11
Joined: 24 Dec 2009 08:27

#6 Post by deploser » 30 Dec 2009 15:48

Hi, I have a problem about connect my database over PHP run on my localhost. I'm trying to use PIC18F4620 and ENC28J60 Ethernet Microcontroller. Thanks for advice.

Best Regards
deploser

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 General”