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

Netduino Plus Ethernet Shield


Best Answer Chris Walker, 25 December 2012 - 09:37 AM

Hi Kazi,

int DeviceID = int.Parse(filename[0].ToString());
this line breaks and
yes for sure, I will upload the video here..

What is the file name?

Unless it's a number string...trying to turn it into an int could cause you troubles.

Chris Go to the full post


  • Please log in to reply
12 replies to this topic

#1 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 23 December 2012 - 06:33 PM

Hello, I deployed the code bellow and for some reason, I kept getting 192.168.5.100 in debug window, what should I do to change the ip to 10.0.0.0  
using System;using Microsoft.SPOT;using System.Net.Sockets;using System.Net;using System.Threading;using System.Text;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware.NetduinoPlus;namespace WebserverHelloWorld{    public class WebServer : IDisposable    {        private Socket socket = null;           //open connection to onbaord led so we can blink it with every request        private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);        public WebServer()        {            //Initialize Socket class            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);            //Request and bind to an IP from DHCP server            socket.Bind(new IPEndPoint(IPAddress.Any, 80));            //Debug print our IP address            Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);            //Start listen for web requests            socket.Listen(10);            ListenForRequest();        }        public void ListenForRequest()        {            while (true)            {                using (Socket clientSocket = socket.Accept())                {                    //Get clients IP                    IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;                    EndPoint clientEndPoint = clientSocket.RemoteEndPoint;                    //int byteCount = cSocket.Available;                    int bytesReceived = clientSocket.Available;                    if (bytesReceived > 0)                    {                        //Get request                        byte[] buffer = new byte[bytesReceived];                        int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);                        string request = new string(Encoding.UTF8.GetChars(buffer));                        Debug.Print(request);                        //Compose a response                        string response = "Hello World";                        string header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";                        clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);                        clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);                        //Blink the onboard LED                        led.Write(true);                        Thread.Sleep(150);                        led.Write(false);                    }                }            }        }        #region IDisposable Members        ~WebServer()        {            Dispose();        }        public void Dispose()        {            if (socket != null)                socket.Close();        }        #endregion    }}
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;namespace WebserverHelloWorld{    public class Program    {        public static void Main()        {                        Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp();            WebServer webServer = new WebServer();            webServer.ListenForRequest();        }    }}


#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 23 December 2012 - 06:45 PM

instead of enabling dhcp setting an ip

#3 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 24 December 2012 - 09:48 AM

instead of enabling dhcp setting an ip

thank you

#4 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 24 December 2012 - 02:39 PM

I keep getting this error from the code below, if this is fixed I have set everything else to control my room lights Posted Image
 
10.0.0.11xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx    #### Exception System.ArgumentOutOfRangeException - CLR_E_OUT_OF_RANGE (1) ####    #### Message:     #### System.String::get_Chars [IP: 0000] ####    #### WebServer.WebServer::ListenForRequest [IP: 0069] ####    #### WebServer.WebServer::.ctor [IP: 0049] ####    #### WebServer.Program::Main [IP: 0016] ####A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dllAn unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll
 
using System;using Microsoft.SPOT;namespace WebServer{    using System;    using Microsoft.SPOT;    using System.Net.Sockets;    using System.Net;    using System.Threading;    using System.Text;    using Microsoft.SPOT.Hardware;    using SecretLabs.NETMF.Hardware.NetduinoPlus;    public class WebServer : IDisposable    {        private Socket socket = null;        //open connection to onbaord led so we can blink it with every request        private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);        public WebServer()        {            //Initialize Socket class            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);            //Request and bind to an IP from DHCP server            socket.Bind(new IPEndPoint(IPAddress.Any, 80));            //Debug print our IP address            Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);            //Start listen for web requests            socket.Listen(10);            ListenForRequest();        }        public void ListenForRequest()        {            while (true)            {                using (Socket clientSocket = socket.Accept())                {                    //Get clients IP                    IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;                    EndPoint clientEndPoint = clientSocket.RemoteEndPoint;                    //int byteCount = cSocket.Available;                    int bytesReceived = clientSocket.Available;                    if (bytesReceived > 0)                    {                        //Get request                        byte[] buffer = new byte[bytesReceived];                        int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);                        string request = new string(Encoding.UTF8.GetChars(buffer));                        string filename = ProcessResponse.GetTextBetween(request, "(java 1.4)");                                                                       Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        filename.ToCharArray();                        int DeviceID = int.Parse(filename[0].ToString());                        int DeviceSTATE = int.Parse(filename[2].ToString());                        Debug.Print("Device ID "+ DeviceID + " Value is " + DeviceSTATE);                        Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        //Compose a response                        string response = "Hello World";                        string header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";                        clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);                        clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);                        //Blink the onboard LED                        led.Write(true);                        Thread.Sleep(150);                        led.Write(false);                    }                }            }        }        #region IDisposable Members        ~WebServer()        {            Dispose();        }        public void Dispose()        {            if (socket != null)                socket.Close();        }        #endregion    }    public static class ProcessResponse    {        public static string GetTextBetween(string str, string a)        {            if (str == null || str == String.Empty) { return String.Empty; }            int aIdx = str.IndexOf(a);            if (aIdx == -1) { return String.Empty; }            int strt = aIdx + a.Length;            return str.Substring(strt).TrimStart();            //return str.Substring(strt, strt).Trim();        }     }}
public class Program    {        public static void Main()        {            Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticIP("10.0.0.11","255.255.255.0","10.0.0.1");            WebServer webServer = new WebServer();            webServer.ListenForRequest();        }    }


#5 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 December 2012 - 01:21 AM

Hi Kazi,

I keep getting this error from the code below, if this is fixed I have set everything else to control my room lights :)

Which line of code throws the exception?

Also...we would love to see video of those room lights once you have it up and running!

Chris

#6 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 25 December 2012 - 09:07 AM

int DeviceID = int.Parse(filename[0].ToString());
this line breaks and yes for sure, I will upload the video here.. and i added below code but it didn't trigger the device
if (DeviceID.Equals("1")) {                             if(DeviceSTATE.Equals("1")){                                Device1.Write(true);                            }                            else if (DeviceSTATE.Equals("0")) {                                Device1.Write(false);                            }                        }                        else if (DeviceID.Equals("2")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device2.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device2.Write(false);                            }                        }                        else if (DeviceID.Equals("3")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device3.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device3.Write(false);                            }                        }                        else if (DeviceID.Equals("4")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device4.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device4.Write(false);                            }                        }                        else if (DeviceID.Equals("5")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device5.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device5.Write(false);                            }                        }                        else if (DeviceID.Equals("6")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device6.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device6.Write(false);                            }                        }


#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 December 2012 - 09:37 AM   Best Answer

Hi Kazi,

int DeviceID = int.Parse(filename[0].ToString());
this line breaks and
yes for sure, I will upload the video here..

What is the file name?

Unless it's a number string...trying to turn it into an int could cause you troubles.

Chris

#8 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 25 December 2012 - 10:25 AM

yea stupid mistake String to Int conversion and then String comparison . its fixed correct code is
using System;using Microsoft.SPOT;namespace WebServer{    using System;    using Microsoft.SPOT;    using System.Net.Sockets;    using System.Net;    using System.Threading;    using System.Text;    using Microsoft.SPOT.Hardware;    using SecretLabs.NETMF.Hardware.NetduinoPlus;    using SecretLabs.NETMF.Hardware;    public class WebServer : IDisposable    {        private Socket socket = null;        //open connection to onbaord led so we can blink it with every request        private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);        static OutputPort Device1 = new OutputPort(Pins.GPIO_PIN_D5, false);        static OutputPort Device2 = new OutputPort(Pins.GPIO_PIN_D6, false);        static OutputPort Device3 = new OutputPort(Pins.GPIO_PIN_D7, false);        static OutputPort Device4 = new OutputPort(Pins.GPIO_PIN_D8, false);        static OutputPort Device5 = new OutputPort(Pins.GPIO_PIN_D9, false);        static OutputPort Device6 = new OutputPort(Pins.GPIO_PIN_D10, false);        public WebServer()        {            //Initialize Socket class            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);            //Request and bind to an IP from DHCP server            socket.Bind(new IPEndPoint(IPAddress.Any, 80));            //Debug print our IP address            Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);            //Start listen for web requests            socket.Listen(10);            ListenForRequest();        }        public void ListenForRequest()        {            while (true)            {                using (Socket clientSocket = socket.Accept())                {                    //Get clients IP                    IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;                    EndPoint clientEndPoint = clientSocket.RemoteEndPoint;                    //int byteCount = cSocket.Available;                    int bytesReceived = clientSocket.Available;                    if (bytesReceived > 0)                    {                        //Get request                        byte[] buffer = new byte[bytesReceived];                        int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);                        string request = new string(Encoding.UTF8.GetChars(buffer));                        string filename = ProcessResponse.GetTextBetween(request, "(java 1.4)");                                                                       //Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        filename.ToCharArray();                        String DeviceID = filename[0].ToString(); //[size="5"][b]<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< code breaks here[/b][/size]                        String DeviceSTATE = filename[2].ToString();                        Debug.Print("Device ID "+ DeviceID + " Value is " + DeviceSTATE);                        //Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        if (DeviceID.Equals("1")) {                             if(DeviceSTATE.Equals("1")){                                Device1.Write(true);                            }                            else if (DeviceSTATE.Equals("0")) {                                Device1.Write(false);                            }                        }                        else if (DeviceID.Equals("2")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device2.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device2.Write(false);                            }                        }                        else if (DeviceID.Equals("3")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device3.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device3.Write(false);                            }                        }                        else if (DeviceID.Equals("4")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device4.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device4.Write(false);                            }                        }                        else if (DeviceID.Equals("5")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device5.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device5.Write(false);                            }                        }                        else if (DeviceID.Equals("6")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device6.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device6.Write(false);                            }                        }                        //Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        //Compose a response                        string response = "Hello World";                        string header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";                        clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);                        clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);                        //Blink the onboard LED                        led.Write(true);                        Thread.Sleep(150);                        led.Write(false);                    }                }            }        }        #region IDisposable Members        ~WebServer()        {            Dispose();        }        public void Dispose()        {            if (socket != null)                socket.Close();        }        #endregion    }    public static class ProcessResponse    {        public static string GetTextBetween(string str, string a)        {            if (str == null || str == String.Empty) { return String.Empty; }            int aIdx = str.IndexOf(a);            if (aIdx == -1) { return String.Empty; }            int strt = aIdx + a.Length;            return str.Substring(strt).TrimStart();            //return str.Substring(strt, strt).Trim();        }     }}
but the code still throws exception above I have marked it, output is below;  
'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1Assemblieslemscorlib.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleMicrosoft.SPOT.Native.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleMicrosoft.SPOT.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleMicrosoft.SPOT.Net.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleSystem.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleMicrosoft.SPOT.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleSystem.IO.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleMicrosoft.SPOT.Hardware.SerialPort.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesMicrosoft .NET Micro Frameworkv4.1AssembliesleMicrosoft.SPOT.Hardware.Usb.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesSecret LabsNetduino SDKAssembliesv4.1leSecretLabs.NETMF.Hardware.dll', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'SecretLabs.NETMF.Diagnostics''Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:UserskazimurtazaAppDataLocalTemporary ProjectsWebServerbinDebugleWebServer.exe', Symbols loaded.'Microsoft.SPOT.Debugger.CorDebug.dll' (Managed): Loaded 'C:Program FilesSecret LabsNetduino SDKAssembliesv4.1leSecretLabs.NETMF.Hardware.NetduinoPlus.dll', Symbols loaded.The thread '<No Name>' (0x2) has exited with code 0 (0x0).10.0.0.11Device ID 3 Value is 1Device ID 3 Value is 0Device ID 3 Value is 1Device ID 3 Value is 0    #### Exception System.ArgumentOutOfRangeException - CLR_E_OUT_OF_RANGE (1) ####    #### Message:     #### System.String::get_Chars [IP: 0000] ####    #### WebServer.WebServer::ListenForRequest [IP: 0062] ####    #### WebServer.WebServer::.ctor [IP: 0049] ####    #### WebServer.Program::Main [IP: 0016] ####A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dllAn unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll


#9 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 25 December 2012 - 01:44 PM

I think its fixed, i am going to connect everything now.I think the error was because of empty string so I am checking the string length before executing anything.
using System;using Microsoft.SPOT;namespace WebServer{    using System;    using System.Net;    using System.Net.Sockets;    using System.Text;    using System.Threading;    using Microsoft.SPOT;    using Microsoft.SPOT.Hardware;    using SecretLabs.NETMF.Hardware;    using SecretLabs.NETMF.Hardware.NetduinoPlus;    public class WebServer : IDisposable    {        private Socket socket = null;        //open connection to onbaord led so we can blink it with every request        private OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);        static OutputPort Device1 = new OutputPort(Pins.GPIO_PIN_D5, false);        static OutputPort Device2 = new OutputPort(Pins.GPIO_PIN_D6, false);        static OutputPort Device3 = new OutputPort(Pins.GPIO_PIN_D7, false);        static OutputPort Device4 = new OutputPort(Pins.GPIO_PIN_D8, false);        static OutputPort Device5 = new OutputPort(Pins.GPIO_PIN_D9, false);        static OutputPort Device6 = new OutputPort(Pins.GPIO_PIN_D10, false);        public WebServer()        {            //Initialize Socket class            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);            //Request and bind to an IP from DHCP server            socket.Bind(new IPEndPoint(IPAddress.Any, 80));            //Debug print our IP address            Debug.Print(Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].IPAddress);            //Start listen for web requests            socket.Listen(10);            ListenForRequest();        }        public void ListenForRequest()        {            while (true)            {                using (Socket clientSocket = socket.Accept())                {                    //Get clients IP                    IPEndPoint clientIP = clientSocket.RemoteEndPoint as IPEndPoint;                    EndPoint clientEndPoint = clientSocket.RemoteEndPoint;                    //int byteCount = cSocket.Available;                    int bytesReceived = clientSocket.Available;                    if (bytesReceived > 0)                    {                        //Get request                        byte[] buffer = new byte[bytesReceived];                        int byteCount = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None);                        string request = new string(Encoding.UTF8.GetChars(buffer));                        string filename = ProcessResponse.GetTextBetween(request, "(java 1.4)");                                                                       //Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        if(filename.Length>0){                        filename.ToCharArray();                        String DeviceID = "0"; if (!(filename[0].Equals(null))) { DeviceID = filename[0].ToString(); }                        String DeviceSTATE = "0"; if (!(filename[2].Equals(null))) { DeviceSTATE = filename[2].ToString(); }                        Debug.Print("Device ID "+ DeviceID + " Value is " + DeviceSTATE);                        //Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        if (DeviceID.Equals("1")) {                             if(DeviceSTATE.Equals("1")){                                Device1.Write(true);                            }                            else if (DeviceSTATE.Equals("0")) {                                Device1.Write(false);                            }                        }                        else if (DeviceID.Equals("2")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device2.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device2.Write(false);                            }                        }                        else if (DeviceID.Equals("3")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device3.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device3.Write(false);                            }                        }                        else if (DeviceID.Equals("4")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device4.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device4.Write(false);                            }                        }                        else if (DeviceID.Equals("5")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device5.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device5.Write(false);                            }                        }                        else if (DeviceID.Equals("6")) {                            if (DeviceSTATE.Equals("1"))                            {                                Device6.Write(true);                            }                            else if (DeviceSTATE.Equals("0"))                            {                                Device6.Write(false);                            }                        }                        }                        //Debug.Print("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");                        //Compose a response                        string response = "Hello World";                        string header = "HTTP/1.0 200 OKrnContent-Type: text; charset=utf-8rnContent-Length: " + response.Length.ToString() + "rnConnection: closernrn";                        clientSocket.Send(Encoding.UTF8.GetBytes(header), header.Length, SocketFlags.None);                        clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None);                        //Blink the onboard LED                        led.Write(true);                        Thread.Sleep(150);                        led.Write(false);                    }                }            }        }        #region IDisposable Members        ~WebServer()        {            Dispose();        }        public void Dispose()        {            if (socket != null)                socket.Close();        }        #endregion    }    public static class ProcessResponse    {        public static string GetTextBetween(string str, string a)        {            if (str == null || str == String.Empty) { return String.Empty; }            int aIdx = str.IndexOf(a);            if (aIdx == -1) { return String.Empty; }            int strt = aIdx + a.Length;            return str.Substring(strt).TrimStart();            //return str.Substring(strt, strt).Trim();        }     }}


#10 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 25 December 2012 - 08:39 PM

Hi Kazi, Which line is throwing an exception now? Chris

#11 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 30 December 2012 - 02:51 PM

no everything works fine.. now my last post has the updated code :) video and other details are availible in the direct link below on my blog, if I am missing something let me know I will share here.

 

http://kazimurtaza.c...thernet-part-2/



#12 Kazi Murtaza

Kazi Murtaza

    New Member

  • Members
  • Pip
  • 9 posts

Posted 31 December 2012 - 12:50 PM

http://forums.netdui...eld/#entry42139

 

this post is the best answer XD, I fixed it myself now no more breaking and to view the video of my experiment go  to my blog i hope i am clear

http://kazimurtaza.c...thernet-part-2/



#13 Gutworks

Gutworks

    Advanced Member

  • Members
  • PipPipPip
  • 363 posts
  • LocationOttawa, Ontario

Posted 31 December 2012 - 05:10 PM

Great work Kazi! I'd love to start automating my house and all of these posts lately from yourself and a few other members are really getting me excited. I can't wait to see some more additions, and please do share more pictures and videos. 

 

Cheers,

Steve






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.