HttpGet Error -40 - Not Enough Data Returned


#1

This is my first attempt at HttpGet

  1. I have already successfully done a get from the command line to my ‘new’ device:

> httpget -r -S "*SRDC2/r" 192.168.1.220:1000

returns:

> 0017.4

My OptoScript code is the following:

> stWeather_Send[0] = "*SRH2/r";
> 
>   iWeather_Cmd_Status = HttpGet(
>     stWeather_Resp,
>     stWeather_Resp_Hdr,
>     stWeather_Send,
>     0,
>     "/",
>     iHttpGet_Cmd_Status,
>     1000,
>     "192.168.1.220");

My variable iHttpGet_Cmd_Status is returning 0, but
My variable iWeather_Cmd_Status is returning -40, Not Enough Data Returned

And nothing is loaded into my string.

Any thoughts on what to try from here? I have already tried making my string tables arbitrarily larger (100 entries, 1024 wide) since I started them at minimal sizes. Also, I have experimented with the forslash or backslash in the string command, either works in the command line, and neither has an effect in OptoScript.


#2

That doesn’t look like an HTTP response.

What kind of utility is this?


#3

It is what I supposed was a copy of the httpget command that the opto functions appear to mimic.

This is for an Omega weather station device.

I popped the executable “httpget.exe” into my windows directory, and was able to get the response “0017.4”, which is the humidy % in my office where this thing is laying.

So, this is my first attempt to use the built-in opto function instead of just a command line utility. I’d rather log this weather station data into my SNAP-PAC-R1 then have to run a separate logging utility.

Since I’ve never used any form of HttpGet or HttpPost, I have no idea that the string I’m getting back on the command line isn’t an http response.


#4

Can you get a wireshark trace and see what that utility is sending and what is coming back?


#5

good idea, will do thanks


#6

A day of firsts, also firs time I’ve successfully used WireShark :wink:


#7

Don’t see the data, but those packet lengths are too short to be http.


#8

Hmm -I looked at that utility and the -r option means to just send raw data - so it may return http if that option wasn’t there, it just crashed when I tried it though.

Also you are using /r when the example has \r. \r is most likely an escape for the carriage return character 13.

So on your string you are sending from your strategy you probably should have “*SRH2” + CHR(13) I would check if that magically works for you. If not, then try the TransmitReceiveString command (You will need to open the comm handle yourself first).


#9

Thank you, good points and something to try!


#10

Quick update, I’m not done cleaning things up, but the following works, and of course, thank you Philip for the help and guidance!

SetCommunicationHandleValue("tcp:192.168.1.220:1000", chWeather);
while (not(IsCommunicationOpen(chWeather)))
  iWeather_Cmd_Status = OpenOutgoingCommunication(chWeather);
  DelayMsec(100); 
wend
ClearCommunicationReceiveBuffer(chWeather);
iWeather_Cmd_Status = TransmitReceiveString("*SRH2/r", chWeather, sWeather_Resp);

#11

Hmm, so /r works when the docs state \r?


#12

yes, either works in the command prompt using their “httpget”