Maik
July 30, 2017, 1:56pm
1
Hi,
I've got a php-script running on a webserver:
function arduino_send($ip,$port,$command) {
$res = fsockopen($ip,$port);
if($res) {
fwrite($res,$command);
echo "gesendet"; //echo "send"
return fread($res,20);
} else {
echo "Fehler, Kommando konnte nicht abgesetzt werden"; //not successful
}
$antwort = arduino_send($arduino_ip, $arduino_port, 'X');
echo $antwort;
}
Arduino:
....
client.write("TEST");
....
The php-scripts connects to the arduino and the arduino returns a string (?) "test". This works perfectly, but if I try to return an integer-value it doesnt work anymore:
....
int sensor_value = 350;
client.write(sensor_value);
serial.print(sensor_value);
....
This doesnt work. On the website I dont see the value "350" but any other character. Maybe I have to convert the integer to a string first ? The goal is to return a sensor-value to the website via client.write. Can somebody explain it to me ?
Thanks...
write and print operate differently. Look up the documentation. Then use the one you really need.
Maik
August 1, 2017, 10:43am
3
Thanks ! It works perfectly.
Now I try to send a GET-Request to an php-script. Can someone tell me how I could do that ?
For example the arduino has to "open" the script
"www.mywebsite_xyz.de/php-script.php?sensor=74"
And how could I do it via a Post-request ?
Thanks !
Maik
August 1, 2017, 3:21pm
4
Okay... I've tried to Connect to my server but it didn't work. So I tried to connect to google and Serial.print the return-value:
EthernetClient client;
int verbindung = client.connect("google.de ", 80);
Serial.println(verbindung);
The printed return-Value is "0". In the documentation it says:
Returns an int (1,-1,-2,-3,-4) indicating connection status :
Why does it return 0 ?
Here are my settings:
#include <SPI.h>
#include <Ethernet.h>
// MAC und IP Konfiguration
byte mac[] = {
0xDE, 0xAD, 0xBC, 0xAF, 0xFE, 0xED };
IPAddress ip(192,168,178, 20); // Local ip... correct ?????
IPAddress gateway(192,168,178, 1);
IPAddress subnet(255, 255, 255, 0)
....setup:
Ethernet.begin(mac, ip, gateway, subnet);