Arduino отправляет данные на веб-сервер

Я работаю с группой, и у нас возникают проблемы с отправкой данных с Arduino на веб-сервер, который мы создали.

Ниже приведен код нашего веб-сервера с кодом locksys_server.ino

/*Web Server

A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.

Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5 (optional)

created 18 Dec 2009
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe

*/

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <Wire.h>// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192, 168, 2, 3 };

char x;
char c1;
char data[13];

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
EthernetClient client;

void setup() {
// Open serial communications and wait for port to open:
Wire.begin(4);                // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event

Serial.begin(9600);
if(Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure ethernet");
}
}void loop() {

if(client.connect(ip, 80) ) {
client.println("POST /Loksys/add.php HTTP/1.1");
client.println("Host: 192.168.2.3:80");
client.println("Content-Type: application/x-www-form-urlencoded");
client.println("Content-Length: ");
//client.println(data.length());
client.println();
client.print(data);
}

}

void receiveEvent(int howMany)
{
for (int i = 0; i < 12; i++)
// while(1 < Wire.available()) // loop through all but the last
{
c1 = Wire.read(); // receive byte as a character
Serial.print(c1);         // print the ch1aracter
data[i] = c1;
}
// x = Wire.read();    // receive byte as an integer
// Serial.println(x);         // print the integer
}

Ниже приведен код из нашего файла add.php

<?php
function Connection(){
$server="192.168.2.3";
$user="root";
$pass="";
$db="LockSys";

$connection = mysql_connect($server, $user, $pass);

if (!$connection) {
die('MySQL ERROR: ' . mysql_error());
}

mysql_select_db($db) or die( 'MySQL ERROR: '. mysql_error() );

return $connection;
}

$link=Connection();$RFID=$_POST["data"];$query = "INSERT INTO `checkin` (`rfid`)
VALUES ('$RFID')";

mysqli_query($query,$link);
mysqli_close($link);

header("Location: locksysHome.php");
?>

Мы загрузили код Arduino, но мы не получаем обновленных значений на веб-сервере всякий раз, когда мы передаем значения от Aruino на веб-сервер.

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …