简体   繁体   English

Arduino以太网盾PHP

[英]Arduino ethernet shield php

I developed a code that counts the number of people passing in front of the infrared sensors. 我开发了一个代码,计算在红外传感器前面经过的人数。

But I wanted the arduino was a client and the FTP server consume these values. 但是我希望arduino是客户端,而FTP服务器使用这些值。 But I do not know php, but it would be something like this. 但是我不知道php,但是这样的话。 The server is localhost. 服务器是本地主机。

file.ino: file.ino:

#include <UIPEthernet.h>

EthernetServer server = EthernetServer(80);

int sensor1 = 8;
int sensor2 = 9;
unsigned long timeS1 = 0, timeS2 = 0;
unsigned long dif;
long int nPessoas = 0;


void setup()
{
    pinMode(sensor1, INPUT);
    pinMode(sensor2, INPUT);

    Serial.begin(9600);

    uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
    IPAddress myIP(192,168,0,25);
    Ethernet.begin(mac,myIP);
    server.begin();
}

void loop()
{
    if (!digitalRead(sensor1))
    {
        timeS1 = millis(); 
    }
    if (!digitalRead(sensor2))
    {
        timeS2 = millis(); 
    }

    dif = timeS2 - timeS1;

    dif = timeS2 - timeS1;
    if(dif >= 500 && dif <= 1500)
    {
       timeS1 = timeS2 = 0;
       nPessoas++;
   }

    size_t size;

    if (EthernetClient client = server.available())
    {
        while((size = client.available()) > 0)
        {
            uint8_t* msg = (uint8_t*)malloc(size);
            size = client.read(msg,size);
            Serial.write(msg,size);
            free(msg);
        }
        if (client.connect("http://192.168.0.7/",80)) { 
        client.println("POST /file.php HTTP/1.1"); 
        client.println("Host: http://192.168.0.7/"); 
        client.println("Content-Type: application/x-www-form-urlencoded"); 
        client.print("Content-Length: "); 
        client.println(); 
        client.print(nPessoas); 
} 
        client.stop();
    }

    delay(10);

}

file.php: file.php:

<?Php
$value = $_GET {['nPessoas']};
echo $value;
?>

File.php: File.php:

<?php
$value = $_POST['nPessoas'];
echo $value;
?>

If it doesn't work by editing the php file, then try to add following before if (client.connect) : 如果通过编辑php文件不起作用,请尝试在if (client.connect)之前添加以下内容:

data = "nPessoas=" + nPessoas;

And then change client.print(nPessoas); 然后更改client.print(nPessoas); to client.print(data); client.print(data);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM