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.
Photo

Ethernet Broken?


  • Please log in to reply
13 replies to this topic

#1 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 18 September 2012 - 01:47 PM

I've spent quite a bit of time trying to get my Netduino Plus to reliably post data to a web server and I think its time to poll the brains in the community as I've tried on 4.1 and 4.2 and am seemingly out of options. Some background: http://forums.netdui...dpost__p__34958 Initially, I wrote the most basic of examples using the HTTPRequest class, then thought that I was missing something silly, so I move to Stephan's toolbox and used his Web_Client but the results are the same. So I'm thinking the bug is in the firmware or maybe its a hardware issue. "Regardless of how long I sleep for (tested between 250 ms and 10000 ms) the application on the N+ becomes unresponsive (led stops blinking) but no exception is thrown and the debugger never disconnects. I also tried this without being attached to the debugger and got that same result." What is going on?

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 18 September 2012 - 02:18 PM

Hi Patrick, This sounds interesting, could you please execute the attached app on your Netduino, and tell me what it outputed? It's kinda the same as C:\> ipconfig /all

Attached Files


"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 18 September 2012 - 02:19 PM

Thanks Stefan (sorry about the mispelling)! Will have it for you later this evening.

#4 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 18 September 2012 - 10:35 PM

Here you go Stefan, thanks! Network interface 0: +-- Type: Ethernet +-- DHCP enabled: no +-- Dynamic DNS servers: no +-- IP Address: 192.168.1.10 +-- Subnet mask: 255.255.255.0 +-- Gateway: 192.168.1.1 +-- DNS Server: 8.8.8.8 +-- DNS Server: 8.8.4.4 '-- MAC address: 5C:86:4A:00:01:71

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 September 2012 - 06:33 AM

Ok cool. So your Netduino Plus is configured correctly, using a static IP address and the Open DNS servers from Google, with a correct MAC address.

Could you try to execute this?
For references you could use the same project file.

I'm curious if it'll brake somewhere. This is the most basic web request I could make...

using System;
using System.Threading;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Microsoft.SPOT;
using Microsoft.SPOT.Net;

namespace NetworkOutput
{
    public class Program
    {
        public static void Main()
        {
            // Queries the DNS
            IPHostEntry ip = Dns.GetHostEntry("www.google.com");
            for (int IpIndex = 0; IpIndex < ip.AddressList.Length; ++IpIndex)
                Debug.Print("www.google.com resolves to " + ip.AddressList[IpIndex].ToString());

            // Connects to Google
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sock.Connect(new IPEndPoint(ip.AddressList[0], 80));

            // Builds the request
            string request = "HEAD / HTTP/1.1\r\n";
            request += "Host: www.google.com\r\n";
            request += "Connection: Close\r\n";
            request += "\r\n";
            sock.Send(Encoding.UTF8.GetBytes(request));

            // Gives google 1 second to reply for now :-)
            Thread.Sleep(1000);

            // Reads out the full buffer
            byte[] RecBuffer = new byte[sock.Available];
            sock.Receive(RecBuffer);
            Debug.Print(new String(Encoding.UTF8.GetChars(RecBuffer)));

            // Nicely closes the connection
            sock.Close();

        }

    }
}

"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 20 September 2012 - 12:53 AM

Thanks Stefan, Surprisingly to me, if I run that code, I don't seem to have any issues even if I execute it in a loop at 1.5 second intervals (that includes the 1 second sleep you had in there) for 720 iterations.

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 20 September 2012 - 08:42 AM

So we can conclude Ethernet is not broken, it must be something else. If you run your project, can you add some breakpoints to see where it'll hold?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 20 September 2012 - 08:28 PM

We can conclude that Ethernet is not broken and I'm very happy that is the case. When execute the following code, it runs through once and does a proper insert, the second time it fails just after executing this line:
StreamWriter stOut = new StreamWriter(req.GetRequestStream());
The N+ just sits there with the onboard led solid and the Ethernet activity light flashing.

Any idea?

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
using Microsoft.SPOT.Net.NetworkInformation;
using System.Text;
using System.IO;
using System.Net;

namespace BC
{
    public class Program
    {
        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);

            int numTests = 720;

            while (numTests > 0)
            {
                //write test data and show LED
                led.Write(true);
                Thread.Sleep(250);

                try
                {
                    string strNewValue;
                    string strResponse;
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://SERVERNAME/PATH/InsertFile.php");
                    req.Method = "POST";
                    req.ContentType = "application/x-www-form-urlencoded";
                    req.KeepAlive = false;

                    // Set values for the request back                
                    strNewValue = "TestID=''&TestDesc=TestData";
                    req.ContentLength = strNewValue.Length;

                    // Write the request
                    StreamWriter stOut = new StreamWriter(req.GetRequestStream());
                    stOut.Write(strNewValue);
                    stOut.Close();

                    // Do the request to get the response
                    StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
                    strResponse = stIn.ReadToEnd();
                    stIn.Close();
                }
                catch (Exception ex)
                {
                    Debug.Print(ex.Message.ToString());
                }

                //hide LED
                led.Write(false);
                Thread.Sleep(250);

                numTests--;
            }
        }
    }
}


#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 September 2012 - 04:16 PM

Your code runs just fine on my Netduino Plus with 4.2. I used the URL http://www.netmftool...com/helloworld/ It could also be the remote host that's giving problems. Could you try my URL for a few times? (please not too long, it's my own webserver B) )
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 21 September 2012 - 04:23 PM

It's looking more like that is the issue but I sure will test later on; thanks Stefan.

#11 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 21 September 2012 - 09:27 PM

It works perfectly well with your web server, so it must be my server side code or my host. Thanks for taking the time to work on it with me Stefan. :D

#12 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 September 2012 - 09:36 PM

It works perfectly well with your web server, so it must be my server side code or my host. Thanks for taking the time to work on it with me Stefan. :D

No problem :)
Glad I could help out a bit. I hope you'll find a proper solution too.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#13 Patrick

Patrick

    Advanced Member

  • Members
  • PipPipPip
  • 54 posts
  • LocationTampa

Posted 21 September 2012 - 09:39 PM

You wouldn't know how to call a .Net web service would you?

#14 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 September 2012 - 09:50 PM

You wouldn't know how to call a .Net web service would you?

Web service, yes. Not really .net specific. It's the HTTP protocol, not the language behind that. It could be .NET, PHP, JSP, etc.

I know of an issue with IIS though, not accepting connections from netduinos. See http://forums.iis.net/t/1166229.aspx for more info about that error.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs




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.