Web Server - client unable to connect

All information, news and questions about the Pine64 IoT-stamp can be found and discussed here
RavenHawk
Posts: 4
Joined: Fri Feb 10, 2017 8:43 am

Web Server - client unable to connect

Postby RavenHawk » Fri Feb 24, 2017 11:07 am

Hi,

I have uploaded a modified SimpleWebServerWiFi sketch from Ameba RTL8170 examples using the official Realtek and pvvx's enviroments, and using LEDs to troubleshoot (I don't have an SPI/I2C LCD or a Serial-to-USB) I found that I am unable to connect to the module because server.available() never turns true. When my module connects to my Samsung Note 4's hotspot, I see its IP (192.168.43.123) and fail to connect to it via a browser (on the phone or with a Windows laptop). Android port scanning apps indicate that the target IP address of the module has no open ports. Code below.

Update1: If I try to access the IP right after the 1st LED, the 2nd and 3rd LEDs light up, but if I try to access the IP a while after, it takes longer to turn on the 2nd and 3rd LEDs. I still don't receive any response from the module in browser.

Code: Select all

/*=================================================================\
|  Build using pvvx's enviroment: https://github.com/pvvx/RtlDuino |
|  Tutorial: https://hackaday.io/project/19163/logs                |
\=================================================================*/

#include <WiFi.h>

const int LED_1 = 0; // GA0
const int LED_2 = 1; // GA1
const int LED_3 = 3; // GA3

char ssid[] = "WiFi_SSIDt";      //  your network SSID (name)
char pass[] = "password";   // your network password
int keyIndex = 0;   // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
WiFiServer server(80);

void setup() {
  pinMode(LED_1, OUTPUT);
  pinMode(LED_2, OUTPUT);
  pinMode(LED_3, OUTPUT);

  // Ensure all LEDs work
  digitalWrite(LED_1, HIGH);
  digitalWrite(LED_2, HIGH);
  digitalWrite(LED_3, HIGH);
  delay(250);
  digitalWrite(LED_1, LOW);
  digitalWrite(LED_2, LOW);
  digitalWrite(LED_3, LOW);
 
  //Serial.begin(38400);      // initialize serial communication
  pinMode(LED_BUILTIN, OUTPUT);      // set the LED pin mode
  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    //Serial.println("WiFi shield not present");
    while (true); // don't continue   
  }
  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    //Serial.println("Please upgrade the firmware");
  }
 
  // 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 0.2 seconds for connection:
    delay(200);
  }
  server.begin();                   // start the web server on port 80
  printWifiStatus();                // you're connected now, so print out the status
}


void loop() {
  digitalWrite(LED_1, HIGH);
 
  WiFiClient client = server.available();   // listen for incoming clients
 
  digitalWrite(LED_2, HIGH);
 
  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,
       
        digitalWrite(LED_3, HIGH);
       
        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(LED_BUILTIN, HIGH);               // GET /H turns the LED on
        }
        if (currentLine.endsWith("GET /L")) {
          digitalWrite(LED_BUILTIN, LOW);                // GET /L turns the LED off
        }
      }
    }
    // close the connection:
    client.stop();
    //Serial.println("client disonnected");
  }
}

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

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

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  //Serial.print("signal strength (RSSI):");
  //Serial.print(rssi);
  //Serial.println(" dBm");
  // print where to go in a browser:
  //Serial.print("To see this page in action, open a browser to http://");
  //Serial.println(ip);
}


Any help is appreciated. Thank you!

Return to “Pine64 - PADI IoT Stamp”

Who is online

Users browsing this forum: No registered users and 1 guest