need help with simple wifly webserver interface

I have bought the Wifly from sparkfun, I have gotten the example to work that sparkfun included, Minus the speaker example as i do not have the components.

Next I found this link and am now using the library that he included:

from here what I am wanting to do, is use the wifly to control a set of LED’s that are running different lighting patters, fades, etc. I would like a button for each pattern I have written. So I found this example using the ethernet shield, which at the moment i do not have. I have copied the majority of the code out of the example so that when i enter the address of the wifly in my browser, it looks identical to the example. I am using the example code from the first link and replacing the HTML code with the code from here:
Now when I click the button a ? mark is added to the link address in the browser. I know that it is basically waiting for an update from the wifly but since i did not include the code from that section, nothing happens, it just sits there and eventually times out. I have included the sketch of where i am at right now. I have tried using the rest of the code but it keeps telling me I am missing different parts or this function is undeclared etc. I have wired an LED to output pin 4 and just want it so that when i click the button, it turns the LED on, and refreshes the page with the status. If I could get this to work I should be able to figure everything else out on my own and adjust the code so it does what I desire it to do. But I am a newb and cant figure out how to adjust the ethernet shield string code to the wifly example sketch to get this to work.

Any help is greatly appreciatted,

wiflydemo.pde (4 KB)

Hi Lapoza,

Okay a couple of things I have noticed but it may or may not help as I can't run your code up to try it from where I am:

  1. You haven't defined your MAC or IP address or anything anywhere? Does the WiFly do this automatically? Am assuming it probably does but you might want to check.

  2. move your boolean LEDON = false; instruction to the top of your code - you're calling that every time you call listenforclients() so all you'll do is keep switching your LED status to off.

  3. You're also missing this code snippet just after your detection:

//lets check if LED should be lighted if(readString.contains("L=1")) { //led has to be turned ON digitalWrite(ledPin, HIGH); // set the LED on LEDON = true; }else{ //led has to be turned OFF digitalWrite(ledPin, LOW); // set the LED OFF LEDON = false; }

  1. Your client.Stop() is being called outside of the conditional where you are creating it, thus you are always stopping the client every time your loop runs and you call your listener function.

  2. Finally you are using if (c == '\n' && currentLineIsBlank) { here currentLineIsBlank is always true because you declare and set it a few lines above. It's probably not relevant for what you're doing anyway just remove it for the moment.

Check the project download for the ScienceProg link you provided above - it's much cleaner than their page. Use that as your base as it's that set up you're looking at and then customise your set up according to the wifly method.

Some other suggestions - use firefox (firebug) or Chrome browsers put it into developer mode and you can watch the headers you are sending and receiving to the Arduino / WiFly. If you print out everything you're receiving to Serial Out on the Arduino side you can see what is occurring on both sides of the request and responses.

Cheers ajfisher

Hello AJ,
Wow is all I can say for the response. Thanks so much. Luckily, after spending major amounts of time on google, and going through example after example, I was able to get this going. So let me explain where I am now.

First off, the Wifly gets Ip assigned through DCHP, so that was not an issue.

I have built a table With all the pushbuttons that I need, when I click each one it changes the address at top, and using serial, I can see that it outputs to the arduino the correct code, by correct code I mean the code I need to change my patterns. I have compiled 3 of the patterns, and I know how to do the rest of what I am wanting to do as far as controlling the LED’s.

Here is my only problem I have left to solve. At the moment, I am using a table with multiple cells to control these. I needed buttons to get the example code I was given to work, In order to be able to have all the buttons I need, I used a table, otherwise it put them one on top of the other and I couldnt put any side by side. I have about 30 buttons or so, so a web page with 30 buttons on top of each other would load fast, but i would have to scroll up and down to see them all. This would not be beneficial for the operator, It is better to have them all in one page of less that 800 x 600 resolution. So I had to use the table.

The problem with this is it takes forever to load. And when the wifly is sending all this data to the browser, it puts the current pattern on hold so to speak. I guess since I am calling the void listenForClients() { function in my loop, it pauses the loop while it performs all the steps in the void listenForClients(). It is taking 8 seconds on average to reload the page, which is how long my LED’s are in pause mode.

when the void listenForClients() loop returns data to start the LED patterns, it works perfectly. they start whatever pattern I have called them to do, ie strobing, color changing. And this continues indefinitly. But when I click a new button in the browser, it pauses the LED’s at their current state, refreshes and reloads the entire browser, then updates the current pattern bit and restarts the LED’s. My issues is I need this to be an instant process. I need it to update the LED’s instantly, and then refresh the web browser in the background after it has changed the pattern. All the while never stopping the LED’s

So I have thought of several solutions, one being using two arduinos as a master/slave configuration, one running the wifly and the second receiving the inputs through serial and updating the LED’s instantly, there would still be the 8 second delay before a change happened, but to the people watching the LED’s they would not notice a delay.

But I am thinking that basically it is a coding issue that can be resolved in the software by restructuring, or using different functions. But I am by no means even a moderate user, kinda teaching myself as I go. I have included the current project of where I am right now, I have deleted a bunch of irrelevant crap and code, like all the html code, as it isnt needed here to shorten it up and make it less confusing.

Once again thanks for having a look and trying to help me out!!!

combined_for_wifly8.pde (12.2 KB)