'--------------------------------------------------------------
'           Atmega8 and WIZ812MJ
'
' All you need to get a PING working
' original from Ben Zijlstra
'
' Annotations by Dietmar Steiner (steiner(at)key-it.de 
' to Support WIZ812MJ:
'
' WIZ812MJ uses SCS input to set the SPI_EN from W5100 high 
' WIZ812MJ uses inverting schmitt trigger, so when SCS is low, 
' SPI_EN goes high.
'
' Set Noss = 0, so SS from µC generates SS signal 
' You can also handle SCS your own, then 
' Set Noss = 1 and use a dedicated Portpin and manage SPI (SS) timing yourself.
' Wiz5100_scs Alias Portb.4 is both used for SCS/(SPI_EN).
'
' Take a look at the datashhet of your Atmega chip to use the correct portpins 
' for the spi interface '
'
' So the only effective change when using WIZ812MJ instead of WIZ810MJ 
' is, that you should be aware that SPI_EN input is now called SCS.
'
' Only one extra portpin i sused for reset of the WIZ:
' Wiz5100_res Alias Portb.0, this may differ from the layout of YOUR hardware, 
' so please take care that you use the correct portpin.
'
' And take a look at the pinout of the used atmega to asure that you connect 
' the correct portpins !
'
'
' The CS (chip select) of the WIZ is never used in SPI mode !
'
'
'           µC          WIZ812MJ
'           ____________________
'
'            MOSI  -->   MOSI
'            MISO  -->   MISO
'            SCK   -->   SCLK
'            SS    -->   SCS
'
'
' tested with Atmega32/64/644
'
' ++++++++++++++++++++++++++++++++++++++++++++++
' + Compiler version :1.11.9.3                 +
' + Compiler build   :1.11.9.3.001             +
' + IDE version      :1.11.9.3                 +
' + ++++++++++++++++++++++++++++++++++++++++++++
'
'--------------------------------------------------------------

' only adjust admin:<Kennwort>
' fusebits:
' KLA987 = 100010 (default 8 Mhz Int RC)
' C      = divide clock by 8 disabled
' G      = Preserve EEPROM
$regfile = "m32def.dat"
$crystal = 8000000
$baud = 9600
'Eeprom:
'001 = Ip(1)
'002 = Ip(2)
'003 = Ip(3)
'004 = Ip(4)
'005 = Mac(1)
'006 = Mac(2)
'007 = Mac(3)
'008 = Mac(4)
'009 = Mac(5)
'010 = Mac(6)
'011 = Netmask(1)
'012 = Netmask(2)
'013 = Netmask(3)
'014 = Netmask(4)
'015 = Gateway(1)
'016 = Gateway(2)
'017 = Gateway(3)
'018 = Gateway(4)
'019 =
'020 = Authentication(ff = Yes / Other = No)
'021 =
'022 =
'023 =
'024 = Systemnames Changed
'025 - 049 = Systeemname1
'050 - 074 = Systeemname2
'075 - 099 = Systeemname3
'100 - 125 = Systeemname4
$hwstack = 128
$swstack = 80
$framesize = 96

'W5100 - registers
$include "w5100.inc"
Dim Adres As Word
Dim Adresl As Byte At Adres Overlay
Dim Adresh As Byte At Adres + 1 Overlay
Dim Value As Byte
'Used variables
Dim Second As Byte
Dim Minute As Byte
Dim Hour As Byte
Dim Day As Word
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 Authentification As Byte
Dim Website As Byte                                         'Flag for website ok / websitewrong selection
Dim Buffer As String * 680                                  '680 Bytes should be enough for the great header of firefox browsers
Dim Mymac(6) As Byte
Dim Ippart(4) As String * 4
Dim Myip(4) As Byte
Dim Mygw(4) As Byte
Dim Mymsk(4) As Byte
Dim Mymacs(6) As String * 3
Dim Http_auth As Byte
Dim System1 As Eram String * 20 At 25
Dim System2 As Eram String * 20 At 50
Dim System3 As Eram String * 20 At 75
Dim System4 As Eram String * 20 At 100

Readeeprom Wert , 24
If Wert = &HFF Then
   System1 = "System1             "
   System2 = "System2             "
   System3 = "System3             "
   System4 = "System4             "
   Wert = 0
   Writeeeprom Wert , 24
End If
                                                            'FF = auth. / other = no auth.
Readeeprom Http_auth , 20
'Used Wiz5100 ports and pins
'Wiz5100_scs Alias Portb.1                                   'Slave Select WIZ5100
Wiz5100_res Alias Portb.0

'Used ports and pins
'Config Wiz5100_scs = Output
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 Relais1 = Output
Config Relais2 = Output
Config Relais3 = Output
Config Relais4 = Output
Relais1 = 1
Relais2 = 1
Relais3 = 1
Relais4 = 1

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
'Here we declare the used sub routines
Declare Sub Wiz5100_init
Declare Sub Wiz5100_receive
Declare Sub Wiz5100_send
Declare Sub Wiz5100_disconnect
Declare Sub Wiz5100_reset
Declare Sub Configure
Declare Sub Read_ip
Declare Sub Print_ip
Declare Sub Read_mac
Declare Sub Print_mac
Declare Sub Read_mask
Declare Sub Print_mask
Declare Sub Read_gw
Declare Sub Print_gw
Declare Sub Wiz5100_readvalue(byval Reg As Word) Declare Sub Wiz5100_writevalue(byval Reg As Word , Byval Value As Byte) Declare Sub Part1 Declare Sub Part2 Declare Sub Mrelais1 Declare Sub Mrelais2 Declare Sub Mrelais3 Declare Sub Mrelais4 Dim Wiz5100_opcode_read As Byte Wiz5100_opcode_read = 15 Dim Wiz5100_opcode_write As Byte Wiz5100_opcode_write = 240
Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0
Print "Press a key for configuration screen..."
Call Read_ip
Call Read_gw
Call Read_mask
Call Read_mac
Call Wiz5100_init                                           'We initialize the Wiz5100
Start Watchdog                                              'Start the watchdog
Config Timer1 = Timer , Prescale = 256                      'Config timer1 for a 1 second interval
Enable Timer1
On Timer1 Isr_timer1                                        'Timer interrupt routine
Enable Interrupts                                           'Activate the Interrupts
Timer1 = 34285                                              'Startvalue for the second timer
Do
   Reset Watchdog                                           'Reset the watchdog
   Value = Ischarwaiting()
   If Value = 1 Then
      Value = Waitkey()
      Call Configure
   End If
   'Get socket status
   Call Wiz5100_readvalue(w5100_s0_sr)
   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(w5100_s0_cr , Sn_cr_close)
   Call Wiz5100_writevalue(w5100_s0_cr , Sn_cr_open)
   Call Wiz5100_writevalue(w5100_s0_cr , Sn_cr_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 Bfr As String * 20
   '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
            Call Part1
            Buffer = Buffer + "MRELAIS1"
            Call Part2
            Bfr = System1
            Buffer = Buffer + Bfr + Chr(34) + "></form>"
     End If
     If Buffer = "%MRELAIS2%" Then
            Call Part1
            Buffer = Buffer + "MRELAIS2"
            Call Part2
            Bfr = System2
            Buffer = Buffer + Bfr + Chr(34) + "></form>"
     End If
     If Buffer = "%MRELAIS3%" Then
            Call Part1
            Buffer = Buffer + "MRELAIS3"
            Call Part2
            Bfr = System3
            Buffer = Buffer + Bfr + Chr(34) + "></form>"
     End If
     If Buffer = "%MRELAIS4%" Then
            Call Part1
            Buffer = Buffer + "MRELAIS4"
            Call Part2
            Bfr = System4
            Buffer = Buffer + Bfr + Chr(34) + "></form>"
      End If
     If Buffer = "%IP%" Then
         'Here we show the client IP-adress
         Call Wiz5100_readvalue(w5100_s0_dipr0)
         Buffer = Str(wert) + "."
         Call Wiz5100_readvalue(w5100_s0_dipr1)
         Buffer = Buffer + Str(wert) + "."
         Call Wiz5100_readvalue(w5100_s0_dipr2)
         Buffer = Buffer + Str(wert) + "."
         Call Wiz5100_readvalue(w5100_s0_dipr3)
         Buffer = Buffer + Str(wert)
      Elseif Buffer = "%DAY%" Then
         Buffer = Str(day)
      Elseif Buffer = "%HOUR%" Then
         Buffer = Str(hour)
      Elseif Buffer = "%MINUTE%" Then
         Buffer = Str(minute)
      Elseif Buffer = "%SECOND%" Then
         Buffer = Str(second)
      End If
      Sendsize = Len(buffer)
      Freesize:
         Call Wiz5100_readvalue(w5100_s0_tx_fsr0)
         Freesize = Wert
         Shift , Freesize , Left , 8
         Call Wiz5100_readvalue(w5100_s0_tx_fsr1)
         Freesize = Freesize + Wert
         If Freesize < Sendsize Then
            Goto Freesize
         End If
      Call Wiz5100_readvalue(w5100_s0_tx_wr0)
      Tx_wr = Wert
      Shift , Tx_wr , Left , 8
      Call Wiz5100_readvalue(w5100_s0_tx_wr1)
      Tx_wr = Tx_wr + Wert
      Startpos = Tx_wr
      Offset = Tx_wr And &H7FF
      Startadress = &H4000 + Offset
      Offsend = Offset + Sendsize
      Pointer = Startadress
      If Offsend > &H800 Then
         Uppersize = &H800 - Offset
         For X = 1 To Uppersize
            Tmp_str = Mid(buffer , X , 1)
            Tmp_value = Asc(tmp_str)
            Call Wiz5100_writevalue(pointer , Tmp_value)
            Incr Pointer
         Next X
         Pointer = &H4000
         Incr Uppersize
         For X = Uppersize To Sendsize
            Tmp_str = Mid(buffer , X , 1)
            Tmp_value = Asc(tmp_str)
            Call Wiz5100_writevalue(pointer , Tmp_value)
            Incr Pointer
         Next X
      Else
         For X = 1 To Sendsize
            Tmp_str = Mid(buffer , X , 1)
            Tmp_value = Asc(tmp_str)
            Call Wiz5100_writevalue(pointer , Tmp_value)
            Incr Pointer
         Next X
      End If
      Call Wiz5100_readvalue(w5100_s0_tx_wr0)
      Startpos = Wert
      Shift , Startpos , Left , 8
      Call Wiz5100_readvalue(w5100_s0_tx_wr1)
      Startpos = Startpos + Wert
      Glaenge = Startpos + Sendsize
      'Send Site
      Highbyte = High(glaenge)
      Call Wiz5100_writevalue(w5100_s0_tx_wr0 , Highbyte)
      Lowbyte = Low(glaenge)
      Call Wiz5100_writevalue(w5100_s0_tx_wr1 , Lowbyte)
     'Set SEND flag
      Call Wiz5100_writevalue(w5100_s0_cr , &H20)
   Loop
   'Set DISCON flag
   Call Wiz5100_writevalue(w5100_s0_cr , &H8) End Sub Sub Part1
     Buffer = "<br/><form action=" + Chr(34) + "/" + Chr(34) + " method=" + Chr(34) + "POST" + Chr(34) + ">"
     Buffer = Buffer + "<input type=" + Chr(34) + "hidden" + Chr(34) + " name=" + Chr(34) End Sub Sub Part2
     Buffer = Buffer + Chr(34) + " value=" + Chr(34) + "0" + Chr(34) + ">"
     Buffer = Buffer + "<input type = " + Chr(34) + "submit" + Chr(34) + " value = " + Chr(34) + "Reboot "
End Sub
'Receive data
Sub Wiz5100_receive
   Local I As Word
   Local Top As Word
   Local Bytes_rcv As Word
   Local Headerend As String * 4
   Local Userpass As String * 12
   Userpass = "admin:bike"                                  'Place a : between username and password (max. 15 character all together)
   Local Tmp_auth As String * 20
   Tmp_auth = Base64enc(userpass)
   'Check for new incomming data
   Call Wiz5100_readvalue(w5100_s0_rx_rsr0)
      Bytes_rcv = Wert
   Shift , Bytes_rcv , Left , 8
   Call Wiz5100_readvalue(w5100_s0_rx_rsr1)
   Bytes_rcv = Bytes_rcv + Wert
   If Bytes_rcv > 0 Then
      Bytes_rcv = Bytes_rcv - 1
      For I = 0 To Bytes_rcv
          Top = I + &H6000                                  'rx-memory
          Call Wiz5100_readvalue(top)
          'We only use correct header, correct header must be < 680 bytes!
          If Bytes_rcv < 700 Then
             Buffer = Buffer + Chr(wert)
          End If
      Next
      'Is header complete or is it a post reply?
      Headerend = Chr(13) + Chr(10) + Chr(13) + Chr(10)
      If Instr(buffer , Headerend) > 0 Then
         Website = 1
         If Http_auth = &HFF Then
            If Instr(buffer , Tmp_auth) > 0 Then
               'Authentification Found And Correct
               Authentification = 0
            If Instr(buffer , "POST /") = 1 Then
               'Toggle RELAIS1
               If Instr(buffer , "MRELAIS1=0") > 0 Then
                  Call Mrelais1
               End If
               'Toggle RELAIS2
               If Instr(buffer , "MRELAIS2=0") > 0 Then
                  Call Mrelais2
               End If
               'Toggle RELAIS3
               If Instr(buffer , "MRELAIS3=0") > 0 Then
                  Call Mrelais3
               End If
               'Toggle RELAIS4
               If Instr(buffer , "MRELAIS4=0") > 0 Then
                  Call Mrelais4
               End If
               End If
            Else
               'Authentification not found or not correct
               Authentification = 1
            End If
         Else
            Authentification = 0
            If Instr(buffer , "POST /") = 1 Then
               'Toggle RELAIS1
               If Instr(buffer , "MRELAIS1=0") > 0 Then
                  Call Mrelais1
               End If
               'Toggle RELAIS2
               If Instr(buffer , "MRELAIS2=0") > 0 Then
                  Call Mrelais2
               End If
               'Toggle RELAIS3
               If Instr(buffer , "MRELAIS3=0") > 0 Then
                  Call Mrelais3
               End If
               'Toggle RELAIS4
               If Instr(buffer , "MRELAIS4=0") > 0 Then
                  Call Mrelais4
               End If
            End If
         End If
         'Set RECV flag
         Call Wiz5100_writevalue(w5100_s0_cr , &H40)
         Call Wiz5100_send()
      Elseif Bytes_rcv > 700 Then
         'Set RECV flag
         Call Wiz5100_writevalue(w5100_s0_cr , &H40)
         Website = 0
         Call Wiz5100_send()
      End If
   End If
End Sub
Sub Mrelais1
    Relais1 = 0
    Waitms 500
    Relais1 = 1
End Sub
Sub Mrelais2
    Relais2 = 0
    Waitms 500
    Relais2 = 1
End Sub
Sub Mrelais3
    Relais3 = 0
    Waitms 500
    Relais3 = 1
End Sub
Sub Mrelais4
    Relais4 = 0
    Waitms 500
    Relais4 = 1
End Sub
Sub Wiz5100_init
    Call Wiz5100_reset                                      'Hardware reset
   'Register reset
   Call Wiz5100_writevalue(w5100_mr , &H80)                 'mr/RST
   'Set gateway IP adress
   Call Wiz5100_writevalue(w5100_gar0 , Mygw(1))
   Call Wiz5100_writevalue(w5100_gar1 , Mygw(2))
   Call Wiz5100_writevalue(w5100_gar2 , Mygw(3))
   Call Wiz5100_writevalue(w5100_gar3 , Mygw(4))
   'Set Subnetmask
   Call Wiz5100_writevalue(w5100_subr0 , Mymsk(1))
   Call Wiz5100_writevalue(w5100_subr1 , Mymsk(2))
   Call Wiz5100_writevalue(w5100_subr2 , Mymsk(3))
   Call Wiz5100_writevalue(w5100_subr3 , Mymsk(4))
   'Set MAC
   Call Wiz5100_writevalue(w5100_shar0 , Mymac(1))
   Call Wiz5100_writevalue(w5100_shar1 , Mymac(2))
   Call Wiz5100_writevalue(w5100_shar2 , Mymac(3))
   Call Wiz5100_writevalue(w5100_shar3 , Mymac(4))
   Call Wiz5100_writevalue(w5100_shar4 , Mymac(5))
   Call Wiz5100_writevalue(w5100_shar5 , Mymac(6))
   'Set own IP adress
   Call Wiz5100_writevalue(w5100_sipr0 , Myip(1))
   Call Wiz5100_writevalue(w5100_sipr1 , Myip(2))
   Call Wiz5100_writevalue(w5100_sipr2 , Myip(3))
   Call Wiz5100_writevalue(w5100_sipr3 , Myip(4))
   'Initialize socket 0 with TCP on port 80
   Call Wiz5100_writevalue(w5100_s0_mr , &H1 )              'TCP
   Call Wiz5100_writevalue(w5100_s0_port0 , &H0 )           'Port 80 HTTP
   Call Wiz5100_writevalue(w5100_s0_port1 , &H50 )
   Call Wiz5100_disconnect()
End Sub
Sub Wiz5100_readvalue(reg)
   Adres = Reg
   'Reset Wiz5100_scs
   Spiout Wiz5100_opcode_read , 1
   Spiout Adresh , 1
   Spiout Adresl , 1
   Spiin Value , 1
   'Set Wiz5100_scs
   Wert = Value
End Sub
Sub Wiz5100_writevalue(reg , Value )
   Adres = Reg
   'Reset Wiz5100_scs
   Spiout Wiz5100_opcode_write , 1
   Spiout Adresh , 1
   Spiout Adresl , 1
   Spiout Value , 1
   'Set Wiz5100_scs
End Sub
Sub Wiz5100_reset
   Wiz5100_res = 1
   Waitms 10
   Wiz5100_res = 0
   Waitms 30                                                'Minimum 20 µs
   Wiz5100_res = 1
End Sub
' Routine to get a configuration-screen on the RS232 port '
Sub Configure
Stop Watchdog
Local Hulp1 As Byte
Local Hulp2 As Byte
Local Hulp3 As Word
Local Hulp4 As Byte
Local Yn As String * 1
Local Ipnr As String * 15
Local Dot1 As Byte
Local Dot2 As Byte
Local Dot3 As Byte
Local Dot4 As Byte
Local Dot5 As Byte
Local Iptemp As String * 1
Local Bfr As String * 20
Call Read_ip
Call Read_gw
Call Read_mask
Call Read_mac
Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0
Print "Remote reboot 1.0 - benshobbycorner.nl"
Print
Configuremode:
Print "Configure mode:"
Print
Print "Network:"
Print
Print "IP-number: ";
Call Print_ip
Input "Change IP-number (y/n) " , Yn
If Yn = "y" Then
   Print
   Print "Input IP-numbers as decimals, seperated by a dot (like 192.168.1.106)"
   Print
   Input Ipnr
   Hulp1 = Split(ipnr , Ippart(1) , ".")
   Myip(1) = Val(ippart(1))
   Myip(2) = Val(ippart(2))
   Myip(3) = Val(ippart(3))
   Myip(4) = Val(ippart(4))
   Print
   Print "New IP-number: ";
   Call Print_ip
   Print
   Input "Accept IP-number (y/n) " , Yn
   If Yn = "y" Then
      Writeeeprom Myip(1) , 1 : Writeeeprom Myip(2) , 2
      Writeeeprom Myip(3) , 3 : Writeeeprom Myip(4) , 4
    End If
    Print
    Print "IP-number: ";
    Call Read_ip
    Call Print_ip
End If
Print
'Netmask
Print "NetMask: ";
Call Print_mask
Input "Change NetMask (y/n) " , Yn
If Yn = "y" Then
   Print
   Print "Input IP-numbers as decimals, seperated by a dot (like 255.255.255.0)"
   Print
   Input Ipnr
   Hulp1 = Split(ipnr , Ippart(1) , ".")
   Mymsk(1) = Val(ippart(1))
   Mymsk(2) = Val(ippart(2))
   Mymsk(3) = Val(ippart(3))
   Mymsk(4) = Val(ippart(4))
   Print
   Print "New Mask: ";
   Call Print_mask
   Print
   Input "Accept NetMask (y/n) " , Yn
   If Yn = "y" Then
      Writeeeprom Mymsk(1) , 11 : Writeeeprom Mymsk(2) , 12
      Writeeeprom Mymsk(3) , 13 : Writeeeprom Mymsk(4) , 14
    End If
    Print
    Print "NetMask: ";
    Call Read_mask
    Call Print_mask
End If
Print
'Gateway
Print "Gateway: ";
Call Print_gw
Input "Change Gateway (y/n) " , Yn
If Yn = "y" Then
   Print
   Print "Input IP-numbers as decimals, seperated by a dot (like 192.168.1.0)"
   Print
   Input Ipnr
   Hulp1 = Split(ipnr , Ippart(1) , ".")
   Mygw(1) = Val(ippart(1))
   Mygw(2) = Val(ippart(2))
   Mygw(3) = Val(ippart(3))
   Mygw(4) = Val(ippart(4))
   Print
   Print "New Gateway: ";
   Call Print_gw
   Print
   Input "Accept Gateway (y/n) " , Yn
   If Yn = "y" Then
      Writeeeprom Mygw(1) , 15 : Writeeeprom Mygw(2) , 16
      Writeeeprom Mygw(3) , 17 : Writeeeprom Mygw(4) , 18
    End If
    Print
    Print "Gateway: ";
    Call Read_gw
    Call Print_gw
End If
Print
Print "MAC-Address: ";
Call Read_mac
Call Print_mac
Input "Change MAC-address (y/n) " , Yn
If Yn = "y" Then
   Mac:
   Print
   Print "Input MAC-address in hexadecimals, seperated by a - (like 00-34-35-36-37-48)"
   Print
   Input Bfr
   If Len(bfr) <> 17 Then Goto Mac
   Hulp1 = Split(bfr , Mymacs(1) , "-")
   Mymac(1) = Hexval(mymacs(1))
   Mymac(2) = Hexval(mymacs(2))
   Mymac(3) = Hexval(mymacs(3))
   Mymac(4) = Hexval(mymacs(4))
   Mymac(5) = Hexval(mymacs(5))
   Mymac(6) = Hexval(mymacs(6))
      Print
      Print "New MAC-address: ";
      Call Print_mac
      'Print
      Input "Accept MAC-address (y/n) " , Yn
      If Yn = "y" Then
         Writeeeprom Mymac(1) , 5 : Writeeeprom Mymac(2) , 6
         Writeeeprom Mymac(3) , 7 : Writeeeprom Mymac(4) , 8
         Writeeeprom Mymac(5) , 9 : Writeeeprom Mymac(6) , 10
       End If
       Print
       Print "MAC-address: ";
       Call Read_mac
       Call Print_mac
End If
Print
Bfr = System1
Print "System1 = " ; Bfr
Print
Input "Change name of first system (y/n) " , Yn If Yn = "y" Then
   Print
   Print "Input systemname (max. 20 characters)"
   Print
   Input Bfr
   System1 = Bfr
   Print
   Print "New name: " ; Bfr
   Print
End If
Print
Bfr = System2
Print "System2 = " ; Bfr
Print
Input "Change name of second system (y/n) " , Yn If Yn = "y" Then
   Print
   Print "Input systemname (max. 20 characters)"
   Print
   Input Bfr
   System2 = Bfr
   Print
   Print "New name: " ; Bfr
   Print
End If
Print
Bfr = System3
Print "System3 = " ; Bfr
Print
Input "Change name of third system (y/n) " , Yn If Yn = "y" Then
   Print
   Print "Input systemname (max. 20 characters)"
   Print
   Input Bfr
   System3 = Bfr
   Print
   Print "New name: " ; Bfr
   Print
End If
Print
Bfr = System4
Print "System4 = " ; Bfr
Print
Input "Change name of fourth system (y/n) " , Yn If Yn = "y" Then
   Print
   Print "Input systemname (max. 20 characters)"
   Print
   Input Bfr
   System4 = Bfr
   Print
   Print "New name: " ; Bfr
   Print
End If
Print
Input "Do you want a logon-screen (y/n) " , Yn If Yn = "y" Then
   Print
   Hulp1 = &HFF
   Writeeeprom Hulp1 , 20
   Print " Authentication ON"
   Print
   Else
   Hulp1 = 0
   Writeeeprom Hulp1 , 20
   Print " Authentication OFF"
   Print
End If
Summary:
Print Chr(&H1b) ; "[2J";                                    ' ANSI goto 0/0
Print "Summary:"
Print
Print "Network:"
Print
Print "IP-number  : " ; Myip(1) ; "." ; Myip(2) ; "." ; Myip(3) ; "." ; Myip(4) Print
Print "NetMask    : " ; Mymsk(1) ; "." ; Mymsk(2) ; "." ; Mymsk(3) ; "." ; Mymsk(4)
Print
Print "Gateway    : " ; Mygw(1) ; "." ; Mygw(2) ; "." ; Mygw(3) ; "." ; Mygw(4)
Print
Print "Mac-address: " ; Hex(mymac(1)) ; "-" ; Hex(mymac(2)) ; "-" ; Hex(mymac(3)) ; "-" ; Hex(mymac(4)) ; "-" ; Hex(mymac(5)) ; "-" ; Hex(mymac(6)) Print Bfr = System1 Print "System1 = " ; Bfr Print Bfr = System2 Print "System2 = " ; Bfr Print Bfr = System3 Print "System3 = " ; Bfr Print Bfr = System4 Print "System4 = " ; Bfr Print Print "Authentication "; If Hulp1 = &HFF Then
   Print "ON"
   Else
   Print "OFF"
End If
Print
Print "Rebooting"
Wait 4
Goto 0000
End Sub
'Read IP-number from Eeprom
'
Sub Read_ip
   Readeeprom Myip(1) , 1 : Readeeprom Myip(2) , 2
   Readeeprom Myip(3) , 3 : Readeeprom Myip(4) , 4
   'Print "end sub read_ip"
End Sub
' Routine to print the IP-number
'
Sub Print_ip
   Print Myip(1) ; "." ; Myip(2) ; "." ; Myip(3) ; "." ; Myip(4) End Sub ' Routine to read the netmask from the EEPROM '
Sub Read_mask
   Readeeprom Mymsk(1) , 11 : Readeeprom Mymsk(2) , 12
   Readeeprom Mymsk(3) , 13 : Readeeprom Mymsk(4) , 14 End Sub ' Routine to print the netmask '
Sub Print_mask
   Print Mymsk(1) ; "." ; Mymsk(2) ; "." ; Mymsk(3) ; "." ; Mymsk(4) End Sub ' Routine to read the gateway from the EEPROM '
Sub Read_gw
   Readeeprom Mygw(1) , 15 : Readeeprom Mygw(2) , 16
   Readeeprom Mygw(3) , 17 : Readeeprom Mygw(4) , 18 End Sub ' Routine to print the gateway '
Sub Print_gw
   Print Mygw(1) ; "." ; Mygw(2) ; "." ; Mygw(3) ; "." ; Mygw(4) End Sub ' Routine to read the MAC-address from the EEPROM '
Sub Read_mac
   Readeeprom Mymac(1) , 5 : Readeeprom Mymac(2) , 6
   Readeeprom Mymac(3) , 7 : Readeeprom Mymac(4) , 8
   Readeeprom Mymac(5) , 9 : Readeeprom Mymac(6) , 10 End Sub ' Routine to print the MAC-address '
Sub Print_mac
   Print Hex(mymac(1)) ; "-" ; Hex(mymac(2)) ; "-" ; Hex(mymac(3)) ; "-" ; Hex(mymac(4)) ; "-" ; Hex(mymac(5)) ; "-" ; Hex(mymac(6)) End Sub
Isr_timer1:                                                 'ISR of Timer1
Timer1 = 34285                                              'Timer1 must start from 34285 again
Incr Second                                                 'Here we increase the seconds
If Second = 60 Then
   Second = 0
   Incr Minute                                              'Here we increase the minutes
   If Minute = 60 Then
      Minute = 0
      Incr Hour                                             'Here we increase the hours
      If Hour = 24 Then
         Hour = 0
         Incr Day                                           'Here we increase the days
      End If
   End If
End If
Return
'Every Website must end with a stand alone Data "%END%" in the last line
Websiteauth:
Data "HTTP/1.0 401 Unauthorized{013}{010}Server: webserver{013}{010}WWW-Authenticate: Basic realm={034}Website{034}{013}{010}Content-Type: text/html{013}{010}{013}{010}"
Data "<html><head><meta http-equiv={034}Pragma{034} Content={034}no cache{034}/>"
Data "<title>Webserver</title></head><body><center><table width={034}600{034}><tr><td align={034}center{034}><font face={034}verdana{034} color={034}#000000{034}>"
Data "<H1>Remote reboot<br></H1><br/>"
Data "<b>This webserver needs a username/password<br><br><br>"
'Data "<br><br><font face={034}verdana{034} color={034}#000000{034}><a href={034}Ben's HobbyCorner{034}>"
Data "</b></a></font></body></html>"
Data "%END%"
Websitewrong:
Data "HTTP/1.0 200 Document follows{013}{010}Server: webserver{013}{010}Content-Type: text/html{013}{010}{013}{010}"
Data "<html><head><meta http-equiv={034}Pragma{034} Content={034}no cache{034}/>"
Data "<title>Remote reboot</title></head><body><center><table width={034}600{034}><tr><td align={034}center{034}><font face={034}verdana{034} color={034}#000000{034}>"
Data "<H1>Remote reboot<br></H1></font><br/>"
Data "<font face={034}verdana{034} color={034}#C00000{034}>"
Data "</b></font></body></html>"
Data "%END%"
'A Variable must stand alone in a separate Line !!!
Websiteok:
Data "HTTP/1.0 200 Document follows{013}{010}Server: webserver{013}{010}Content-Type: text/html{013}{010}{013}{010}"
Data "<html><head><meta http-equiv={034}Pragma{034} Content={034}no cache{034}/>"
Data "<title>Remote reboot</title></head><body><center><table width={034}600{034}><tr><td align={034}center{034}><font face={034}verdana{034} color={034}#000000{034}>"
Data "<H1>Remote reboot</H1><br>System 1"
Data "%MRELAIS1%"
Data "<br>System 2"
Data "%MRELAIS2%"
Data "<br>System 3"
Data "%MRELAIS3%"
Data "<br>System 4"
Data "%MRELAIS4%"
Data "<br><br><font face={034}verdana{034} color={034}#000000{034}>Your IP-number is: <b>"
Data "%IP%"
Data "</b><br>This server is online: <b>"
Data "%DAY%"
Data "</b> Days, <b>"
Data "%HOUR%"
Data "</b> Hours, <b>"
Data "%MINUTE%"
Data "</b> Minutes and <b>"
Data "%SECOND%"
Data "</b> Seconds<br>"
Data "<br><hr><br>benshobbycorner.nl"
Data "</a></font></td></tr></table></center></body></html>"
Data "%END%"