Pada kesempatan yang berbahagia kali ini, saya akan menjelaskan mengenai bagaimana cara membuat alat untuk memonitoring suatu object tertentu dengan menggunakan web base atau TCP-IP, keunggulan dari komunikasi secara web ini yaitu bisa diakses oleh banyak client, kecepatannya stabil, dan tidak menggunakan kabel, maka dari itu biasanya para elektro freak memanfaatkan komunikasi ini dengan menambahkan router sebagai wifi, jadi tidak perlu menggunakan kabel LAN untuk berhubungan ke server, hanya perlu konekkan saja ke router server. selain itu pada pembahasan kali ini juga menggunakan sebuah aplikasi VB 6 yang difungsikan sebagai aplikasi untuk menampilkan 8 buah data yang dikirimkan oleh server. berikut penjelasan selebihnya.
a. VIDEO HASILNYA
b. Minimum System + RS232
c. Program Bascom AVR
'//menggunakan bascom ver 1.1
$regfile = "m32def.dat"
$crystal = 16000000
$baud = 9600
$hwstack = 32
$swstack = 32
$framesize = 100
'used constants
Const Sock_stream = $01
Const Sock_dgram = $02
Const Sock_ipl_raw = $03
Const Sock_macl_raw = $04
Const Sel_control = 0
Const Sel_send = 1
Const Sel_recv = 2
'socket status
Const Sock_closed = $00
Const Sock_arp = $01
Const Sock_listen = $02
Const Sock_synsent = $03
Const Sock_synsent_ack = $04
Const Sock_synrecv = $05
Const Sock_established = $06
Const Sock_close_wait = $07
Const Sock_last_ack = $08
Const Sock_fin_wait1 = $09
Const Sock_fin_wait2 = $0a
Const Sock_closing = $0b
Const Sock_time_wait = $0c
Const Sock_reset = $0d
Const Sock_init = $0e
Const Sock_udp = $0f
Const Sock_raw = $10
Enable Interrupts
Config Tcpip = Int0 , Mac = 12.128.12.34.56.78 , Ip = 192.168.1.121 , Submask = 255.255.255.0 , Gateway = 192.168.1.1 , Localport = 1000 , Tx = $55 , Rx = $55 , Twi = &H80 , Clock = 100000
Config Adc = Single , Prescaler = Auto , Reference = Avcc
Dim Shtml As String * 200
Dim Tempw As Word
Dim I As Byte , P As Byte
Dim S As String * 900
Dim Test(2) As String * 200
Dim V As String * 50
Config Portc.7 = Output
Config Portc.6 = Output
Config Portc.5 = Output
Config Portc.4 = Output
Config Portc.3 = Output
Config Portc.2 = Output
Portc.7 = 1
Portc.6 = 1
Portc.5 = 1
Portc.4 = 1
Portc.3 = 1
Portc.2 = 1
Sw1 Alias Portc.7
Sw2 Alias Portc.6
Sw3 Alias Portc.5
Sw4 Alias Portc.4
Sw5 Alias Portc.3
Sw6 Alias Portc.2
Do
Tempw = Socketstat(0 , 0)
If Tempw = Sock_established Then
Tempw = Socketstat(0 , Sel_recv)
If Tempw > 0 Then
Do
Tempw = Tcpread(0 , S)
P = Split(s , Test(1) , " ")
If Test(1) = "GET" Then
Gosub Webpage
End If
Loop Until S = ""
Tempw = Tcpwrite(0 , " ")
Gosub Kirim_data
Closesocket 0
End If
Elseif Tempw = Sock_close_wait Then
Closesocket 0
Elseif Tempw = Sock_closed Then
I = Getsocket(0 , Sock_stream , 80 , 0)
Socketlisten 0
End If
Loop
End
Webpage:
P = Split(s , Test(1) , " ")
Shtml = Test(2)
Return
Kirim_data:
Dim Wsize As Word , Icount As Integer
Dim Data_adc As Word
Dim Adc_teg As Single
Dim Teg As String * 5
Dim Data_adc1 As Word
Dim Adc_teg1 As Single
Dim Teg1 As String * 5
Dim Data_adc2 As Word
Dim Adc_teg2 As Single
Dim Teg2 As String * 5
Dim Data_adc3 As Word
Dim Adc_teg3 As Single
Dim Teg3 As String * 5
Dim Data_arus4 As Word
Dim Adc_arus4 As Single
Dim Arus4 As String * 5
Dim Data_arus5 As Word
Dim Adc_arus5 As Single
Dim Arus5 As String * 5
Dim Data_arus6 As Word
Dim Adc_arus6 As Single
Dim Arus6 As String * 5
Dim Data_arus7 As Word
Dim Adc_arus7 As Single
Dim Arus7 As String * 5
Dim Buffer As String * 20
Dim Y As Byte , X As Byte
Start Adc
Data_adc = Getadc(0)
Adc_teg = Data_adc / 1023
Adc_teg = Adc_teg * 5
Teg = Fusing(adc_teg , "#.###")
Data_adc1 = Getadc(1)
Adc_teg1 = Data_adc1 / 1023
Adc_teg1 = Adc_teg1 * 5
Teg1 = Fusing(adc_teg1 , "#.###")
Data_adc2 = Getadc(2)
Adc_teg2 = Data_adc2 / 1023
Adc_teg2 = Adc_teg2 * 5
Teg2 = Fusing(adc_teg2 , "#.###")
Data_adc3 = Getadc(3)
Adc_teg3 = Data_adc3 / 1023
Adc_teg3 = Adc_teg3 * 5
Teg3 = Fusing(adc_teg3 , "#.###")
Data_arus4 = Getadc(4)
Adc_arus4 = Data_arus4 / 1023
Adc_arus4 = Adc_arus4 * 5
Arus4 = Fusing(adc_arus4 , "#.###")
Data_arus5 = Getadc(5)
Adc_arus5 = Data_arus5 / 1023
Adc_arus5 = Adc_arus5 * 5
Arus5 = Fusing(adc_arus5 , "#.###")
Data_arus6 = Getadc(6)
Adc_arus6 = Data_arus6 / 1023
Adc_arus6 = Adc_arus6 * 5
Arus6 = Fusing(adc_arus6 , "#.###")
Data_arus7 = Getadc(7)
Adc_arus7 = Data_arus7 / 1023
Adc_arus7 = Adc_arus7 * 5
Arus7 = Fusing(adc_arus7 , "#.###")
Print Teg
Print Teg1
Print Teg2
Print Teg3
Print Arus4
Print Arus5
Print Arus6
Print Arus7
Waitms 500
If Shtml = "/main.htm" Then
'S = "<html><head><title>Monitor</title><meta http-equiv='refresh' content='1'></head><center><body><p> V1 = " + Teg + " volt" + " <br> I1 = " + Arus4 + " A" + " </p><p> </p><p> </p></br><a href = '/Led.htm' > SW ON/OFF </a></body></center></html>"
'S = "<html><head><title>Monitor</title><meta http-equiv='refresh'content='1'></head><center><body><p>V1=" + Teg + "v" + "<br>V2=" + Teg1 + "v" + "<br>V3=" + Teg2 + "v" + "<br>V4=" + Teg3 + "v" + "<br>I1=" + Arus4 + "A" + "<br>I2=" + Arus5 + "A" + "<br>I3=" + Arus6 + "A" + "<br>I4=" + Arus7 + "A" + "<br><br><a href='/CS1.htm'>X</a></p></body></center></html>"
S = "<html><head><title>Monitor</title><meta http-equiv='refresh'content='1'></head><center><body><p>V1=" + Teg + "v" + "<br>V2=" + Teg1 + "v" + "<br>V3=" + Teg2 + "v" + "<br>V4=" + Teg3 + "v" + "<br>I1=" + Arus4 + "A" + "<br>I2=" + Arus5 + "A" + "<br>I3=" + Arus6 + "A" + "<br>I4=" + Arus7 + "A" + "<br><br><a href='/CS1.htm'>X</a></p></body></center></html>"
'=========== database =============
Elseif Shtml = "/Logger.htm" Then
S = "<html><head><title>Database</title></head><?php $link = mysql_connect('localhost','root','root');Mysql_select_db('charging');$result = mysql_query('SELECT * FROM tbcharging');while ($row=mysql_fetch_row($result)){ echo '$row[0]$row[1]$row[2]$row[3]$row[4]$row[5]$row[6]$row[7]$row[8]$row[9]';}?></html>"
'=========== kontrol ==============
Elseif Shtml = "/CS1.htm" Then
S = "<html><head><title>kendali</title></head><center><a href='/SW1.htm'>SW1</a><br><a href='/SW2.htm'>SW2</a><br><a href='/SW3.htm'>SW3</a><br><a href='/SW4.htm'>SW4</a><br><a href='/SW5.htm'>SW5</a><br><a href='/SW6.htm'>SW6</a><br><br><a href='/main.htm'>X</a></body></center></html>"
'=========== GAMBAR ================
Elseif Shtml = "/g.htm" Then
S = "<html><head><title>Monitor</title></head><center><body><a href='/CS1.htm'>BACK</a>  <a href='/main.htm'>HOME</a><Br><img src= 'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRevG0WQEF6s3qXyOLgRyIj3UQObY7cxwWV9WeNsfYlDUSMUtf3Ac7bcygVyGePRkjAxld2015Yxa7hhfmBODTKBJAjHGwTveovlQkym5_tHlb3lRvekG5D9DfMExq5DCYwfNiPDk2HHxv/s1600/fix.jpg' witdh = '600' height ='600'></body></center></html>"
'=========== Switch 1 ==============
Elseif Shtml = "/SW1.htm" Then
S = "<html><head><title>SW1</title></head><center><a href='/SW1ON.htm'>SW1 ON</a><br><a href='/SW1OFF.htm'>SW1 OFF</a><br><br><a href='/CS1.htm'>BACK</a><br><a href='/g.htm'>GAMBAR</a></center></body></html>"
Elseif Shtml = "/SW1ON.htm" Then
S = "<html><head><title>SW1ON</title></head><center><p>SWITCH 1 ON</p><br><br><a href='/SW1.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Reset Sw1
Elseif Shtml = "/SW1OFF.htm" Then
S = "<html><head><title>SW1OFF</title></head><center><p>SWITCH 1 OFF</p><br><br><a href='/SW1.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Set Sw1
'========== Switch 2 ===============
Elseif Shtml = "/SW2.htm" Then
S = "<html><head><title>SW2</title></head><center><a href='/SW2ON.htm'>SW2 ON</a><br><a href='/SW2OFF.htm'>SW2 OFF</a><br><br><a href='/CS1.htm'>BACK</a><br><a href='/g.htm'>GAMBAR</a></center></body></html>"
Elseif Shtml = "/SW2ON.htm" Then
S = "<html><head><title>SW2ON</title></head><center><p>SWITCH 2 ON</p><br><br><a href='/SW2.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Reset Sw2
Elseif Shtml = "/SW2OFF.htm" Then
S = "<html><head><title>SW2OFF</title></head><center><p>SWITCH 2 OFF</p><br><br><a href='/SW2.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Set Sw2
'========== Switch 3 ===============
Elseif Shtml = "/SW3.htm" Then
S = "<html><head><title>SW3</title></head><center><a href='/SW3ON.htm'>SW3 ON</a><br><a href='/SW3OFF.htm'>SW3 OFF</a><br><br><a href='/CS1.htm'>BACK</a><br><a href='/g.htm'>GAMBAR</a></center></body></html>"
Elseif Shtml = "/SW3ON.htm" Then
S = "<html><head><title>SW3ON</title></head><center><p>SWITCH 3 ON</p><br><br><a href='/SW3.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Reset Sw3
Elseif Shtml = "/SW3OFF.htm" Then
S = "<html><head><title>SW3OFF</title></head><center><p>SWITCH 3 OFF</p><br><br><a href='/SW3.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Set Sw3
'========== Switch 4 ===============
Elseif Shtml = "/SW4.htm" Then
S = "<html><head><title>SW4</title></head><center><a href='/SW4ON.htm'>SW4 ON</a><br><a href='/SW4OFF.htm'>SW4 OFF</a><br><br><a href='/CS1.htm'>BACK</a><br><a href='/g.htm'>GAMBAR</a></center></body></html>"
Elseif Shtml = "/SW4ON.htm" Then
S = "<html><head><title>SW4ON</title></head><center><p>SWITCH 4 ON</p><br><br><a href='/SW4.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Reset Sw4
Elseif Shtml = "/SW4OFF.htm" Then
S = "<html><head><title>SW4OFF</title></head><center><p>SWITCH 4 OFF</p><br><br><a href='/SW4.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Set Sw4
'========== Switch 5 ===============
Elseif Shtml = "/SW5.htm" Then
S = "<html><head><title>SW5</title></head><center><a href='/SW5ON.htm'>SW5 ON</a><br><a href='/SW5OFF.htm'>SW5 OFF</a><br><br><a href='/CS1.htm'>BACK</a><br><a href='/g.htm'>GAMBAR</a></center></body></html>"
Elseif Shtml = "/SW5ON.htm" Then
S = "<html><head><title>SW5ON</title></head><center><p>SWITCH 5 ON</p><br><br><a href='/SW5.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Reset Sw5
Elseif Shtml = "/SW5OFF.htm" Then
S = "<html><head><title>SW5OFF</title></head><center><p>SWITCH 5 OFF</p><br><br><a href='/SW5.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Set Sw5
'========== Switch 6 ===============
Elseif Shtml = "/SW6.htm" Then
S = "<html><head><title>SW6</title></head><center><a href='/SW6ON.htm'>SW6 ON</a><br><a href='/SW6OFF.htm'>SW6 OFF</a><br><br><a href='/CS1.htm'>BACK</a><br><a href='/g.htm'>GAMBAR</a></center></body></html>"
Elseif Shtml = "/SW6ON.htm" Then
S = "<html><head><title>SW6ON</title></head><center><p>SWITCH 6 ON</p><br><br><a href='/SW6.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Reset Sw6
Elseif Shtml = "/SW6OFF.htm" Then
S = "<html><head><title>SW6OFF</title></head><center><p>SWITCH 6 OFF</p><br><br><a href='/SW6.htm'>BACK</a><br><a href='/main.htm'>HOME</a></center></body></html>"
Set Sw6
Else
S = "<html><head><title>Error Loading Page</title></head><center><b>Address web yang Anda pilih Salah!!!</b></br><a href = '/main.htm' >HOME</a></center></body></html>"
End If
Wsize = Len(s)
Tempw = Tcpwrite(0 , S , Wsize)
Shtml = ""
Return
d. Program VB 6
DOWNLOAD
'----------------------------------
Option Explicit
Dim sHari As String 'Deklarasi variabel global, karena digunakan
Dim aHari 'oleh lebih dari satu prosedur
Dim jam, menit, detik, waktu_shutdown
Private Sub cmd_Connect_Click()
On Error GoTo a
If Winsock.State <> sckClosed Then Winsock.Close
Winsock.RemoteHost = Text_IP
Winsock.RemotePort = Text_PORT
Winsock.Connect
cmd_Connect.Enabled = False
cmd_Disconnect.Enabled = True
Command_save.Enabled = True
CmdSet.Enabled = True
Exit Sub
a:
MsgBox "error: " & Err.Description, vbCritical, "Error"
End Sub
Private Sub cmd_Disconnect_Click()
Winsock.Close
MsgBox ("Koneksi dengan Server selesai")
cmd_Connect.Enabled = True
cmd_Disconnect.Enabled = False
End Sub
Private Sub CmdCancel_Click()
Text2.Text = " "
Text3.Text = " "
Text4.Text = " "
waktu_shutdown = "Cancel"
MsgBox ("Batal melakukan monitoring secara otomatis")
End Sub
Private Sub CmdSet_Click()
jam = Text2.Text
menit = Text3.Text
detik = Text4.Text
waktu_shutdown = jam + ":" + menit + ":" + detik
MsgBox "Selesai Monitoring pada pukul : " & waktu_shutdown
End Sub
Private Sub Command_Clear_Click()
Text1.Text = ""
End Sub
Private Sub Command_save_Click()
Dim i As Integer
i = FreeFile
Open "D:\hasil.txt" For Append As #i
Print #1, "--------------------------"
Print #1, lblTanggal.Caption
'Print #1, LblWaktu.Caption
Print #1, Text1.Text
Print #i, "--------------------------"
Close #i
Text1.Text = ""
MsgBox ("Data suhu dan kelembaban sudah tersimpan")
End Sub
Private Sub Form_Load()
aHari = Array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat", "Sabtu")
Timer1.Enabled = True
cmd_Connect.Enabled = True
cmd_Disconnect.Enabled = False
Command_save.Enabled = False
'CmdSet.Enabled = False
End Sub
Private Sub Timer1_Timer()
sHari = aHari(Abs(Weekday(Date) - 1))
lblTanggal.Caption = "" & sHari & "," & Format(Date, "dd mmmm yyyy")
LblWaktu.Caption = Format(Time, "hh:mm:ss")
Label10.Caption = waktu_shutdown
If LblWaktu.Caption = waktu_shutdown Then
MsgBox ("PENGUKURAN SELESAI")
Call Command_save_Click
End If
End Sub
Private Sub Winsock_Connect()
MsgBox ("terkoneksi dengan server")
End Sub
Private Sub Winsock_ConnectionRequest(ByVal requestID As Long)
Winsock.Accept requestID
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim buffer As String
Dim temp As String
Dim pisah() As String
Dim i As Integer
Dim data As String
data = ""
Winsock.GetData data, vbString
Text1.Text = Text1.Text & data & vbCr
buffer = data
'pisah = Split(buffer, Chr$(13))
pisah = Split(buffer, "|")
On Error Resume Next
If buffer <> " " Then
With Text5
.SelStart = Len(.Text)
.SelText = buffer
End With
For i = 0 To 8
If 0 < 9 Then
Text6(i).Text = CStr(pisah(i))
End If
Next i
Else
buffer = " "
End If
End Sub
e. Cara Memasang
1. Install dulu software toolnya wiz110sr
2. Hubungkan Port Rj45 Wiz110sr dengan kabel LAN CROSS ke Rj45 komputer
2. Kemudian pilih "search" maka akan terlihat IP default dan Portnya
3. Rubah IP Local dan IP server dengan IP yang sama dan satu kelas dengan router
4. Kemudian ubah baudrate menjadi 9600
5. Klik "setting", maka semua yang dirubah telah tersimpan
6. Hubungkan kabel serial mikro dengan wiz110sr secara CROOS (RX,TX,GND)
7. Hubungkan juga port RJ45 ke router dengan kabel LAN CROSS
8. Konekkan komputer / laptop client dengan router
9. Buka comand prompt lalu PING IP address server
10. Jika berhasil maka buka hyperterminal lalu masukkan IP dan portnya
11. Data dari server akan terkirim ke client.....
No comments:
Post a Comment