Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Infomation on webserver with page on sd card

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
snow

Bascom Member



Joined: 28 Jun 2005
Posts: 212
Location: Ashburton / Mid Canterbury / New Zealand

newzealand.gif
PostPosted: Sat Apr 18, 2015 10:35 pm    Post subject: Infomation on webserver with page on sd card Reply with quote

Hello All.

I starting out playing around with a Freetronics EtherTen module. Basically Arduino UNO+ LAN+SD card on one board.
I have had a play with the webserver_SPI.bas sample and have got it running nicely on the module.

Where can i find help on having the webpages on the SD card and loading them up when required?

I know there is a fantastic amount of material in web servers on the MCS forums.Most are fairly complex for me to begin with. I'm starting to get information overload
Thanks
Snow

(BASCOM-AVR version : 2.0.7.8 )
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Apr 19, 2015 1:21 am    Post subject: Reply with quote

Hello snow

If you download my web server project do not look at it as one big bit of code look at the .INC files as bricks that make the whole project
these bricks can be used on their own this is the .INC that sends files from SD card
At the top you see Case Filetype you need to send this to the web browser so it knows what it should be displaying
You would need to make the 900s smaller as you do not have as much ram
The Parse_data .INC file looks at the request to find out what type of file is wanted
it also shows how to use a user name & password

The problem with having less than 8K of ram is that the web browsers send large lumps of data so you need to make use of
the buffer ram in the W5100 chip as you can only read small parts of it each time

I know how you feel I found it daunting at first it takes some time to get your head around this.

Keep asking questions and I will help all I can as will others.



Code:


'--Send_sd_data.inc
'*******************************************************************************
' send data from SD Card
'*******************************************************************************
Sub Sd_html()
   Local Fl As Long
   Local Wsize As Word

   Select Case Filetype
           Case 9 : Tempw = Tcpwrite(i , "Content-Type: image/gif{013}{010}")
           Case 12 : Tempw = Tcpwrite(i , "Content-Type: image/jpeg{013}{010}")
           Case 2 : Tempw = Tcpwrite(i , "Content-Type: application/x-javascript{013}{010}")
           Case 14 : Tempw = Tcpwrite(i , "text/css{013}{010}")
           Case Else : Tempw = Tcpwrite(i , "Content-Type: text/html{013}{010}")
   End Select

    Print "Ext=" ; Ext
    Print "send " ; Shtml ; " on Sock= " ; I

    Call Activate_sdcard()
      Fl = Filelen(shtml)
    Call Activate_wiz812

     #if Cdebug
      Print "size :" ; Fl
     #endif

     Locate 1 , 1
     Lcd "Size>" ; Fl

      Buffer = "Content-Length: " + Str(fl) + "{013}{010}"
      Tempw = Tcpwritestr(i , Buffer , 900)                 ' add additional CR and LF

      Call Activate_sdcard()
      Open Shtml For Binary As #4
      Do
          Call Activate_sdcard()
          If Fl > 900 Then                                  'send 128 Byte
             Get #4 , Buf(1) , , 900
             Fl = Fl - 900 : Wsize = 900
          Else
            Get #4 , Buf(1) , , Fl                          'send the rest
            Wsize = Fl : Fl = 0
          End If
          Call Activate_wiz812
          Tempw = Tcpwrite(i , Buf(1) , Wsize)              ' write data
          If Tempw <> Wsize Then
            Print Tempw ; " - " ; Wsize ; " written : error"       'when error
            Exit Do
          End If
      Loop Until Fl = 0
      Close #4
     Buffer = ""
End Sub
 
Back to top
View user's profile
snow

Bascom Member



Joined: 28 Jun 2005
Posts: 212
Location: Ashburton / Mid Canterbury / New Zealand

newzealand.gif
PostPosted: Sun Apr 19, 2015 10:44 am    Post subject: Reply with quote

Hello Paul.
Thanks you for the reply.
Ive got a bug that need to be sorted in the demo I'm running up.

When i query the module on a Iphone it seems to hang for a few seconds and up to a minute in some cases. So if i query it from another computer it times out.

On a PC with Chrome it seems to tick along nicely


I got a terminal listening to the print statements and it seem to hang between the
'done' and the 'CLOSED' statement in the continue remark

Code:



Continue:
               Print "closing socket"
               Socketdisconnect I                                               ' close the connection
               Print "done"   ----------------------------------------- Prints this
            End If
       Case Sock_close_wait
            #if Cdebug
                Print "CLOSE_WAIT"
            #endif
            Socketdisconnect I                                                  ' we need to close
       Case Sock_closed
            #if Cdebug
                Print "CLOSED"---------------------------------------hangs badly before it gets here
                Wait 1
            #endif
            I = Getsocket(0 , Sock_stream , 5000 , 0)                           ' get a new socket
            Socketlisten I                                                      ' listen
            #if Cdebug
                Print "Listening on socket : " ; I
            #endif
    End Select

 


This is in the webserver_SPI.bas sample W5100 folder

I thought i would like to get this corrected before i get any further

Thanks
Snow
Back to top
View user's profile
Paulvk

Bascom Member



Joined: 28 Jul 2006
Posts: 1257
Location: SYDNEY

australia.gif
PostPosted: Sun Apr 19, 2015 12:33 pm    Post subject: Reply with quote

The problem will be in the expected return to the browser.
I had to print the data the browser sent to a terminal to debug what was going on
You will probably see the browser sending the request multiple times looking for the correct reply.
You have to send the correct reply to the browser
Fire fox has a debug function that helps show errors that are returned.

I do not know what file you are sending back but start with a text or simple HTML file

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-AVR All times are GMT + 1 Hour
Page 1 of 1

 
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