Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Build a Webserver with ENC28J60 +AVR
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog
View previous topic :: View next topic  
Author Message
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Wed Nov 16, 2011 12:06 pm    Post subject: Build a Webserver with ENC28J60 +AVR Reply with quote

An update to this first post at the top:-

You will find in the posted code a lot of methods to use data in eeprom & flash, the program is now very large with many sub routines that can be cut and pasted into your own code to do various tasks there is a RS232 command line which can be used to communicate with the avr, various ways of decoding information sent to an avr and many more these can be put to work in many projects!


Now working along with the 74HC595s and the clock I wanted an AVR to set the time from the Network Time Protocol so needed a server to do this first I have another project that uses a DSPIC this works but it is very hard to change the way it works firstly because I do not use the C language (C = Latin for most people) and second there is just so much C program.

Now Ben Zijlstra wrote a tutorial on the ENC28J60 and the Mega8 a long while ago to which Viktor Varga sent some more code to Ben who added it. Now Thomas Heldt liked this and added lots more to it but it is in German so I thought I would use this, change it into english, put it on my own hardware, modify it to suit my needs and change the micro to a mega1284p as it has 128K flash, 4Keeprom, big 16K of ram and runs at 20mhz.

I then thought why not put it all up here including the circuit and board files (in KiCad a free program that all can use). At present I have a prototype board with a m644p (20mhz), rs232, LCD, SD socket (not yet fitted) on it which is working very well! It will make a great little automation device I intend to make the final boards surface mount and small but hand solderable no real little stuff.

Wrote to Thomas and Ben who said ok to put up the code.

Thus far I have changed most of the german to english, found a problem with the soft clock stopping the LCD from working (yet to get working) , the NTP also needs work.

As this is a blog the intent is to show the work as it goes along so I have put the code up thus far.


Last edited by Paulvk on Mon Jan 09, 2012 1:07 pm; edited 1 time in total
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Mon Nov 21, 2011 12:46 pm    Post subject: CIRCUIT DIAGRAM Reply with quote

Here is the circuit diagram of the prototype

Notes:

The AP1117D is a low drop out voltage regulator and requires heat sink

The TXB0104D is a level converter for the 5V to 3.3V

The 25AA02E48 contains a MAC address that should not be used by other manufactures

I have not yet installed the SD card, level converter or 25AA02E48.

Have not posted a PCB yet the prototype had a 3 errors.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Fri Nov 25, 2011 10:58 am    Post subject: Reply with quote

Have been working on the RS232 commands added the ability to change the IP addresses and MAC numbers they are now stored in EEPROM also adding a lot of constants in an effort to make it easy to change the language of at least the RS232 commands and by using the SPLIT function the length of them will not matter as long as they fit into the variable. Left some print commands in that show what is comming into the server as commands from the TCPIP.

Passed the 50% of flash still have 1817 of RAM left and 2763 lines (including space and comments).
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Sun Nov 27, 2011 12:13 pm    Post subject: Reply with quote

After adding the ability to change the settings via RS232 I wanted to also be able to do this on a web page so I first built a page to display the servers IP address made some code to substitute the data into the page as it was read from flash and this worked great. I then made another page for server MAC address I then thought why not make one for it all this sounds great but then I thought five pages one for each takes too much flash and one page for all will still take a large chunk then down the track maybe some other inputs more pages, there has to be a better way well I think I have found one!
I built a common page that has a box to display the present value and another input box to put in the new value and a button to send it. Now contained in the page is some special text "CHANGE01", "CHANGE02" and so on this gives me 100, when it is being sent out the program comes accross these then substitutes the wanted HTML so now I have a generic input page for all the server settings. Thinking about how you make the pages and making them common in their data you may get away with even just one page by using this method.

Code is below showing this in action I made some '---------------- comments to make them easy to find the HTML page is Servcom_html
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Mon Nov 28, 2011 11:43 am    Post subject: Reply with quote

Ok it was hot outside today so came inside and changed a lot of code from things like

IF THEN
ELSE IF
THEN
and a lot of IF THEN
xxxxxxxxx
END if

Changed these to SELECT CASE and this eventually saved 840 bytes but most of all made the code much clearer and it is obvious where to add more CASE statements and not have to worry about the END IFs

Now leading from my previous post I can see where I can get rid of another web page in the flash data statements so thats next.

So here is the updated code
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Wed Nov 30, 2011 6:49 pm    Post subject: Thanks for sharing Reply with quote

Thanks for sharing.

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Thu Dec 01, 2011 11:03 am    Post subject: Reply with quote

Thank You Ben for the ENC28J60 code!!!!!!!!!!

I am now implimenting full dynamic web pages the Index.html no longer exists it is generated from a common menu page which can be used over and over all that needs to be added for more is some case statements these need only be references to a HTML page for the hyperlink and the words that become the link. This also means that with constants or even variables from EEPROM the language can be changed after the code is written into the flash just up load the new words to the EEPROM using a web page or the RS232 command line!

The basic menu has 6 entries which could then generate another page with another 6, as many as you need just add case statements. Added a bit of colour to the menu (this could also be made to change look into that later). Working on a new dynamic input page it is included but not implimented yet. Removed some of the old replaced code to make it easyer to read and work on you can still see it in the older versions.
Have decided on making a surface mount board like the wiznet web board but using the ENC28J60 and a Mega1284 ( running 5volts so we can use 20Mhz) will have them made by a comercial company so should have some spares for anybody that wants them this will have to wait till next year want to keep working on the code on the prototype before spending time on board design.

Ok here is the latest code
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Fri Dec 02, 2011 12:19 pm    Post subject: Reply with quote

The input page is now working you can use the Server Settings Page to go to various settings and watch what you input printed to the serial port. This means you could control other devices via the serial port. Note that there are limitations on characters used as some will be changed by the browser so you need to select ones that are not!

Note settings are not yet changed via web will combine this with the RS232 soon.

Found more code that could be done by a For / Next and replaced about 24 lines of code with 4 still more to be done in other parts.



Here is the codeup till now..
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Dec 02, 2011 12:27 pm    Post subject: INSTR with search for /GET Reply with quote

Paul

There is also a part I have put in with a search for /GET
It can be replaced by INSTR
Now it looks a bit strange, going through a string with a step, it is working, but I think with INSTR easier.

Have fun
Ben Zijlstra

P.s. Any pictures of the hardware?


Last edited by bzijlstra on Fri Dec 02, 2011 11:59 pm; edited 1 time in total
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Fri Dec 02, 2011 11:39 pm    Post subject: Reply with quote

Ben

They were the 24 lines I replaced where the program did 12 increments of a variable one after the other I also thought why not INSTR but for the now just removed the 24 lines to come back to it later as there are other changes that I am working on that may mean doing it diffrently and with the M1284 one was why not just get the whole lot out of the buffer as one string and work on it since there will be plenty of RAM for big variables.

I made 2 more pages to go on the sever one is just a table with 2 cells one for a hyperlink the other large cell for text this one is a general information page the other page has 2 cells in one table for hyperlinks and 16 cells 2 rows of 8 for use with inputs/outputs should have these working soon and will get rid of all the old pages from Thomas so now all are dynamic and re-useable.


Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Fri Dec 09, 2011 12:45 am    Post subject: Reply with quote

Ok I have now got to the point where I have added these functions --

Dynamic pages you can change via case statements.

Change of IP & MAC via RS232.

Dynamic input page to send commands to server via web-page.

and in this code.

Change IP & MAC via web-pages.

Program checks if IP/MAC is different value by value and only changes them if they are, if they all do not change it aborts and makes no changes.

I left the print commands that show via RS232 what we receive from the we-pages and how split breaks them up

Great command this split I have found many uses for it!!

NOTE ALSO that I am putting lots of comments in, not just for others to follow its also for me as the program is so large and will be a good reference when I do more project in the future.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Sun Dec 11, 2011 10:18 am    Post subject: Reply with quote

Done a lot more now

SUB to count commands that come from web

SUB to divide commands and data (for command) that come via web and put them is separate arrays to work with

SUB to print data to LCD

SUB that takes the data send via web browser and decodes it eg %27 is the hex value of & , this is how the characters that can not normally be used are sent.

Have replaced the find GET by looking for the space after the command then getting the rest of the buffer if needed which has another space at its end

Have begun to build the serial input output SUBs

Removing most of the code for old relay and digital inputs.

Still lots more to do.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1192
Location: SYDNEY

australia.gif
PostPosted: Mon Dec 12, 2011 12:44 pm    Post subject: Reply with quote

There is a small bug in the last lot of code where the decoding of the HEX from the browser sees the leading text as HEX have fixed this and when I post the next lot of code it will be ok.

Have been seeking a way to send more multiple pages without re-writing the ENC28J60 packet routine and I have found it. I have now begun to add Iframes to the dynamic page system so now we can display pages in pages, even pages in pages in pages so now we can display a number of menus on one page using Iframes. This limits the size of page sent by allowing one dynamic page to call for other dynamic pages which could also contain Iframes this gives three or more levels of complexity to the page that will be shown on the computer screen. The other useful thing that this does is it allows the header to be removed from all the pages (making them smaller) so that we just call the header and place the main menu (for example) in an Iframe saving more flash space!

I will have to clean things up before I post the next lot of code.
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Dec 12, 2011 1:01 pm    Post subject: Thanks!!! Reply with quote

Great work!! Thanks for sharing.
Back to top
View user's profile Visit poster's website
PaulC

Bascom Member



Joined: 09 Jan 2008
Posts: 122
Location: Ireland

ireland.gif
PostPosted: Mon Dec 12, 2011 7:38 pm    Post subject: Very nice project Reply with quote

Very nice project
thank you for sharing this with us

_________________
Bascom Avr 2.0.7.3
Works for me
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM Project Blog All times are GMT + 1 Hour
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum