Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Can';t连接Arduino Y和xF9;n到本地服务器_Php_Mysql_Arduino - Fatal编程技术网

Php Can';t连接Arduino Y和xF9;n到本地服务器

Php Can';t连接Arduino Y和xF9;n到本地服务器,php,mysql,arduino,Php,Mysql,Arduino,我是Arduino编程新手,在让我的Arduino yùn连接到本地服务器时遇到了很多问题。我的目标是能够将温度数据从arduino发送到phpmyadmin,但到目前为止,我甚至无法连接。这是我试图测试连接的代码: #include <SPI.h> #include <Ethernet.h> byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192,168,240,126); IPAd

我是Arduino编程新手,在让我的Arduino yùn连接到本地服务器时遇到了很多问题。我的目标是能够将温度数据从arduino发送到phpmyadmin,但到目前为止,我甚至无法连接。这是我试图测试连接的代码:

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,240,126);
IPAddress gateway(192, 168, 240, 1);
IPAddress subnet(255, 255, 255, 0);

IPAddress server(127,0,0,1); // Change to your server ip

EthernetClient client;
int totalCount = 0;
int loopCount = 0;

void setup() {
  Serial.begin(9600);

  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  Serial.println("Ready");
}

char pageAdd[32];
void loop()
{
  if(loopCount < 30)
  {
    delay(1000);
  }
  else
  {
    loopCount = 0;
    sprintf(pageAdd,"/arduino.php?temp1=%d",totalCount);
    if(!getPage(server,pageAdd)) Serial.print("Fail ");
    else Serial.print("Pass ");
    totalCount++;
    Serial.println(totalCount,DEC);
  }    

  loopCount++;
}

byte getPage(IPAddress ipBuf,char *page)
{
  int inChar;
  char outBuf[128];

  Serial.print("connecting...");

  if(client.connect(ipBuf,80))
  {
    Serial.println("connected");

    sprintf(outBuf,"GET %s HTTP/1.0\r\n\r\n",page);
    client.write(outBuf);
  } 
  else
  {
    Serial.println("failed");
    return 0;
  }

  int connectLoop = 0;

  while(client.connected())
  {
    while(client.available())
    {
      inChar = client.read();
      Serial.write(inChar);
      connectLoop = 0;
    }

    delay(10);
    connectLoop++;
        if(connectLoop > 1000)
        {
          Serial.println();
          Serial.println("Timeout");
          client.stop();
        }

      }

      Serial.println();

      Serial.println("disconnecting.");
      client.stop();

      return 1;
    }
#包括
#包括
字节mac[]={0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
ip地址ip(192168240126);
IP地址网关(192、168、240、1);
IP地址子网(255、255、255、0);
IP地址服务器(127,0,0,1);//更改您的服务器ip地址
以太网络客户端;
int totalCount=0;
int loopCount=0;
无效设置(){
Serial.begin(9600);
pinMode(4,输出);
数字写入(4,高);
以太网开始(mac、ip、网关、网关、子网);
延迟(2000年);
Serial.println(“就绪”);
}
char pageAdd[32];
void循环()
{
如果(循环计数<30)
{
延迟(1000);
}
其他的
{
循环计数=0;
sprintf(pageAdd,“/arduino.php?temp1=%d”,totalCount);
如果(!getPage(服务器,pageAdd))串行打印(“失败”);
else序列号。打印(“通过”);
totalCount++;
串行打印项次(总计数,12月);
}    
loopCount++;
}
字节getPage(IPAddress ipBuf,char*page)
{
英查;
char-f[128];
串行打印(“连接…”);
if(客户端连接(ipBuf,80))
{
Serial.println(“已连接”);
sprintf(EXBUF,“获取%s HTTP/1.0\r\n\r\n”,第页);
client.write(extruf);
} 
其他的
{
Serial.println(“失败”);
返回0;
}
int connectLoop=0;
while(client.connected())
{
while(client.available())
{
inChar=client.read();
串行写入(英寸);
connectLoop=0;
}
延迟(10);
connectLoop++;
如果(连接回路>1000)
{
Serial.println();
Serial.println(“超时”);
client.stop();
}
}
Serial.println();
Serial.println(“断开”);
client.stop();
返回1;
}
以下是.php文件:

<?
    $temp1 = $HTTP_GET_VARS['temp1'];
?>
<html>
<body>
test server page<br>
<? echo('temp1 = ' . $temp1 . ' '); ?>
</body>
</html>

测试服务器页面
IP地址服务器(127,0,0,1)


这是服务器的本地主机地址。将其更改为您服务器的IPv4地址。

您知道了吗?我也在试着做同样的事情。我插入arduino并能够访问arduino.local,但一旦我尝试使用我的wifi配置它(我知道我使用的是正确的wifi密码),它就会重置,然后我就无法再回到arduino.local了!最终,我只是试图从我的php网站读取数据并发出命令,但首先我需要弄清楚如何连接这该死的东西