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

Networking Trouble with VB


  • Please log in to reply
5 replies to this topic

#1 Bejay

Bejay

    New Member

  • Members
  • Pip
  • 6 posts
  • LocationAustralia

Posted 23 January 2012 - 10:46 AM

I have tried to get a 'simple' networking server running with VB on the netduino plus and now I am feeling really dumb because no matter what I do it just will not work.
The first step is to go get an IP through the Dhcp and then tell me what it is so I can move onto the next bit, but all it does is repeat the waiting for IP
I connected and disconnected the cable several times but it just will not progress, it there something else I need to do?

Here is the code:

Private wSocket As System.Net.Sockets.Socket
Private wPortNumber as Int32 = 4000

Sub Main()
   Microsoft.SPOT.Debug.Print("Starting System...")
   Dim Led As New Microsoft.SPOT.Hardware.OutputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.ONBOARD_LED, False)
   Led.Write(False)

   Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).EnableDhcp()
   Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).ReleaseDhcpLease()
   Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).RenewDhcpLease()

   'this is a test to determine the IP address of the device
   Dim LocalIp As String = "0.0.0.0"                                                                           'Set the address to an invalid value
   LocalIp = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).IPAddress       'attempt to get the ip address
   Do While LocalIp = "0.0.0.0"                                                                                'while it stays invalid keep looping
      Microsoft.SPOT.Debug.Print("Waiting for IP address...")                                                  'write in the debug display that we are still waiting
      System.Threading.Thread.Sleep(1000)                                                                      'wait a second before trying again

      LocalIp = Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces(0).IPAddress    'attempt to get the ip address
   Loop
   Microsoft.SPOT.Debug.Print("The local IP address of your device is " & LocalIp)                             'report the ip address to the debug log
   Led.Write(True)                                                                                             'turn on the status led to indicate that the self setup is complete

   wSocket = New System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork, System.Net.Sockets.SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp)
   wSocket.Bind(New System.Net.IPEndPoint(System.Net.IPAddress.Any, wPortNumber))
   wSocket.Listen(Int32.MaxValue)
   
   'call code to wait for connection

End Sub



Here is what the debug produces:

A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.SPOT.Native.dll
Starting System...
Waiting for IP address...
Waiting for IP address...
Waiting for IP address...
Waiting for IP address...
Waiting for IP address...
Waiting for IP address...
Waiting for IP address...
Waiting for IP address... <== This repeats endlessly even after I connect the network cable


I would be greatful for any help

#2 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 23 January 2012 - 11:15 AM

Hi Things to check. Do the little green and yellow leds light up to show you are connected? I guess you have a DHCP server running on your network? Check your router to see if there is an arp entry for the netduino. The following is what I would do, I am sure many would disagree. I normally dont configure the network as part of my program. I would remove any calls to GetAllNetworkInterfaces, especially anything that writes configuration, such as EnableDhcp. I am sure this guy has overwritten my mac address. I would run framework 4.2 rc3. Go to mfdeploy for your framework and set you network settings there. Then you don't have to touch them. (Unless you change networks of course.) Check if your MAC address is ok. I would also write in C#, the only reasons being, it seems to be better supported, there is slightly less scope for errors and you don't have to write so many Dim statements.
STEFF Shield High Powered Led Driver shield.

#3 Bejay

Bejay

    New Member

  • Members
  • Pip
  • 6 posts
  • LocationAustralia

Posted 23 January 2012 - 11:58 AM

Hello Magpie, Thanks for your reply, Yes the Network leds come on and yes DHCP is set up and working fine on my network, No there is no device listed in the router with the netduino's Mac address, and yes the Mac address is fine in the Netduino. In the application I am writing portability is vital, it will need to adapt to what ever network it is moved to, so dhcp has to stay. (If I didn't need it I wouldn't have used it.) I am running framework 4.2 rc3 already (I needed it for VB to work) and although it is true that C# is better supported, that is undeniable. VB is my first langage. Codeing in C# for me is like the langage I did for a year back in high school fifteen years ago. Sure I can remember how to count to 10 or ask for the bathroom, but I don't have a hope in hell of conducting an indepth conversation on the nature of space, time and its relation to the universe as a whole. In otherwords, I can read C# just fine but when it comes to writting it I am stupidly slow. (VB capability was the whole resson I selected the netduino as my platform of choice.) And as for the count of Dim statement the number of them in C# is the same, C# justs insists they be written backwards and assums it is a decleration (No command name requred). They are still there, sure this may feel like an optimization but you have to tell it were every line ends with a good old semi-colon. My point is both langages are more or less the same, just some of us are more fluent in one dilect than the other.

#4 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 23 January 2012 - 12:38 PM

I can think of a couple things which may help.

You could set DHCP in the config and remove the lines in code. I have read also setting your config address to 0.0.0.0 may work.

If you download wireshark and figure out how to use it, (which isn't obvious) you should be able to see if the netduino is sending a dhcp request.
The dhcp request may be corrupted or not standard in some way. Wireshark will tell you this.

If you start with somebody else's code, that is code that is known to be working, you can keep adding and changing things and find where it breaks.

I have read that some DHCP servers don't work with the Netduino+ wireshark should tell you if this is the case.

Good luck
STEFF Shield High Powered Led Driver shield.

#5 Bejay

Bejay

    New Member

  • Members
  • Pip
  • 6 posts
  • LocationAustralia

Posted 24 January 2012 - 04:00 AM

I already have the DHCP set in MF Deploy. However if I do not release and renew the address before the first collecting of the IP Address the Netduino has a address that it seemed to make up itself (Nothing I put in.) which did not match my network. The address is already set to 0.0.0.0 and the problem seems to be Dhcp does not seem to be providing a valid replacement. I down loaded wireshark and right here and now I want to say THANK YOU! I have been looking for a packet sniffer that works under Win7 x64 for sometime. Any way after constructing a few complicated filters I can see the Netduino making the intial request if the network is connected during the program start up. However if unplugged or plugged in late no new request is made. Either way none of the three networks I tested this on returned anything that I could see. (It is possible I filtered it out, but I don't think so) So I am left still scratching my head. As for starting with someone elses code, I have not seen anyone doing what I am trying to achive yet, otherwise I would have had a look. Infact most of the socket listener part was written after studing things like Nevyn's SimpleWebServer Translated to VB, my problem is it is not breaking, it is working, by I am not reciving a valid address from the DHCP. I think my request may have gone wrong or something... (Though wireshark says all the packets that are there are good, maybe one is missing. I am going to look into what I should see in a DHCP exchange) As for DHCP's not working with it, I have now tried three different ones. So either I am just incredably unlucky or it isn't the DHCP (Home: Netgear, Work: Cisco, Friends: Dlink) Thanks for continueing to try though, I am open for the next suggestion(s)

#6 Magpie

Magpie

    Advanced Member

  • Members
  • PipPipPip
  • 279 posts
  • LocationAustralia (south island)

Posted 24 January 2012 - 05:02 AM

Well no one can say your not trying. I would look into the DHCP request. Wireshark normally lets you know if there is a malformed packet. Also you could look on the DHCP servers log, it may give details of what is wrong with the DHCP discover whatever packet. Or You could try it in c#, just see what happens, remember that the vb code is all new. I think I'm out of ideas after that.
STEFF Shield High Powered Led Driver shield.




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.