Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strstr((char *)Ethernet::buffer not working stable. #400

Open
droided4u opened this issue Aug 25, 2020 · 1 comment
Open

strstr((char *)Ethernet::buffer not working stable. #400

droided4u opened this issue Aug 25, 2020 · 1 comment

Comments

@droided4u
Copy link

droided4u commented Aug 25, 2020

`#include <EtherCard.h>

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte targetmac1[] = {0x!!,0x!!,0x!!,0x!!,0x!!,0x!!}; //don't want to share my mac
byte Ethernet::buffer[500];

char const page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
""
"<title>"
"N'S REMOTE PC CONTROL"
"</title>"
"

<a href="http://icantsharethislink.ddns.net/?ONE\">TURN PC-1 ON OVER THE NET

"
"

<a href="http://192.168.1.177/?ONE\">TURN PC-1 ON OVER LAN

"
""
;

void setup ()
{
ether.begin(sizeof Ethernet::buffer, mymac);
ether.dhcpSetup();
}

void loop ()
{
word len = ether.packetReceive();
word pos = ether.packetLoop(len);

/////////////////////////////////////////////////////////////////////
if(strstr((char *)Ethernet::buffer + pos, "GET /?ONE") != 0)
{
ether.sendWol(targetmac1);
}
////////////////////////////////////////////////////////////////////

memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);

}`

The whole purpose of the thing is to turn on PC over the internet when I'm not home.
This is the latest version of this code, its name is baremin.ino atm, you can guess why I call it that way. I eliminated everything to get down to the core of the issue but even this simple version is not running stable. I have no clue about this library nor my C++ is efficient. So If I could simplify this further I would.

The page displays alright. However, the sendwol command sometimes either does not work or works late.
Sometimes it's working very smoothly almost immediate action, sometimes it just keeps waiting and waiting forever.
What can I do about this?
Is there any other alternative way to achieve this?

The webpage works fine, I can see it with my dynamic DNS. The issue is not dynamic DNS because sometimes sendwol works ok, also I tried using direct IP as well and the problem persists. Dynamic DNS should be working identical anyways, it's just name server.

I use DHCP because I already gave it the IP 192.168.1.177 from the router. Idk why but Static caused some issues. Also, it was setting mask 0.0.0.0 despite I was using 255.255.255.0

DDNS and MAC addresses are changed due to security concerns.

When I run it LAN only, it seems to work fine. When I start messing around with my phone, which is on mobile data it starts having issues.
When I wait a while it gets better for a while and then drops again. When the issue starts happening even though the page loads fine the wol command does not work. Somehow the request from the internet locks it up. When it locks up internal IP LAN method does not work stable either. Page loads slow, wol command does not work, sends 1 every once in a while and locks up right after.

I tried all sorts of buffer size, did not change a thing.

The Setup

  • Dynamic DNS something.ddns.net
  • Router is set to give arduino 192.168.1.177 IP, which works perfectly fine.
  • Router is set to forward http port to arduino.

I tested arduino's capability to send wol messages, it can send a lot of them.
I'm using wake on lan monitor app to check wol messages and when I put sendwol on loop it freezes the wol monitor program.
So the issue is with http requests I think, whatever is going on it's locking up.

@BlueAndi
Copy link
Contributor

Note, strstr() expects a terminated string, but the ethernet buffer is not a string and a tcp payload is not terminated.
The ethernet buffer may also be a little low with 500. Currently I am using 768 (multiple of 256), because e.g. the firefox browser request header is about 500 bytes.

BTW the method + resource + version is terminated by a CR LF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants