fork(1) download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. return 0;
  6. }
  7.  
Success #stdin #stdout 0s 5284KB
stdin
#include <WiFi.h>
#include <WebServer.h>

const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

WebServer server(80);

const int relayPin = 5; // พินที่เชื่อมต่อกับรีเลย์

void setup() {
  Serial.begin(115200);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH); // ปิดน้ำเริ่มต้น

  // เชื่อมต่อกับ Wi-Fi
  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi...");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  Serial.println("\nConnected to Wi-Fi");

  // กำหนด endpoint ให้กับ API
  server.on("/open", HTTP_GET, []() {
    digitalWrite(relayPin, LOW); // เปิดน้ำ
    server.send(200, "text/plain", "Water is ON");
  });

  server.on("/close", HTTP_GET, []() {
    digitalWrite(relayPin, HIGH); // ปิดน้ำ
    server.send(200, "text/plain", "Water is OFF");
  });

  server.onNotFound([]() {
    server.send(404, "text/plain", "Not found");
  });

  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}
stdout
Standard output is empty