使用EtherCard.h库将arduino数据发送到我的数据库

使用EtherCard.h库将arduino数据发送到我的数据库,arduino,ethernet,Arduino,Ethernet,我在将Arduino数据发送到数据库时遇到问题。我目前正在使用WAMPSERVER。我有一个arduino miniw/ATMEGA 328,我使用的是ENC28J60。问题是我尝试了不同的库和示例将数据发送到服务器,但失败了。我只是注意到一些库与我的enc28J60不兼容。我试过UIPEthernet.h、Ethernet.h、etherShield.h和EtherCard.h。etherShield.h和EtherCard.h似乎工作得很好。但我更喜欢使用EtherCard.h,因为我听说e

我在将Arduino数据发送到数据库时遇到问题。我目前正在使用
WAMPSERVER
。我有一个arduino mini
w/ATMEGA 328
,我使用的是ENC28J60。问题是我尝试了不同的库和示例将数据发送到服务器,但失败了。我只是注意到一些库与我的enc28J60不兼容。我试过UIPEthernet.h、Ethernet.h、etherShield.h和EtherCard.h。etherShield.h和EtherCard.h似乎工作得很好。但我更喜欢使用EtherCard.h,因为我听说etherShield是较旧的lib。我懂一点php


我认为可以指导我的是看一个使用EtherCard.h库的工作示例,演示如何将传感器数据从arduino发送到我的数据库中。我目前正在进行的网络设置是,
ENC28J60
连接在我的家庭网络中,ip地址为192.168.10.10。我放置数据库的服务器是我的笔记本电脑,IP地址为192.168.10.2。我将php文件放在这个目录
C:\wamp\www
。我希望我已经解释清楚了。我为我的英语感到抱歉。

我目前正在使用Ethercard lib(或UIPEthernet)将我的一个端口从Arduino Uno w Ethernet lib连接到AVR-NETIO

在服务器端有一个Apache/PHP/MySQL服务器

要更新与web服务器连接的数据库上的数据,可以使用对php网页的POST或GET请求。然后,可以轻松地将这些数据添加到数据库中,同一个或另一个网页也可以显示数据库的数据

<?php
require 'dbhelp.php';

//header('Content-type: text/plain');
echo "<html>";
echo "<head>";
echo "<meta name='viewport' content='width=device-width, user-scalable=false, initial-scale=1;'>";
echo "</head>";
echo "<body>" .        "<h2>Temperatur und Luftfeuchte</h2>";


// GET requests are sent as a query string on the URL:
// GET index.html?name1=value&name2=value HTTP/1.1
// Host: about.com
// http://192.168.0.40/homewatch/index.php?channel=1&temp=165&humidity=80&datetime=010120131234
if($DEBUG){
       print("<pre>");
print_r($_GET);
print("</pre>");
}

openDB();

if( isset($_GET['channel']) && isset($_GET['temp']) && isset($_GET['humidity']) )
{
  if($DEBUG)
    echo "<p>addData()";
  $c=$_GET['channel'];
  $t=$_GET['temp'];
  $h=$_GET['humidity'];
  addData($c, $t, $h);
  if($DEBUG)
     echo "<p>all done";
  //listData();
  echo "<p>OK updated data for channel:" . $c . "</p>";
}
else
{
  if($DEBUG)
    echo "listData()";
  //listData();
  //echo "<p>missing arg";
}
echo "<p><a href='linechart_hour.php'>Stunden-&Uuml;bersicht</a></p>";
echo "<p><a href='barchart_days.php'>Tages-&Uuml;bersicht</a></p>";
echo "<p><a href='http://www.unwetterzentrale.de/uwz/getwarning_de.php?plz=41363&uwz=UWZ-DE&lang=de'>Unwetterwarnungen J&uuml;chen</a></p>";

echo showAllCharts();
//#################################################################################
// see http://code.google.com/p/googlechartphplib/wiki/GettingStarted
//#################################################################################
// don't forget to update the path here
require './lib/GoogleChart.php';

$chart = new GoogleChart('lc', 500, 200);

// manually forcing the scale to [0,100]
$chart->setScale(0,100);

// add one line
$data = new GoogleChartData(array(49,74,78,71,40,39,35,20,50,61,45));
$chart->addData($data);

// customize y axis
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawTickMarks(false)->setLabels(array(0,50,100));
$chart->addAxis($y_axis);

// customize x axis
$x_axis = new GoogleChartAxis('x');
$x_axis->setTickMarks(5);
$chart->addAxis($x_axis);

echo $chart->toHtml();
//#################################################################################
// END
//#################################################################################

echo "<p>v0.9" . "</body>" . "</html>";
?>
:

字符串“GET/homewatch/index.php?channel=%i&temp=%i&湿度=%i&time=%i\0”仅用实际传感器数据填充,服务器将其保存到其数据库中

<?php
require 'dbhelp.php';

//header('Content-type: text/plain');
echo "<html>";
echo "<head>";
echo "<meta name='viewport' content='width=device-width, user-scalable=false, initial-scale=1;'>";
echo "</head>";
echo "<body>" .        "<h2>Temperatur und Luftfeuchte</h2>";


// GET requests are sent as a query string on the URL:
// GET index.html?name1=value&name2=value HTTP/1.1
// Host: about.com
// http://192.168.0.40/homewatch/index.php?channel=1&temp=165&humidity=80&datetime=010120131234
if($DEBUG){
       print("<pre>");
print_r($_GET);
print("</pre>");
}

openDB();

if( isset($_GET['channel']) && isset($_GET['temp']) && isset($_GET['humidity']) )
{
  if($DEBUG)
    echo "<p>addData()";
  $c=$_GET['channel'];
  $t=$_GET['temp'];
  $h=$_GET['humidity'];
  addData($c, $t, $h);
  if($DEBUG)
     echo "<p>all done";
  //listData();
  echo "<p>OK updated data for channel:" . $c . "</p>";
}
else
{
  if($DEBUG)
    echo "listData()";
  //listData();
  //echo "<p>missing arg";
}
echo "<p><a href='linechart_hour.php'>Stunden-&Uuml;bersicht</a></p>";
echo "<p><a href='barchart_days.php'>Tages-&Uuml;bersicht</a></p>";
echo "<p><a href='http://www.unwetterzentrale.de/uwz/getwarning_de.php?plz=41363&uwz=UWZ-DE&lang=de'>Unwetterwarnungen J&uuml;chen</a></p>";

echo showAllCharts();
//#################################################################################
// see http://code.google.com/p/googlechartphplib/wiki/GettingStarted
//#################################################################################
// don't forget to update the path here
require './lib/GoogleChart.php';

$chart = new GoogleChart('lc', 500, 200);

// manually forcing the scale to [0,100]
$chart->setScale(0,100);

// add one line
$data = new GoogleChartData(array(49,74,78,71,40,39,35,20,50,61,45));
$chart->addData($data);

// customize y axis
$y_axis = new GoogleChartAxis('y');
$y_axis->setDrawTickMarks(false)->setLabels(array(0,50,100));
$chart->addAxis($y_axis);

// customize x axis
$x_axis = new GoogleChartAxis('x');
$x_axis->setTickMarks(5);
$chart->addAxis($x_axis);

echo $chart->toHtml();
//#################################################################################
// END
//#################################################################################

echo "<p>v0.9" . "</body>" . "</html>";
?>
Ethercard库附带了类似的示例:请参阅noipClient、pachube和webclient示例。不幸的是,我还不能将这些应用于我的AVR-NETIO

将一些数据发布(获取)到我当前工作的服务器的代码是

PSTR("GET http://$F/homewatch/index.php?channel=$D&temp=$D&humidity=$D&time=$S"
如您所见,有一个格式化的字符串


它充满了变量$F从闪存中填充,$D a数字变量,$S从RAM内存字符串中填充。在不使用我的传感器代码(使用中断)的情况下使用此功能是可行的。

谢谢!。。我还没有访问过这个页面,但我使用UIPEthernet库实现了它。我使用了给出的示例并对其进行了调整。无论如何,这将是一个很好的参考,以防我将使用以太卡库,。谢谢。我也用UIPEthernet lib获得了它,但结果是使用情况有点不同。你是否使用android应用程序来监控你的系统?我的数据库现在每5秒更新一次,目前我正在开发一个android应用程序来监控读数。只是我在以文本视图格式而不是表格格式显示值时遇到问题。对不起,我的homewatch使用网页,可以在连接到我的网络的任何浏览器上显示。无需Android或iOS应用程序:
void sendData(int idxChannel){
    Serial.print(F("in sendData for idx=")); Serial.println(idxChannel);
    byte sd;
    int channel=sensorData[idxChannel].channel;
    int temp=sensorData[idxChannel].temp;
    int humidity=sensorData[idxChannel].humidity;
    char* stime="201301011122";
    stime=printDateTime((char*)&stime, 13, sensorData[idxChannel].time_long);

    if(sensorData[idxChannel].bUpdated==0){
      //nothing new
      if (MYDEBUG==0){
        Serial.println(F("leaving for not updated channel data"));
        goto exit_sendData;
      }
      else
      {
        sensorData[idxChannel].channel=idxChannel;
        sensorData[idxChannel].temp=222;
        sensorData[idxChannel].humidity=55;
        sensorData[idxChannel].time_long=now();      
      }
    }

    // generate two fake values as payload - by using a separate stash,
    // we can determine the size of the generated message ahead of time
    sd = stash.create();
    stash.print("0,");
    stash.println((word) millis() / 123);
    stash.print("1,");
    stash.println((word) micros() / 456);
    stash.save();

    // generate the header with payload - note that the stash size is used,
    // and that a "stash descriptor" is passed in as argument using "$H"
    Stash::prepare(PSTR("GET http://$F/homewatch/index.php?channel=$D&temp=$D&humidity=$D&time=$S" "\r\n"
                        "Host: $F" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),
            website, 
            channel,
            temp,
            humidity,
            stime,
            website, stash.size(), sd);

    // send the packet - this also releases all stash buffers once done
    ether.tcpSend();
exit_sendData:
  lastConnectionTime = now();//millis();
  Serial.println(F("...end of sendData()"));
}
PSTR("GET http://$F/homewatch/index.php?channel=$D&temp=$D&humidity=$D&time=$S"