Main Site Documentation

Panda II with FEZ Connect Shield: HttpWebResponse: CLR_E_NULL_REFERENCE


#1

Sorry for bothering yall… I am making progress!

This code was working great on a netduino. I now have the code running on the Panda, but it would seem some additional code is needed?

Here is the code that matters:

using System;
using System.Threading;
using System.IO;
using System.Text;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;


namespace FEZ_Panda_II_Application1
{
    public class Program
    {
        public static void Main()
        {

                byte[] ip = { 192, 168, 40, 3 };
                byte[] subnet = { 255, 255, 255, 0 };
                byte[] gateway = { 192, 168, 40, 1 };
                byte[] mac = { 0x00, 0x88, 0x98, 0x90, 0xD4, 0xE0 };
                // Enable the Ethernet    
                WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, 
                                                    (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
                
                
                NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);

                Debug.Print("");
                Debug.Print("");
                Debug.Print("Starting....");

                var requestUri = "http://192.168.40.1:8080/Service1.svc/GetData";
                int count = 150;
                for (int i = 1; i <= count; i++)
                {
                    ProcessRequest(requestUri, count);
                    Debug.Print("sleeping for 30 seconds...");
                    Debug.Print("");
                    Debug.Print("");
                    Thread.Sleep(30000); // sleep 30 seconds
                }
        }

        public static void ProcessRequest(string requestUri, int count)
        {
            // var request = (HttpWebRequest)WebRequest.Create(requestUri);
            using (var request = (HttpWebRequest)WebRequest.Create(requestUri))
                
            {
                request.Method = "GET";
                // send request and receive response

                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    Debug.Print("have a response, consuming....");
                    // consume response
                    HandleResponse(response, count); [b] // On Panda, this is NULL issues, on Netduino has valid response![/b]
                }
               
            }
        }

Thanks in advance!


#2

You might have a look at this thread: http://www.tinyclr.com/forum/2/3793/

It seems that adding a brief Thread.Sleep after the Create and before the GetResponse helps.


#3

Jasdev,

No joy, sorry to say.

I tried sleeps of 100ms, 250ms, and 1250ms, and it just does not fly.

The same code flow on netduino works fine (which does not use the 5100 for networking, of course).

I may have to rewrite this in sockets, which would be a real pita for me (it is a lot of code, and I prefer to use the high level stuff).

Community: Is there a simple, “known good” http GET example using HttpWebRequest/HttpWebResponse?



        public static void ProcessRequest(string requestUri, int count)
        {
            // var request = (HttpWebRequest)WebRequest.Create(requestUri);
            // Thread.Sleep(250); // suggested by http://www.tinyclr.com/forum/2/5313/
            using (var request = (HttpWebRequest)WebRequest.Create(requestUri))
                
            {
                request.Method = "GET";
                // send request and receive response
                Thread.Sleep(1250); // suggested by http://www.tinyclr.com/forum/2/5313/
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    Debug.Print("have a response, consuming....");
                    // consume response
                    HandleResponse(response, count);
                }
               
            }
        }


#4

I’m know expert but it look slike to me your Thread.Sleep is in the wrong place.

 public static void ProcessRequest(string requestUri, int count)
        {
            // var request = (HttpWebRequest)WebRequest.Create(requestUri);
            // Thread.Sleep(250); // suggested by http://www.tinyclr.com/forum/2/5313/
            using (var request = (HttpWebRequest)WebRequest.Create(requestUri))
 
            {
                request.Method = "GET";
                // send request and receive response
                // !!!!!! Wrong place? Thread.Sleep(1250); // suggested by http://www.tinyclr.com/forum/2/5313/
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    // !!!!! The line above is where the request is made so wait here for return
                    Thread.Sleep(1250); 
                    Debug.Print("have a response, consuming....");
                    // consume response
                    HandleResponse(response, count);
                }
 
            }
        }


#5

Jeff,

Thank you for the suggestion!

I tried it as you documented, with delays of 1250 ms and 200 ms, and there is no change in the behavior.

I fear I am going back to netduino for networking. Waaaah! (I have $150 of GHI gear… but no networking = no joy.)


#6

Please keep in mind that different platforms might not be 100% compatible code-wise. and I guess the book that you are referring to was specifically made for Netduino. So please try to avoid to use the same example code in this book with FEZ Panda II. For example the networking library, http class and the hardware is completely different.

We have a lot of examples online. Here where you need to start:
http://www.tinyclr.com/support/

Here is a full project that uses HTTP on FEZ Panda II and FEZ Connect and as I remember it uses GET:

[quote]WIZnet W5100 HTTP FileServer:
Here is a example that has been adopted from NETMF SDK examples (…\Documents\Microsoft .NET Micro Framework 4.1\Samples\HttpServer) and edited to get it working with W5100 sockets libraries and the SD card. Only minor addition is needed as you can see because the W5100 libraries made to be compatible with the original System.Net libraries.

The example runs on FEZ Panda II or FEZ Domino with FEZ Connect and a microSD card with few files.

When the devices IP address is access from the web browser, the page will show the files on the microSD card.[/quote]

http://wiki.tinyclr.com/index.php?title=WIZnet_W5100_HTTP_FileServer

This project requires a lot of Flash and Ram that I doubt that it can work on other NETMF platforms with limited resources.


#7

Joe,

Thanks!

Not useful though… I need an HTTP client, to do HTTP GET calls.

The project you reference is for a server.

I am writing a CLIENT.

Thanks!


#8

Have you searched our code website? :slight_smile:

Is this what you need?
http://code.tinyclr.com/project/288/http-client-sample-code-for-fez-connect/


#9

I did search… but only now did I find, same thing you just posted.

thx!!