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.

Kazi Murtaza

Member Since 21 Dec 2012
Offline Last Active Dec 31 2012 12:49 PM
-----

Posts I've Made

In Topic: Netduino Plus Ethernet Shield

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/


In Topic: Netduino Plus Ethernet Shield

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/


In Topic: Netduino Plus Ethernet Shield

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();        }     }}

In Topic: Netduino Plus Ethernet Shield

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

In Topic: Netduino Plus Ethernet Shield

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);                            }                        }

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.