What I'm trying to do is to save the SSID and the password in the EEPROM.
if there is no value in the SSID and password in the EEPROM it runs as a server where you can set your SSID and password (HTML). when i enter the SSID and Password and click submit it executes okay but the problem is it gives the utf-8 or ASCII (not sure) code of the characters.
Sample output is this
To see this page in action, connect to Tappluxe_Unit and open a browser to http://192.168.1.1
[WiFiEsp] Server started on port 80
Server started
[WiFiEsp] New client 0
Post data:
49
User: Action-WAPPassword: User: %2B1111%3A%3B1111Buffer:
[WiFiEsp] Disconnecting 0
there is a part that is "%2B"then1111
the %2B is supposedly a "+" but thats what i receive when i send a POST from HTML
below is my code
#include <WiFiEsp.h>
#include <EEPROM.h>
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(12, 13); // RX, TX
#endif
const char ssid[] = "Tappluxe_Unit"; // your network SSID (name)
const char pass[] = "12345678"; // your network password
String ussid = "";
String upass = "";
int status = WL_IDLE_STATUS; // the Wifi radio's status
int reqCount = 0; // number of requests received
byte buffer[100];
String data = "";
WiFiEspServer server(80);
void setup()
{
Serial.begin(9600); // initialize serial for debugging
Serial1.begin(9600); // initialize serial for ESP module
WiFi.init(&Serial1); // initialize ESP module
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while (true); // don't continue
}
// for (int i = 0 ; i < EEPROM.length() ; i++) {
// EEPROM.write(i, 0);
// }
Serial.println("Done write");
Serial.println("Startup");
Serial.println("Reading EEPROM ssid");
for (int i = 0; i < 32; ++i) {
if (EEPROM.read(i) != 0) {
ussid += char(EEPROM.read(i));
}
}
Serial.print("SSID: ");
Serial.println(ussid);
Serial.println(ussid.length());
Serial.println("Reading EEPROM pass");
for (int i = 32; i < 96; ++i) {
if (EEPROM.read(i) != 0) {
upass += char(EEPROM.read(i));
}
}
Serial.print("PASS: ");
Serial.println(upass);
Serial.println(upass.length());
if ( ussid.length() > 1 ) {
WiFi.begin(ussid.c_str(), upass.c_str());
//if ( testWifi() == 20 ) {
//launchWeb(0);
//return;
//}
} else {
Serial.print("Attempting to start AP ");
Serial.println(ssid);
IPAddress localIp(192, 168, 1, 1); // uncomment these two lines if you want to set the IP address of the AP
WiFi.configAP(localIp);
status = WiFi.beginAP(ssid, 10, pass, ENC_TYPE_WPA2_PSK);// start access point
Serial.println("Access point started");
printWifiStatus();
// start the web server on port 80
server.begin();
Serial.println("Server started");
while (ussid = "") {
WiFiEspClient client = server.available(); // listen for incoming clients
if (client) {
int ctr = 0;
buffer[100] = "";
//Serial.println("Client connected");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
while (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// Here is where the POST data is.
Serial.println("Post data: ");
while (client.available())
{
buffer[ctr] = client.read();
data =+ char(buffer[ctr]);
ctr++;
}
Serial.println(data);
int datactr = 0;
int andctr = 0;
int userctr = 0;
int passctr = 32;
for (int x = 0; x < ctr; x++) {
if (buffer[x] == '=') {
datactr++;
x++;
Serial.print("User: ");
}
if (buffer[x] == '&') {
andctr++;
x++;
Serial.print("Password: ");
}
if (datactr == 1 && andctr == 0) {
// EEPROM.write(userctr, buffer[x] );
Serial.write(buffer[x]);
userctr++;
}
if (datactr == 2 && andctr == 1) {
// EEPROM.write(passctr, buffer[x]);
Serial.write(buffer[x]);
passctr++;
}
}
for (int i = 0; i < 32; ++i) {
if (EEPROM.read(i) != 0) {
ussid += char(EEPROM.read(i));
}
}
Serial.print("Buffer: ");
//Serial.write(buffer);
Serial.println();
//Serial.println("Sending response");
// send a standard http response header
client.println("HTTP/1.0 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: keep-alive");
client.println();
//form added to send data from browser and view received data in serial monitor
client.println();
client.println("<!DOCTYPE html>");
client.println("<html lang=\"en\">");
client.println("<body>");
client.println(" <FORM action=\"\" method=\"POST\">");
client.println(" <P>");
client.println(" <LABEL for=\"username\">SSID:</LABEL>");
client.println(" <INPUT type=\"text\" name=\"uname\"><BR><BR>");
client.println(" <LABEL for=\"password\">Password:</LABEL>");
client.println(" <INPUT type=\"password\" name=\"pwd\"><BR><BR>");
client.println(" <INPUT type=\"submit\" value=\"Submit\">");
client.println(" </P>");
client.println(" </FORM>");
if (ussid != "") {
client.println(" <p>You have succesfully changed your SSID and password</p> ");
//client.println(" <p></p> ");
}
client.println("</body>");
client.println("</html>");
client.println();
client.stop();
}
else 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;
}
}
}
//Serial.println("Disconnected");
Serial.println();
}
}
}
}
void loop()
{
Serial.println("Your now in the loop");
}
void printWifiStatus()
{
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print where to go in the browser
Serial.println();
Serial.print("To see this page in action, connect to ");
Serial.print(ssid);
Serial.print(" and open a browser to http://");
Serial.println(ip);
Serial.println();
}
the characters "a" to "z" and "0" to "9" works fine and "-" and "_" works fine too but other characters shows the code, not sure if its during the sending of from the mobile from the html page to the arduino or the library itself.
Sorry kinda messy any help would be appreciated
Thanks!