Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

TheBrian's Content

There have been 2 items by TheBrian (Search limited from 29-April 23)


By content type

See this member's

Sort by                Order  

#64879 Web server, socket, reading buffer data?

Posted by TheBrian on 11 February 2016 - 06:52 PM in Netduino 3

Hi Ian,

 

Thanks for the reply. Actually at the end of my post I mention that I am currently using HTTPWebRequest, but the result is the same i.e. I only see the header info in the buffer received. So as a workaround I am using the UserAgent property and setting that value to the degrees I want my servo to turn to since I can see that property in the heading.

 

The code using WebRequest came directly from here:

https://msdn.microso...(v=vs.110).aspx

 

In that example a long string value is put in a field called postData and sent to the web server. It is that string that I would like to Debug.Print on the Netduino 3 end.

 

I read through the post you referenced. I also downloaded the XivelyClient you mentioned, put it in a quick console app, and altered it to send to my Netduino 3. The result is also the same. All versions, WebRequest, HttpWebRequest, and XivelyClient's HttpWebRequest, successfully enter the Netduino 3 code listening for requests (ListenForRequest above) . I just don't seem to be able to tweeze out the data value I purposefully put in the byte array. The buffer received only prints:

POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: 10.0.1.240
Content-Length: 3
Expect: 100-continue
Connection: Keep-Alive

Thanks again,

Brian




#64873 Web server, socket, reading buffer data?

Posted by TheBrian on 10 February 2016 - 06:25 PM in Netduino 3

How do I get at the data put into the buffer and sent to the web server? When using the web server code found on the netduino forums, I only seem to be able to read the header info from the buffer received. I need to see the degrees of rotation I'm trying to send. 
 
Sending code from MVC app:
 public ActionResult PostDegrees(string degree)
        {
            WebRequest request = WebRequest.Create("http://10.0.1.240"); // my N3 static IP
            request.Method = "POST";
            string postData = degree; //Degree to turn servo.
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            return null; //Probably should be something else.
        }

Receiving Code on Netduino 3:

  public void ListenForRequest(Servo servo)
        {
            while (true)
            {
                using (Socket clientSocket = socket.Accept())
                {
                    //Get clients IP
                    IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;
                    EndPoint clientEndPoint = clientSocket.RemoteEndPoint;
                    int bytesReceived = clientSocket.Available;
                    if (bytesReceived > 0)
                    {
                        //Get request
                        byte[] buffer = new byte[bytesReceived];
                        int byteCount = clientSocket.Receive(buffer);
                        string request = new string(Encoding.UTF8.GetChars(buffer));
                        Debug.Print(request);
                        //Servo code to rotate motor follows...
                    }
                }
            }
        }

Output from Debug.Print statement:
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: 10.0.1.240
Content-Length: 3
Expect: 100-continue
Connection: Keep-Alive

I'm moving a slider on a web page with a numeric range of 0-180, which is the range of motion of my servo connected to my Netduino 3. I just seem to be missing some important concept in reading the degree value that I believe I'm sending. At the moment my workaround is changing the sending code from WebRequest to HTTPWebRequest and stashing the degrees in the user agent property. This works great but just feels oh so wrong. Any insight/suggestions would really be appreciated.

 

 





home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.