The connection of the WIZ610wi is not done
on a real hardware UART of the Atmega168. The FT232RL USB connector is
fitted there to program the Arduino from the outside world. So a
soft-UART must be used. SIX1 has seen that Olimex used INT0 and INT1
pins for RX and TX between microcontroller and WIZ610wi module so the
serial communication between the Arduino and the shield could be done on
interrupt base. Very clever!!
'--------------------------------------------------------------
' ATMega 168 ARDUINO WIZ610wi SHIELD
' 2011/2 by six1 Michael Köcher
' this software is not free!
' only for private use!
'--------------------------------------------------------------
$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 38400
$hwstack = 50
$swstack = 50
$framesize = 150
Led1 Alias Portb.5
Config Led1 = Output
Aux_led Alias Portd.7
Config Aux_led = Output
Aux_led = 1
Wiz_cfg Alias Portb.4
Config Wiz_cfg = Output
Wiz_power Alias Portd.4
Config Wiz_power = Output
' enable Power and serial
communication on WIZ610 Board
'Wiz_power = 1
Wait 1
Wiz_power = 0
Wiz_cfg = 1
'-------------------------------------------------------------------------------
' WIZ610 RX/TX SOFTWARE SERIAL
'-------------------------------------------------------------------------------
'PD.3 = TX
Open "comd.3:38400,8,n,1" For Output As #10
'PD.2 = RX
Open "comd.2:38400,8,n,1" For Input As #11
'-------------------------------------------------------------------------------
' ARDUINO HARDWARE SERIAL
'-------------------------------------------------------------------------------
Config Serialin = Buffered ,
Size = 60 , Bytematch = 13
Open "com1:" For Binary As #1
Dim Incoming_data As String * 60
'-------------------------------------------------------------------------------
' INT0 RX INTERRUPT
'-------------------------------------------------------------------------------
Dim Timeout_rx As Word
Dim Rx_ok As Byte
On Int0 Isr_rx Nosave
Config Int0 = Change
Enable Int0
Enable Interrupts
'-------------------------------------------------------------------------------
'
VARIABLES
'-------------------------------------------------------------------------------
Dim B As Byte
Dim Pos As Byte
Const Max_rx = 100
Dim Incoming_str As String * 150
Dim Incoming(max_rx) As Byte At Incoming_str Overlay
Dim Pagecounter As Word
Pagecounter = 0
Dim Get_filename As String * 20
Dim Ajax As Byte
' WLAN CLIENT PARAMETERS
Dim Ip As String * 19
Dim Mask As String * 19
Dim Gw As String * 19
Dim Dns As String * 19
Dim Server_port As String * 8
Dim Ssid As String * 20
Dim Security_control As String * 30
Dim Auth_mode As String * 1
Dim Encrypt As String * 1
Dim Keylength As String * 1
Dim Keyformat_wep As String * 1
Dim Keyformat_wap As String * 1
Dim Keyvalue As String * 15
'AuthMode: 0(Open or Shared),
1(Open), 2(802.1x), 3(Shared), 4(wpa) , 5(wpa -psk) , 6(wpa2) , 7(wpa2 -psk),
Auth_mode = "0"
'Encrypt: 0(None),1 (WEP), 2(TKIP),
3(AES), 4(TKIP_AES)
Encrypt = "1"
'KeyLength: 0(None),
1(WEP64), 2(WEP128)
Keylength = "1"
'KeyFormat(WEP): 0(Ascii), 1(Hex)
Keyformat_wep = "1"
'KeyFormat(WPA-PSK): 0(Passphrase),
1(Hex)
Keyformat_wap = "0"
'WPA-PSK KeyValue: 8~63byte)
Keyvalue = "hobby"
'IP Setting 0=Static _Ipaddress
_Subnet _Gateway _DNS
Ip = "192.168.0.55" 'your Server IP
Mask = "255.255.255.0" 'your
Subnet Mask
Gw = "192.168.0.1" 'your
Gateway -> this is normaly your Router Address
Dns = "192.168.0.1" 'your DNS
Server -> normaly your Router Address
'Webserver Port
Server_port = "81"
'SSID to connect to
Ssid = "BensHobbyCorner"
'DON'T CHANGE!
Security_control = "<GU" + Auth_mode + "_" + Encrypt + "_" + Keylength +
"_" + Keyformat_wep + "_" + Keyformat_wap + "_" + Keyvalue + ">"
Ssid = "<GS" + Ssid + ">"
'-------------------------------------------------------------------------------
' FUNCTIONS
'-------------------------------------------------------------------------------
Declare Function Wiz610_com(byval
Timeoutvalue As Byte , Byval Result As String , Byval Command As String
) As Byte
Declare Sub Wiz610_send_header()
'-------------------------------------------------------------------------------
' START PROGRAM
'-------------------------------------------------------------------------------
Print #1 , "Arduino WIZ610wi"
'-------------------------------------------------------------------------------
' INIT SEQUENCE for connecting as Client to Access point
'-------------------------------------------------------------------------------
Start_sequence:
'wait on WIZ610 response...
'If Wiz610_com(4 , "<Sv" , "<RF>"
) > 0 Then Goto Start_sequence
'If Wiz610_com(10 , "<S>" ,
"<WF>") > 0 Then Goto Start_sequence
Factorydefault:
If Wiz610_com(10 , "<Sv" , "<RF>") > 0 Then Goto Factorydefault
'Channel
If Wiz610_com(10 , "<S>" , "<GC0>" ) > 0 Then Goto Start_sequence
'WIFI Power (0=off - 16)
If Wiz610_com(10 , "<S>" , "<GP10>" ) > 0 Then Goto Start_sequence
'alias name
If Wiz610_com(5 , "<S>" , "<GNBensHobbyCorner>" ) > 0 Then Goto Start_sequence
If Wiz610_com(5 , "<S>" , "<GSBensHobbyCorner>"
) > 0 Then Goto Start_sequence
'Check connected (if we're
already connected to ssid, we can jump to activate server!)
If Wiz610_com(10 , "<S1" , "<QP>" ) = 0 Then Goto Already_connected
Clientmode:
If Wiz610_com(10 , "<S>" , "<GO3>" ) > 0 Then Goto Start_sequence
'SET DHCP SERVER! OFF
If Wiz610_com(50 , "<S>" , "<WD0>" ) > 0 Then Goto Start_sequence
'SET IP Address
Incoming_str = "<WT0_" + Ip + "_" + Mask + "_" + Gw + "_" + Dns + ">"
If Wiz610_com(50 , "<S>" ,
Incoming_str ) > 0 Then Goto Start_sequence
'connect to SSID
'If Wiz610_com( "<DI>" , "<S" , 30) > 0 Then Goto Start_sequence
Con_ssid:
If Wiz610_com(5 , "<S>" , Ssid ) > 0 Then Goto Con_ssid
'security parameters
If Wiz610_com(20 , "<S>" , Security_control ) > 0 Then Goto Start_sequence
'set server protokoll to
TCP(0) or UDP(1)
Server_protokoll:
If Wiz610_com(2 , "<S>" , "<WK0>" ) > 0 Then Goto Server_protokoll
'set server Port
Serverport:
If Wiz610_com(2 , "<S>" , "<WP" + Server_port + ">" ) > 0 Then Goto
Serverport
'char when this char is send
to serial, buffer is send to tcpip
Charbreak:
If Wiz610_com(2 , "<S>" , "<OCFF>" ) > 0 Then Goto Charbreak
'size when size is reached,
data is send to tcpip
Sizebreak:
If Wiz610_com(2 , "<S>" , "<OS255>" ) > 0 Then Goto Sizebreak
'time when time is reached,
data is send to tcpip ; value * 3,8 = value in ms
Timebreak:
If Wiz610_com(2 , "<S>" , "<OT2000>" ) > 0 Then Goto Timebreak
Already_connected:
'activate Client 0:Client, 1:Mixed, 2:Server
Activate_client:
If Wiz610_com(2 , "<S>" ,
"<WM2>") > 0 Then Goto Activate_client
Aux_led = 0 'show connection
on led
Wiz_cfg = 0 'change to Server
communication mode (Command Mode off)
'-------------------------------------------------------------------------------
' Mainloop
'-------------------------------------------------------------------------------
Do
If Mid(incoming_str , 1 , 3) = "GET" Then
Disable Int0
Ajax = 0
Get_filename = Mid(incoming_str
, 1 , 20)
'Send Page Header
Call Wiz610_send_header()
If Mid(get_filename , 1 ,
6) = "GET / " Then
Incr Pagecounter
Restore Index
Elseif Mid(get_filename , 1 , 14) = "GET /index.htm" Then
Incr
Pagecounter
Restore Index
Elseif Mid(get_filename , 1 , 14) = "GET /clicks.ax" Then
'lets do dynamic content! :-)
Print #10 , "Counter: " ; Str(pagecounter) ; "{010}";
Ajax = 1
Elseif Mid(get_filename , 1 , 11) = "GET /led.ax" Then
Toggle Aux_led
If Aux_led = 1 Then
Print #10 , "<font color=#ff0000><b>LED OFF</b></font>" ;
Else
Print #10 , "<font color=#00bb00><b>LED ON</b></font>" ;
End If
Ajax = 1
Else
Restore 404 'Page not found 404 Error
End If
If Ajax = 0 Then
Do
Read Incoming_str
If Incoming_str = "%END%" Then Exit Do
If Incoming_str = "%crlf%" Then
Print #10 , "{010}{013}";
Else
Print #10 , Incoming_str ; "{010}";
End If
Loop
End If
Print #10 , " " ;
Incoming_str = ""
Enable Int0
End If
Loop
End
'-------------------------------------------------------------------------------
' send Header "HTTP/1.1 200 OK"
'-------------------------------------------------------------------------------
Sub Wiz610_send_header()
Restore 200
Do
Read Incoming_str
If Incoming_str = "%END%" Then Exit Do
If Incoming_str = "%crlf%" Then
Print #10 , "{010}{013}";
Else
Print
#10 , Incoming_str ; "{010}";
End If
Loop
End Sub
'-------------------------------------------------------------------------------
' send USB RX to WIZ
'-------------------------------------------------------------------------------
Serial0charmatch:
' send command from USB to WIZ610
Input Incoming_data Noecho
Print #10 , Incoming_data
Return
'-------------------------------------------------------------------------------
' Wiz610_com send command and wait for result
' if result = "" then function waits on timeout and gives back OK!
'-------------------------------------------------------------------------------
Function Wiz610_com(byval
Timeoutvalue As Byte , Byval Result As String , Byval Command1 As String
) As Byte
Local Timeout_wiz610_com As Word
Local B_b As Byte
Timeout_wiz610_com = 0
' send Command to WIZ
Rx_ok = 0
Incoming_str = ""
Print #1 , Command;
Print #1 , ": ";
If Result = "" Then Print #1 , " "
Print #10 , Command
'wait on
result
Do
Incr Timeout_wiz610_com
Waitms 1000
Loop Until Timeout_wiz610_com =
Timeoutvalue Or Rx_ok = 1
If Incoming_str <> "" And
Result <> "" Then
B_b = Instr(incoming_str , Result)
If B_b > 0 Then
Wiz610_com
= 0 'got result, OK
'Print #1 , "ok"
Else
Wiz610_com = 1 'got wrong result, ERROR
'Print #1 , "wrong "; incoming_str
End If
Else
If Result = "" Then
Wiz610_com
= 0 'got result, OK
Else
Wiz610_com
= &HFF 'Timeout ERROR
Print #1 ,
"Timeout"
End If
End If
End Function
'-------------------------------------------------------------------------------
' RX from WIZ on SoftSer
'-------------------------------------------------------------------------------
Isr_rx:
Disable Int0
Timeout_rx = 0
Incoming_str = ""
Pos = 1
Do
B = Inkey(#11)
If B > 0 Then
If Pos < 120 Then
Incoming(pos) = B
Incr Pos
End If
Timeout_rx = 0
Else
Incr Timeout_rx
End If
Loop Until Timeout_rx = &H1FFF
'set string end position!
Incoming(pos) = 0
Print #1 , Incoming_str
Print #1 , "-"
Rx_ok = 1
'clear INT0 Int Flag, because
int can be flaged in meantime!
Eifr.intf0 = 1
Enable Int0
Return
200:
Data "HTTP/1.1 200 OK"
Data "Server: WIZ610wi"
Data "Content-Type: text/html"
Data "%crlf%"
Data "%crlf%"
Data "%END%"
Index:
Data "<html>"
Data "<meta http-equiv={034}Content-Language{034} content={034}en-us<meta
http-equiv={034}Content-Language{034} content={034}en-us"
Data "<head>"
Data "<meta http-equiv={034}Content-Language{034} content={034}en-us{034}>"
Data "<meta http-equiv={034}Content-Type{034} content={034}text/html;
charset=windows-1252{034}>"
Data "<meta
name={034}DESCRIPTION{034} content={034}ARDUINO WIZ610wi SHIELD{034}>"
Data "<title>ARDUINO WIZ610 SHIELD</title>"
Data "</head>"
Data "<script type={034}text/javascript{034}>"
Data ""
Data " XMLHttp=function(url,dst){"
Data " var browser=navigator.appName;"
Data " var script;"
Data " if(browser=={034}Microsoft Internet Explorer{034})"
Data " {"
Data " var http=new ActiveXObject({034}microsoft.xmlhttp{034});"
Data " }"
Data " else"
Data " {"
Data " var http=new XMLHttpRequest();"
Data " }"
Data " http.open({034}get{034},url,true);"
Data " http.onreadystatechange=function()"
Data " {"
Data " if ((http.readyState==4) && (http.status == 200))"
Data " {"
Data " if (typeof http.responseText != {034}undefined{034}) {"
Data " document.getElementById(dst).innerHTML=http.responseText;"
Data " }"
Data " }"
Data " }"
Data " http.send(null);"
Data " }"
Data "</script>"
Data ""
Data "<body bgcolor={034}#ACA899{034}>"
Data ""
Data "<center><b><font size={034}7{034} face={034}Arial{034}>ARDUINO
WIZ610 SHIELD</font></b></center>"
Data "<div align={034}center{034}>"
Data " <center>"
Data " <table border={034}0{034} cellpadding={034}5{034} cellspacing={034}0{034}
width={034}672{034} height={034}622{034}>"
Data " <tr>"
Data " <td width={034}136{034} height={034}246{034}>"
Data " <div align={034}center{034}>"
Data " <table border={034}0{034} cellspacing={034}1{034} width={034}136{034}
height={034}238{034} bordercolorlight={034}#000000{034} "
Data " cellpadding={034}3{034} bordercolordark={034}#000000{034} bgcolor={034}#000000{034}>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#225AD9{034}>"
Data " <p align={034}center{034}><font color={034}#FFFFFF{034}
face={034}Arial{034} size={034}2{034}>"
Data " <b>Links to WIZ610wi</b></font></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#ECE9D8{034}>"
Data "<a href={034}https://www.benshobbycorner.nl/bzijlstra/software/examples/wiz610wi.htm{034}>Ben
Zijlstra</td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#ECE9D8{034}>"
Data "<a href={034}https://www.six1.net/index.php?option=com_virtuemart&page="
Data "shop.browse&category_id=17&Itemid=76&lang=de{034}>six1 shop</td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#ECE9D8{034}>"
Data "<a href={034}https://www.mcselec.com/index2.php?option=com_forum&Itemid=59&page=viewtopic&t=9410{034}>Topic
at MCS Forum</a>"
Data "</td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}128{034} height={034}34{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " </table>"
Data " </div>"
Data " </td>"
Data " <td width={034}514{034} height={034}612{034} rowspan={034}3{034}
valign={034}top{034} bgcolor={034}#FFFAF0{034}>"
Data " <p align={034}center{034}><b><font size={034}5{034}>Webserver
with WIZ610wi</font></b></p>"
Data " <p align={034}left{034}>This is the Story about the WIZ610wi WIFI
Modul"
Data " and Ben and myself.<br>One Day, Ben send me a FREEDUINO (Arduino
with diecimila M168)."
Data "<br>I never worked with an ARDUINO Board before. First thing was,
to burn the MCS Bascom Bootloader"
Data "on it :-) So it's quite easy to programm the ARDUINO from Bascom.
One thing to the Hardware of FREEDUINO:<br>"
Data "There is a C (CRS) wich is used, to reset the M168 from DTS. This
is not a good Solution! Better change this"
Data "C (100nf) with R470. In Bascom you select MCS Bootloader and RESET
BY DTS.. Works fine!"
Data "<br><br>The Webserver is running by now, but we are testing the
Setup as WIFI Client."
Data "WIZ610wi is connected on Software Serial to ATMega168 with
38400Bd. So the Webserver isn't that fast."
Data "But it is fast enough to switch Ports or do tiny Applications!"
Data "<br>There are some Problems to solve, before publishing a stable
Code!"
Data "</b></p>"
Data " <p align={034}left{034}><b> </b></p>"
Data " <p align={034}center{034}>"
Data " <img src={034}https://www.benshobbycorner.nl/hobbycorner/images/wiz610wi/conf_mode.jpg{034}
width={034}300{034}></p>"
Data " <p align={034}center{034}> </p>"
Data " <p align={034}left{034}><b> </b></p>"
Data " <p align={034}center{034}><font size={034}4{034}>little
Playground :-)</font></p>"
Data " <p align={034}center{034}><span id={034}led1{034}></span> "
Data "<button onclick={034}ajaxObj=new XMLHttp("
Data "{039}led.ax{039},{039}led1{039});{034} style={034}cursor: pointer;
cursor: hand;{034}>Switch LED</button>"
Data "</p>"
Data " <p align={034}center{034}> "
Data " <p align={034}center{034}> "
Data " <p align={034}center{034}><font size={034}3{034}>"
Data "<span id={034}clicks{034} onclick={034}ajaxObj=new XMLHttp"
Data "('clicks.ax','clicks');{034} style={034}cursor: pointer; cursor:
hand;{034}> Site Counter (click for update! AJAX Request!)</span>"
Data " <br>"
Data " <p align={034}center{034}><font size={034}2{034} face={034}Arial{034}>Above
Samples are made with AJAX Requests. "
Data "So there is no need to reload whole Page!</font></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}136{034} height={034}136{034}>"
Data
" <div align={034}center{034}>"
Data " <table border={034}0{034} cellspacing={034}1{034} width={034}136{034}
height={034}132{034} bordercolorlight={034}#000000{034}"
Data " bordercolordark={034}#000000{034} bgcolor={034}#000000{034}>"
Data " <tr>"
Data " <td width={034}128{034} height={034}128{034} bgcolor={034}#ECE9D8{034}>"
Data " <p align={034}center{034}><img src={034}https://www.benshobbycorner.nl/hobbycorner/images/wiz610wi/"
Data "WIZ610wi.jpg{034} width={034}125{034}></td>"
Data " </tr>"
Data " </table>"
Data " </div>"
Data " </td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}136{034} height={034}230{034}>"Data " <div align={034}center{034}>"
Data " <table border={034}0{034} cellspacing={034}1{034} width={034}135{034}
height={034}230{034} bordercolorlight={034}#000000{034} "
Data "bordercolordark={034}#000000{034} bgcolor={034}#000000{034}
cellpadding={034}3{034}>"
Data " <tr>"
Data " <td width={034}127{034} height={034}32{034} bgcolor={034}#225AD9{034}>"
Data " <p align={034}center{034}><font color={034}#FFFFFF{034}
face={034}Arial{034} size={034}2{034}><b></b></font></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}127{034} height={034}33{034} bgcolor={034}#ECE9D8{034}></a></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}127{034} height={034}33{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}127{034} height={034}33{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}127{034} height={034}33{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}127{034} height={034}33{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " <tr>"
Data " <td width={034}127{034} height={034}33{034} bgcolor={034}#ECE9D8{034}></td>"
Data " </tr>"
Data " </table>"
Data " </div>"
Data " </td>"
Data " </tr>"
Data " </table>"
Data " </center>"
Data "</div>"
Data ""
Data "<div align={034}center{034}>"
Data " <center>"
Data " <table border={034}0{034} cellspacing={034}1{034} width={034}675{034}>"
Data " <tr>"
Data " <td width={034}667{034}>"
Data " <p align={034}center{034}><b><font size={034}2{034} face={034}Arial{034}>six1
2/2011</font></b></td>"
Data " </tr>"
Data " </table>"
Data " </center>"
Data "</div>"
Data "</body>"
Data "</html>"
Data "%END%"
404:
Data "<!DOCTYPE HTML PUBLIC {034}-//IETF//DTD HTML 2.0//EN{034}>"
Data "<html><head>"
Data "<title>404 Not Found</title>"
Data "</head><body>"
Data "<h1>Not Found</h1>"
Data "<p>The requested URL was not found on WIZ610wi Server.</p>"
Data "<hr>"
Data "</body></html>"
Data "%END%"
|