Quantcast
Channel: Intel Communities: Message List
Viewing all articles
Browse latest Browse all 17969

Re: Problem running simplewifi example sketch

$
0
0

With all respect, I find the answer "ignore the software we ship with the system and try some diametrically different approach" unsatisfying.  If the WiFi example doesn't work, we shouldn't ship it.  If it ships, it should work.

 

The example actually does almost works.  It mostly just has a lot of irrelevant fluff that should be taken out.  Also, by default my Edison is hosting a settings page on port 80, so you either need to kill that daemon or use a different port.  I've modified the example to work by doing three things:

 

1) Changed the port from 80 to 83.

2) Changed the LED from 9 to 13 (the built-in one for Edison).

3) removed much extraneous code

 

/*

  WiFi Web Server LED Blink

 

A simple web server that lets you blink an LED via the web.

 

If the IP address of your shield is yourAddress:

http://yourAddress:83/H turns the LED on

http://yourAddress:83/L turns it off

 

Circuit:

* Edison

* LED attached to pin 13

 

created 25 Nov 2012

by Tom Igoe

mods by Mikal Hart 11/13/2014

*/

#include <SPI.h>

#include <WiFi.h>

 

int status = WL_IDLE_STATUS;

WiFiServer server(83);

 

void setup() {

  Serial.begin(9600);      // initialize serial communication

  pinMode(13, OUTPUT);      // set the LED pin mode

 

  server.begin();                           // start the web server on port 80

}

 

void loop() {

  WiFiClient 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");

            client.println("Content-type:text/html");

            client.println();

 

            // the content of the HTTP response follows the header:

            client.print("Click <a href=\"/H\">here</a> turn the LED on pin 13 on<br>");

            client.print("Click <a href=\"/L\">here</a> turn the LED on pin 13 off<br>");

 

            // The HTTP response ends with another blank line:

            client.println();

            // break out of the while loop:

            break;        

          }

          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 /H")) {

          digitalWrite(13, HIGH);               // GET /H turns the LED on

        }

        if (currentLine.endsWith("GET /L")) {

          digitalWrite(13, LOW);                // GET /L turns the LED off

        }

      }

    }

    // close the connection:

    client.stop();

    Serial.println("client disonnected");

  }

}


Viewing all articles
Browse latest Browse all 17969

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>