enc28j60 error HTTP/1.1 404 Not Found

I have tried to post sensors data to local web server.
I’m using nano v3 + enc28j60, and web server on WR703n.

my sketch

#include <EtherCard.h>
#include "DHT.h"
#include <Wire.h>
#include <BMP085.h>

#define DHTPIN 8
#define DHTTYPE DHT11   // DHT 11 
DHT dht(DHTPIN, DHTTYPE);
BMP085 dps = BMP085(); 

long pr = 0, al = 0, tm = 0;
unsigned long time1=0;

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

byte Ethernet::buffer[700];
static uint32_t timer;

char website[] PROGMEM = "192.168.1.110";
static byte hisip[] = {192,168,1,110};
boolean use_hisip = true; 

// ether.hisip[0] = 192; 
// ether.hisip[1] = 168; 
 //ether.hisip[2] = 1; 
// ether.hisip[3] = 110;

// called when the client request is complete
static void my_callback (byte status, word off, word len) {
  Serial.println(">>>");
  Ethernet::buffer[off+300] = 0;
  Serial.print((const char*) Ethernet::buffer + off);
  Serial.println("...");
}

void setup () {
  Serial.begin(57600);
  Wire.begin();
  Serial.println("\n[webClient]");
  dht.begin();
  dps.init(MODE_STANDARD, 19000, true);

   if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 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 (!ether.dnsLookup(website))
    Serial.println("DNS failed");
    ether.printIp("SRV: ", ether.hisip);
}

void loop () {
  ether.packetLoop(ether.packetReceive());
  
  if (millis() > timer) {
    timer = millis() + 3000;
    
    int t = dht.readTemperature();
    int h = dht.readHumidity();
    dps.getPressure(&pr);
    int p = pr/133.322368;
    dps.getAltitude(&al);
    int a = al/100;
    
    char buff[1];
    sprintf(buff, "?t=%d&h=%d&a=%d&p=%d", t, h, a, p);
    
    Serial.println();
    Serial.println(buff);
    Serial.print("<<< REQ ");
    ether.browseUrl(PSTR("/update.php"), buff, website, my_callback);
  }
}

and I have an error

?t=27&h=36&a=195&p=754
<<< REQ >>>
[b]HTTP/1.1 404 Not Found[/b]
Connection: close
Content-Type: text/plain
Transfer-Encoding: chunked

But if I change string

sprintf(buff, "?t=%d&h=%d&a=%d&p=%d", t, h, a, p);

to

sprintf(buff, "?t=%d&h=%d&p=%d", t, h, p);

it works perfectly

If I post http://192.168.XXX.XXX/update.php?t=27&h=36&a=195&p=754
it works

What is the problem?

Thanks in advance

sprintf constructs a character string and puts it into the first arg (buff, in your case). You define buff to be just one char large though, and the string sprintf is creating is much larger. Make sure buff is large enough for everything you're putting into it.

But how it is possible that command

 Serial.println(buff);

with configuration

char buff[1];

has as a result

?t=27&h=36&a=195&p=754

I can not understand this

Writing past the end of an array like that is undefined. Do not rely on it working, even if it appears to be printing out ok.

I found out one stranger feature If I change string

int a = al/100;

to

int a = al/100+dht.readHumidity()-dht.readHumidity();

it works i just added dht.readHumidity and subtracted it

Maybe some problems with data type? and in case with

int a = al/100;

"a" is not converting to int?

When sprintf constructs its string, it puts it into the buffer you give it. In your case the buffer is just one byte large. The string it builds is much larger than one byte.

So, where do you suppose it's putting all those extra bytes?

Ok. I’ve got your point
But how can it works with following parameters?

char buff[1];
sprintf(buff, "?t=%d&h=%d&p=%d", t, h, p);

Ok. I've got your point But how can it works with following parameters?

Clearly, you didn't get the point. Your array size is one. You need it to be bigger than 1. It doesn't take a rocket surgeon to figure out that the buffer is too small. It is then trivial to fix the problem.

Would you like to see where the extra characters are put?

char buff[1];
char testBuf[16];
sprintf(buff, "?t=%d&h=%d&p=%d", t, h, p);
Serial.println(buff);
Serial.println(testBuf);
strcpy(testBuf,"Bad data");
Serial.println(buff);

Last time I checked, testBuf should show all characters except the '?', and the last line should show "?Bad data". You have just been lucky the SRAM was not being used before.

I suggest you stop using sprintf() and start using snprintf() instead, and make sure the size you pass in is the actual size of the buffer.

Yes, PaulS, SurferTim, PeterH Thanks for useful suggestions, it works