RTL8170 is a new module, which is in many ways better than the old ESP8266 module. We are able to flash this module with Arduino using an Ameba Writer, and it should be able to support any code that is supported by the ESP (with some adjustments). It has been officially supported by Realtek's environment but it does not use all the GPIO (only 2). Luckily, pvvx developed an environment for Arduino IDE, which we can install and use through this tutorial: https://hackaday.io/project/19163/logs
I have uploaded a modified SimpleWebServerWiFi sketch from Ameba RTL8170 examples by both trying the official Realtek and pvvx's environments, and using LEDs to troubleshoot (I don't have an SPI/I2C LCD or a Serial-to-USB) I found the module being able to connect to my Samsung's hotspot but unable to communicate with 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.
Update2: I've made adjustments to the code according to suggestions, but it still didn't respond. Updated code below:
/*-----------------------------------------------------------------|
| Build using pvvx's enviroment: https://github.com/pvvx/RtlDuino |
| Tutorial: https://hackaday.io/project/19163/logs |
|=================================================================*/
#include <WiFi.h>
char ssid[] = "WiFi_SSID"; // your network SSID (name)
char pass[] = "password"; // your network password
int keyIndex = 0; // your network key Index number (needed only for WEP)
String currentLine = ""; // make a String to hold incoming data from the client
int status = WL_IDLE_STATUS;
WiFiServer server(80);
void setup() {
pinMode(1,OUTPUT);
//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
}
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
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-Length: 88");
client.println("Content-Type: text/html");
client.println("Connection: Closed");
client.println();
// the content of the HTTP response follows the header:
client.print("Click <a href=\"/H\">here</a> turn the BUILTIN_LED on<br>");
client.print("Click <a href=\"/L\">here</a> turn the BUILTIN_LED 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:
//digitalWrite(1,HIGH); // Doesn't turn ON
currentLine = "";
}
} else if (c != '\r') { // if you got anything else but a carriage return character,
//digitalWrite(1,HIGH); // Turns ON
currentLine += c; // add it to the end of the currentLine
}
//digitalWrite(1,HIGH); // Turns ON
// 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
}
}
}
//digitalWrite(1,HIGH); // Turns ON
// close the connection:
client.stop();
}
}
Update 1:
I am still unable to fix the code. If no one can fix this code, please feel free to provide a totally new code.
P.S.: If this question keeps stagnating, I'll remove it and recreate it.
Any help is appreciated. Thank you!