Hello everyone.
I am trying to send a TCP data from my ENC28J60 to WAMPServer , I want to be able to send data to a php page.
The ip of wamp is 192.168.0.100:80 and the location of the test page is 192.168.0.100/seguranca/callback.php. With the code below is correct to get/post the value sent from the arduino?
Arduino code:
// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
#include <EtherCard.h>
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[700];
static uint32_t timer;
char website[] PROGMEM = "192.168.0.100";
//char website[] PROGMEM = "google.com";
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
}
void setup () {
Serial.begin(9600);
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
Serial.println();
Serial.print("<<< REQ ");
ether.hisport = 80;//to access local host
ether.browseUrl(PSTR("/seguranca/callback.php?"), "get=Hello", website, my_callback);
}
}
PHP code(only test):
if(isset($_GET['get']) or isset($_POST['get'])){
mkdir('/teste', 0777, true);
chmod('/teste', 0777);
echo "Feito";
}else{
echo "Vazio";
}