Need Help ( I am doing something wrong - but what?)

So I am trying like crazy to get data to flow from the ethernet - but everything
I try is not working.

I am getting the IP address OK (DHCP or static - it all works).
I am setting up the call-back event handler.
I am sending the request.
But my event handler is never called.

I must be doing something basic wrong here - but I am looking too closely. The attached
file is the simplest code to illustrate what I am trying – and what doesnt work. In the attached
file - I load “www.google.com”. The event handler should be called - and never is.

I have two spider boards - so I am fairly sure the hardware is OK. FW is up to date.

Anyone see where I have gone wrong?

Thanks

s

~

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerAppTest
{
public partial class Program
{

    // This method is run when the mainboard is powered up or reset.   
    void ProgramStarted()
    {
        //PulseDebugLED();
        Debug.Print("Program Started");
        led.GreenBlueSwapped = true;
        ethernet.NetworkUp += OnNetworkUp;
        ethernet.NetworkDown += OnNetworkDown;

        //ethernet.UseDHCP();
        ethernet.UseStaticIP("192.168.1.111", "255.255.255.0", "192.168.1.1");



        while (true) {
            if (ethernet.IsNetworkUp)
            {                    
                led.BlinkOnce(GT.Color.Blue);
                WebClient.GetFromWeb("http://www.google.com/").ResponseReceived += new HttpRequest.ResponseHandler(request_ResponseReceived);

            }
            else{
                led.BlinkOnce(GT.Color.Red);
            }
            Thread.Sleep(10000); 

        }       
    }

    //~~~~~~~~~~~~~~~~~~~~~~~~~~~
    void request_ResponseReceived(HttpRequest request, HttpResponse response) {

        led.BlinkOnce(GT.Color.White);
    }

//////////////////////
void OnNetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
{
led.BlinkOnce(GT.Color.Purple);
Debug.Print(“Network up.”);
}

    void OnNetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
    {
        Debug.Print("Network dn.");
    }

 }

}

No need for the while(true)
get rid of it… you are blocking the events…

It’s spending its time in sleep(10000).
Its just a main loop.

Are you saying no events while sleeping?

s

You need to move that code to another thread or use a timer if you want … DO NOT Put while statement in the Program Starter or you will BLOCK the whole application…
Gadgeteer needs to exit From Program Stater to execute the events…

BTW when you exit Program Stater your application stays running, it is different from standard netmf applications.

please read here:
http://blogs.msdn.com/b/net_gadgeteer/archive/2011/12/19/why-not-while-true.aspx

Jay

Perfect!

Thanks VM.

s

Anytime and welcome to Gadgeteer World :wink: