File 8
File 8
File 8
#include <SoftwareSerial.h>
#include <espduino.h>
#include <rest.h>
char response[266];
char buff[64];
String strId,strData,strCode;
String strData_Last1,strData_Last2,strData_Last3,strData_Last4;
void clearBuffer(void) {
for (int i = 0;i<266;i++ ) {
response[i]=0;
}
}
wifiConnected = true;
} else {
wifiConnected = false;
}
}
}
void setup() {
pinMode(relay1, OUTPUT);
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
pinMode(relay5, OUTPUT);
pinMode(relay6, OUTPUT);
pinMode(relay7, OUTPUT);
pinMode(relay8, OUTPUT);
digitalWrite(relay1,HIGH);
digitalWrite(relay2,HIGH);
digitalWrite(relay3,HIGH);
digitalWrite(relay4,HIGH);
digitalWrite(relay5,HIGH);
digitalWrite(relay6,HIGH);
digitalWrite(relay7,HIGH);
digitalWrite(relay8,HIGH);
Serial.begin(9600);
espPort.begin(19200);
esp.enable();
delay(1000);
esp.reset();
delay(1000);
while(!esp.ready());
esp.wifiConnect("Oppo X9009","google123");
Serial.println("ARDUINO: System sudah siap!");
}
void loop() {
loop_start:
esp.process();
if(wifiConnected) {
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData();
delay(1000);
loop_2:
sprintf(buff, "/channels/236342/fields/2/last");
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData();
if (strId == "1" || strId == "1.0" || strId == "1.00"){
digitalWrite(relay2,LOW);
data2 = true;
}
clearBuffer();
goto loop_2;
delay(1000);
loop_3:
sprintf(buff, "/channels/236342/fields/3/last");
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData(); // GET DATA
clearBuffer();
goto loop_3;
}
delay(1000);
loop_4:
sprintf(buff, "/channels/236342/fields/4/last"); // field x last Data
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData(); // GET DATA
delay(1000);
loop_5:
sprintf(buff, "/channels/236342/fields/5/last");
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData();
clearBuffer();
goto loop_5;
}
delay(1000);
loop_6:
sprintf(buff, "/channels/236342/fields/6/last");
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData();
clearBuffer();
goto loop_6;
delay(1000);
loop_7:
sprintf(buff, "/channels/236342/fields/7/last");
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData();
if (strId == "1" || strId == "1.0" || strId == "1.00"){
digitalWrite(relay7,LOW);
data2 = true;
}
clearBuffer();
goto loop_7;
delay(1000);
loop_8:
sprintf(buff, "/channels/236342/fields/8/last");
Serial.println(buff);
rest.get((const char*)buff);
if(rest.getResponse(response, 266) == HTTP_STATUS_OK){
strId = "";
getData();
clearBuffer();
goto loop_8;
delay(1000);
loop_count++;
Serial.println("LOOP : ");
Serial.println(loop_count);
else{
}
void getData(){
int i=0;
if (response[i] == '\n'){
i++;
break;
}
}
Serial.println("");
Serial.print("ID : ");
Serial.print(strId);
Serial.println("");
}
boolean hardReset() {
String tmpData;
}
<title>Laporan Akhir</title>
<link href="css/bootstrap.css" rel="stylesheet">
</head>
<style>
div.polaroid {
margin: auto;
width: 80%;
background-color: white;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
margin-bottom: 25px;
}
img {
border-radius: 8px;
}
div.polaroidbot {
text-align: center;
padding: 10px 20px;
}
</style>
<body>
<div class="container">
<div class="container">
<h1 style="text-align:center;">Laporan Akhir</h1>
<br>
<br>
<br>
</div>
<div class="polaroid">
<img src="a.jpg" alt="Norway" style="width:100%">
<div class="polaroidbot">
<p>Kendali Stop Kontak Melalui Internet. Anda Dapat dengan mudah mengendalikan perabotan
rumah anda seperti Televisi, Pompa Air, Kulkas, Penanak Nasi, Kipas, Air Conditioner, dan peralatan
lainnya yang terhubung langsung dengan Stop Kontak A.K.A memerlukan listrik</p>
</div>
</div>
<div class="container">
<br>
<br>
</div>
<div class="container">
<table style="width:100%">
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url1='https://api.thingspeak.com//channels/236342/fields/1/last';
$data=file_get_contents($url1);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field1=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field1=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 1</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url2='https://api.thingspeak.com//channels/236342/fields/1/last';
$data=file_get_contents($url2);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?>
</td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url3='https://api.thingspeak.com//channels/236342/fields/2/last';
$data=file_get_contents($url3);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field2=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field2=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 2</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url4='https://api.thingspeak.com//channels/236342/fields/2/last';
$data=file_get_contents($url4);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url5='https://api.thingspeak.com//channels/236342/fields/3/last';
$data=file_get_contents($url5);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field3=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field3=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 3</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url6='https://api.thingspeak.com//channels/236342/fields/3/last';
$data=file_get_contents($url6);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url7='https://api.thingspeak.com//channels/236342/fields/4/last';
$data=file_get_contents($url7);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field4=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field4=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 4</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url8='https://api.thingspeak.com//channels/236342/fields/4/last';
$data=file_get_contents($url8);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url9='https://api.thingspeak.com//channels/236342/fields/5/last';
$data=file_get_contents($url9);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field5=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field5=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 5</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url10='https://api.thingspeak.com//channels/236342/fields/5/last';
$data=file_get_contents($url10);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url11='https://api.thingspeak.com//channels/236342/fields/6/last';
$data=file_get_contents($url11);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field6=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field6=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 6</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url12='https://api.thingspeak.com//channels/236342/fields/6/last';
$data=file_get_contents($url12);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url13='https://api.thingspeak.com//channels/236342/fields/7/last';
$data=file_get_contents($url13);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field7=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field7=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 7</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url14='https://api.thingspeak.com//channels/236342/fields/7/last';
$data=file_get_contents($url14);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
<tr>
<td style="text-align: right;width:40%"><a href=https://<?php
$url15='https://api.thingspeak.com//channels/236342/fields/8/last';
$data=file_get_contents($url15);
if ($data == "1") {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field8=0";
} else {
echo "api.thingspeak.com/update?key=KWK24V4E5I9RBNZ0&field8=1";
} ?> target="iframe_a"><button class="btn btn-default"
onClick="document.location.reload(true)">Relay 8</button></a></td>
<td style="width:20%"></td>
<td style="width:40%"><?php
$url16='https://api.thingspeak.com//channels/236342/fields/8/last';
$data=file_get_contents($url16);
if ($data == "1") {
echo "Hidup";
} else {
echo "Mati";
} ?></td>
</tr>
</div>
<iframe src="demo_iframe.htm" height="200" width="300" name="iframe_a" hidden></iframe>
</div>
</div>
</div>
</div>
<br>
<br>
<br>
</body>
</html>