- #include <ESP8266HTTPClient.h>
- #include <ESP8266WiFi.h>
- // Variabel global
- const char* ssid = "Chanyeol's wife hotspot";
- const char* password = "ceyeloveocha";
- int led1 = D1;
- int led2 = D2;
- int led3 = D3;
- #define ON HIGH
- #define OFF LOW
- //tambahan
- int firstVal, secondVal;
- WiFiClient WifiClientnya;
- void setup() {
- // put your setup code here, to run once:
- // Konfigurasi Modul
- Serial.begin(115200);
- // Connect to WiFi network
- Serial.print("Connecting to ");
- Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) { //Wait till connects
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println(WiFi.localIP());
- // --- End of Connect wifi
- // Deklarasi PIN GPIO 1
- pinMode(led1, OUTPUT);
- pinMode(led2, OUTPUT);
- pinMode(led3, OUTPUT);
- }
- //tambahan
- String getValue(String data, char separator, int index)
- {
- int found = 0;
- int strIndex[] = {0, -1};
- int maxIndex = data.length()-1;
- for(int i=0; i<=maxIndex && found<=index; i++){
- if(data.charAt(i)==separator || i==maxIndex){
- found++;
- strIndex[0] = strIndex[1]+1;
- strIndex[1] = (i == maxIndex) ? i+1 : i;
- }
- }
- String ketemu = found>index ? data.substring(strIndex[0], strIndex[1]) : "";
- return ketemu;
- }
- void loop() {
- Serial.println("Masyuk loop");
- // put your main code here, to run repeatedly:
- if(WiFi.status() == WL_CONNECTED){
- HTTPClient http;
- http.begin(WifiClientnya, "http://192.168.6.199/IOT3/control.php");
- int httpCode = http.GET();
- Serial.println("httpcode ---> "+httpCode);
- if(httpCode > 0){
- String status = http.getString();
- //status = "1,1,1,1, ";
- //tambahan
- Serial.println(status);
- Serial.print("LED 1 --> ");
- String nilai1 = getValue(status, ',',0);
- Serial.println(nilai1);
- Serial.print("LED 2 --> ");
- String nilai2 = getValue(status, ',',1);
- Serial.println(nilai2);
- Serial.print("LED 3 --> ");
- String nilai3 = getValue(status, ',',2);
- Serial.println(nilai3);
- Serial.println("------------------------");
- if(nilai1 == "0"){
- digitalWrite(led1, OFF);
- }else {
- digitalWrite(led1, ON);
- }
- if(nilai2 == "0"){
- digitalWrite(led2, OFF);
- }else {
- digitalWrite(led2, ON);
- }
- if(nilai3 == "0"){
- digitalWrite(led3, OFF);
- }else {
- digitalWrite(led3, ON);
- }
- }
- http.end();
- }else {
- Serial.println("Delay...");
- }
- delay(500);
- }
[text] a
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: