Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Building a Webserver with a Wiznet W5100
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: 1111
Location: SYDNEY

australia.gif
PostPosted: Fri May 30, 2014 12:14 pm    Post subject: Building a Webserver with a Wiznet W5100 Reply with quote

In the share your working code section Ben posted a web server code example I had met with a bit of a dead end with the ENC28J60 web server not being able to send more than one packet so I decided to move my code to the Wiznet W5100 but something went wrong and the only way to move forward was to start from scratch adding code slowly to find out what went wrong. So why not document it here posting the code as I go then if all goes well every one will have the code for a versatile little web server or home automation server.

Some things to note from my experience with the ENC28J60.

1. You will need a lot of ram as the browsers send a lot of data (PCs and servers now normally have gigabytes) 8K is good but more is better so the M1284 with 16K is my choice

2. Arduino does not come in M1284 so I have made a board that takes the Arduino shields with a M1284 and will publish the files when it is tested fully

3. You need a high clock rate so again the 20Mhz M1284 is ideal

4. I am making it modular with the project mode of Bascom as it becomes impossible to manage due to its size.

Thus far I have written code that reads the whole buffer from the W5100 into a buffer on the AVR so that we can search it quickly , code to find the requested file and file type
so we can determine if a password is needed to see it , changed the sending of the file so that we make best use of the transmit buffer sending up to 900 bytes to it (this really sped up the display of the page)

I am using the Arduino MEGA2560 with the W5100 shield in the code below it is working, with a lot of print commands for debug and used almost half of the 8K of ram

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Sat May 31, 2014 1:21 pm    Post subject: Reply with quote

Now I have added the ability to read the network settings from the SD card its a simple text file and more settings will be added to it later.

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Mon Jun 02, 2014 11:48 am    Post subject: Reply with quote

Now I have added a transmit buffer of 1000 characters we can not use one buffer for both transmit and receive as we need to search the received request and build a response depending what was requested there is still 3546 bytes of the 8K of ram left so still ok. Also note the double speed bit is set for SPI not all AVRs support this, what this does is run the SPI buss at half the cpu clock so M2560 = 8Mhz & M1284 = 10Mhz

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Wed Jun 04, 2014 2:06 pm    Post subject: Reply with quote

Now a big step forward using the file extension cgi .

When we read a .cgi file it is read one byte at a time and we are looking for a byte value of 126 (~) this tells us that the two bytes that follow are a string of two characters that are a HEX number and we will replace the 3 bytes with a variable that can represent for example our IP Number , MAC address or the value of an ADC Chanel. By using a HEX number we can have up to 256 variables with just 2 bytes. So now by putting the text ~E0 in a .cgi file it will be replaced by our MAC address.
This lets us write web pages on the SD card with variables embedded in them. Note all other files without the cgi extension are read 1000 bytes at a time making it faster to send graphics files etc.

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Sat Jun 07, 2014 8:22 am    Post subject: Reply with quote

Now with some pages for the SD card that show the variables loaded from the settings file. There is basic.cgi and home.cgi you can change the user and password with the basic.cgi the other buttons are not yet implemented, the user & password are stored in EEPROM so this shows how to write to EEPROM using a web page.

Some things I want to add in the future:
1. Update firmware via web page
2. Update firmware via SD card
This has been done by others just have to integrate their examples.

4. Add my serial BUSS (74HC595s etc)
5. E-Mail alerts
6.Real time clock from NTP
7.Add command prompt on RS232

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Sun Jun 15, 2014 12:26 pm    Post subject: Reply with quote

I have made changes to the way the server works with the digital output port it responds to a post command with the data being DIO=X+STATE so to make port 0 to a 1 (high) the data in the post would be DIO=0+1 or DIO=0+Toggle to toggle the port this format simplifies the code as you get the port pin number from the data sent in the POST. Sub Decode does all the work using the Split command. The web page home.cgi has buttons on it to set the pins to a 1 , a 0 or to toggle the pin by making a web page with eight toggle buttons on it you would have an eight button remote control with a smart phone or pad. Note I have used port K on the M2560.

Regards Paul
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 535

germany.gif
PostPosted: Mon Jun 16, 2014 8:34 am    Post subject: Reply with quote

Hi Paul,
life can be so easy... have a look at WIZ200WEB Modul...
There is a lot of Code samples for it on this Board availible.

Advantage of WIZ200WEB is:
-ready made modul, no need to solder
-only needs 3,3V Supply for running
-serial Flash on board
-ATMega128
-W5300 with lot of RAM an 8 Channels

and more....

regards, michael

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Mon Jun 16, 2014 2:20 pm    Post subject: Reply with quote

Hello Michael

Yes I have two of them one problem is they are hard/expensive to get here in Australia, the ones I have are only 8Mhz , lots more ports on the 2560. Arduino boards are easy to get here and cheap. Then the M1284 has half the ram of the WIZ200WEB but runs at 20Mhz and I was building a Arduino shield compatible board to put it in. Eventually I will have it running on all of them just for the fun of it. The main thing is the web pages I already have which use flash objects that work with the server which I will post soon.

Regards Paul
Back to top
View user's profile
bzijlstra

Bascom Ambassador



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

netherlands.gif
PostPosted: Mon Jun 16, 2014 3:24 pm    Post subject: Well done - work on W5100... Reply with quote

Paul

Did not want to interrupt your blog.. I appriciate your work on the W5100.

Well done

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

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Tue Jun 17, 2014 12:36 am    Post subject: Reply with quote

Hello Ben
I appreciate input as I still have much to learn.
One of the problems with an AVR as a web server is that it can not run programs like an Apache server so the only way is to run in the browser so I am using Ajax, Javascript & Flash to do the work this makes it possible to have a very graphical display of an automation set up.
I hope to have this posted and working in a few days I already have it loading the Ajax & Flash just need to get the exchange of data between the two working fully.

Regards Paul
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 535

germany.gif
PostPosted: Tue Jun 17, 2014 7:51 am    Post subject: Reply with quote

Paul, you may have to think about the Problems you want to fix and if an AVR is the right "tool" to reach it...
An AVR for small Web Applications is ok. Javascript is possible but even if you are in front of big data, it isn't the right solution.

Acting as an apache server is neary impossible but can be made easy with different platforms like RASP or many other.

Lower your Claim in relation to ATMega or try different Hardware to reach goal Wink

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Wed Jun 18, 2014 12:51 pm    Post subject: Reply with quote

Now have the flash page loading and getting its data from the server at about one second intervals , the data is set at dummy values at the moment to test the page.

This is what the page looks like the meters will show the ADC values and the buttons will operate the digital outputs but are just for my testing at the moment.

Regards Paul
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 4761
Location: Holland

blank.gif
PostPosted: Thu Jun 19, 2014 10:04 am    Post subject: Reply with quote

it looks really nice.
_________________
Mark
Back to top
View user's profile Visit poster's website
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Thu Jun 19, 2014 12:55 pm    Post subject: Reply with quote

I can not lay claim to the flash meters I found them on the web but I did get them working with the small web servers, loading into a table and working with the Ajax. Note there are also digital meters, bar graphs, thermometers and some variations they are free to use. I am going to get all of them working if I can. The one addition to Bascom that would make a big difference to using SPI would be getting the second SPI port by using the SPI mode of the USART then we could have the SD card on one port and the Wiznet on the other no activating deactivating all the time.

Regards Paul
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1111
Location: SYDNEY

australia.gif
PostPosted: Mon Jun 23, 2014 10:12 am    Post subject: Reply with quote

Found the website for the gauges so here it is for those that might like to use them.

Demo page http://www.digitaldarknet.net/flash/

The down load page http://www.darkartistry.com/?page_id=51

Regards Paul
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