get request with ENC28J60 Ethernet module

Hello to everyone.

I try to make a simple http get request from Arduino uno to my website (shared hosting) where i fetch the data to db. I use the EtherCard library and ENC28J60 Ethernet module. Here is the code:

#include <EtherCard.h>

// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

const char website[] PROGMEM = "xxx.com";

static byte session;
byte hisip[] = { xx,xx,xx,xx };
byte Ethernet::buffer[700];
Stash stash;



void setup () {
  Serial.begin(57600);

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println(F("Failed to access Ethernet controller"));
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  

  if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp("SRV: ", ether.hisip);

  getReq();

}

void loop () {
  
  ether.packetLoop(ether.packetReceive());

  const char* reply = ether.tcpReply(session);
  if (reply != 0) {
    Serial.println(reply);
  }
}


static void getReq () {
  Serial.println("Sending tweet...");
  byte sd = stash.create();

    stash.print("unique=unique1&temp=11");
    stash.save();
    int stash_size = stash.size();

  
    Stash::prepare(PSTR("GET http://$F/laravel/measures/input HTTP/1.1" "\r\n"
    "Host: $D" "\r\n"
    "User-Agent: Arduino/1.0" "\r\n"
    "Content-Length: $D" "\r\n"
    "\r\n"
    "$H"),
  website, website, stash_size, sd);
  

  

  // send the packet - this also releases all stash buffers once done
  // Save the session ID so we can watch for it in the main loop.
  session = ether.tcpSend();
}

here is what i get from serial:

IP:  xx
GW:  xx
DNS: xx
SRV: xx
Sending tweet...
HTTP/1.1 200 OK
Date: Fri, 12 Jan 2018 23:40:00 GMT
Server: Apache
X-Powered-By: PHP/7.1.13
Cache-Control: no-cache
Set-Cookie: XSRF-TOKEN=eyJpdiI6IlBnT0ZVZVJwb3ROZkh4Z3ZIUDVrZGc9PSIsInZhbHVlIjoiU0NWZEQ2aSsxT3JlNlp3ek1oRTFtajBsZVVVRUxSMGFQSGpITzFTMWpScEdFZExCXC9rQ1FRT2prbVFyMVJtdnRUazBPY1RBS3JONCt1bVJFQjB1MEVnPT0iLCJtYWMiOiJiZDRjMjZmZjE5ODNlYjBjOTc3NTY4NDM2NmEyMzA2NGU1ZmM1ZGI3MzJjMGY3MjdiN2FmYTg2NDg1NmY1NTFhIn0%3D; expires=Sat, 13-Jan-2018 01:40:00 GMT; Max-Age=7200; path=/
Set-Cookie: laravel_session

and here is what i get from server log:

xx.com xx.xx.xx.xx - - [12/Jan/2018:23:18:12 +0000] "GET http://xx.com/laravel/measures/input HTTP/1.1" 200 - "-" "Arduino/1.0"

however nothing goes on db. Can anyone please give me a suggestion? Server problem, permissions, or code?

Furthermore i tested and this block of code with no result either:

if (millis() > timer) {
    timer = millis() + 5000;
    Serial.println();
    Serial.print("<<< REQ ");
    ether.browseUrl(PSTR("/laravel/measures/input/"), PSTR("?unique=unique1&temp=21"), PSTR("http://xx.com"), my_callback);
  }
  
  ether.packetLoop(ether.packetReceive());
  • (web project built in laravel framework)

Thanks in advance!

Also posted at:

If you’re going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.