I don't think i can use a HTTP library since the arduino acts like a webserver, and the HTTP library i found was a client. (GitHub - amcewen/HttpClient: Arduino HTTP library)
But I've changed the HTML code to use POST instead of GET, but now the data I receive on the serial monitor is POST / HTTP/1.1
What is going wrong here?
My code is
#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 20); // IP address, may need to change depending on network
EthernetServer server(80); // create a server at port 80
String readString;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7); // Set the LCD I2C address
void setup()
{
// disable Ethernet chip
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
pinMode(4, OUTPUT);
Serial.begin(115200); // for debugging
lcd.begin(16, 2);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
lcd.clear();
// Message on LCD
lcd.setCursor(2, 0);
lcd.print("Initializing");
Serial.println("Initializing...");
// initialize SD card
if (Ethernet.begin(mac) == 0) {
lcd.clear();
lcd.setCursor(2, 0);
lcd.print(F("DHCP Failed!"));
lcd.setCursor(5, 1);
lcd.print(F("Halted"));
Serial.println("DHCP Failed!");
Serial.println("Application halted");
LoopForever();
}
server.begin(); // start to listen for clients
// End of initialization message on LCD + print IP address
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(F("IP:"));
lcd.setCursor(0, 1);
lcd.print(Ethernet.localIP());
Serial.print("Current IP: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(readString); //print to serial monitor for debuging
//now output HTML data header
if (readString.indexOf('?') >= 0) { //don't send new page
client.println("HTTP/1.1 204 Sander");
client.println();
client.println();
}
else {
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<title>Network billboard</title>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Network billboard</H1>");
// Dit gedeelte HTML code is zo omgezet dat het wel meegecompileerd kan worden in C
// Gebruikte website: http://tomeko.net/online_tools/cpp_text_escape.php?lang=en
client.println("<form action=\"\" method=\"post\">"); //"<form action="" method="post">"
client.println("First line: <input type=\"text\" name=\"fline\" maxlength=\"50\" autocomplete=\"off\" autocorrect=\"off\">
"); //"First line: <input type="text" name="fline" maxlength="50" autocomplete="off" autocorrect="off">
"
client.println("Second line: <input type=\"text\" name=\"sline\" maxlength=\"50\" autocomplete=\"off\" autocorrect=\"off\">
"); //"Second line: <input type="text" name="sline" maxlength="50" autocomplete="off" autocorrect="off">
"
client.println("<input type=\"submit\" value=\"Submit\">"); //<input type="submit" value="Submit">
client.println("</form>");
client.println("</BODY>");
client.println("</HTML>");
}
delay(1);
//stopping client
client.stop();
Serial.println(readString);
// Parse incoming data code goes here //
/////////////////////////////////////////////
//clearing string for next read
readString = "";
}
}
}
}
}
void LoopForever()
{
// Looping forever here
LoopForever();
}