Using TCPIP client demo for sending and recive data from server.

Author
Pea5
New Member
  • Total Posts : 17
  • Reward points : 0
  • Joined: 2012/01/11 04:05:26
  • Location: 0
  • Status: offline
2013/07/07 05:32:46 (permalink)
0

Using TCPIP client demo for sending and recive data from server.

Hi everybody, I am using TCPIP client demo for sending data on serwer. To send data I am using GET, for example:
static BYTE ServerName[] ="www.pea5.cba.pl";
static ROM BYTE RemoteURL[] ="/?data=17";

On the www.pea5.cba.pl I have got a simple script in php:
<?php
$test= $_GET['data'];
echo $test;
?>
So The script create a echo answer to my uP. But I have got a problem with receive data from serwer. I have no idea how to do it. Of course I can download all source of web page (the same as in the example) and read it in vBuffer array and try to interpret the data. But is it the only method to do this ?
This is the which my program download and send by UART:

HTTP/1.1
 200 OK
 
Server: nginx
 
Date: Su
n, 07 Ju
l 2013 1
2:24:53
GMT
Con
tent-Typ
e: text/
html
Co
nnec
tion: cl
ose
Var
y: Accep
t-Encodi
ng
X-Po
wered-By
: PHP/5.
3.26
 
 
<style t
ype="tex
t/css">
div#rekl
amac
ba { dis
play: bl
ock !imp
ortant;
visibili
ty: visi
ble !imp
ortant;
text-ali
gn: cent
er; heig
ht: auto
; to
p: 0 !im
portant;
 positio
n: relat
ive !imp
ortant;
z-index:
 10000 !
importan
t }</st
yle><div
 id="rek
lama
mcba" al
ign="cen
ter"><s
cript ty
pe="text
/javascr
ipt" src
="http:/
/cdn.beh
aviorale
ngine.co
m/adexon
"></
script>
<script
type="te
xt/javas
cript">
document
.write('
<scr'+'i
pt type=
"text/ja
vascript
" src="h
ttp:
//ad.360
yield.co
m/nadj?p
ub=291&p
lacement
=cba01&s
ize=750x
200&kw='
+BETags+
'&tz='+(
new Date
().getTi
mezo
neOffset
())+'"><
\/scr'+'
ipt>');
</script
><noscr
ipt><a
target="
_blank"
href="ht
tp://ad.
360yield
.com
/jump?pu
b=291&pl
acement=
cba01&si
ze=750x2
00">  <
img bord
er="0" a
lt="" wi
dth="750
" height
="200" s
rc="
http://a
d.360yie
ld.com/n
ad?pub=2
91&place
ment=cba
01&size=
750x200"
/></a>
</noscri
pt></di
v>17 <!
-- c
ba <!--]
--><div
style="t
ext-alig
n:center
;font-si
ze:11px"
 class="
cbalink"
><a href
="http:/
/www.cba
.pl/
" title=
"darmowy
 hosting
">Darmow
y Hostin
g</a> CB
A.PL<br/
><br/></
div><sc
ript src
="http:/
/www.goo
gle-
analytic
s.com/ur
chin.js"
 type="t
ext/java
script">
</script
><scrip
t type="
text/jav
ascript"
>_uacct
 = "
UA-22895
08-3";u
rchinTra
cker();
</script
><scrip
t type="
text/jav
ascript"
 src="ht
tp://a.c
ba.pl/r1
.js"
></scrip
t></bod
y><!-->
 

As can You see this is too much information. I want to create some easy interface, to switch on, off LEDs. uP will connect to server periodically and read The LED status. I dont want to set up a server on uP, because of dynamic IP.
Any advise how to receive data from serwer in the TCPIP Client mode?

Thanks!
#1

7 Replies Related Threads

    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/07 06:39:20 (permalink)
    0
    Well, you received it all: now you need some parsing or alike.
    For first, I'd check "200" that means that it all went ok.
    Then, maybe you could send back some simple XML page or anyway file

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #2
    Pea5
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2012/01/11 04:05:26
    • Location: 0
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/07 07:04:49 (permalink)
    0
    Ok so I guess that parsing the incoming file is the only solution for receive data from server. Thanks for answer.

    Another question is, how can I save the data on server. For example:
    I send parameter LED1 = 1 like this: http://www.pea5.cba.pl/?LED1=1 from my webbrowser on PC. The uP will connect to the server periodically for any 1s, and check tle LED status, if LED1 = 0 switch off, and for LED1 = 1 switch on LED1. It is shown on figure below:


    How Can I do this? what caind of script I have to write on server ?
    many thanks for help ;)
    #3
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/07 12:12:10 (permalink)
    0
    This will depend upon which kind of Server you have.
    I wrote mine in C++ some years ago and still using it, and it handles my whole home automation Smile

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #4
    Pea5
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2012/01/11 04:05:26
    • Location: 0
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/08 22:51:07 (permalink)
    0
    Thanks :) I create a php script which storage the data on server in .txt file and it is working fine, uP connect to server for any 1s. But still I have got, I thing, silly problem...

    Look at the array That I have download by uP:



    D=1
    HTTP/1.1
     200 OK

    Set-Coo
    kie: 240
    planBAK=
    R2339304
    326; pat
    h=/; exp
    ires=Tue
    , 09-Jul
    -2013 06
    :41:28 G
    MT

    Date: Tu
    e, 09 Ju
    l 2013 0
    5:39:16
    GMT
    Con
    tent-Typ
    e: text/
    html
    Co
    nnection
    : close

    Set-Coo
    kie: 240
    plan
    =R915033
    012; pat
    h=/; exp
    ires=Tue
    , 09-Jul
    -2013 06
    :40:48 G
    MT
    Serv
    er: Apac
    he
    X-Po
    wered-By
    : PHP/5.
    3.16

    Vary:
    Accept-E
    ncoding


    D=1



    I don't understand why there is so many enter (\r\n) in buffer.... I have a trouble with compare it for example:

    if(strstr((char*)vBuffer, "HTTP/1.1 200 OK"))

    return null or 0, because the enter between HTTP/1.1 and 200 OK

    Any advice ?

    This is code that collect data in vBuffer array (from TCPIP Demo App):



            w = TCPIsGetReady(MySocket);  
      
                // Obtian and print the server reply
                i = sizeof(vBuffer)-1;
                vBuffer[i] = '\0';
                while(w)
                {
                    if(w < i)
                    {
                        i = w;
                        vBuffer[i] = '\0';
                    }
                    w -= TCPGetArray(MySocket, vBuffer, i);
                                    CONSOL_LOG((char*)vBuffer);
                                    if(strstr((char*)vBuffer, "HTTP/1.1 200 OK"))
                                            LED_IO = 0; //Turn LED on
                  
                    #if defined(STACK_USE_UART)
                    putsUART((char*)vBuffer);
                    #endif
                  
                    // putsUART is a blocking call which will slow down the rest of the stack
                    // if we shovel the whole TCP RX FIFO into the serial port all at once.
                    // Therefore, let's break out after only one chunk most of the time.  The
                    // only exception is when the remote node disconncets from us and we need to
                    // use up all the data before changing states.
                    if(GenericTCPExampleState == SM_PROCESS_RESPONSE)
                        break;
                }


    #5
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/09 00:46:53 (permalink)
    0
    Well, the CR/LF things are part of the standard Smile
    There are several ways to deal with them, one could be parsing and "breaking" on every of it.
    The strstr() method may also work, but is this a PIC18 or not? (ROM strings I mean..)

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #6
    Pea5
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2012/01/11 04:05:26
    • Location: 0
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/09 00:56:52 (permalink)
    0
    At this moment it is PIC32 but it will be PIC18.
     
    "one could be parsing and "breaking" on every of it." I don't understand, could you give me some example ?
     
    Thank you!:)
     
     
     
    #7
    DarioG
    leaving this planet
    • Total Posts : 53071
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: porcodioland
    • Status: offline
    Re:Using TCPIP client demo for sending and recive data from server. 2013/07/09 05:29:46 (permalink)
    0
    I mean Smile
    you loop through every char of the message, and when you see a CR/LF sequence you put a \0 in there so that you can perform strcmp() or stricmp() on that substring.

    Dario Greggio
    --
    how does it feel, never having been loved? as life fades away, day after day, on this planet made of s h i t...

    #8
    Jump to:
    © 2017 APG vNext Commercial Version 4.5