Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <WiFi.

h>

const char* ssid = "your_SSID";


const char* password = "your_PASSWORD";
const char* serverAddress = "35.192.135.4"; // replace with your API server IP
address
const int serverPort = 8017; // replace with your API server port
const int transactionId = 1; // replace with your transaction ID
const int locationId = 1; // replace with your location ID
const int subLocationId = 1; // replace with your sub-location ID
const int machineId = 1; // replace with your machine ID

void setup() {
Serial.begin(9600);
delay(1000);

WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}

void loop() {
if (WiFi.status() == WL_CONNECTED) {
// Send GET request
WiFiClient client;
if (!client.connect(serverAddress, serverPort)) {
Serial.println("Connection failed");
return;
}

String requestUrl = "/api/washing/GetPingHistory";


requestUrl += "?TransactionId=" + String(transactionId);
requestUrl += "&LocationId=" + String(locationId);
requestUrl += "&SubLocationId=" + String(subLocationId);
requestUrl += "&MachineId=" + String(machineId);

client.print(String("GET ") + requestUrl + " HTTP/1.1\r\n" +


"Host: " + serverAddress + "\r\n" +
"Connection: close\r\n\r\n");

while (!client.available()) {
delay(100);
}

while (client.available()) {
String line = client.readStringUntil('\r');
Serial.println(line);
}

client.stop();

// Send POST request


WiFiClient postClient;
if (!postClient.connect(serverAddress, serverPort)) {
Serial.println("Connection failed");
return;
}

String postRequestUrl = "/api/washing/PostPingHistory";


String postRequestBody = "{ \"TransactionId\": " + String(transactionId) +
", \"LocationId\": " + String(locationId) +
", \"SubLocationId\": " + String(subLocationId) +
", \"MachineId\": " + String(machineId) +
", \"Status\": true }"; // replace with your data

postClient.print(String("POST ") + postRequestUrl + " HTTP/1.1\r\n" +


"Host: " + serverAddress + "\r\n" +
"Content-Type: application/json\r\n" +
"Content-Length: " + String(postRequestBody.length()) + "\r\n" +
"Connection: close\r\n\r\n" +
postRequestBody);

while (!postClient.available()) {
delay(100);
}

while (postClient.available()) {
String line = postClient.readStringUntil('\r');
Serial.println(line);
}

postClient.stop();
} else {
Serial.println("WiFi Disconnected");
}

delay(5000); // wait for 5 seconds before sending another request


}

You might also like