Go Down

Topic: New to Arduino and WiFly (Read 911 times) previous topic - next topic

bresslerz

I am trying to run a simple sketch through an Arduino Pro Mini connected to the WiFly using the WiFlySerial library.  I am VERY new to this and I'm using some code I have pulled from other sketches.  I have included my .ino file...

All I want to do is call a local server (192.168.1.23) and pull some data from the response.

This is the serial monitor of it when I upload and run it...

Code: [Select]
Starting Light Manager.
Free memory:915
Setting up WiFly
Starting WiFly...WiFlySerial v1.08 Free memory:901
MAC: 00:06:66:52:68:97
IP: 192.168.1.16:2000
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DNS: 192.168.1.1
WiFly Sensors: 1
WiFly Temp: 1After Setup mem:901
Now RUNNING
Debug options:
Press '1' to send a test tweet
Press '2' to print current readings
Press '[' to access WiFly terminal to send commands to WiFly module

Beginning of Loop RAM:915
GET request:GET /api/newdeveloper/lights/3 HTTP/1.1
Host: 192.168.1.23
Connection: close



RAM: 657
Get request sent
Closing connection.


I was expecting to see the following response (which is what I get when I put 192.168.1.23/api/newdeveloper/lights/3 in a browser):

Code: [Select]
{"state": {"on":false,"bri":0,"hue":0,"sat":0,"xy":[0.0000,0.0000],"ct":0,"alert":"none","effect":"none","colormode":"hs","reachable":true}, "type": "Extended color light", "name": "Living room", "modelid": "LCT001", "swversion": "65003148", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }}

Can anyone explain why this code:
Code: [Select]
while (  TimeOut > millis() && WiFly.isConnectionOpen() )
    {
      if (  WiFly.available() > 0 ) {
        Serial << (char) WiFly.read();
      }
    }


is not returning the response that I am showing above?  It seems to be establishing a connection, but no response is being written to the serial monitor.  Any help would be appreciated!

pylon

Code: [Select]
  strRequest << F("GET ") << MY_SERVER_GET_URL
     << F(" HTTP/1.1") << "\n"
     << F("Host: ") << MY_SERVER_GET << "\n"
     << F("Connection: close") << "\n"
     << "\n\n";


Lines in networking code usually end in "\r\n" and not only "\n". It depends on the server you're requesting the page from if it answers your request without getting correct data.

bresslerz

Okay, I tried adding the \r, but it didn't seem to make any difference.  I still seem to get no response.

Code: [Select]
  strRequest << F("GET ") << MY_SERVER_GET_URL
     << F(" HTTP/1.1") << "\r\n"
     << F("Host: ") << MY_SERVER_GET << "\r\n"
     << F("Connection: close") << "\r\n"
     << "\r\n\r\n";


Any other suggestions?

bresslerz

I tried another thing...  I put a serial output displaying the WiFly.isConnectionOpen() and WiFly.available() variables in the following while loop:

Code: [Select]
while (  TimeOut > millis() && WiFly.isConnectionOpen() )
    {
      if (  WiFly.available() > 0 ) {
        Serial << (char) WiFly.read();
      }
    }


It seems that the connection remains open during the while loop, but the available is 0, which would explain why no response data is being sent to the serial monitor.  What does that mean?  What does WiFly.available() check?

pylon

Quote
What does that mean?  What does WiFly.available() check?


It checks how many bytes already arrived in the buffer. A value of 0 usually means that the server didn't respond.

Are you able to sniff the network traffic on your server with a tool like WireShark (http://www.wireshark.org)? If so, check what's actually being sent and compare to your expectations.

kasperkamperman.com

Just a suggestion. I found that the WiFly manual provided a good detail. I've shared a WiFly communicator library (actually a fork from the Seeed WiFishield library).With that library you can use the native commands from the WiFly.

More info: http://www.kasperkamperman.com/blog/arduino-leonardo-or-helios-wifly-library/
https://github.com/kasperkamperman/WiFly_communicator

The Wifly can be buggy sometimes with data and opening and closing connections.

bresslerz

How can I test what the server is or isn't responding given what the WiFly is sending?  Is the get request string the data being sent to the server?

Will Wireshark enable me to see how the server responds?

bresslerz

It seems that Wireshark has to be installed on the server.  Is that right?

That will be impossible since the "server" I am connecting to is actually the Phillips Hue bridge and not an actual server.  It provides a simple API as you can see at this link...

http://developers.meethue.com/gettingstarted.html


pylon

WireShark has to be installed on a computer that gets the full network traffic. This might be any computer on a mirroring port of a switch or if everything is connected to a hub it works too.

Have you tried to use the telnet command to send the same data to the server?

telnet 192.168.1.23 80

Then send the data ("\r\n" is just hitting the return key). What do you get? Please post it.

bresslerz

I haven't tried that yet.  I will give that a try later today.  Thanks

bresslerz

I tried to telnet to the bridge (192.168.1.23) and I get "Connection closed by foreign host."

Is there any other way that I can send the data to the bridge manually?

pylon

Did you try the command I posted or did you type your own command? My command connects to port 80, did yours too?

If you used my command and got this error message you probably also cannot connect with a browser from that computer.

Go Up