View previous topic :: View next topic |
Author |
Message |
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Tue Apr 01, 2014 8:38 pm Post subject: Webserver HTML POST function |
|
|
Hello, i have the simple webserver. The program waits for POST data and then it compares received string. The problem is that if i push button the program halts on function TCPREAD. If i push stop button on my web browser, the program continues. Could you help ?
Code: |
Tempw = Tcpread(i , S)
print s ' read a line
If Left(s , 3) = "GET" Then
Bcmd = 1
Gosub Page
ELSEIF Left(s, 4) = "POST" Then
Bcmd = 3
ElSEIF Left(s , 15) = "Content-Length:" Then ' for post
S = Mid(s , 16) : Bcontent = Val(s)
End If
Loop Until S = "" ' wait until we get an empty line
Tempw = Tcpwrite(i , "HTTP/1.0 200 OK{013}{010}")
If Bcmd = 3 then
Tempw = Tcpread(i , s , Bcontent)
'
Select Case s
Case "ALL_OFF=OFF"
Portc.0 = 1
PORTC.1 = 1
PORTc.2 = 1
PORTc.3 = 1
Case "ALL_ON=ON"
Portc.0 = 0
PORTC.1 = 0
PORTc.2 = 0
PORTc.3 = 0
End SELECT
Shtml = "/ovladanie.html"
End If
|
|
|
Back to top |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Tue Apr 01, 2014 9:04 pm Post subject: |
|
|
which wiznet chip do you use?
tcpread, used with a string expects a cr+lf.
when the server does not send it, the functions keeps waiting.
I would advise to first analyze the data you receive from the server. you can do this by using tcpread with a byte array. then dump the data (the hex values).
firefox also has some great tools build in like a webconsole. _________________ Mark |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Tue Apr 01, 2014 9:15 pm Post subject: |
|
|
I use Wiz820io. I cannot paste entire code because my web browser shows a error.
Edit: I understand. Thanks a lot. |
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Tue Apr 01, 2014 10:41 pm Post subject: |
|
|
Note with a POST you do not get CRLF at the end of the data in the buffer.
Regards Paul |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Wed Apr 02, 2014 7:19 am Post subject: |
|
|
Okay, thanks |
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Wed Apr 02, 2014 4:36 pm Post subject: |
|
|
Hello, Could you correct me ? I cannot to get complet string. The code below gets string AL_OFF=OFF instead of ALL_OFF=OFF
Code: |
If Bcmd = 3 then
D = ""
Tempw = Tcpread(i , Buf(1) , Bcontent)
for x = 1 to Bcontent
S = chr(buf(x))
D = D + S
Next
Print D '
Select Case D
Case "ALL_OFF=OFF"
Portc.0 = 1
PORTC.1 = 1
PORTc.2 = 1
PORTc.3 = 1
Case "ALL_ON=ON"
Portc.0 = 0
PORTC.1 = 0
PORTc.2 = 0
PORTc.3 = 0
End SELECT
Shtml = "/ovladanie.html"
End If |
|
|
Back to top |
|
|
bibibo
Joined: 30 Nov 2009 Posts: 168
|
Posted: Wed Apr 02, 2014 5:41 pm Post subject: |
|
|
So, i solved my problem but i do not understand why variable S contains received string.
Code: |
If Bcmd = 3 then
Tempw = Tcpread(i , Buf(1) , Bcontent)
Bcontent = Bcontent + 1
Buf(bcontent) = 0 ' put string terminator at end of data so we can handle it as a string
Print S
'Print D '
Select Case S
Case "ALL_OFF=OFF"
Portc.0 = 1
PORTC.1 = 1
PORTc.2 = 1
PORTc.3 = 1
Case "ALL_ON=ON"
Portc.0 = 0
PORTC.1 = 0
PORTc.2 = 0
PORTc.3 = 0
End SELECT
Shtml = "/ovladanie.html"
End If |
|
|
Back to top |
|
|
Paulvk
Joined: 28 Jul 2006 Posts: 1257 Location: SYDNEY
|
Posted: Thu Apr 03, 2014 2:29 am Post subject: |
|
|
Hello bibibo
S contains received string because buf() is overlayed on to it, thus it breakes up the variable S into single bytes.
The Overlay function in Bascom is a very usefull and powerfull one it is good to learn what it does and how to use it as it saves a lot of code.
Regards Paul |
|
Back to top |
|
|
|