Go Down

Topic: Arduino WiFi server / client (Read 1 time) previous topic - next topic


This section seems to be a better place for my problem..

I want to be able to access the arduino from ip/get_variables
and based on those variables to send a response to another page.

So it must be a client and a server.

Here's my code.
The problem seems to be the sendGET function, because the program halts (it won't respond when i access it from the browser) after it executes.

Code: [Select]

#include <SPI.h>
#include <WiFi.h>

char ssid[] = "PinkLink";      //  your network SSID (name)
char pass[] = "unu1doi2trei3";   // your network password

int status = WL_IDLE_STATUS;
WiFiServer server(80);
WiFiClient client;

char serverName[] = "puiucristian.com";

void setup() {
  Serial.begin(115200);      // initialize serial communication

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while(true);        // don't continue

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to Network named: ");
    Serial.println(ssid);                   // print the network name (SSID);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:   
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
  server.begin();                           // start the web server on port 80
  //printWifiStatus();                        // you're connected now, so print out the status

int x = 0; // if it's 1, it will trigger the sendget function
void loop() {
  x = 0; // is 1 only if there's a get variable named .....
  client = server.available();   // listen for incoming clients
  if (client) {                             // if you get a client,
    Serial.println("new client");           // print a message out the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) { 
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:   
            client.println("HTTP/1.1 200 OK");

            // The HTTP response ends with another blank line:
            // break out of the while loop:
          else {      // if you got a newline, then clear currentLine:
            currentLine = "";
        else if (c != '\r') {    // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine

        // Check to see if the client request was "GET /H" or "GET /L":
        if (currentLine.endsWith("GET /doSomething")) {
          x = 1;
    // close the connection:
    Serial.println("client disonnected");
  //check if x is 1
  if (x == 1) sendGET();

void sendGET() {
  if (client.connect(serverName, 80)) {
    client.println("GET /bu.php HTTP/1.0");
  else {
    Serial.println("connection failed");

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read();


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");

Go Up