I have a wireless card called a WiFly RN-XV that I am using to to send data to a PHP script on my drupal server. The script currently writes that data to an HTML file on the server.

<?php
     $data
=$_GET["DATA"];
    
$mac=$_GET["mac"];
    
$rtc=$_GET["rtc"];
    
$id=$_GET["id"];
    
$bss=$_GET["bss"];
    
$bat=$_GET["bat"];
    
$io=$_GET["io"];
    
$wake=$_GET["wake"];
    
$seq=$_GET["seq"]; 
    
$rtc_val=hexdec($rtc);
    
$rtc_sec=$rtc_val % 60; $rtc_val/=60;
    
$rtc_min=$rtc_val % 60; $rtc_val/=60;
    
$rtc_hr =$rtc_val % 24; $rtc_val/=24;
     echo
"Got data " . $data . " " . $rtc;
    
$file_name="userdata.htm";
    
$dataf=fopen($file_name, 'w') or die();
    
flock($dataf, 2) or die();
    
fputs($dataf,"<html>\n");
    
fputs($dataf,"<head>\n<title>User Data</title></head>\n");
    
fputs($dataf,"<body>\n");
    
fputs($dataf,"Id:   " . $id   . "<br>");
    
fputs($dataf,"Mac:  " . $mac  . "<br>");
    
fputs($dataf,"Data: " . $data . "<br>");
    
fputs($dataf,"RTC:  " . $rtc  . "<br>");
    
fputs($dataf,"ID:   " . $id   . "<br>");
    
fputs($dataf,"BSS:  " . $bss  . "<br>");
    
fputs($dataf,"Bat:  " . $bat  . "<br>");
    
fputs($dataf,"IO:   " . $io   . "<br>");
    
fputs($dataf,"Wake: " . $wake . "<br>");
    
fputs($dataf,"Seq:  " . $seq . "<br>");
    
fclose($dataf);
?>

Since I am not that familiar with PHP, I was wondering if anyone knows a better way to import data using PHP in to Drupal. I only really need to import in to one page, view, or block.

I have also tried Feeds using an XPATH HTML parser, but am having problems filtering out the HTML from the actual data.

Any help would be greatly appreciated.

Comments

VM’s picture

per: https://drupal.org/node/643758 please edit the opening post and move this thread to a more appropriate forum. As you have code, the most appropriate forum would be the module development and code questions forum.

coffeenmusic’s picture

Well I figured out how to add this information in to a database (see below), but I am still at a loss for how to take the database information and graph it. Does any one have an idea of how to pull database values in to Views or straight in to a chart/graph? I have tried the data module, which I was able to pull database info but cannot see it in Views. I can't seem to find a chart module that pulls directly from a database.

PHP file to get WiFly module data in to my database:

<?php
define
('DB_NAME','my_db');
define('DB_USER','my_user_name');
define('DB_PASSWORD','my_password');
define('DB_HOST','localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!
$link){
    die(
'Could not connect:' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if(!
$db_selected){
    die(
'Can\'t use ' . DB_NAME . ': ' . mysql_error());
}

echo
'Connected Successfully!';

$data=$_GET["DATA"];
$channel2hex=substr($data,12,4);
$channel2hexshift=str_pad($channel2hex, 5, "0", STR_PAD_RIGHT);    
$channel2decimal=base_convert($channel2hexshift,16,10);
$channel2voltage=($channel2decimal*0.000006755)-0.230097;
$channel2millivoltage=$channel2voltage*1000;

$sql = "INSERT INTO wifly (CH2) VALUES ('$channel2millivoltage')";

if(!
mysql_query($sql)){
    die(
'Error: ' . mysql_error());
}

mysql_close();
?>
Jaypan’s picture

What does this have to do with Drupal? Your code is for a non-Drupal script.

coffeenmusic’s picture

My question is Drupal related, I am using this on my Drupal site, and I was hoping to help anyone else with similar issues out in the future.