Connect from a WP8-Phone to the Netduino + dont work - Visual Basic Support - Netduino Forums
   
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

Connect from a WP8-Phone to the Netduino + dont work


  • Please log in to reply
2 replies to this topic

#1 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 05 September 2013 - 06:46 AM

Hi,

 

i try to connect my WP8 via HTTP to the Netduino Plus (Port 80).

 

The strange part: The Local PC can see the Netduino-Website, but the phone not. I tried to ping the netduino from the phone and he found it. But the IE cant find it.

Imports SystemImports System.TextImports System.NetImports System.Net.SocketsImports System.ThreadingImports Microsoft.SPOTImports Microsoft.SPOT.HardwareImports SecretLabs.NETMF.HardwareImports SecretLabs.NETMF.Hardware.NetduinoPlusImports System.IO.PortsModule Module1    Private socket As Socket = Nothing    Private web As New OutputPort(Pins.GPIO_PIN_D10, False)    Private led As New OutputPort(Pins.GPIO_PIN_D8, False)    Private onb As New OutputPort(Pins.ONBOARD_LED, False)    Dim serial As SerialPort    Dim cmd_PIN As String = "PIN"    Dim cmd_PIN_ON As String = "ON"    Dim cmd_PIN_OFF As String = "OFF"    Dim cmd_PIN_TOGGLE As String = "TOGGLE"    Dim cmd_Serial As String = "S"    Dim count As Integer = 0    Sub Main()        Debug.EnableGCMessages(True)        '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)        ' initialize the serial port for COM1 (using D0 & D1)        serial = New SerialPort(SerialPorts.COM1, 19200, Parity.None, 8, StopBits.One)        ' open the serial-port, so we can send & receive data        serial.Open()        While True            Using clientSocket As Socket = socket.Accept()                'Get clients IP                Dim clientIP As IPEndPoint = TryCast(clientSocket.RemoteEndPoint, IPEndPoint)                Dim clientEndPoint As EndPoint = clientSocket.RemoteEndPoint                'int byteCount = cSocket.Available;                Dim bytesReceived As Integer = clientSocket.Available                If bytesReceived > 0 Then                    'Get request                    Dim buffer As Byte() = New Byte(bytesReceived - 1) {}                    Dim byteCount As Integer = clientSocket.Receive(buffer, bytesReceived, SocketFlags.None)                    Dim request As New String(Encoding.UTF8.GetChars(buffer))                    count += 1                    Debug.Print("Counter: " + count.ToString + Constants.vbCrLf + "Free RAM: " + Microsoft.SPOT.Debug.GC(False).ToString + " Bytes" + Constants.vbCrLf + "Anfrage von: " + clientIP.ToString + Constants.vbCrLf + request)                    If request.Contains(CChar("GET")) Then                        If Not (request.Split(CChar("/"))(1)).Split(CChar(" "))(0).Trim = Nothing Then                            Dim temp As String = ""                            If ((request.Split(CChar("/"))(1).Split(CChar(" "))(0).Split(CChar("="))(0).ToUpper)) = cmd_Serial Then                                Dim rgb As String = ((request.Split(CChar("/"))(1).Split(CChar(" "))(0).Split(CChar("="))(1).ToUpper))                                Debug.Print(rgb)                                Dim Data As Byte() = Encoding.UTF8.GetBytes(rgb)                                serial.Write(Data, 0, Data.Length)                                temp = rgb                            ElseIf ((request.Split(CChar("/"))(1).Split(CChar(" "))(0).Split(CChar("="))(0).ToUpper)) = cmd_PIN Then                                If ((request.Split(CChar("/"))(1).Split(CChar(" "))(0).Split(CChar("="))(1).ToUpper)) = cmd_PIN_ON Then onb.Write(True)                                If ((request.Split(CChar("/"))(1).Split(CChar(" "))(0).Split(CChar("="))(1).ToUpper)) = cmd_PIN_OFF Then onb.Write(False)                                If ((request.Split(CChar("/"))(1).Split(CChar(" "))(0).Split(CChar("="))(1).ToUpper)) = cmd_PIN_TOGGLE Then                                    temp = " (TOGGLE)"                                    LED_Toggle(3)                                End If                                If onb.Read() = True Then temp = "ON" + temp                                If onb.Read() = False Then temp = "OFF" + temp                            End If                            Dim response As String = "<!DOCTYPE html>" + Constants.vbLf + "<html>" + Constants.vbLf + "<body>" + Constants.vbLf + "<div align=""center"">" + Constants.vbLf + "<h1>Netduino Websteuerung</h1>" + Constants.vbLf + "<p>LED = " + temp + "</p>" + Constants.vbLf + "</div>" + Constants.vbLf + "</body>" + Constants.vbLf + "</html>"                            clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None)                            LED_Toggle(2)                            Thread.Sleep(500)                            LED_Toggle(2)                        ElseENDE:                       Dim response As String = "<!DOCTYPE html>" + Constants.vbLf _                                                   + "<html>" + Constants.vbLf _                                                   + "<body>" + Constants.vbLf _                                                   + "<div align=""center"">" + Constants.vbLf _                                                   + "<h1>Netduino Websteuerung</h1>" + Constants.vbLf _                                                   + "<p>Zur Pinsteuerung einfach /PIN=ON/OFF/TOGGLE eingeben</p>" + Constants.vbLf _                                                   + "</div>" + Constants.vbLf _                                                   + "</body>" + Constants.vbLf _                                                   + "</html>"                            clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None)                            'Blink the onboard LED                            LED_Toggle(2)                            Thread.Sleep(500)                            LED_Toggle(2)                        End If                    Else                        Dim show As Boolean = False                        Dim temp As String = ""                        If request.Trim.ToUpper = "ON" Then                            show = True                            led.Write(True)                        ElseIf request.Trim.ToUpper = "OFF" Then                            show = True                            led.Write(False)                        ElseIf request.Trim.ToUpper = "TOGGLE" Then                            show = True                            LED_Toggle(1)                            temp = "(TOGGLE)"                        ElseIf request.Trim.ToUpper = "COUNTER" Then                            temp = "Bisher gezaehlte Anfragen: " + count.ToString                        ElseIf request.Trim.ToUpper = "HELP" Then                            temp = "ON/OFF/TOGGLE/COUNTER/HELP"                        Else                            temp = "Unbekannter Befehl: " + request                        End If                        If show = True Then                            If led.Read() = True Then temp = "ON " + temp                            If led.Read() = False Then temp = "OFF " + temp                            Dim response As String = "LED = " + temp                            clientSocket.Send(Encoding.UTF8.GetBytes(response), response.Length, SocketFlags.None)                        Else                            clientSocket.Send(Encoding.UTF8.GetBytes(temp), temp.Length, SocketFlags.None)                        End IfBB:                 End If                    request = Nothing                End If            End Using        End While    End Sub    ' Einfacher Toggle-Befehl für alle Definierten LED's    Sub LED_Toggle(ByVal stat As Integer)        Dim status0 As Boolean = led.Read()        Dim status1 As Boolean = web.Read()        Dim status2 As Boolean = onb.Read()        If stat = 1 Then led.Write(Not status0)        If stat = 2 Then web.Write(Not status1)        If stat = 3 Then onb.Write(Not status2)    End Sub    ' Contains-Ersatz (Da die eigentliche Funktion nicht vorhanden ist)    <System.Runtime.CompilerServices.Extension()> _    Public Function Contains(ByVal _src As [String], ByVal _search As Char) As Boolean        For i As Integer = _src.Length - 1 To 0 Step -1            If _src.IndexOf(_search) >= 0 Then                Return True            End If        Next        Return False    End Function    Public Function Replace(ByVal str As String, ByVal unwanted As String, ByVal replacement As String) As String        Dim sb As New StringBuilder(str)        sb.Replace(unwanted, replacement)        Return sb.ToString()    End FunctionEnd Module

Is my code maybe false? In Debug-Mode i dont get any request from the WP8...

 

What am I doing wrong?

 

mfg

 

gfc



#2 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 05 September 2013 - 07:48 AM

Have you tried Wireshark to see if the traffic from the phone is getting through to the network OK?

 

Regards,

Mark


To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#3 gfcwfzkm

gfcwfzkm

    Advanced Member

  • Members
  • PipPipPip
  • 52 posts
  • LocationBrig-Glis, Switzerland

Posted 05 September 2013 - 08:11 AM

Good idea. I tried Wireshark and no WinPhone-Data was found. And i think that its more an firewall-problem. Every LAN-Computer in the company can connect to the netduino, but no Wireless-Device can connect to it :/

 

mfg

 

gfc






1 user(s) are reading this topic

0 members, 1 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.