I'm using ENC28J60 with Arduino and using Ethercard library. When i url parse data from browser the data gets to the mysql db. But from Arduino it is post blank. below is my sketch and please help me to resolve this.
#include <EtherCard.h>
// your variable
String KEY = "A123DS";
String SID = "PS1"
// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
const char website[] PROGMEM = "192.168.1.106";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup () {
Serial.begin(57600);
Serial.println("\n[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac, 4) == 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 0
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
#else
ether.parseIp(ether.hisip, "192.168.1.106");
#endif
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
byte sd = stash.create();
stash.print("apikey=");
stash.print(KEY);
stash.print("station_id=");
stash.print(SID);
stash.save();
Stash::prepare(PSTR("POST http://192.168.1.106/saveContactinfo.php?sd HTTP/1.0" "\r\n"
"Host: 192.168.1.106 \r\n"
"Content-Length: $D" "\r\n"
"Content-Type: application/x-www-form-urlencoded \r\n"
"\r\n"
"$H"),
stash.size(), sd);// website, PSTR(PATH), website,
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
when i try this it send the data so maybe problem with stash or something when sending as stash
Stash::prepare(PSTR("POST http://192.168.1.106/saveContactinfo.php?apikey=A123DS&station_id=PS1 HTTP/1.0" "\r\n"
"Host: 192.168.1.106 \r\n"
"Content-Length: $D" "\r\n"
"Content-Type: application/x-www-form-urlencoded \r\n"
"\r\n"
"$H"),
stash.size(), sd);// website, PSTR(PATH), website,
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
So someone please tell me what i am doing wrong. I need an urgent help from you guys
Thanks is advance
have you tried to ensure reachability form your arduino to your network? are you sure that works?
what web server do you use? are you sure it's reachable outside the hosting machine?
what do you see in the logs of your web server?
as a side note, don't think it matters but
you have an extra space at the end of "Host: 192.168.1.106 \r\n" before the \r\n --> get rid of it
usually the size is the last element before the empty line, so I would move "Content-Type: application/x-www-form-urlencoded \r\n"before "Content-Length: $D" "\r\n"
I have done as mentioned. But still same issue. Blank data.
The connection between local server and device is working perfectly only thing is the data is empty.
a POST method is not like a GET, you send the data outside the URL, in your HTTP request header which is what the $H and your sd variable will do
try with this:
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) { // THAT'S NOT THE RIGHT WAY TO DO THIS, should be millis()-timer >= 5000
timer = millis() + 5000; // and here timer += 5000;
byte sd = stash.create();
stash.print("apikey=");
stash.print(KEY);
stash.print("station_id=");
stash.print(SID);
stash.save();
Stash::prepare(PSTR("POST http://192.168.1.106/saveContactinfo.php HTTP/1.0" "\r\n"
"Host: 192.168.1.106 \r\n"
"Content-Type: application/x-www-form-urlencoded \r\n"
"Content-Length: $D" "\r\n"
"\r\n"
"$H"),
stash.size(), sd);// website, PSTR(PATH), website,
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
--> but if your PHP expects things in the URL, that won't work. what you need then is a GET
My php code will GET the values fed to URL. Exactly i was expecting something as J-M-L mentioned. when the stash sd value send from arduino i thought it would be as url formated. So what else i have to do to fix this. If you guide me i can try.
I already tried
``ether.browseUrl(PSTR("/post.php?"),buffer_data, website, my_callback);
this method and i am struggling to put double variables into the buffer_data. I am working on these two methods. but each is stuck in the middle.