Using Wifly with Phone App

Hi,

I will be very grateful if anyone could assist with the problems I’m having with my project setup.

With this project, I am connecting a phone (using a hotspot) to a Wifly and Arduino with the Wifly library (https://github.com/bobbrez/WiFly). I can successfully connect the Wifly with the phone. Running on the phone is an app created using NS Basic App Studio. This is a permanent app on my phone.

Within my app program, I have below. This first line sends the text to the Wifly along with the rest of the connection data. The second line and below is to confirm to the app that the text was successfully received. The app has a URL.

BASIC code (App)

req = Ajax("http://192.168.43.56/text_to_send")
If req.status = 200 Then 'wifi successful
       MsgBox("", 0, "Wifi ok")
Else 'wifi failed
       MsgBox("", 0, req.status & " Wifi fail")
End If

Arduino code (Wifly)

////////////////////////////Wifly/////////////////////
#include "WiFly.h"
#include "Credentials.h"
#include "SPI.h"

#define maxLength 255
String receivedText = String(maxLength);
int what =0;

WiFlyServer server(80);

#include <Wire.h>

///////////////////////////////////////////////////////////////////
void setup() 
{
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  Serial1.begin(9600);
  
  //////////////////////////  Wifly   ///////////////////////////////

  server.begin();
  Serial2.begin(9600);
  
  Serial.println("Searching for device...");
  
  WiFly.setUart(&Serial2);
  //WiFly.begin();
  WiFly.begin();

  if (!WiFly.join(ssid, passphrase)) {
    Serial.println("Failed to find device");
    while (1)
    {
      // Hang on failure.
    }
  }

  Serial.println("Successfully connected to device");
  Serial.print("IP: ");
  Serial.println(WiFly.ip());
}

void loop() 
{

 /////////////////////////////    Wifly   //////////////////////////////// 

 WiFlyClient client = server.available();
  if (client) 
  {
      // an http request ends with a blank line
      boolean current_line_is_blank = true;
      while (client.connected()) 
      {
          if (client.available()) 
          {
                char c = client.read();
                
                Serial.print(c);
            
                //////////////////////////
                if (receivedText.length() < maxLength)
                {
                  receivedText += c;
                }
                //////////////////////////
                // If first request upon connexion, the 3 first characters will be "GET"
                // If "GET" is caught, skip the request info
                       
                // Otherwise, if the request contains data,
                // the first characters will be "POST"
                // We then skip the request header and this "if" becomes our main function
                if( receivedText.equals("POST"))
                {
                  Serial.println("");
         
                  // Read the data package length
                  receivedText="";
                }
                /////////////////////////
                
                                                    
                // if we've gotten to the end of the line (received a newline
                // character) and the line is blank, the http request has ended,
                // so we can send a reply
                if (c == '\n' && current_line_is_blank) 
                {                                                
                        //delay(2000);
                        // send a standard http response header
                        client.println("HTTP/1.1 200 OK");


                        DO SOMETHING HERE??

                          
                        break;
                }
                
                if (c == '\n') 
                {
                      // we're starting a new line
                     current_line_is_blank = true;
                } 
                else if (c != '\r') {
                     // we've gotten a character on the current line
                      current_line_is_blank = false;
                }
          }
      }
      // give the web browser time to receive the data    
      delay(500);
   
      client.stop();
    }
 } //end loop(

The problem I am having relates to the status of the communication. The data is successfully sent to the Wifly but I’m unable to send the correct response from the Arduino code to the app to confirm a successful data transfer. What code from the Arduino should be sent so the status of 200 is received in my app if transfer is successful?

I would greatly appreciate any help here.