Open
Description
#include <ArduinoHttpClient.h>
#include <SPI.h>
#include <WiFi.h>
#include "config.h"
//char ssid[] = "JioFi2_C5E559"; // your network SSID (name)
//char pass[] = "8nfdtyc8jf"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
IPAddress server(35,154,192,57);
//char serverAddress[] = "35.154.192.57";
int port = 8080;
WiFiClient client;
HttpClient client1 = HttpClient(client, server, port);
String response;
int statusCode = 0;
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
Serial.println("Please upgrade the firmware");
}
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
}
void loop() {
Serial.println("making POST request");
String contentType = "application/json";
String postData = "one";
client1.post("/smart_stove/api.php/checkText", contentType, postData);
statusCode = client1.responseStatusCode();
response = client1.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
//Serial.println("Wait five seconds");
//delay(5000);
/*while (client.available()) {
char c = client.read();
Serial.write(c);
}*/
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while (true);
}
}
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");
}
The response I am getting is status code: -2
Response:
I am new to github, I hope I am using it right. Sorry otherwise.