0

So I recently got a nodeMCU Lua V1, I started it up connected to my WiFi, and loaded the default HTTP server from https://en.wikipedia.org/wiki/NodeMCU#HTTP_server. Excitedly I did a port forward on my ADSL router and asked friends to connect to see my hello world response. My friends that has apple devices (iPhone/iPad) where unable to load the website. Where as friends with android devices or computers had no trouble viewing the site. I tried using my iPad that is on the same WiFi network. It also had this behavior. To find out what is going on, I tried different browsers on the iPad. I did a Wireshark trace and saw the NodeMCU sending the response to the iPad. But the iPad kept showing either connection error, or a you are offline message. Thinking it might be html headers that is missing I changed the response the nodeMCU is sending to:

<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>

Still the iPad showed the same message.

So my question is why is iOS behaving this way, what is blocking it and making the browser think it has no internet connection? Is the browser on iOS behaving this way, or is the OS doing something odd. What would I need to do in order for an iOS device to see the web page?

Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
LL.
  • 129
  • 1
  • 12

1 Answers1

1

Oh man, that Wikipedia article really is awful (also see https://github.com/nodemcu/nodemcu-firmware/issues/832). I've seen this code example many times but never realized where it originated from.

First of all, you shouldn't use the old 0.9.x binaries your NodeMCU module probably come loaded with. They're no longer supported and contain lots of bugs. Build a custom firmware from the dev or master branch. Second, checkout the official documentation on socket:send() to learn how to do that properly.

The actual problem though is conn:send("<h1> Hello, NodeMcu.</h1>") because that message is NOT a valid HTTP response. You need to prefix that with HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n.

Similar questions & answers are here and here.

Community
  • 1
  • 1
Marcel Stör
  • 22,695
  • 19
  • 92
  • 198
  • Thank you for resolving this, it works now, why though is it only iOS devices that reject this as not being a valid response? It seems that the iOS network stack rejects the message and tries to get the TCP packet again 2 more times. Why does adding the HTTP/1.0... solve the issue that only seems to happen on iOS devices. – LL. Jun 10 '16 at 07:28
  • You'd have to ask Apple...I can only guess that other browsers are a bit more "lenient" and forgiving when they process responses. IMO that's actually bad behavior because it masks fundamental errors. – Marcel Stör Jun 10 '16 at 08:09