Martin
Martin

Reputation: 29

Winsock Disconnects in Excel VBA

I've got a ESP8266 NodeMCU device which acts as a LAN Node server using ports 80(html) and 81(websocket server).

It works fine with a browser webpage I designed for a control application, but I'm trying to port it over to Excel using Winsock. In place of the webpage, I just use a form and need to access cells on the worksheet. This has value for other IOT apps where I want to import data to Excel and take advantage of Excel's graphs, export data, etc.

Here's the issue I can get port 81 to upgrade to TCP but as soon as I try to send a small text message, the NodeMCU disconnects with no error message. The code follows:

oString = "GET / HTTP/1.1" & vbCrLf
oString = oString & "Host: ws://192.168.0.9:81/" & vbCrLf
oString = oString & "Connection: Upgrade" & vbCrLf
oString = oString & "Pragma: no-cache" & vbCrLf
oString = oString & "cache-Control: no-cache" & vbCrLf
oString = oString & "Upgrade: WebSocket" & vbCrLf
oString = oString & "Sec-WebSocket-Version: 13" & vbCrLf
oString = oString & "Sec-WebSocket-Key: yaVX9fn9sKEiN2YbqvF/fg==" & vbCrLf
oString = oString & "Sec-WebSocket-Protocol: arduino " & vbCrLf
oString = oString & vbCrLf
ws81.SendData (oString)

NodeMCU1.0 Response:

HTTP/1.1 101 Switching Protocols
Server: arduino-WebSocketsServer
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Version: 13
Sec-WebSocket-Accept: xaeFOTHpxO8e54UJtOnwdL+odwo=  
Sec-WebSocket-Protocol: arduino

NodeMCU (via serial monitor) tells me I'm connected and starts pinging and Winsock pongs back: reading but not doing anything with the Accept key(Don't think it's necessary).

Now the problem is as soon as I try to send text the NodeMCU disconnects and there's no specific error message.

I've looked at RFC 6455 and I think that the header protocol is part of MSWinsock(otherwise what's it existing for?). Looking at wireShark, the header is there for sure, but larger than I would have expected by 20 bytes. I would have pegged it at 16 bytes given the short message(about 20B) that I am sending.

It does appear to have the mask bytes in place but the Extended Payload Size bytes are populated. I would think that they would be zeros.

One important note

My client is sending unmasked and the message is clear text. Why wouldn't the Xor algorithm be being applied since RFC 6455 says ALL client uploads to server are masked? But still, that would just mean the NodeMCU would just receive garbage and react badly, but not disconnect. I've already duplicated the masking algorithm and I could apply it to the Payload but I have no way to set the MASK bit or the mask bytes in the header(at least not that I know of). If it has anything to do with Big vs Little Endian then I'm doomed because even if I swapped the payload data endian I couldn't change the header.

Anyone have any ideas?

Upvotes: 0

Views: 172

Answers (0)

Related Questions