Problem with GetHostEntry

Developer
Oct 17, 2011 at 4:32 AM

I'm having a really weird problem trying to get MicroTweet to work.  It seems that the Dns.GetHostEntry() doesn't work when the code in the MicroTweet library is being executed.  However, it works just fine outside.  For example..

using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.NetworkInformation;
using Komodex.NETMF.MicroTweet;

namespace FEZTweet
{
    public class Program
    {
        private static readonly OutputPort _led = new OutputPort((Cpu.Pin) FEZ_Pin.Digital.LED, true);

        public static void Main()
        {
            // Make a network connection.
            byte[] ip = {192, 168, 1, 222};
            byte[] subnet = {255, 255, 255, 0};
            byte[] gateway = {192, 168, 1, 1};
            byte[] mac = {0x00, 0xF0, 0xA3, 0xC0, 0x96, 0x27};
            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);
            NetworkInterface.EnableStaticDns(new byte[] {192, 168, 1, 1});

            //  THIS WORKS FINE
            var timeServerIP = Dns.GetHostEntry("time.nist.gov");
            Debug.Print("Time Server IP = " + timeServerIP.AddressList[0]);

            // Update the clock with exact time.
            // THIS FAILS WHEN Dns.GetHostEntry() is called.
            NTP.UpdateTimeFromNTPServer("time.nist.gov");

            // Send a tweet.
            // THIS FAILS WHEN Dns.GetHostEntry() is called.            var twitterClient = new TwitterClient(secretStuff);
            var tweetSent = twitterClient.SendTweet("Testing sending a tweet from #NETMF.");
            if (tweetSent)
            {
                Debug.Print("Tweet sent.");
            }
            while (true)
            {
                _led.Write(false);
                Thread.Sleep(300);
                _led.Write(true);
                Thread.Sleep(300);
            }
        }
    }
}

When it fails, I get an error that says "A first chance exception of type 'System.NotSupportedException' occurred in System.dll"

Any ideas what is going on and how to fix?

Thanks,

Ian

Coordinator
Oct 17, 2011 at 6:44 AM

Hi Ian,

I don't think I've heard from anyone using MicroTweet with one of the FEZ boards or a W5100 adapter, so there may be some issues with their firmware or W5100 driver.

Are you using the NuGet package or are you compiling the source from here on CodePlex?  It may be possible to get more specific debug information by compiling the library from its source.

Also, just to clarify -- Does NTP.UpdateTimeFromNTPServer actually update the device's time correctly as long as you don't call Dns.GetHostEntry?  You could verify that by using:

Debug.Print("Date before updating (should be incorrect): " + DateTime.Now.ToString());
bool result = NTP.UpdateTimeFromNTPServer("time.nist.gov");
Debug.Print("Update result: " + result.ToString());
Debug.Print("Current date: " + DateTime.Now.ToString());

I just tested this out with my Netduino Plus and got the following result:

Time Server IP = 192.43.244.18
Date before updating (should be incorrect): 01/01/2009 00:17:19
Update result: True
Current date: 10/17/2011 05:22:26

(I actually called GetHostEntry before setting the time without trouble, but try running the above code without calling GetHostEntry to see what happens.)

I actually have a W5100 shield here so if I get a chance I will test that out tomorrow to see if I can find anything else.

 

Let me know if you have any other questions.  Thanks,

Matt

Developer
Oct 17, 2011 at 7:11 AM

Matt,

Thanks for the reply.  After failing with the nuget package, I started debugging with the code.  That's where I discovered the problem is with the call to GetHostEntry().  I simplified the first line of your GetNTPTime() to the following to further drill it down.

        private static DateTime GetNTPTime(String TimeServer)
        {
            // Find endpoint for TimeServer
            var timeServerIP = Dns.GetHostEntry(TimeServer);				// <-- Fails here.
            IPEndPoint ep = new IPEndPoint(timeServerIP.AddressList[0], 123);

This is very odd.  I don't think it's firmware because the exact same line executes fine in my code but fails when executed from within your project.  It's like something about your project is perhaps stuck on an old version of NETMF or something?  I checked all the project properties and re-added referenced files.  

I tried your test code and got the same result.  

Thanks,

Ian

Coordinator
Oct 17, 2011 at 7:31 AM

It sounds like my project is referencing a different set of assemblies than what is needed for your board (and what you're using in your project).  It could be a version number difference or they could be different assemblies altogether.

I would try removing all the assembly references from my project and replacing them with the same references used in your project.  That should clear up any version number (etc.) issues.

Developer
Oct 17, 2011 at 4:47 PM

That's what I did but it didn't make a difference.  The only thing I did take out was VikingErik.NetMF.MicroLinq since I didn't have the source.  I'll see if I can strip it out tonight w/o impacting the parts I need.  May be that there's something in there that's causing the problem.

Developer
Oct 18, 2011 at 4:49 AM

I've figured out the problem.  It was indeed a problem with references.  Your library was referencing the netduino System.Net & System.Net.Sockets assemblies which aren't named the same with the GHI boards...  Since I have the netduino SDK installed also it didn't cause any compile issues but obviously didn't execute properly once it stepped into your assembly.  There are also several other small syntactical things that are going to have to be changed to make this work on the GHI boards.  My question to you now is as I make these changes do you want them contributed back or are you only interested in keeping this library netduino specific?  In my NETMFx library (netmfx.codeplex.com) I've tried to keep compatibility with both boards through the use of conditional compile conditions.  I'd be glad to be your GHI tester/contributor on this project if you're interested since I'm going to be doing it anyway.  Let me know if you're interested in working together on this.

Thanks,

Ian

Coordinator
Oct 19, 2011 at 3:56 AM

Hi Ian,

Good to know, and glad to hear you had some success.  I would definitely be interested in making this library work with GHI boards, but I'm not sure what it will take to maintain compatibility for the NuGet package (especially if I have to build different assemblies for different boards).  It might be necessary to post it as a separate package, I'll have to check what can be configured in the nuspec file, etc.

I haven't had much time to work on this project lately so I'd definitely be interested in your help.  Do you have an idea of how many changes are necessary, and whether it might be possible to build a single assembly for both boards?

Also, out of curiosity which specific board are you using?

Thanks,

Matt

Developer
Oct 19, 2011 at 4:24 AM
Matt,

Great. Unfortunately, I don't think it's possible to build a single assembly that will work for both boards because they have different SDK references. Hopefully, one day NETMF will evolve to the point where this isn't necessary... So, you probably would have to post multiple nuget packages. I started making some changes last night and there will be a number of changes necessary mostly because of syntax differences in the APIs and not so much because of functionality. Also, I talked to another guy in the GHI forums today who has also been working on this who started with MicroTweet but said he found several problems. I think this may be due to recent changes in the Twitter authentication APIs. Once I get his code, I'll also compare his changes and integrate them into the MicroTweet code.

I have GHI FEZ Panda-II, Panda, & netduino boards to test with. I also have a Tahoe-II if there's ever any need to port in that direction. I'm fairly busy myself at the moment but I should be able to get this done within the next couple weeks. How do you want to work the source? Do you want to add me as a contributor to the project and have me check in a branch there or just submit changes as a patch?

Take care,

Ian

On Tue, Oct 18, 2011 at 21:56, misenhower <notifications@codeplex.com> wrote:

From: misenhower

Hi Ian,

Good to know, and glad to hear you had some success. I would definitely be interested in making this library work with GHI boards, but I'm not sure what it will take to maintain compatibility for the NuGet package (especially if I have to build different assemblies for different boards). It might be necessary to post it as a separate package, I'll have to check what can be configured in the nuspec file, etc.

I haven't had much time to work on this project lately so I'd definitely be interested in your help. Do you have an idea of how many changes are necessary, and whether it might be possible to build a single assembly for both boards?

Also, out of curiosity which specific board are you using?

Thanks,

Matt

Read the full discussion online.

To add a post to this discussion, reply to this email (microtweet@discussions.codeplex.com)

To start a new discussion for this project, email microtweet@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com




--
------------------------------------------------
R. Ian Lee, Sr.
http://www.linkedin.com/in/rianlee
http://facebook.com/ianlee74
Twitter: ianlee74

Coordinator
Oct 19, 2011 at 5:04 AM

I just added you as a developer so you can commit or make a branch, etc.  Might be a good idea to start it out as a branch in case there is any trouble.  I have been committing the source to CodePlex via TFS rather than SVN so if you check out the source via SVN it won't have any svn:ignore properties defined.

I haven't heard of any recent changes with Twitter's auth that would affect this but it is possible that compiling it with a different set of references could introduce some bugs.  OAuth is a major pain to deal with, and it can be very difficult to determine exactly what part of the process is making a request fail.  Let me know if you run into that and I'll see what I can find.

Thanks again for the help.

Developer
Oct 19, 2011 at 5:43 AM

Great.  I'll definitely start with a branch.  You'll want to test it on your netduino plus to make sure I don't break anything there.  I have a netduino that I'll test with also.  I use TFS also, so SVN isn't an issue.  I saw that you posted to the tinyclr.com forum also.  When Skewworks posts his code to the wiki we'll be able to see what changes/improvements he made.