Попытка подключить сетевой экран к локальному серверу Apache

По большей части мне очень повезло с сетевым экраном, который я недавно приобрел. Я сейчас пытаюсь загрузить аналоговые данные из Arduino в локальную базу данных MySQL. Мой файл write_data.php, кажется, работает отлично, и я могу загружать данные в базу данных всякий раз, когда я вызываю файл write_data.php в URL. Хотя arduino всегда не может подключиться. Я использую маршрутизатор Netgear, и я проверил список разрешенных устройств в администраторе сети NetGein Genie, и был указан Arduino, что имеет смысл, потому что он работал для всех других моих проектов. Буду очень признателен за некоторые советы и идеи здесь. Кроме того, не уверен, что это будет иметь значение, но я использую mamp в качестве среды локального сервера. Файлы с цензурой находятся ниже:

write_data.php:

<?php

// Prepare variables for database connection

$dbusername = "test";  // enter database username, I used "arduino"    in step 2.2
$dbpassword = "test";  // enter database password, I used   "arduinotest" in step 2.2
$server = "50.135.xxx.xxx"; // IMPORTANT: if you are using XAMPP enter "localhost", but if you have an online website enter its address, ie."www.yourwebsite.com"
// Connect to your database

$dbconnect = mysql_pconnect($server, $dbusername, $dbpassword);
$dbselect = mysql_select_db("Test",$dbconnect);

// Prepare the SQL statement

$sql = "INSERT INTO Test.Sensor (value) VALUES   ('".$_GET["value"]."')";

// Execute SQL statement

mysql_query($sql);

?>

эскиз Arduino:

#include SPI.h

#include Ethernet.h

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Enter the IP address for Arduino, as mentioned we will use   192.168.0.16
// Be careful to use , insetead of . when you enter the address here

IPAddress ip(192,xxx,xx,xx);

int photocellPin = 2;  // Analog input pin on Arduino we connected the    SIG pin from sensor
int photocellReading;  // Here we will place our reading

char server[] = "50.135.xxx.xxx"; // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. "www.yourwebpage.com")

// Initialize the Ethernet server library
EthernetClient client;

void setup() {

// Serial.begin starts the serial connection between computer and Arduino
Serial.begin(9600);

// start the Ethernet connection
Ethernet.begin(mac ,ip);

}void loop() {

photocellReading = analogRead(photocellPin); // Fill the    sensorReading with the information from sensor

// Connect to the server (your computer or web page)
if (client.connect(server,8888)) {
client.print("GET /write_data.php?"); // This
client.print("value="); // This
client.print(photocellReading); // And this is what we did in the   testing section above. We are making a GET request just like we would from   our browser but now with live data from the sensor
client.println(" HTTP/1.1"); // Part of the GET request
client.println("Host: 50.135.xxx.xxx"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
client.println(); // Empty line
client.println(); // Empty line
client.stop();    // Closing connection to server

}

else {
// If Arduino can't connect to the server (your computer or web page)
Serial.println("--> connection failed\n");
}

// Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
delay(10000);
}

0

Решение

Была такая же проблема несколько недель назад.
Вы «недавно» приобрели щит Ethernet, так что это может быть щит Ethernet2, а не щит Ethernet.
Вы должны включить «Ethernet2.h» вместо «Ethernet.h», который находится только в IDE от Arduino.org, а не в Arduino.cc.

0

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

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

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector