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

RN-XV WiFly Module driver


  • Please log in to reply
98 replies to this topic

#1 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 January 2012 - 09:57 PM

Posted Image

Okay, I wanted to make my 1000th post worth it.

There's a Netduino Plus in the picture above, but it really doesn't need to. It's just that my Netduino Classic is otherwise occupied ;)

The above picture shows a Netduino, XBee Shield and RN-XV WiFly Module. This module is in simple terms, a serial-to-tcp-bridge. It can handle one tcp socket at the same time, but for many applications this is exactly enough!

So I wrote two classes, one in generic to drive the module, and one as socket wrapper. The outcome is that the code below works. Keep in mind, it's not actually ment as IP stack, but it works. Some things are a bit hackish though.

// Declares the WiFly module, configures the IP address and joins a wireless network
WiFlyGSX WifiModule = new WiFlyGSX();
WifiModule.EnableDHCP();
WifiModule.JoinNetwork("Mynetwork", 0, WiFlyGSX.AuthMode.MixedWPA1_WPA2, "MyTopSecretPassword");

// Showing some interesting output
Debug.Print("Local IP: " + WifiModule.LocalIP);
Debug.Print("MAC address: " + WifiModule.MacAddress);

// Creates a socket
SimpleSocket Socket = new WiFlySocket("www.netduino.com", 80, WifiModule);

// Connects to the socket
Socket.Connect();

// Does a plain HTTP request
Socket.Send("GET / HTTP/1.1\r\n");
Socket.Send("Host: " + Socket.Hostname + "\r\n");
Socket.Send("Connection: Close\r\n");
Socket.Send("\r\n");

// Prints all received data to the debug window, until the connection is terminated and there's no data left anymore
while (Socket.IsConnected || Socket.BytesAvailable > 0)
{
    string Text = Socket.Receive();
    if (Text != "")
        Debug.Print(Text);
}

// Closes down the socket
Socket.Close();

Stuff can be downloaded, including samples, at http://netmftoolbox....ol/BrowseLatest

By the way, for those who know that netmftoolbox thingy, I also added an SNTP client today
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 30 January 2012 - 10:07 PM

Oh hey, that's pretty awesome! I know that WiFi is something people really want to do with their Netduinos...hopefully this helps more people build wirelessly-connected devices! Chris P.S. You might consider changing your WPA2 password ;)

#3 Terry Massey

Terry Massey

    Advanced Member

  • Members
  • PipPipPip
  • 77 posts
  • LocationPekin, IL

Posted 02 February 2012 - 04:37 PM

Stefan, I was in the middle of writing drivers myself for this module for work and after chatting with Walker telling me about the drivers. Well I tried them out today. OMG frigging awesome. way less complex than i was making mine and well quite incredible. I have found a few minor bugs but they might be related to some timing issues. Mostly when adding in my own command Mode settings such as Scan and Sleep. I see that there are times your ignoring some of the garbage that comes back. so it might just be an issue with me debugging. but occasionally I expect my code to get a value back and you have ignored something like DHCP=on coming back. Here is a few methods I have implemented you could add to the WiFlyGSX class and an additional class I implemented. public void GoToSleep() { CommandModeStart(); WriteBuffer("sleep\r"); } public WirelessNetwork[] Scan() { CommandModeStart(); WriteBuffer("set sys printlvl 0x4000\r"); CommandModeRead(true); WriteBuffer("scan\r"); Thread.Sleep(3000); CommandModeRead(); string found = CommandModeRead(true); short count = Convert.ToInt16(found.Split("SCAN:Found ".ToCharArray())[11]); var retVal = new WirelessNetwork[count]; for (short x = 0; x < count;x++ ) { string s = CommandModeRead(); string[] cols=s.Split(",".ToCharArray()); var w = new WirelessNetwork { Id = Convert.ToInt16(cols[0]), Channel = Convert.ToInt16(cols[1]), Rssi = Convert.ToInt32(cols[2]), Security = (AuthMode) Convert.ToInt32(cols[3]), Capibilities = cols[4], //This is not documented well at least that I can find and can be more than on comma delimited Field MacAddress = cols[cols.Length-2], Ssid = cols[cols.Length-1] }; retVal[x] = w; } WriteBuffer("set sys printlvl 0\r"); CommandModeRead(true); CommandModeStop(); return retVal; } public class WirelessNetwork { public short Id; public short Channel; public int Rssi; public AuthMode Security; public string Capibilities; public string MacAddress; public string Ssid; }
Thanks,
Terry Massey

#4 tranceash

tranceash

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 March 2012 - 01:08 PM

I got the netduino classic and WiFlyGSX module attached to the XBee Shield same as the picture you have posted except the netduino us a classic one. Have added the .NET Micro Framework Toolbox references so I can have access to the WiFlyGSX class but when I try run the program the code hangs when creating an instance and nothing happens. Any advise The code I have is just creating an instance and getting tryint o get the mac address Debug.Print("Starting wifi config..."); WiFlyGSX WifiModule = new WiFlyGSX(); Debug.Print("Mac Address"+WifiModule.MacAddress); It print "Starting wifi config..." and is hanging in the debugger. Any advise netduino hardware Pinging... TinyCLR HalSystemInfo.halVersion: 4.1.2821.0 HalSystemInfo.halVendorInfo: Netduino by Secret Labs LLC HalSystemInfo.oemCode: 34 HalSystemInfo.modelCode: 177 HalSystemInfo.skuCode: 4096 ClrInfo.clrVendorInfo: Netduino by Secret Labs LLC ClrInfo.targetFrameworkVersion: 4.1.2821.0 SolutionReleaseInfo.solutionVersion: 4.1.0.6 SolutionReleaseInfo.solutionVendorInfo: Netduino by Secret Labs LLC SoftwareVersion.BuildDate: Feb 14 2011 SoftwareVersion.CompilerVersion: 400902

#5 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 March 2012 - 01:18 PM

Hi tranceash, Have you added the reference as DLLs or from source? At the top of the wifly code there's a #define debug (see http://netmftoolbox....ew/13101#197130) If you enable it, it'll output some more details which might help.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#6 tranceash

tranceash

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 March 2012 - 01:42 PM

Hi tranceash,

Have you added the reference as DLLs or from source? At the top of the wifly code there's a #define debug (see http://netmftoolbox....ew/13101#197130)
If you enable it, it'll output some more details which might help.



I have added references as dlls. It seems like the board is not seen by netduino but the lights are flashing on the board, d1 an d3 leds flash on the module and d105 on xigbee are flashing .
I also enabled WIFLY_DEBUG nothing gets printed same thing.
How does netduino communicate to the wifi module ? anything else I need to do ? . If I remove the wifi module from the xigbee board its the same behavior ?

Also I see that the contructor connects to com1 how does that work does it not connect to com1 from netduino board ?

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 March 2012 - 02:03 PM

It uses a serial port, COM1 = pins 0 & 1, COM2 = pins 2 & 3. You could change it in the constructor and change the switch on the XBee shield (it has a switch on it that can switch between those two) As final step you could wire the module directly to your Netduino without any shield at all. I can guide you through that if you dont know how to.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 tranceash

tranceash

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 March 2012 - 02:19 PM

It uses a serial port, COM1 = pins 0 & 1, COM2 = pins 2 & 3.
You could change it in the constructor and change the switch on the XBee shield (it has a switch on it that can switch between those two)
As final step you could wire the module directly to your Netduino without any shield at all. I can guide you through that if you dont know how to.



On the xbee there is a switch that says uart and dline. It is set to dline.
I did a step through the code and it hangs at this line.
this._Port = new SerialPort(PortName, BaudRate, Parity.None, 8, StopBits.One);

Also how do you connect the wire the module directly to the netduino . I am new to electronics so any guide?
Do you think the xbee is the problem ?

#9 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 March 2012 - 02:40 PM

On the xbee there is a switch that says uart and dline. It is set to dline.
I did a step through the code and it hangs at this line.
this._Port = new SerialPort(PortName, BaudRate, Parity.None, 8, StopBits.One);

DLine is COM2 if I'm correct, with that shield. You could try that.


If that doesn't help, try connecting it directly:
Posted Image
Same pin-out counts for the WiFly module

Connect pin 1 of the WiFly module to 3V3 on your Netduino
Connect pin 10 of the WiFly module to Gnd on your Netduino
Connect pin 2 of the WiFly module to digital pin 0 on your Netduino
Connect pin 3 of the WiFly module to digital pin 1 on your Netduino

That should link it to COM1.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#10 tranceash

tranceash

    Member

  • Members
  • PipPip
  • 12 posts

Posted 16 March 2012 - 02:58 PM

DLine is COM2 if I'm correct, with that shield. You could try that.


If that doesn't help, try connecting it directly:
Posted Image
Same pin-out counts for the WiFly module

Connect pin 1 of the WiFly module to 3V3 on your Netduino
Connect pin 10 of the WiFly module to Gnd on your Netduino
Connect pin 2 of the WiFly module to digital pin 0 on your Netduino
Connect pin 3 of the WiFly module to digital pin 1 on your Netduino

That should link it to COM1.


I will require some jumper wires to do that will order some tomorrow and will let you know how it goes .

One question I need to connect a pir sensor http://www.ebay.com....=item415a6ec012

to netduino board . The idea is the pir sensor detects movement and sends a signal to a web server with the help of the WiFly module. How do I interface all this if I connect the wiFly module using jumper wires ?

#11 tranceash

tranceash

    Member

  • Members
  • PipPip
  • 12 posts

Posted 19 March 2012 - 08:57 AM

DLine is COM2 if I'm correct, with that shield. You could try that.


If that doesn't help, try connecting it directly:
Posted Image
Same pin-out counts for the WiFly module

Connect pin 1 of the WiFly module to 3V3 on your Netduino
Connect pin 10 of the WiFly module to Gnd on your Netduino
Connect pin 2 of the WiFly module to digital pin 0 on your Netduino
Connect pin 3 of the WiFly module to digital pin 1 on your Netduino

That should link it to COM1.


One question I need to connect a pir sensor http://www.ebay.com....=item415a6ec012

to netduino board . The idea is the pir sensor detects movement and sends a signal to a web server with the help of the WiFly module. How do I interface all this if I connect the wiFly module using jumper wires ?

#12 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 19 March 2012 - 09:34 AM

One question I need to connect a pir sensor http://www.ebay.com....=item415a6ec012

to netduino board . The idea is the pir sensor detects movement and sends a signal to a web server with the help of the WiFly module. How do I interface all this if I connect the wiFly module using jumper wires ?

You could do the same for the PIR sensor, also with jumper wires :)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#13 tranceash

tranceash

    Member

  • Members
  • PipPip
  • 12 posts

Posted 21 March 2012 - 08:45 AM

You could do the same for the PIR sensor, also with jumper wires :)



Sorry Stefan can you show me a diagram how I will connect the classic netduino + Wifly + pir sensor ? As the power is connected to wifly so should I connect the pir to the wifly pin ?

#14 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 21 March 2012 - 08:52 AM

Sorry Stefan can show me a diagram how I will connect the classic netduino + Wifly + pir sensor ? As the power is connected to wifly so should I connect the pir to the wifly pin ?

Hi Tranceash,

It all depends on the kind of pir sensor, but you could connect multiple devices to power pins. For this you could use a breadboard. Just connect the PIR sensor to the Netduino with a breadboard, then connect the RN-XV module to the breadboard. Should work.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#15 Kaeptn Linux

Kaeptn Linux

    New Member

  • Members
  • Pip
  • 8 posts

Posted 30 March 2012 - 04:08 PM

Hello, if i debug the method private void _CommandMode_Start() of the WiFlyGSX class i only get in Teststring the message: "Auto-Assoc roving1 chan=0 mode=NONE FAILED" and the module stucks in the while loop. So i think the module can't get into command mode. Has anyone an idea ?

#16 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 March 2012 - 04:23 PM

Hi Kaeptn Linux, Could you share some more info? Did you initiate a wireless accesspoint first?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#17 Kaeptn Linux

Kaeptn Linux

    New Member

  • Members
  • Pip
  • 8 posts

Posted 30 March 2012 - 04:48 PM

Hello Stefan, i used the WiFly_Socket Example Project with th adaption of WifiModule.JoinNetwork("<<my access point>>", 0, WiFlyGSX.AuthMode.WPA2_PSK, "<<my very secret pass>>", 1); but before that the call of Constructor: WiFlyGSX WifiModule = new WiFlyGSX(); hangs in the mentioned loop.

#18 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 March 2012 - 04:54 PM

Interesting, it looks like the tx line from your netduino to your wifi module doesn't send the command strings... how have you connected your module?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#19 Kaeptn Linux

Kaeptn Linux

    New Member

  • Members
  • Pip
  • 8 posts

Posted 30 March 2012 - 04:58 PM

I connected the netduino with the module over the sparkfun xbee shield

#20 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 30 March 2012 - 05:00 PM

Could it be you're suffering the same problem as described here? http://forums.netdui...dpost__p__25848 Appairently that shield (or at least one version) has some issues.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs




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.