Netduino home hardware projects downloads community

Jump to content


Photo

Hang in CC3100 socket for HttpWebRequest


Best Answer Brian Ingenito, 24 May 2015 - 07:34 PM

Kicked off a thread for the call from the button event and it works great now so it is definitely related to attempting on that same thread as the interrupt.  Strange.  I miss async delegates, etc.  Will clean up with a hacky timer or possibly a queue/waithandle/processing thread of some sort.  This will go on my desk at work under a big red staples easy button to kick off a teamcity build.

 

I'm making this as solved but I'd love to hear some thoughts on why it doesn't work within the event handler.  That is a common scenario that will hit people.

Go to the full post


  • Please log in to reply
12 replies to this topic

#1 Brian Ingenito

Brian Ingenito

    Member

  • Members
  • PipPip
  • 16 posts

Posted 24 May 2015 - 05:37 PM

mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext)  
[Managed to Native Transition] 
Netduino.IP.LinkLayers.CC3100!Netduino.IP.LinkLayers.CC3100.CallFunction + 0xcb bytes      
Netduino.IP.LinkLayers.CC3100!Netduino.IP.LinkLayers.CC3100.sl_Socket + 0x29 bytes      
Netduino.IP.LinkLayers.CC3100!Netduino.IP.LinkLayers.CC3100SocketNative.socket + 0x60 bytes      
[Native to Managed Transition] 
[Managed to Native Transition] 
Microsoft.SPOT.Net.dll!Microsoft.SPOT.Net.SocketNative.socket(int family, int type, int protocol) + 0x2e bytes           
System.dll!System.Net.Sockets.Socket.Socket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) Line 41 + 0x28 bytes      C#
System.Http.dll!System.Net.HttpWebRequest.EstablishConnection(System.Uri proxyServer, System.Uri targetServer) Line 1393 + 0x189 bytes   C#
System.Http.dll!System.Net.HttpWebRequest.SubmitRequest() Line 1481 + 0x20 bytes           C#
System.Http.dll!System.Net.HttpWebRequest.GetResponse() Line 1700 + 0xd bytes             C#
BuildTrigger.exe!BuildTrigger.Program.SendRequest() Line 79 + 0x27 bytes              C#
BuildTrigger.exe!BuildTrigger.Program.Button_ButtonPressed(object sender, bool isPressed) Line 44 + 0x23 bytes       C#
NetduinoGo.Button.dll!NetduinoGo.Button.OnInterrupt() Line 59 + 0x1e bytes         C#
GoBus.dll!GoBus.GoModule._interruptPort_OnInterrupt(uint data1, uint state, System.DateTime 

I have a successful DCHP connection (thanks again Chris and DevBiker!) and can debug print an IP (I see it on my router network object lists too), but when I attempt to make a request via HttpWebRequest it hangs indefinitely within CC3100 socket waiting for a what I assume is a connection.  I get the same behavior with the netmf toolbox HTTP_Client/IntegatedSocket.  Putting a timeout on HttpWebRequest does nothing.  Could it be related to attempting to make the socket within the interrupt callback for the Go button?

 

 

 

 

 

 

 

 



#2 Frode

Frode

    Advanced Member

  • Members
  • PipPipPip
  • 202 posts
  • LocationNorway

Posted 24 May 2015 - 05:40 PM

Could you include the code you're using?



#3 Brian Ingenito

Brian Ingenito

    Member

  • Members
  • PipPip
  • 16 posts

Posted 24 May 2015 - 05:49 PM

  public class Program
  {
    private static OutputPort _led;
    private static NetduinoGo.Button _button;

    public static void Main()
    {
      _led = new OutputPort(Pins.ONBOARD_LED, false);
      _button = new NetduinoGo.Button((GoBus.GoPort)1);

      while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any);

      _button.ButtonPressed += Button_ButtonPressed;

      Debug.Print(IPAddress.GetDefaultLocalAddress().ToString());

      while (true) { Thread.Sleep(100); }
    }

    private static void Button_ButtonPressed(object sender, bool isPressed)
    {
      try
      {
        _button.ButtonPressed -= Button_ButtonPressed;
        _led.Write(true);

         SendRequest();
      }
      finally
      {
        _button.ButtonPressed += Button_ButtonPressed;
        _led.Write(false);
      }
    }

    private static void SendRequest()
    {

      try
      {
        HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(@"http://192.168.1.15/BuildTrigger/StartBuild.aspx");
        request.Timeout = 10000;
        request.ReadWriteTimeout = 10000;

        // I don't care about the response...
        WebResponse response = request.GetResponse();
        if (response != null)
        {
          response.Close();
        }
      }
      catch (Exception ex)
      {
        Debug.Print(ex.ToString());
      }
    }
  }

I have to say that I really don't feel good about the while/sleep in the main but I haven't yet figured out a way to keep the program running under the debugger or standalone unless the main thread keeps going.   I can include the HTTP_Client code if you want too, but it is essentially the same thing.  The only real difference is it looks at the response code and debug prints the response.



#4 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1070 posts
  • LocationNorth Yorkshire, UK

Posted 24 May 2015 - 05:55 PM

I have to say that I really don't feel good about the while/sleep in the main but I haven't yet figured out a way to keep the program running under the debugger or standalone unless the main thread keeps going.

Replace the while loop with:

Thread.Sleep(Timeout.Infinite);

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#5 Brian Ingenito

Brian Ingenito

    Member

  • Members
  • PipPip
  • 16 posts

Posted 24 May 2015 - 06:02 PM

Thanks Mark.  I wasn't sure if there was a pump going on the main thread that you weren't supposed to infinitely put to sleep.  I've been doing UI dev on windows for too long.



#6 Brian Ingenito

Brian Ingenito

    Member

  • Members
  • PipPip
  • 16 posts

Posted 24 May 2015 - 06:10 PM

I can get to the URL from other machines on my network so I know it is accessible.  As a test, I switched to requesting google on the board and it hangs in the same CC3100.CallFunction within getaddrinfo on the DNS lookup.  I changed it to request by IP and back to the problem above.

 

- Green light for wifi

- When I print out Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0] in the immediate window, the gateway looks fine (it is my router).  No dns though so I guess I need to manually put that in the network config.  Sorry to fork the thread again, but is there a way to get the dynamic dns enabled so that it can pick up a dns from dhcp?



#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 May 2015 - 07:11 PM

Hi Brian,

The timeouts are wired up, so this should really be returning if it can't get a connection.

Could you please run the SocketClient sample that comes with NETMF just to make sure that that connections is fine...and then we can debug into your code.

To debug into your code, we should also take the code from the SendRequest function and just replace the code in the Main() function with it. That will let us eliminate other potential issues. Then if necessary we can get you on a debug build of Netduino.IP; since it's managed code you'll actually be able to debug into it and see exactly what's going on--which feels a bit like having superpowers if you've ever dealt with debugging native stacks. :)

Chris

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 24 May 2015 - 07:12 PM

Hi Brian,

- When I print out Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0] in the immediate window, the gateway looks fine (it is my router).  No dns though so I guess I need to manually put that in the network config.  Sorry to fork the thread again, but is there a way to get the dynamic dns enabled so that it can pick up a dns from dhcp?

Grab a copy of our updated MFDeploy tool. It should configure DNS-via-DHCP for you. If you're still not getting a DNS address at that point, there's something going on "on the wire" or in the AP configuration that we need to figure out.

http://forums.netdui...h-ipv6-support/

Chris

#9 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1070 posts
  • LocationNorth Yorkshire, UK

Posted 24 May 2015 - 07:23 PM

I've tried the sample and it locks for me too.  Note that I did not use a NetduinoGo button but the on board button.

 

However, if you move the call to SendRequest from inside the interrupt for the button and place it just above the last line of code (I replaced the while with a Thread.Sleep(Timeout.Inifinte)) call then you get a response from Google in a reasonable time.

 

Hope this helps,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#10 Brian Ingenito

Brian Ingenito

    Member

  • Members
  • PipPip
  • 16 posts

Posted 24 May 2015 - 07:34 PM   Best Answer

Kicked off a thread for the call from the button event and it works great now so it is definitely related to attempting on that same thread as the interrupt.  Strange.  I miss async delegates, etc.  Will clean up with a hacky timer or possibly a queue/waithandle/processing thread of some sort.  This will go on my desk at work under a big red staples easy button to kick off a teamcity build.

 

I'm making this as solved but I'd love to hear some thoughts on why it doesn't work within the event handler.  That is a common scenario that will hit people.



#11 volleynerd

volleynerd

    Member

  • Members
  • PipPip
  • 11 posts

Posted 27 May 2015 - 11:12 PM

Thanks for posting this problem and especially your current work-around.  I am seeing the same issue, also using a GoButton.  When using WebRequest from within an event handler (or call stack that originates from one), the call to GetResponse() hangs.

 

Note: works fine using the other button pressed handling pattern of checking IsPressed in the while loop, but I definitely would prefer the event driven approach.



#12 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 28 May 2015 - 12:10 AM

Hey Brian, volleynerd:

Can you please add an issue for this over at our GitHub repo?
https://github.com/n...duino.IP_CC3100

We have identified the core issue in the NETMF interpreter and have come up with both a short-term fix as well as an elegant longer-term enhancement to NETMF. If you can post the issue on GitHub, we'll get a fix for this implemented and checked into an upcoming firmware update for you boards--and then mark it as completed. :)

Thank you very much for bringing this to our attention. You are helping make NETMF even better :)

Chris

#13 Brian Ingenito

Brian Ingenito

    Member

  • Members
  • PipPip
  • 16 posts

Posted 28 May 2015 - 01:03 AM

Thanks Chris.  Done - https://github.com/n...CC3100/issues/3






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

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.