Wiznet WIZ110SR

botronics

New Member
Trying post #12 would have saved some time...
I tried the post in #12 and I always got a blank page. I just went back to it just now and added a CRLF after the header. That made it work. I didn't learn about that till later. If everything always worked, we wouldn't learn anything.
 

botronics

New Member
Incrementing Variable

Having looked at the WIZNET manual it seems there is no option but to let the browser know the size of data so it displays then tells the WIZNET to close the connection, or have the WIZNET timeout and close after sending the data then the browser hopefully displays what it has received when it sees that close.

What works may depend on the browser. I have a Kodak picture frame that pulls images over the net and that doesn't work unless it is told exactly how much data is being sent with a Content-Length header. Simply having the server close the connection, actively or on timeout, isn't enough to make it work.

The good news is that you should be able to make it work.

Added : Coss-posted, and it seems it does work ! Try taking out the Content-Length line and seeing if it works when using a WIZNET timeout. If so that will probably make things much easier, allow you not to have to worry about how much data you are sending back.

Extra added : And try this ( the rest the same ). It will help let you see if pages are being cached or not ...

SerOut b.4,T1200_4,( "<html><body>Yay-",#b9,"</body></html>")
b9 = b9 + 1 // 10
I added the extra lines. Every time I reload, the count goes up. Shows HelloYay-<b9 value>. This means a new page is loaded with a new value for b9. This is nice.

Code:
'picaxe server
'picaxe 14m2 and Wisnet110SR (timeout 1 sec enabled)
'cachetest.bas


settle:
low B.1
pause 1000

readport:
serin c.1, T1200_4,("GET /"),b1
sertxd ("b1= ",#b1,13,10) 'optional diagnostic port
if b1 = 49 then 'got a "1"
gosub header1
end if
goto readport
 
header1:

SerOut b.4,T1200_4,( "HTTP/1.1 200 OK",13,10 )
SerOut b.4,T1200_4,( "Content-Type: text/html",13,10 )
SerOut b.4,T1200_4,( 13,10 )
SerOut b.4,T1200_4,( "<html><body>Hello</body></html>" ) 
SerOut b.4,T1200_4,( "<html><body>Yay-",#b9,"</body></html>")
b9 = b9 + 1 // 10 

high B.1 'click relay on/off
pause 500
low B.1

return


end
 

botronics

New Member
Code for Control-by-Web

Code for controlling 3 relays, read 4 inputs and read temperature in F. You start out by going to your own URL and port/0. A webpage will come up allowing control of 3 relays, read inputs and temperature. The webpage is fully generated by the picaxe. You will of course, need to create your own link/port and add it to the code marked "YourURLhere". Added is a photo of what the webpage generated by the picaxe looks like.

Schematic here:
View attachment webcontrol.pdf

Code:
'webcontrolHTML.bas
'picaxe program to control a single relay
'picaxe 14m2 and Wisnet110SR with 1 sec timeout
'1613 bytes out of 2048
'Use HTTP 1.1 

'Relays:
'B.1 relay 1
'B.2 relay 2
'B.3 relay 3

'Inputs:
'J3-1 C.0
'J3-2 C.2
'J3-3 C.3
'J3-4 C.4

'Temperature:
'B.5 

'Serial Ports
'Serin C.1
'Serout B.4

input c.0
input c.2
input c.3
input c.4


settle:
low B.1
pause 1000


readport:
serin c.1, T1200_4,("GET /"),b1

header: 'response header
SerOut b.4,T1200_4,( "HTTP/1.1 200 OK",13,10 )
SerOut b.4,T1200_4,( "Content-Type: text/html",13,10 )
SerOut b.4,T1200_4,( 13,10 )

sertxd ("b1= ",#b1,13,10) 'optional diagnostic port

if b1 = 48 then '0

goto printhtml

endif


if b1 = 49 then '1

goto on1

endif

if b1 = 50 then '2

goto off1

endif

if b1 = 51 then '3

goto on2

endif

if b1 = 52 then '4

goto off2

endif

if b1 =53 then '5

goto on3

endif

if b1 = 54 then '6

goto off3

endif

if b1 = 55 then '7

goto inport

endif

goto readport
 
 
on1:
high B.1
b2=1
goto printHTML


off1:
low B.1
b2=0
goto printHTML


on2:
high B.2
b3=1
goto printHTML


off2:
low B.2
b3=0
goto printHTML


on3:
high B.3
b4=1
goto printHTML


off3:
low B.3
b4=0
goto printHTML


printHTML:

serout b.4, T1200_4,("<!DOCTYPE html><html><body>",13,10)

serout b.4, T1200_4,("<h1>PICAXE WEB SERVER</h1><br>",13,10)

serout b.4, T1200_4,("<b>SELECT RELAY TO CONTROL<br>",13,10)

serout b.4, T1200_4,("<a href=http://YourURLhere:port/1>Relay1 ON</a><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/2>Relay1 OFF</a><br><br>",13,10)

serout b.4, T1200_4,("<a href=http://YourURLhere:port/3>Relay2 ON</a><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/4>Relay2 OFF</a><br><br>",13,10)

serout b.4, T1200_4,("<a href=http://YourURLhere:port/5>Relay3 ON</a><br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/6>Relay3 OFF</a><br><br>",13,10)



serout b.4, T1200_4,("<b>RELAY STATUS<br>",13,10)


if b2 = 1 then

serout b.4, T1200_4,("RELAY1=",#b2,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)

endif

if b2 = 0 then

serout b.4, T1200_4,("RELAY1=",#b2,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)

endif

if b3 = 1 then

serout b.4, T1200_4,("RELAY2=",#b3,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)

endif

if b3 = 0 then

serout b.4, T1200_4,("RELAY2=",#b3,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)

endif

if b4 = 1 then

serout b.4, T1200_4,("RELAY3=",#b4,"<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)

endif

if b4 = 0 then

serout b.4, T1200_4,("RELAY3=",#b4,"<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)


endif


Inport:

SerTxd (#pinc.0,#pinc.2,#pinc.3,#pinc.4,13,10)

'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("<b>READ INPUTS<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input1=",#pinc.0,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input2=",#pinc.2,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input3=",#pinc.3,"<br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("Input4=",#pinc.4,"<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)


Ftemp:
Readtemp12 b.5,w0                                 ' read in result ds18b20

convert:
w0 = w0+880/16*9/5-67                                    
  let b9 =43                                      ' Display + (43) space (32)
IF w0 > 65468 THEN                                ' If negative                              
  let b9 =45                                      ' Display - (45)
w0 = -w0                                         
endif                                
                                          
BINTOASCII w0,b8,b7,b6 
IF b8 = "0" THEN : b8 = " ": endif                      ' zero blanking b8
IF b7 = "0" THEN : b7 = " ": endif                      ' zero blanking b7
 

printtempF:
'SERTXD ("tempF=",b9,b8,b7,b6,13,10)'resolution to 1
serout b.4,T1200_4, ("<b>Temperature " ,b9,b8,b7,b6," F<br><br>",13,10)
'serout b.4, T1200_4,("<br>",13,10)
serout b.4, T1200_4,("<a href=http://YourURLhere:port/0>Reload this Page</a></body></html>",10,13)
goto readport 


end
 

Attachments

Last edited:

Hemi345

Senior Member
You should probably have a diode shunt across legs 1 and 3 of U3 since you have the option of supplying 5V thru JK1.
 

botronics

New Member
You should probably have a diode shunt across legs 1 and 3 of U3 since you have the option of supplying 5V thru JK1.
Only a problem if the output of the regulator is 7 volts or more (TI uA7800 series). If I plan to bring in 5 volts at JK1, I would leave the regulator out. If you plan to run the wiznet off jk1, a heat sink is needed. I probably could squeeze in a diode on the pcb just to be safe.
 
Last edited:

matherp

Senior Member
botsmaker

I'm trying to replicate this great piece of work but can't get anything to display in a browser.

I've set up the serial ethernet as a TCP server on port 80. I can connect to it using telnet (hyperterm) and if I send it a string such as "GET /1" it responds with the expected html string which I have cut and paste below.

However, if I use a browser (I've tried IE9 and CHROME) the ethernet adapter receives the get command properly and sends it to the picaxe which outputs it using sertxd, the picaxe also outputs to the ethernet serial adapter exactly the same as when I'm using telnet but I'm getting nothing displayed on the browser. I'm obviously missing something. Was there any setting you needed to use in the browser to get it to accept the incoming data?

All ideas appreciated

Thanks

Peter
Code:
HTTP/1.1 200 OK
Content-Type: text/html

<!DOCTYPE html><html><body>
<h1>PICAXE WEB SERVER</h1><br>
<b>SELECT RELAY TO CONTROL<br>
<a href=http://YourURLhere:port/1>Relay1 ON</a><br>
<a href=http://YourURLhere:port/2>Relay1 OFF</a><br><br>
<a href=http://YourURLhere:port/3>Relay2 ON</a><br>
<a href=http://YourURLhere:port/4>Relay2 OFF</a><br><br>
<a href=http://YourURLhere:port/5>Relay3 ON</a><br>
<a href=http://YourURLhere:port/6>Relay3 OFF</a><br><br>
<b>RELAY STATUS<br>
RELAY1=1<br>
RELAY2=0<br>
RELAY3=0<br><br>
<b>READ INPUTS<br>
Input1=0<br>
Input2=0<br>
Input3=0<br>
Input4=0<br><br>
<b>Temperature + 32 F<br><br>
<a href=http://YourURLhere:port/0>Reload this Page</a></body></html>
 
Last edited:

g6ejd

Senior Member
Your HTML reponse file looks OK, so assuming the Ethernet is receiving the stream OK, then I suspect an IP address : port issue. Have you tried pinging your IP address?

Have you checked for address conflicts on your router?

I have had simialr problems, mostly to do with the Browser, but you've tried another so unlikely. It's odd.

If you copy your copy as above, then paste it into an html file, does your browser display the page? It partially displays OK on my browser, it's the first line that shows some malformation, but otherwise OK.
 
Last edited:

Hooter

Senior Member
Silly question - but where the code says 'YourURLhere:port' - you have actually inserted your IP address and port number?
 

hippy

Ex-Staff (retired)
I'm trying to replicate this great piece of work but can't get anything to display in a browser.
Start with a simpler page response, note HTTP/1.0, and make sure the WIZNET timeout is set so the connection is closed after the page is sent.

SerOut ... ( "HTTP/1.0 200 OK", CR, LF )
SerOut ... ( "Content-Type: text/html", CR, LF )
SerOut ... ( "Content-Length: 31", CR, LF )
SerOut ... ( CR, LF )
SerOut ... ( "<html><body>Hello</body></html>" )
 

Hooter

Senior Member
Has anyone managed to get the serial comms to work on 4800 bd? I have it running on 1200 and 2400 but ceases to work on 4800.
Both the Picaxe and Wiznet are set at 4800.

Cheers
 

Hemi345

Senior Member
I read in another thread that if you increase the frequency of the PICAXE to 8mhz or 16mhz (can't recall atm) it helps.
 
Another example.

I've been fooling around with a WIZ110SR and botsmaker's code. Here is what I came up with for testing.

View attachment PicaxeWeb.bas

It's pretty rough but serves as a good starting point for me, and hopefully others.

Here's what it looks like in Firefox and IE:
WebInterface.jpg
 
Last edited:
US$30 PICAXE &quot;Web Server&quot;

Here is the program from my previous post but without the code for the DS1307, auto-refresh, or data-only mode. This reduced size version of a US$30 PICAXE "Web Server" should be simpler to follow and easier to modify. Also, this one uses CSS to format the text (including the text 'dots' representing the LEDs) and will likely result in smaller code size once you expand it to do something besides turn a couple LEDs off and on and read an LDR.

I also tried it with links to images on a public server which represented the LEDs in the ON and OFF state (instead of the text dots), included a PICAXE logo and other images. By linking to images on a public server, the page can be made much more interesting without having to store and serve up the images, etc. through the PICAXE. You can just save them on the public server and link to them with the picaxe code.

For $29.95 (from sparkfun) it was too hard for me to resist.

Here is what the web interface looks like now:
SmallWebInterface.jpg

Here is the code:
View attachment PicaxeWebSmall.bas
Don't forget to change lines 84-88 to match the IP address and port of your WIZ110SR before programming your picaxe.
 

beb101

Senior Member
Nice work, vectorspace ...

I just bought a WIZ105SR with a 3.3V LVTTL serial interface and wanted to try your code.
Unfortunately, this module has a 2 x 6, 2mm pitch pin header and it's very difficult to find
a companion female socket to make a cable. The normal 0.1" female jumper wires are too large.
 

Hemi345

Senior Member
vectorspace, you can save a little program space and complexity by not referencing the URL/IP address in the anchor tags. For example, using:
Code:
serout serTx, T19200_64,("<a href=",34,"/5",34," class=",34,"off",34,">&#9679;</a><br>",CR,LF)
[\code]

is sufficient.  It's how I'm handling most hyperlinks on mine with a 14M2.  I'm using a remote javascript file in addition to a remote stylesheet.  I've moved most of the markup to that with very little needing to reside in the small program space of the 14M2.

beb101, that was the main drawback for myself buying the 105 vs the 110.  I figured if I did get it, I would probably just use female-to-male jumper wires to connect it up.  Here's a [url=http://www.mouser.com/ProductDetail/Hirose-Connector/DF11-12DS-2R2605/?qs=sGAEpiMZZMs%252bGHln7q6pm7BjqI3J1T15T6RCNzHri%252bE%3d]connector that is 2mm spaced[/url] but after a quick glance at the datasheet, it is unclear whether a special tool is needed to crimp the wires in it.
 
Last edited:

beb101

Senior Member
Thanks for the part link, Hemi345. I think you are right about the special tool. The connector looks
like the one on Wiznet cable sold with the SR105 evaluation kit.

Mouser and DigiKey both carry the Molex through-hole part (79107-7005), but it has a long
backorder time.

http://www.mouser.com/Molex/Connectors/_/N-5g3yZ1z0zlew?Keyword=79107-7005

I have a couple of female to female wires that have a connector that is only slightly larger than
the wire and they fit on the pin header side by side, but I can't remember what they are called in
order to search for them. I originally bought a package of them at Frys in Los Angeles in the oscilloscope
section.
 

Hemi345

Senior Member
What about this part:
http://www.mouser.com/ProductDetail/Molex/79107-7055

Do you have a pic of those connectors from Fry's?
 
FANTASTIC Hemi345! :D What an elegant simplification.

That simplifies the program immensely. Not only is the code smaller but there is no need to put any IP address or port # in it at all!

THANKS!
 

beb101

Senior Member
@Hemi345
The wires are about 13" long and they have heat shrink on each end that extends to the very
tip of the female socket. I think they are custom made. I ordered some of these 2mm crimp
sockets so it should be possible to duplicate them.

http://www.mouser.com/ProductDetail/Molex/39-00-0289/?qs=sGAEpiMZZMuzXLcWrSfMryrO71U79m5u1xwrQDEEYIk=

The 12 pin socket that you referenced (7055) is in stock and is what I was looking for in the first place.
It appears identical to the one I found (7005) which is 10 weeks backordered ... thanks.

Cable.jpg
 

Hemi345

Senior Member
beb101, I was just placing an order for furnace filters from Amazon.com and saw these in my wishlist:

http://www.amazon.com/Gino-2-0mm-Double-Female-Headers/dp/B00899WM6O/ref=sr_1_3?s=electronics&ie=UTF8&qid=1361925847&sr=1-3&keywords=gino+2mm+header+strips

I must have bookmarked those when I was considering the 105SR. haha

Vectorspace, glad that helped. I am really trying to condense my code down so I could pack as much into the program space as I can. I'm in the process of adding a connection between my humdistat project and my PICAXE webserver to see the status of it, so I'm also using another method for hyperlinks:

Code:
serout serTx, T19200_64,("<script type=",34,"text/javascript",34," src=",34,"http://code.jquery.com/jquery-latest.min.js",34,"></script>",13,10) ;link to current jQuery API
serout serTx, T19200_64,("<link type=",34,"text/css",34," rel=",34,"stylesheet",34," href=",34,"[my remote website URL]/picaxe.css",34,">",13,10) ;my remote stylesheet
...
buildDiv:                    ;op = On or Off, urlID = 1 thru 9
    serout serTx, T19200_64,("<div class=",34,#op,34," id=",34,#urlID,34,"></div>") ;this is the object that is clickable, the id value is used for the hyperlink
    return
...
serout serTx, T19200_64,("<script type=",34,"text/javascript",34," src=",34,"[my remote website URL]/picaxe.js",34,"></script>") ;my remote javascript file
the remote picaxe.css stylesheet defines the "on" class so the div is center aligned, has a nice "power switch" image that looks like it's lit up green, and the cursor changes to a hand to indicate it's something clickable.

Code:
.on {
    background-image: url([my remote website URL]/graphics/power_on.png);
    width: 20px;
    height: 20px;
    cursor:pointer;
    margin:0 auto;
}
Then in the remote picaxe.js script, I have a function that looks at the ID field and uses it to redirect the browser with that value appended:

Code:
  $('.on').click(function(e) {
	var currentId = "?" + $(this).attr('id'); //snag the id value to use for the URL
	//alert(currentId);  //popup box for debugging;
        window.location = currentId; //redirect browser with id value appended
  });
Ofcourse, this all relies on having a web accessible location to store the stylesheet and javascript file.
 
Top