Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <SoftwareSerial.h>
- #include <ESP8266HTTPClient.h>
- #include <WiFiClient.h>
- SoftwareSerial s(3,1);
- HTTPClient http;
- WiFiClient client;
- int httpCode;
- String payload;
- // Replace with your network credentials
- const char* ssid = "RIFQA";
- const char* password = "09200011";
- // Set web server port number to 80
- WiFiServer server(80);
- // Variable to store the HTTP request
- String header;
- // Auxiliar variables to store the current output state
- String output5State = "off";
- String output4State = "off";
- // Assign output variables to GPIO pins
- const int output5 = 5;
- const int output4 = 4;
- // Current time
- unsigned long currentTime = millis();
- // Previous time
- unsigned long previousTime = 0;
- // Define timeout time in milliseconds (example: 2000ms = 2s)
- const long timeoutTime = 2000;
- // Set your Static IP address
- IPAddress local_IP(192, xxx, xxx, xxx);
- // Set your Gateway IP address
- IPAddress gateway(192, xxx, xxx, 1);
- IPAddress subnet(255, 255, 255, 0);
- //IPAddress primaryDNS(8, 8, 8, 8); //optional
- //IPAddress secondaryDNS(8, 8, 4, 4); //optional
- void setup()
- {
- s.begin(115200);
- // Initialize the output variables as outputs
- pinMode(output5, OUTPUT);
- pinMode(output4, OUTPUT);
- // Set outputs to LOW
- digitalWrite(output5, LOW);
- digitalWrite(output4, LOW);
- // Configures static IP address
- if (!WiFi.config(local_IP, gateway, subnet)) {
- s.println("STA Failed to configure");
- }
- // Connect to Wi-Fi network with SSID and password
- s.print("Connecting to ");
- s.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- s.print(".");
- }
- // Print local IP address and start web server
- s.println("");
- s.println("WiFi connected.");
- s.println("IP address: ");
- s.println(WiFi.localIP());
- server.begin();
- }
- void loop()
- {
- if (WiFi.status() == WL_CONNECTED)
- {
- http.begin(client, "http://192.xxx.xxx.xxx:80/skripsi/cekktp.php?id=136410060212");
- httpCode = http.GET();
- if (httpCode > 0)
- {
- payload = http.getString();
- if(payload.equals("b")) s.print('b');
- else if(payload.equals("c")) s.print('c');
- }
- else
- {
- s.print('x');//connection refused / read timeout
- s.println(http.errorToString(httpCode));
- }
- http.end(); //Close connection
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement