Paso 4: código
Utilice el IDE de arduino para subir el código a la Junta, debe modificar el IDE para que sea apoyo a la Junta un Linkit. También Introduzca el ssid de la red y la contraseña.
<p>/*<br> WiFi Web Server</p><p> Change the macro WIFI_AP, WIFI_PASSWORD and WIFI_AUTH to your own router settings.</p><p> */ #include #include #include #include </p><p>#define WIFI_AP "ssid" #define WIFI_PASSWORD "password" #define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP according to your WiFi AP configuration //I would try LWIFI_WPA first //if that fails LWIFI_WEP //if that fails LWIFI_OPEN (and find out why you are giving WiFi to the neighbours!)</p><p>int serverPort = 80; LWiFiServer server(serverPort); int LED = 13;</p><p>void setup() { pinMode(LED, OUTPUT); LWiFi.begin(); Serial.begin(115200); // keep retrying until connected to AP Serial.println("Connecting to AP"); while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD))) { digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(100); digitalWrite(LED, HIGH); delay(100); digitalWrite(LED, LOW); delay(600);</p><p> } digitalWrite(LED, HIGH); printWifiStatus(); Serial.println("Start Server"); server.begin(); Serial.println("Server Started"); digitalWrite(LED, LOW); }</p><p>int loopCount = 0;</p><p>void loop() { // put your main code here, to run repeatedly: String str = ""; String url = ""; int i; delay(500); loopCount++; LWiFiClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { // we basically ignores client request, but wait for HTTP request end char c = client.read(); Serial.print(c); if(c != '\n') str += c; if(c == '\n') { //Serial.println(str); if(str.startsWith("GET ")) { url = str.substring(4, str.lastIndexOf(" ")); Serial.print("URL:"); Serial.print(url); Serial.println(":"); } str = ""; }</p><p> if (c == '\n' && currentLineIsBlank) { Serial.println("send response"); // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed after completion of the response client.println(); if(url != String("favicon.ico")) { client.println(""); client.println(" \n \n </p><p>\n</p><p>"); IPAddress ip = LWiFi.localIP(); client.println(" </p>"); client.println(" Tell your device what to do!<br><br>Turn the LED on.<br>Turn the LED off.<br><br><p>"); //i = digitalRead(LED); url.toLowerCase(); if(url == String("/?q=on")) { digitalWrite(LED, HIGH); client.println("LED on<br>"); } else if(url == String("/?q=off")) { digitalWrite(LED, LOW); client.println("LED off<br>"); } else { client.println("Doing nothing<br>"); } client.println("</p><p>\n</p><p>"); client.println(); break; } } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(50);</p><p> // close the connection: Serial.println("close connection"); client.stop(); Serial.println("client disconnected"); } }</p><p>void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(LWiFi.SSID());</p><p> // print your WiFi shield's IP address: IPAddress ip = LWiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);</p><p> Serial.print("subnet mask: "); Serial.println(LWiFi.subnetMask());</p><p> Serial.print("gateway IP: "); Serial.println(LWiFi.gatewayIP());</p><p> // print the received signal strength: long rssi = LWiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); }</p>