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

I need help changing a static ip address programatically

Socket Exception Static IP

  • Please log in to reply
1 reply to this topic

#1 bgreer5050

bgreer5050

    Member

  • Members
  • PipPip
  • 28 posts

Posted 16 April 2015 - 05:45 PM

I have my Netduino Plus 2 go out to a web service to look up some values that I would like it to use in my project.  One of the values that I have the Netduino check is its IP address.  There may be a reason for me to change an IP address of a Netduino that is in the field so I have a method in my project that I would like to change the static IP address when it is called.  The method takes a string.  

 

I am getting a SocketException with a code of 10022 for invalid argument.  This happens when I call this.Socket.Bind.  My class has a property called Socket to hold the Socket value.  Is it because my socket already has an endpoint ?  I adding this.Socket = null and then this.Socket = new (....... thinking we need a new socket to work with.  

 

Please advise how I can change my IP address from one static IP address to another.

 

 

 public void BindIPAddress(string strIPAddress)
        {
            try
            {
 
                Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticIP(strIPAddress, "255.255.240.0", "10.0.200.250");
                Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticDns(new string[] { "10.0.200.7", "10.0.100.5" });
                IPEndPoint ep = new IPEndPoint(IPAddress.Parse(strIPAddress), 80);
             
 
                this.Socket.Bind(ep);
                this.IpAddress = strIPAddress;
            }
            catch(SocketException exc)
            {
                Debug.Print(exc.Message);
                Debug.Print(exc.ErrorCode.ToString());
             
 
            }
            catch(Exception ex)
            {
                Debug.Print(ex.Message);
               
                
 
            }
            //Debug.Print(ep.Address.ToString());
        }


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 12 May 2015 - 03:35 AM

Hi bgreer,

Have you tried doing a PowerState.RebootDevice?
https://msdn.microso...y/ee435764.aspx

I'm not sure if the NETMF+lwIP integration is designed to handle this scenario well, without a reboot.

Chris





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.