0

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. If i try it manually from browser it works. 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());
  • what tests have you performed to make sure that you can connect to the internet? – jsotola Jan 13 '18 at 2:53
  • Also asked at: forum.arduino.cc/index.php?topic=522343 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. – per1234 Jan 13 '18 at 3:04
  • except from the 2 log reports nothing else. What kind of test are you speaking about? – billyVal Jan 13 '18 at 4:05
  • So your Arduino sends the request, the web server receives it, sends a response and you can see the Arduino receives it over serial but you're asking us why your db doesn't work? Can you add details about your db. – jdwolf Jan 13 '18 at 4:13
  • !! I found it guys. The get request that i want to send has greek words and maybe that the reason that fails. (ex. ?Θερμοκρασία=1&...) When i tried in english it worked. Anyways thanks for the help! – billyVal Jan 13 '18 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.