ENC28J60/Ethercard.h Stash issues

Hello,
I’m new to useing Arduino’s and this forum. But I’ve been trying to solve this problem for the past couple of days and the related forum material is not helping.

I’ve been trying to let my Arduino communicate with a webserver on the same network.

192.168.1.1 Webserver with PHP backend
192.168.1.2 Arduino with ENC28J60 ethernet connector

with Stash ( if there is a better way im open to it )

The webserver on ip 192.168.1.1 has a functional php back end that would allow an URL as

http://192.168.2.5/add_data.php?uid=1234567890&busy=1

to insert data into the SQL database.

So far based on examples and documentation I’ve made this with

#include <EtherCard.h>

// Define Static IP
#define STATIC 1  // set to 1 to disable DHCP (adjust myip/gwip values below) 
// if static use this :
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,2 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// Variables
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
const char website[] PROGMEM = "192.168.2.5";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
int uidvalue = 1;  // gone for simplicty
int busyvalue = 1; // gone for simplicity



/*
 * Setup config
 */
void setup() {
  
  //netwerk
  Serial.begin(57600);
  Serial.println("\n[Starting up network]");

  if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
    Serial.println( "Failed to access Ethernet controller");
  #if STATIC
  ether.staticSetup(myip, gwip);
  #else
  if (!ether.dhcpSetup())
    Serial.println("DHCP failed");
  #endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);  
  ether.printIp("DNS: ", ether.dnsip);  
}
/*
 * Loop config
 */

void loop() {
  ether.packetLoop(ether.packetReceive());
  if (millis() > timer) {
    timer = millis() + 10000;
    
 // generate two fake values as payload - by using a separate stash,
    // we can determine the size of the generated message ahead of time
    byte sd = stash.create();
    stash.print("0,");
    stash.println((word) millis() / 123);
    stash.print("1,");
    stash.println((word) micros() / 456);
    stash.save();
    
    // generate the header with payload - note that the stash size is used,
    // and that a "stash descriptor" is passed in as argument using "$H"
    Stash::prepare(PSTR("http://192.168.1.1/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                        "Host: 192.168.1.1" "\r\n"
                        "Content-Length: $D" "\r\n"
                        "\r\n"
                        "$H"),stash.size(), sd);

    ether.tcpSend();
    Serial.print("tcp package send ");Serial.println();  
    }
}

No entries into the database thusfar

Watching with wireshark on the port where the arduino is connected shows :

The destination 0.0.0.0 has me woried. And I’ve run out of ideas where to look next,

Any help would be greatly appreciated.

Entire code

You need to post ALL of your code.
You need to post a link to the Stash library.

PaulS:
You need to post ALL of your code.
You need to post a link to the Stash library.

oh excuse me for that the entire code is linked in the bottom to pastebin, thought it would make the post easier to read, my bad but here it is again

#include <EtherCard.h>

// Define Static IP
#define STATIC 1  // set to 1 to disable DHCP (adjust myip/gwip values below) 
// if static use this :
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,1,2 };
// gateway ip address
static byte gwip[] = { 192,168,1,1 };
#endif

// Variables
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
const char website[] PROGMEM = "192.168.2.5";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
int uidvalue = 1;  // gone for simplicty
int busyvalue = 1; // gone for simplicity



/*
* Setup config
*/
void setup() {

//netwerk
Serial.begin(57600);
Serial.println("\n[Starting up network]");

if (ether.begin(sizeof Ethernet::buffer, mymac) == 0) 
  Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
  Serial.println("DHCP failed");
#endif

ether.printIp("IP:  ", ether.myip);
ether.printIp("GW:  ", ether.gwip);  
ether.printIp("DNS: ", ether.dnsip);  
}
/*
* Loop config
*/

void loop() {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
  timer = millis() + 10000;
  
// generate two fake values as payload - by using a separate stash,
  // we can determine the size of the generated message ahead of time
  byte sd = stash.create();
  stash.print("0,");
  stash.println((word) millis() / 123);
  stash.print("1,");
  stash.println((word) micros() / 456);
  stash.save();
  
  // generate the header with payload - note that the stash size is used,
  // and that a "stash descriptor" is passed in as argument using "$H"
  Stash::prepare(PSTR("http://192.168.1.1/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                      "Host: 192.168.1.1" "\r\n"
                      "Content-Length: $D" "\r\n"
                      "\r\n"
                      "$H"),stash.size(), sd);

  ether.tcpSend();
  Serial.print("tcp package send ");Serial.println();  
  }
}

the library I am useing is EtherCard.h

the library I am useing is EtherCard.h

Did I say "post the name of the library..."? I can read. I know that you are using EtherCard.h.

Where did you get that library?

PaulS:
Did I say “post the name of the library…”? I can read. I know that you are using EtherCard.h.

Where did you get that library?

Sorry, https://github.com/jcw/ethercard

I have no idea how the Stash class works, and no real desire to dig into it, but, this looks wrong:

    Stash::prepare(PSTR("http://192.168.2.5/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                        "Host: 192.168.1.1" "\r\n"

If the first argument is supposed to be a GET or POST, the verb is missing. The server to talk to, and the protocol to use, are already defined, so the GET or POST request does not duplicate them.

It hardly makes sense to send a GET or POST request to one machine, and tell it that the host is some other machine. Unless your server is serving up pages for many domains, the Host statement is not needed. Incredibly few home servers host multiple domains.

PaulS:
I have no idea how the Stash class works, and no real desire to dig into it, but, this looks wrong:

    Stash::prepare(PSTR("http://192.168.2.5/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"

"Host: 192.168.1.1" "\r\n"



If the first argument is supposed to be a GET or POST, the verb is missing. The server to talk to, and the protocol to use, are already defined, so the GET or POST request does not duplicate them.

It hardly makes sense to send a GET or POST request to one machine, and tell it that the host is some other machine. Unless your server is serving up pages for many domains, the Host statement is not needed. Incredibly few home servers host multiple domains.
    Stash::prepare(PSTR(" **** http://192.168.1.1/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                        "Host: 192.168.1.1" "\r\n"

Putting in Get / Post / Put does not work here, removing it had no effect on the outcome.

As for the host, it seems it was a late edit that did not come trough. the host and directed machine are the same. ( 192.168.2.5 was the DHCP address I forgot to remove for this example, my bad )

Putting in Get / Post / Put does not work here,

We would still need to see that code.

PaulS:
We would still need to see that code.

    Stash::prepare(PSTR("POST http://192.168.1.1/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                        "Host: 192.168.1.1" "\r\n"
    Stash::prepare(PSTR("GET http://192.168.1.1/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                        "Host: 192.168.1.1" "\r\n"
    Stash::prepare(PSTR("PUT http://192.168.1.1/add_data.php?uid=1234567890&busy=1 HTTP/1.0" "\r\n"
                        "Host: 192.168.1.1" "\r\n"

You obviously failed to read:

The server to talk to, and the protocol to use, are already defined, so the GET or POST request does not duplicate them.

You obviously failed to read:

Unless your server is serving up pages for many domains, the Host statement is not needed. Incredibly few home servers host multiple domains.