I am writing a code to send my arduino ip to my server but i am not getting any request from arduino even after sending request i don't know what is wrong with my code.The line ether.tcpsend() is executed in the code but i am not recieving any request.
#include <EtherCard.h>
#define STATIC 0 // set to 1 to disable DHCP (adjust myip/gwip values below)
// mac address
static byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
// ethernet interface ip address
static byte myip[] = { 172, 26, 40, 250 };
// gateway ip address
static byte gwip[] = { 172, 26, 40, 1 };
// LED to control output
int fPin = 10;
int bPin = 9;
byte Ethernet::buffer[700];
const char website[] PROGMEM = "172.26.42.240";
Stash stash;
void sendData() { // function to send post request
Stash stash;
byte sd = stash.create();
stash.print("ip=");
stash.print("ip");
stash.print("&mac=");
stash.println("mac");
stash.save();
int stash_size = stash.size();
Stash::prepare(PSTR("POST http://$F:8080/Connect/Arduino_data HTTP/1.0" "\r\n"
"Host: $F:8080" "\r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
ether.hisip, ether.hisip, stash_size, sd); // i tried placing website in place of ether.hisip but it is not working either
ether.tcpSend();
}
void setup () {
pinMode(fPin, OUTPUT);
pinMode(bPin, OUTPUT);
digitalWrite(bPin,HIGH);
Serial.begin(9600);
Serial.println("Trying to get an IP...");
Serial.print("MAC: ");
for (byte i = 0; i < 6; ++i) {
Serial.print(mymac[i], HEX);
if (i < 5)
Serial.print(':');
}
ether.begin(sizeof Ethernet::buffer, mymac, 8);
#if STATIC
Serial.println( "Getting static IP.");
if (!ether.staticSetup(myip, gwip)) {
Serial.println( "could not get a static IP");
}
#else
Serial.println("Setting up DHCP");
if (!ether.dhcpSetup()) {
Serial.println( "DHCP failed");
}
#endif
ether.printIp("My IP: ", ether.myip);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
ether.hisip[0] = 172;
ether.hisip[1] = 26;
ether.hisip[2] = 42;
ether.hisip[3] = 240;
ether.hisport = 8080;
sendData(); // function call to send post request
}
void loop () {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN9=ON") != 0) {
Serial.println("Received ON command");
digitalWrite(bPin, HIGH);
}
if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN9=OFF") != 0) {
Serial.println("Received OFF command");
digitalWrite(bPin, LOW);
}
if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN10=ON") != 0) {
Serial.println("Received ON command");
digitalWrite(fPin, HIGH);
}
if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN10=OFF") != 0) {
Serial.println("Received OFF command");
digitalWrite(fPin, LOW);
}
}
ether.tcpsend() returns 1