'With a few modifications this works on a Arduino Duemilanove
'with an W5100 Ethernet Shield
'--------------------------------------------------------------
' Atmega168 and WIZ810MJ I/O-Webserver
' Build for the WIZ810MJ Evaluation Board build by Thomas Heldt
'--------------------------------------------------------------
' Software Version 3.0 Copyright by Thomas Heldt
' Free only for non comercial use !!!
' For commercial use contact thomas@heldt-web.de
'--------------------------------------------------------------
$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 9600 'put terminal on 9600 baud
$hwstack = 80
$swstack = 80
$framesize = 90
'Used variables
Dim Second As Byte
Dim Minute As Byte
Dim Hour As Byte
Dim Day As Word
Dim A As Byte
Dim Wert As Byte
Dim Status As Byte
Dim Oldstatus As Byte
Dim Pointer As Word
Dim Tmp_value As Byte
Dim Tmp_str As String * 1
Dim Highbyte As Byte
Dim Lowbyte As Byte
Dim X As Integer
Dim Userpass As String * 20
Dim Tmp_auth As String * 20
Dim Authentification As Byte
Dim Website As Byte 'Flag for website ok / websitewrong selection
Dim Buffer As String * 700 '700 Bytes should be enough for the great header of firefox browsers
Const Http_auth = 0 '0= no HTTP-AUTH, 1= with HTTP-AUTH
Userpass = "admin:demo" 'Place a : between username and password (max. 20 character all together)
Tmp_auth = Base64enc(userpass)
'Used Wiz5100 ports and pins
Wiz5100_cs Alias Portb.2 'Chipselect WIZ5100
'Wiz5100_int Alias Portb.1 'INT of WIZ5100
'Wiz5100_res Alias Portc.0 'Reset of WIZ5100
'Used ports and pins
Config Wiz5100_cs = Output
'Config Wiz5100_int = Input
'Config Wiz5100_res = Output
'Other used ports and pins
Relais1 Alias Portd.4
Relais2 Alias Portd.5
Relais3 Alias Portd.6
Relais4 Alias Portd.7
'Config the port/pin directions
'Config Led = Output
Config Relais1 = Output
Config Relais2 = Output
Config Relais3 = Output
Config Relais4 = Output
Relais1 = 0
Relais2 = 0
Relais3 = 0
Relais4 = 0
Config Watchdog = 2048 'Watchdog configuration for stable reboot if system hangs
'Configuration of the SPI-bus
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 0
'Init the spi pins
Spiinit
Const Ip[1] = 192
Const Ip[2] = 168 'Own IP-Adress
Const Ip[3] = 0
Const Ip[4] = 50
Const Sn[1] = 255 'Own Networkmask
Const Sn[2] = 255
Const Sn[3] = 255
Const Sn[4] = 0
Const Gw[1] = 192 'IP-Adress of the gateway
Const Gw[2] = 168
Const Gw[3] = 0
Const Gw[4] = 1
Const Mac[1] = &H00 'Own MAC-Adress
Const Mac[2] = &H20
Const Mac[3] = &H18
Const Mac[4] = &HB1
Const Mac[5] = &H15
Const Mac[6] = &H5F
Const Wiz5100_opcode_read = 15 'OP-Code for Read from the Wiz5100
Const Wiz5100_opcode_write = 240 'OP-Code for write to the Wiz5100
'Here we declare the used sub routines
Declare Sub Wiz5100_init
Declare Sub Wiz5100_readvalue(byval Highbyte As Byte , Byval Lowbyte As Byte)
Declare Sub Wiz5100_writevalue(byval Highbyte As Byte , Byval Lowbyte As Byte , Byval Value As Byte)
Declare Sub Wiz5100_receive
Declare Sub Wiz5100_send
Declare Sub Wiz5100_disconnect
Declare Sub Wiz5100_reset
Call Wiz5100_init 'We initialize the Wiz5100
Start Watchdog 'Start the watchdog
Config Timer1 = Timer , Prescale = 256 'Config timer1 fora 1 second interval
Enable Timer1
On Timer1 Isr_timer1 'Timer interrupt routine
Enable Interrupts 'Activate the Interrupts
Timer1 = 68570 '34285 'Startvalue for the second timer
Do
Reset Watchdog 'Reset the watchdog
'Get socket status
Call Wiz5100_readvalue(&H4 , &H3)
Status = Wert
If Status <> Oldstatus Then
Oldstatus = Status
End If
'Connection was closed, we start the socket new
If Status = &H0 Or Status = &H1C Then
Call Wiz5100_disconnect()
End If
'As long as connection is etablished (&H17) we will look if client send new data
If Status = &H17 Then
Buffer = ""
Call Wiz5100_receive()
End If
Loop
End
'Disconnect connection: close socket, reopen socket and wait for new connection
Sub Wiz5100_disconnect
Call Wiz5100_writevalue(&H4 , &H1 , &H0) 'CLOSE
Call Wiz5100_writevalue(&H4 , &H1 , &H1) 'OPEN
Call Wiz5100_writevalue(&H4 , &H1 , &H2) 'LISTEN
End Sub
'Send headers and websites
Sub Wiz5100_send
Local Sendsize As Integer , Pos_tx As Word , Freesize As Word , Offset As Word , Tx_wr As Word
Local Startadress As Word , Offsend As Word , Uppersize As Word , Glaenge As Word , Startpos As Word
Local Adctemp As Word , Tablewidth As Word , Color As String * 7
'We restore the used website data
If Website = 0 Then
Restore Websitewrong
Elseif Authentification = 0 Then
Restore Websiteok
Else
Restore Websiteauth
End If
Do
Read Buffer
'Look for the end of a website
If Buffer = "%END%" Then
Exit Do
End If
'Look for variable and replace them, here we can insert new own variables if we want
If Buffer = "%MRELAIS1%" Then
Buffer = "
"
Data "Remote reboot" Data "This webserver needs a username/password " Data " " Data "" Data "%END%" Websitewrong: Data "HTTP/1.0 200 Document follows{013}{010}Server: WIZ810MJ AVR I/O-Webserver{013}{010}Content-Type: text/html{013}{010}{013}{010}" Data "" Data "
|