【问题标题】:Arduino ethernet shield phpArduino以太网屏蔽php
【发布时间】:2016-10-21 18:22:09
【问题描述】:

我开发了一个代码,用于计算通过红外传感器前的人数。

但我希望 arduino 是客户端,而 FTP 服务器使用这些值。但我不知道php,但它会是这样的。服务器是本地主机。

文件.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);

}

文件.php:

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

【问题讨论】:

    标签: php arduino


    【解决方案1】:

    文件.php:

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

    如果编辑php文件不起作用,请尝试在if (client.connect)之前添加以下内容:

    data = "nPessoas=" + nPessoas;
    

    然后将client.print(nPessoas);改为client.print(data);

    【讨论】:

    • 注意:未定义索引:第 2 行 /opt/lampp/htdocs/teste.php 中的 nPessoas
    • 尝试print_r($_POST);
    • 他好像没过岗。
    • 打印邮寄有什么收获吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    相关资源
    最近更新 更多