Understanding the Wifi module

Expansion modules and attachments
Post Reply
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Understanding the Wifi module

Post by thekameleon »

So I am trying to figure out how the wifi module works. I just setup a new Reef Angel at work and I am looking to figure out, how I can read the response after a SendPortal is sent I see the two \n\n. Does that instruct the wifi module to send the data? I am not 100% clear on how that works. I think by reading the response if it times out, I can send a reset command to the wifi module to force it to reboot. this should keep it humming along for as long as possible.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Understanding the Wifi module

Post by rimai »

It is a UART to TCP converter.
Whatever comes into the UART side is transmitted to the TCP side and whatever comes in from the TCP side is transmitted to the UART side.
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Understanding the Wifi module

Post by thekameleon »

So looking at the wifi code that is there... I am not sure how I would get the response back of a http request made from the reef angel.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Understanding the Wifi module

Post by rimai »

What kind of response?
You want to initiate a request and parse the response within RA?
If so, you can't.
For one, the wifi attachment only works in a single host (right now it is www.reefangel.com), which means it can only initiate requests to that particular host.
Then, even if you change that to another 3rd party server, we don't have any parser implemented within our libraries.
If you would like to try creating a parser, we would really appreciate it :)
Just keep in mind that we have very limited memory.
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Understanding the Wifi module

Post by thekameleon »

A simple JSON parser should not take up much memory... I can't even figure out how to just read the entire body of a response, once I get there. i can figure out how to parse it. But speaking of memory. How does one know how much memory they are consuming?
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Understanding the Wifi module

Post by rimai »

It has to be done inside the libraries right now.
But if you want to test it without the libraries, use a simple sketch and send serial data to the wifi attachment.
If you send for example "GET / " to the serial port, you will get the HTML response from www.reefangel.com home page.
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Understanding the Wifi module

Post by thekameleon »

OK another question. How many requests can the module take in a minute. It seems if I tried polling any more frequently than once per say 15 seconds, the controller/wifi stopped responding.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Understanding the Wifi module

Post by rimai »

You can do multiple requests per minute. The problem you will face will be the internet latency.
The module can only handle one request at a time. So, if you send a request and it takes 5 seconds to go through the internet and reach the wifi and you send a second request in less than 5 seconds and it hits the wifi while it's processing the 1st one, the second one will time out.
But, maybe you have more knowledge on the server side to maintain the socket open, so you don't have to keep polling. If you can maintain the socket open on the server side and can create some sort of relay service, we can forget about port forwarding and have a dedicated channel of communication with the controller.
We would need to come up with some sort of API key for security.
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Understanding the Wifi module

Post by thekameleon »

Agreed... But I think I need your help on getting the Wifi module to like sockets. :)
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Understanding the Wifi module

Post by rimai »

Looking at the manual, I think we can set the protocol to tcp client only and use idle timer 0.
This should create a permanent link with your server.
The problem is that when you make this change, no other apps will be able to communicate with the attachment, since it can only handle one connection and it will be connected to your server.
So, we will need some sort of API to make remote calls that would in turn be routed to the controller through the established socket.
Does it make sense?
The commands would be:

Code: Select all

set i p 8
set c i 0
If you want to put it back to what we are using, we use:

Code: Select all

set i p 1
set c i 3
Just keep in mind that the wifi attachment will be changed to client only, which means it will not accept any incoming connection. It will only establish a connection with an external server.
The connection will be established as soon as the first character is received through the serial port.
Roberto.
rimai
Posts: 12857
Joined: Fri Mar 18, 2011 6:47 pm

Re: Understanding the Wifi module

Post by rimai »

So, I went ahead today and played around with the idea.
I used yaler.net service and was able to make a connection and maintain it open.
Then I used my browser to go to http://gsiot-feme-rgaq.try.yaler.net/, which is the web address that I setup for my RA.
I got nothing at first.
The libraries needed to be changed a bit to make it work, but at last, I was able to get it to answer back.
This proves that the idea works :)
I was able to browse to a website and connect to my RA with no port forwarding and no firewall issues :)
Roberto.
thekameleon
Posts: 137
Joined: Sat Feb 16, 2013 7:44 am

Re: Understanding the Wifi module

Post by thekameleon »

This is huge... Especially for commercial applications, where firewalls are more prevalent.
Post Reply