Akhirnya setelah sekian lama tidak memperbaharui postingan kali ini, aku bisa juga membuat pot baru.
Kali ini tentang mata kuliah yang aku pelajari yaitu CGI atau Common Gateway Interface. Common Gateway Interface adalah Sekumpulan aturan yang mengarahkan
bagaimana sebuah server web berkomunikasi dengan sebagian software dalam
mesin yang sama dan bagaimana sebagian dari software (CGI Program)
berkomunikasi dengan server web.
Pada postingan kali ini aku akan memberikan contoh program tugas yang diberikan oleh Bapak dosen di kampusku. Tugasnya adalah membuat "Lamp Controller". Jadi dalam tugas ini dibutuhkan hardaware berupa arduino uno lengkap dengan lampu LED nya yang berwarna merah-kuning-hijau. Nantinya dibutuhkan file php ataupun html untuk mengontrol lampu dan juga file.cgi sebagai CGInya.
pertama kita buat dulu file cgi-nya. Disini saya membuat file actuator.cpp yg kemudian nantinya saya ubah menjadi actuator.cgi
#using <System.dll>
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <conio.h>
#include <string>
using namespace
System;
using namespace
System::IO::Ports;
using namespace
std;
int main(){
char
*data;
int
a,b,c,d,e;
cout<<"Content-Type:b
text/html"<<endl<<endl;
cout<<"<title>Tugas
CGI</title>"<<endl;
data = getenv("QUERY_STRING");
if(data==NULL)
{
cout <<"<p>Kesalahan pada pengiriman
data<p>"<<endl;
}
else if (sscanf (data,"a=%ld
& b=%ld & c=%ld",&a,&b,&c) !=3)
{
cout <<"<p> Data salah, masukkan data
numerik</p> "<<endl;
}
else
{
if
(a==1){
cout <<"<p>
Lampu Merah Menyala</p> "<<endl;
cout <<"<form>
"<<endl;
cout <<"<input
type = \"button\" value = \"Back\"
onclick=\"window.location='http://167.205.66.247/TugasCGI/lampu.php'\">"
<<endl;
cout <<"</form>
"<<endl;
SerialPort^ mySerialPort = gcnew SerialPort("COM15");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake = Handshake::None;
mySerialPort->Open();
mySerialPort->Write("a");
mySerialPort->Close();
}else{
SerialPort^ mySerialPort = gcnew SerialPort("COM15");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake =
Handshake::None;
mySerialPort->Open();
mySerialPort->Write("s");
mySerialPort->Close();
}
if
(b==1){
cout <<"<p>
Lampu Kuning Menyala</p> "<<endl;
cout <<"<form>
"<<endl;
cout <<"<input
type = \"button\" value = \"Back\"
onclick=\"window.location='http://167.205.66.247/TugasCGI/lampu.php'\">"
<<endl;
SerialPort^ mySerialPort = gcnew SerialPort("COM15");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake =
Handshake::None;
mySerialPort->Open();
mySerialPort->Write("d");
mySerialPort->Close();
}else{
SerialPort^ mySerialPort = gcnew SerialPort("COM15");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake =
Handshake::None;
mySerialPort->Open();
mySerialPort->Write("f");
mySerialPort->Close();
}
if
(c==1){
cout <<"<p>
Lampu Hijau Menyala</p> "<<endl;
cout <<"<form>
"<<endl;
cout <<"<input
type = \"button\" value = \"Back\"
onclick=\"window.location='http://167.205.66.247/TugasCGI/lampu.php'\">"
<<endl;
SerialPort^ mySerialPort = gcnew SerialPort("COM15");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake =
Handshake::None;
mySerialPort->Open();
mySerialPort->Write("g");
mySerialPort->Close();
}else{
SerialPort^ mySerialPort = gcnew SerialPort("COM15");
mySerialPort->BaudRate = 9600;
mySerialPort->Parity = Parity::None;
mySerialPort->StopBits = StopBits::One;
mySerialPort->DataBits = 8;
mySerialPort->Handshake =
Handshake::None;
mySerialPort->Open();
mySerialPort->Write("h");
mySerialPort->Close();
}
return 0;
}
}
|
selanjutnya buat file lampu.php
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" lang="en">
<head>
<meta name="Description"
content="Information architecture, Web Design, Web Standards."
/>
<meta name="Keywords" content="your,
keywords" />
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1" />
<meta name="Distribution"
content="Global" />
<meta name="Author" content="Erwin Aligam -
ealigam@gmail.com" />
<meta name="Robots"
content="index,follow" />
<link rel="stylesheet"
href="images/MarketPlace2.css" type="text/css" />
<link rel="shortcut icon"
href="abc.gif">
<title>Lamp Controller</title>
<script language="JavaScript"
type="text/javascript">
var d=new Date();
var monthname=new
Array("Januari","Februari","Maret","April","Mei","Juni","Juli","Agstus",
"September","Oktober","November","Desember");
var TODAY = d.getDate() + " " +
monthname[d.getMonth()] + " " + d.getFullYear();
</script>
<script language="javascript" type="text/javascript"
src="swfobject.js" ></script>
<script type="text/javascript"
src="textsizer.js"></script>
</head>
<style type="text/css">
<!--
body {
background-image:
none;
background-repeat:
no-repeat;
}
#wrap #content-wrap #rightcolumn #FlashID {
text-align:
center;
}
tengaahhh {
text-align:
center;
}
foot {
text-align:
center;
}
vote {
color: #666;
}
voting {
font-weight: bold;
}
vvvv {
font-weight: bold;
}
jajaja {
color: #326ea1;
}
.style1 {color: #1F9A82}
.style2 {
font-size: 36px;
font-weight: bold;
}
.style4 {
color: #FF0000;
font-weight: bold;
}
-->
</style>
</head>
<body onLoad="show3()">
<div id="wrap">
<div
id="header">
<div
id="header-links">
<p><span class="style1">
Tanggal,</span>
<script
language="JavaScript" type="text/javascript">
document.write(TODAY); </script>
</p>
</div>
<!--header ends-->
</div>
<p
align="center" class="style2">LAMP CONTROLLER
</p>
<p
align="center"><img src="images/IMG-20130613-04847.jpg"
width="315" height="211"></p>
<p
align="center"> </p>
<div
align="center" id="x"><blink><span
class="style4"> Pilih Lampu yang Akan Dinyalakan
!!
</span></blink></div>
<p
align="center"><a
href="http://167.205.66.247/cgi-bin/actuator.cgi?a=1&b=0&c=0"
title="Nyalakan Lampu Merah" ><img
src="images/ans-4_03.png" alt="" width="50"
height="50"></a>
<a
href="http://167.205.66.247/cgi-bin/actuator.cgi?a=0&b=0&c=0"
title="Matikan Lampu Merah">
<img
src="images/off_03.png" alt="" width="50"
height="50"></a>
<br><a
href="http://167.205.66.247/cgi-bin/actuator.cgi?a=0&b=1&c=0"
title="Nyalakan Lampu Kuning">
<img
src="images/ans-4_05.png" alt="" width="50"
height="50"></a>
<a
href="http://167.205.66.247/cgi-bin/actuator.cgi?a=0&b=0&c=0"
title="Matikan Lampu Kuning">
<img
src="images/off_05.png" alt="" width="50" height="50"></a>
<br><a
href="http://167.205.66.247/cgi-bin/actuator.cgi?a=0&b=0&c=1"
title="Nyalakan Lampu Hijau">
<img
src="images/ans-4_07.png" alt="" width="50"
height="50"></a>
<a
href="http://167.205.66.247/cgi-bin/actuator.cgi?a=0&b=0&c=0"
title="Matikan Lampu Hijau"><img
src="images/off_07.png" alt="" width="50"
height="50"></a></p>
<p> </p>
<div id="nav"><!-- navigation
ends-->
</div>
<!-- content-wrap starts --><!-- footer starts -->
<div
id="footer-wrap"><div id="footer">
<p
class="style1">© Juni 2013 Tugas CGI- Ayu Novalina
(49012043)</p>
</div>
</div>
<!-- footer
ends-->
<!-- wrap ends here -->
</div>
</body>
</html>
|
dan yg terakhir buat file arduinonya.
int led1 = 13;
int led2 = 12;
int led3 = 11;
void setup(){
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
Serial.begin(9600);
}
void loop(){
int data =
Serial.read();
if (data=='a'){
digitalWrite(led1,HIGH);
}else if (data=='s'){
digitalWrite(led1,LOW);
}else if (data=='d'){
digitalWrite(led2,HIGH);
}else if(data=='f'){
digitalWrite(led2,LOW);
}else if(data=='g'){
digitalWrite(led3,HIGH);
}else if (data=='h'){
digitalWrite(led3,LOW);
}
}
|
yak, dan "Lamp Controller" yang saya buat sudah jadi. Berikut video simulasinya.
0 comments:
Post a Comment