IoT-enabled Appointment Device
Arduino Yun HTTP Client
#include <Bridge.h>
#include <YunClient.h>
#include <SPI.h>
const char *server = "raffieki.comli.com";
YunClient client;
char buffer[64];
void send_request()
{
Serial.println("connecting");
if (client.connect(server, 80)) {
Serial.print("sending");
// POST URI
client.println("POST /quick_request.php HTTP/1.1");
// Host header
sprintf(buffer, "Host: %s", server);
client.println(buffer);
client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
;
client.println("Content-Length: 108");
// End of headers
client.println();
// Request body
client.println("Username=Raffy&Password=Pogi&StudentName=Raffy&StudentNumber=201021623&Purpose=I want to set an appointment");
} else {
Serial.println("connection failed"); }
}
/* Wait for a response */
void wait_response()
{
while (!client.available()) {
if (!client.connected()) {
return;
} }
}
/* Read the response and output to the serial monitor */
void read_response()
{
bool print = true;
while (client.available()) {
char c = client.read();
// Print only until the first carriage return
if (c == '\n')
print = false;
if (print)
Serial.print(c);
}
}
void end_request()
{
client.stop();
}
void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();
send_request();
wait_response();
read_response();
}
void loop()
{
//send_request();
//wait_response();
//read_response();
//send_request();
//delay(1000);
}