WIFI does not communicate

Hello,
I disconnected wifi and flashed Cobra because I needed use cobra without wifi. Now I need wifi again, but if I connect it and call Wifi.Enable() the Cobra freezes and I must flash it again (It Comunicate only as virtual serial port, in MFDeploy I try ping and it is not working.)
If I flash Cobra and run program without Wifi initializing, it is run normally.
I think that wifi is connected correctly (pink wire on both sides to GND/3,3V)

What should I do to be able to use wifi again?
Thanks

It should be that simple. I am not sure why you are having problems

so let me check - you had a previously working application, and you’re trying to re-use that, but it doesn’t work even though you didn’t change anything??

By any chance in your activities between your original wifi app was working did you upgrade your SDK? If so you might just need a new app.

Second, if you didn’t do SDK, I’d be inclined to think that you have a connection issue. That means checking and re-checking wiring and making sure things were put back as expected.

Can you also explain exactly what you’re doing to reset the cobra, do you go into bootloader and clear your app with E?

I’d also try stepping into your code and seeing if you get any indicaiton from the device of what is going on.

If I use only the example to wifi initialize from GHI Library documentation, and run program with debugger (breakpoint on first row in Main method), Its running normaly, but only to WiFi.Enable(SPI.SPI_module.SPI2, (Cpu.Pin)FEZ_Pin.Digital.IO2, (Cpu.Pin)FEZ_Pin.Interrupt.IO26); - then I can’t continue.
Last rows in Output window is

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
Step into: Stepping over non-user code 'Microsoft.SPOT.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged.add'
Step into: Stepping over non-user code 'Microsoft.SPOT.Net.NetworkInformation.NetworkChange.NetworkAvailabilityChanged.add'
Step into: Stepping over non-user code 'GHIElectronics.NETMF.Net.WiFi.Enable'

If I stop debugging, Reconnect cobra on USB, I can’t Ping it in MFDeploy (I see EMX_EMX in USB, but I get only Error: No response from device)

I can erase all memory (E) with Teraterm and send new Firmware (X) and in MFDeploy deploy TinyCLR (3files). Then I can ping Cobra again.

If I run only FEZ Cobra Console Aplication It’s run normaly (LED blinking), and I can debugging row by row normally too.

Is it understandable? My english is not very good, I’m sorry.

The cable might be tricky. Take another look, the Polarizing Key at the connector should be at the 3.3V pin side.

Show me the code you are using please.

Ok I attach photo and here is my code:

using System;
using System.IO.Ports;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Socket = System.Net.Sockets.Socket;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net.NetworkInformation;

using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Net;

namespace Auticko
{
    public class Program
    {
        public static bool wifi_event = false;
        public static bool wifi_last_status = false;
        public static bool network_is_read = false;

        public static ManualResetEvent NetworkAvailablityBlocking = null;

        public static void Main()
        {
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
            if (!WiFi.IsEnabled)
            {
                WiFi.Enable(SPI.SPI_module.SPI2, (Cpu.Pin)FEZ_Pin.Digital.IO2, (Cpu.Pin)FEZ_Pin.Interrupt.IO26);
            }

            // WiFi settings
            NetworkInterface[] netif = NetworkInterface.GetAllNetworkInterfaces();
            Wireless80211 WiFiSettings = null;
            for (int index = 0; index < netif.Length; ++index)
            {
                if (netif[index] is Wireless80211)
                {
                    WiFiSettings = (Wireless80211)netif[index];

                }
            }

            //WPAPSK v HK
            //WiFiSettings.Ssid = "thomas";
            //WiFiSettings.NetworkKey = new byte[] { 0x36, 0x3e, 0x65, 0x19, 0x9d, 0xa4, 0x29, 0x3d, 0x19, 0x87, 0xb1, 0xe5, 0x99, 0x29, 0x1e, 0x51, 0xc5, 0xc2, 0xfa, 0x93, 0x5b, 0x40, 0xbc, 0x4f, 0x61, 0x4f, 0x98, 0x24, 0x49, 0xf3, 0xf1, 0x28 };
            //WiFiSettings.Encryption = Wireless80211.EncryptionType.WPAPSK;
            //WiFiSettings.Authentication = Wireless80211.AuthenticationType.Shared;

            WiFiSettings.Ssid = "Adoss";
            WiFiSettings.Encryption = Wireless80211.EncryptionType.None;
            WiFiSettings.Authentication = Wireless80211.AuthenticationType.Open;

            Wireless80211.SaveConfiguration(new Wireless80211[] { WiFiSettings }, false);

            NetworkAvailablityBlocking = new ManualResetEvent(false);
            if (!WiFi.IsLinkConnected)
            {
                Debug.Print("Waiting for WiFi link!");
                NetworkAvailablityBlocking.Reset();
                while (!NetworkAvailablityBlocking.WaitOne(5000, false))
                {
                    if (!WiFi.IsLinkConnected)
                    {
                        Debug.Print("WiFi link is not available yet! Wrong AP settings?Still waiting.");
                        Debug.Print("Still waiting.");
                    }
                    else
                        break;
                }
            }

            try
            {
                if (!WiFiSettings.IsDhcpEnabled)
                    WiFiSettings.EnableDhcp();// This function is blocking
                else
                {
                    WiFiSettings.RenewDhcpLease();// This function is blocking
                }
                network_is_read = true;
                Debug.Print("Network settings:");
                Debug.Print("IP Address: " + WiFiSettings.IPAddress);
                Debug.Print("Subnet Mask: " + WiFiSettings.SubnetMask);
                Debug.Print("Default Getway: " + WiFiSettings.GatewayAddress);
                Debug.Print("DNS Server: " + WiFiSettings.DnsAddresses[0]);
            }
            catch
            {
                Debug.Print("DHCP Failed");
            }

            Debug.Print("WiFi link is ready!");

            








            Thread listener = new Thread(listen);
            listener.Start();

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            EndPoint remoteEndPoint = new IPEndPoint(new IPAddress(new byte[] { 192, 168, 1, 7 }), 2000);
            //socket.Bind(remoteEndPoint);
            //socket.Connect(remoteEndPoint);
            socket.SendTo(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, remoteEndPoint);
            //socket.Send(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, SocketFlags.None);
            socket.Close();

            Debug.Print("Ready");
        }

        static void listen()
        {
            SerialPort serialPort = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
            serialPort.Open();

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 2000);
            socket.Bind(remoteEndPoint);

            while (true)
            {
                if (socket.Poll(-1, SelectMode.SelectRead))
                {
                    byte[] inBuf = new byte[socket.Available];
                    int count = socket.ReceiveFrom(inBuf, ref remoteEndPoint);
                    //if (count == 0) continue;

                    string s = "Recieved ";
                    for (int i = 0; i < inBuf.Length; i++)
                        s += inBuf[i] + ";";

                    Debug.Print(s);

                    if (inBuf[0] == 255)
                    {
                        serialPort.Open();
                        serialPort.Write(inBuf, 0, inBuf.Length);
                        serialPort.Close();
                    }

                    Debug.Print("Servo " + inBuf[1] + "is at " + inBuf[2]);
                }
            }
        }

        static void NetworkChange_NetworkAvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
        {
            if (e.IsAvailable)
            {
                if (WiFi.IsLinkConnected)
                {
                    if (wifi_last_status != true)
                    {
                        wifi_last_status = true;
                        NetworkAvailablityBlocking.Set();
                    }
                }
            }
            else
            {
                if (!WiFi.IsLinkConnected)
                {
                    if (wifi_last_status != false)
                    {
                        wifi_last_status = false;
                        network_is_read = false;
                    }
                }
            }
        }
    }
}

but if I’m debbuging, it freezes on third row in main method - Wifi.Enable()

This cable does not look like the ones we usually ship with the wifi expansion. It looks to me that the red wire (3.3V) is connected on 3.3V on the expansion and it is at GND pin on FEZ Cobra board.

Can you some how make sure that the 3.3V pin at the expansion is connect 3.3V on the FEZ Cobra? You can use a volt meter.

On the other hand, your code looks fine to me.

Weird, I got this cable with Cobra and Wifi… but If i used wifi module on tuesday, it worked and now not. At home I try 3,3V pin with voltmeter for sure…

the cable that usually ships with the wifi expansion looks like the one you see in the images in this user manual:
http://www.ghielectronics.com/downloads/NETMF_WiFi/NETMF%20WiFi%20User%20Guide%202.pdf
But if you used this cable before and it worked before then I assume that it OK.

So I assume the connection is correct.

I am sorry but I am out of ideas. You need to investigate it more.

  1. take a look at the pins. check the connection pin-to-pin.
  2. attach the debugger on MFDeploy and see what debugging messages do you get on start up.

Can I see debugging messages from wifi if I have clear Cobra? (Immediately after flashing? (Erase and deploy firmware?))
If is it true, I can’t see it.

And cable - it is made by my school teacher and he said, it is ok. And in tuesday it is work, so i think that it is really ok…

[quote]Can I see debugging messages from wifi if I have clear Cobra? (Immediately after flashing? (Erase and deploy firmware?))
[/quote]

Yes you are right, you can not see debugging messages. even if you deployed your wifi application, you will not be able to attach the debugger since the system is trying to enable the wifi module. and the debugging messages will not help a lot anyway.

So just make sure that the connection is OK as I mentioned before.

Did you use UEXT header with any other application lately? are you sure that the any of the ports are not damaged somehow?

You can easily test the pins by running a program to toggle the pins then use a scope to verify the pins are fine.

OK my bad. It was forgotten file in project. thanks for your help

But I have another problem with wifi… I have thread that listening udp packets on port 2000. After it’s working for a while, it freezes and ignores incomming data. How Can I do listening thread, that that listening forever?

Here is my code:


        static void listen()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 2000);
            socket.Bind(remoteEndPoint);


            while (true)
            {
                if (socket.Poll(-1, SelectMode.SelectRead))
                {
                    byte[] inBuf = new byte[socket.Available];
                    int count = socket.ReceiveFrom(inBuf, ref remoteEndPoint);
                    //if (count == 0) continue;

                    if(inBuf[0] == 255)
                        Debug.Print(inBuf[1] + ";" + inBuf[2]);
                }
           }