Main Site Documentation

WiFi RN171 - Default settings


#1

I started playing with my new WiFi RN171 module but I could not get the device initialized using the driver that ships with the latest GHI SDK. Fortuantely it was quite clear what the problem was, I was getting garbage from the serial interface which normally indicates that the serial port is not configured correctly.

It turns out my module was set out of the box to run at a baud rate of 115200. The driver however assumes that the baud rate is 9600 which is the specified default in the datasheet.

I was able to discover this by connecting to the device using a telnet client on my iPad. The telnet IP/port was
192.168.1.1:80

@ Gus - It might be worth having the developer page for the module updated with all the settings that deviate from the defaults specified in the datasheet. The sample code there will also not compile, it is a minor problem, but someone still learning C# might find this to be an additional hurdle.

The is really a very exciting module, I can’t wait to connect it to my FEZ Cerbot and have the PC sending it instructions! This might be a nice way to interactively tune the PID for the balancing of the robot… Thanks for the great module!


#2

Interesting. I was going to use Bluetooth module for that purpose.


#3

We will take care of this quickly. Thanks


#4

@ Architect - I definitely need to get a Bluetooth module…

@ Gus - Thank you. As I am exploring the module, I am finding a few driver issues. How would you like me to report them? I have used reflector to get the driver code and I tweaking it to overcome any issues I find and I would like to share those back somehow.


#5

I’ve been tinkering with the RV-XV module on a Fez Cerbuino Bee board. I didn’t even notice GHI had a driver for this RN171 based module until now! I was using the NETMF TOOLBOX driver located here: http://netmftoolbox.codeplex.com/wikipage?title=Toolbox.NETMF.Hardware.WiFlyGSX&referringTitle=Toolbox.NETMF.NET.WiFlySocket

It had the same baud rate issue but I’m able to tell the driver what it should be fortunately. I’ve had an issue with sending an email using the toolbox drivers. Does the GHI driver allow for email sending frickin easily?

I’ve had issues with getting the GHI Bluetooth module to go into server mode so got a Roving Networks xbee form factor module. It is much easier to get into server mode. They offer different antenna connection type also so you can have an external to enclosure antenna if needed which was another reason to goto that type of module.


#6

One other nice thing about the netmf toolbox is you can grab and add the files you want to use only and edit/tinker as needed on the fly in your own project.


#7

@ logictechs - Thanks, I did not even think to look a the NETMF toolbox project. I will definitely go check that out.


#8

Unfortunately we do not support SMTP, but it is nearly identical to the HTML protocol, so a few changes to the source would allow this easily.


#9

Thank you for offering your help, you can report the issues directly to me (james.dudeck at ghielectronics dot com). Also, the source is available on Gadgeteer Codeplex. Thirdly, the baudrate should only be defaulted to 9600 so that it would be compatible with the XBee holder RN-171 combination, so a developer page would be the perfect thing to ease this issue, as you said.


#10

FYI there is a decent driver for the WiFly module at http://netmftoolbox.codeplex.com/wikipage?title=Toolbox.NETMF.Hardware.WiFlyGSX&referringTitle=Available%20classes

To get around the 1 socket limitation I modified the driver so I can send and receive UDP through my home router… so if anyone is interested in that I could tell you how I added that… but it’s a real hack job.


#11

I uploaded a patch codeplex: https://www.codeplex.com/Download?ProjectName=gadgeteer&DownloadId=704539

Which fixes:

  • WiFi_RN171_42.cs
    Driver was not working because of wrong baudrate. The device works with baudrate 115200, driver used 9600
  • HttpResponse.cs
    StatusCode was always OK, no matter what value was provided.
    Body was not send to client, because it was send in two Send instructions.
    Added convenience method for sending string body text instead of byte[]
  • HttpHeaderList.cs
    Added space to header mark-up

I also have an example project (but that needs the patch as well) It uses both http and http ajax requests. See: http://www.fsays.eu/downloads/WifiRN171_Example.zip


#12

Default baud rate issue has been resolved and will make it into the next SDK along with a method to change the baudrate at runtime. We will review your other proposed changes for applicability.

As for the split sends, what browser were you using that you encountered an issue with the header being sent separately than the body? The split sends were tested with every major browser, in current and 1 previous versions.


#13

The problem occurred in IE10, Google Chrome and also in Fiddler2 (all running on Windows 8 ) I used the example code of the RN171 module. When I send data to the client without combining header and body as one send action I could see in Fiddler that only header data was send and no body data. In Chrome and IE the browser keeps waiting until a timeout occurs. When I send both header and body in one action, everything works like a charm. I’ll undo my changes and will let you if I can/can’t reproduce the problem stated above.


#14

What header options did you use, and what hardware was used when this problem occurred? The HTTP Protocol should allow for an infinite number of sends (since the packets are split by TCP anyway) until the byte count has been satisfied.

The only reason I am asking this, is sending it in a singular transaction, in the method you proposed, could create memory issues very quickly. If you had, say a 45kb markup file, that you sent to that Send method, you would have consumed nearly 100kb, 140 if you held the markup in an object and converted to bytes from the original string object, plus the overhead to the Serial line.


#15

@ James
I found the cause of the problem. When I undid my changes and used the library as is (except for the baudrate) and the example code as provided at https://www.ghielectronics.com/catalog/product/444 I could reproduce the problem. (see also attached image)

So I started to adjust the code step-by-step back to my version. Then all of a sudden I thought maybe it’s the missing header information about the content length. So I did another go and bingo, that solved the issue with the multiple Sends.

So either the library should be changed into:

public void Send(byte[] document)
{
[em]HeaderData[“Content-Length”] = document.Length.ToString();[/em]
byte[] header = System.Text.Encoding.UTF8.GetBytes(this.HeaderData.ToString());

        _stream.Write(header, 0, header.Length);

        _stream.Write(document, 0, document.Length);

}

or the customer’s application code must add the content length information.


#16

@ James Is the below the source being discussed?
.NET Gadgeteer Core 2.43.800
http://gadgeteer.codeplex.com/SourceControl/latest#Main/Modules/GHIElectronics/WiFi RN171/Software/WiFi RN171/WiFi_RN171_42/WiFi_RN171_42.cs


        /// <summary>
        /// Send data to the currently connected client
        /// </summary>
        /// <param name="data">Data</param>
        public void Send(byte[] data)
        {

            if (data.Length <= _wifly.BaudRate)
            {
                //Write-out directly
                _wifly.Write(data, 0, data.Length);
            }
            else
            {
                int baud_rate = _wifly.BaudRate;
                int iterations = data.Length / baud_rate;
                int exceeding = data.Length % baud_rate;
                int segment_start = 0;

                for (int i = 0; i < iterations; i++)
                {
                    //Calculate segment range
                    segment_start = i * baud_rate;

                    //Write the current segment
                    _wifly.Write(data, segment_start, baud_rate);

                    //Write the remaining segment
                    if (i == (iterations - 1) && exceeding > 0)
                    {
                        _wifly.Write(data, segment_start, exceeding);
                    }
                }
            }

            return;
        }

        /// <summary>
        /// Send data to the currently connected client
        /// </summary>
        /// <param name="data">Data</param>
        public void Send(ref string data)
        {
            //Convert string to byte array
            byte[] _data = System.Text.Encoding.UTF8.GetBytes(data);
            data = "";

            if (_data.Length <= _wifly.BaudRate)
            {
                //Write-out
                _wifly.Write(_data, 0, _data.Length);
            }
            else
            {
                int baud_rate = _wifly.BaudRate;
                int iterations = data.Length / baud_rate;
                int exceeding = data.Length % baud_rate;
                int segment_start = 0;

                for (int i = 0; i < iterations; i++)
                {
                    //Calculate segment range
                    segment_start = i * baud_rate;

                    //Write the current segment
                    _wifly.Write(_data, segment_start, baud_rate);

                    //Write the remaining segment
                    if (i == (iterations - 1) && exceeding > 0)
                    {
                        _wifly.Write(_data, segment_start, exceeding);
                    }
                }
            }

            return;
        }

Is the above and the baud rate adjustment included in “Install the latest NETMF and Gadgeteer Package 2013 R2 (NEW)” ?
Is NETMF and Gadgeteer Package 2013 R2 and .NET Gadgeteer Core 2.43.800 not the same thing or different?
If I wish to compile a debug version of .NET Gadgeteer Core 2.43.800 so that I may step through the code while running the example, where do I start and could someone guide me through the process please?
How do I send Roving Networks (RN171) commands to my Cobra II + RN171 module using Tera Term Pro?
Your help would be much appreciated.
Kevin


#17

Here is my attempt to modify the example on theRN171 module developers page:


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerControllerA
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {

            Debug.Print("Program Started");
            wifi_RN171.Initialize(GTM.GHIElectronics.WiFi_RN171.SocketProtocol.TCP_Server); //Init as TCP Server
            wifi_RN171.EnableHttpServer(); //Enable HTTP Parsing
            wifi_RN171.HttpRequestReceived += new GTM.GHIElectronics.WiFi_RN171.HttpRequestReceivedHandler(wifi_RN171_HttpRequestReceived);

        }
        void wifi_RN171_HttpRequestReceived(GTM.GHIElectronics.HttpStream request)
        {
            string requestedURL = request.Request.URL;

            if (requestedURL == "/index.html")
            {
                //HeaderData["Content-Length"] = document.Length.ToString();
                string document = "<html><head></head><body>HELLO! KG1 KG1 KG1 KG1 KG1 KG1 KG1 KG1 KG1</body></html>";
                request.Response.HeaderData["Content-type"] = "text/html";
                request.Response.HeaderData["Content-Length"] = document.Length.ToString();
                request.Response.HeaderData["Connection"] = "close";
                request.Response.HeaderData["Cache-Control"] = "no-cache";
                request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK;

                //All you have to do is send the document data through the response object.
                //Header data is automatically applied for you when you chose to send.
                request.Response.Send(System.Text.Encoding.UTF8.GetBytes(document));
            }
        }
    }
}

On my tablet I can not get a web page on 192.168.1.1:80. However I have improved my telnet skills on my tablet: see the attached photos.
I ran the above (modified) code and the RN171 LEDs are: Red flashing and Green flashing (Red flashing twice as fast as Green). When I connect my tablet to the GHI Hotspot the Red LED switches off and the Green continues to flash.
Has the WiFi initialised correctly? Should I be able to see the web page on my tablet browser?


#18

I have now found a document about modifying “drivers” which is about modifying Modules: https://www.ghielectronics.com/docs/122/gadgeteer-driver-modification. Please look above to answer my other questions.