Author Topic: How to let SB65EC retrieve data from webserver outside local lan?  (Read 7880 times)

certeza

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
I want my SBC65EC board to retrieve data from a webserver outside my local lan
and display that data on a serial display.

How can SBC65EC connect to webserver www.xyz.com? 
How and where can I configure the DNS?

Can someone point me to some sample code?

Any help is greatly appreciated.

- Harm

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #1 on: November 10, 2007, 07:50:38 AM »
hi certeza,

First of all download the firmware 3.06

firmware SBC65EC 3.06


Second in his file projdefs.h make the following Changing:

 
Quote from: in your projdefs.h

...

/** @addtogroup mod_conf_projdefs
 * @code #define STACK_USE_DNS @endcode
 * Uncomment if stack should implement DNS
 */
#define STACK_USE_DNS

...

/** @addtogroup mod_conf_projdefs
 * @code
 * #define MY_DEFAULT_DNS_BYTE1 (n)
 * #define MY_DEFAULT_DNS_BYTE2 (n)
 * #define MY_DEFAULT_DNS_BYTE3 (n)
 * #define MY_DEFAULT_DNS_BYTE4 (n)
 * @endcode
 * Use these defines to define the default Primary DNS server IP address.
 */
#define MY_DEFAULT_DNS_BYTE1      (0x50)//  MY_DEFAULT_GATE_BYTE1
#define MY_DEFAULT_DNS_BYTE2      (0x3A)//  MY_DEFAULT_GATE_BYTE2
#define MY_DEFAULT_DNS_BYTE3      (0x3D)//  MY_DEFAULT_GATE_BYTE3
#define MY_DEFAULT_DNS_BYTE4      (0xFA)//  MY_DEFAULT_GATE_BYTE4

...


And in his mxwebsrvr.c these Changing:

Quote from: in your mxwebsrvr.c

#if defined(STACK_USE_DNS)
#include "net\dns.h"
#endif

////////////////////////Inside the main function

char domainName[] = "www.google.com\0";   
IP_ADDR myipcra;   

...

    DNSResolve(domainName); 

...

while(1)
{
    ...

           //Blink SYSTEM LED every second.
        if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) {
            if ( TickGetDiff8bit(t) >= ((TICK8)TICKS_PER_SECOND /(TICK8)2)) /// (TICK8)2
            {
                t = TickGet8bit();
                TRISB_RB6 = 0;
                LATB6 ^= 1;
 

                 //------------------ADD CODE

                    if(DNSIsResolved(&myipcra)){
                   
                             
                         //Do something with your IP                         


                         //DEBUG CODE   
                         //---------------------The IP prints by serial

                            serPutString('your IP resolve is: ');
                            serPutString(itoa(((int)myipcra.v[0]),10));
                            serPutByte('.');
                            serPutString(itoa(((int)myipcra.v[1]),10));
                            serPutByte('.');
                            serPutString(itoa(((int)myipcra.v[2]),10));
                            serPutByte('.');
                            serPutString(itoa(((int)myipcra.v[3]),10));

                           
                    }
                   
                   ...
            }


       ...
}



How to send and receive data TCP / UDP download this examples made available by Modtronix :

Example TCP/IP projects for the SBC65EC

I hope you serve.

Byee.
« Last Edit: November 10, 2007, 08:21:47 AM by niroblock »
do not make any questions, if you already have the answer!

certeza

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #2 on: November 10, 2007, 10:37:31 AM »
First of all, thank you very much for your help.

I am not a experienced C programmer but your instructions were very easy to follow.
I got a few warnings when I tried to compile the code in MPLAB IDE v7.60, like:
'C:\www.modtronix.com\websrvr65_v306\src\mxwebsrvr.c:330:Warning [2054] suspicious pointer conversion'
It seems the compiler doesn't like things like: serPutString('your IP resolve is: '); and serPutString(itoa(((int)myipcra.v[0]),10));
I had to declare a string like this: char sDNS[] = 'your IP resolve is: ';  to be able to print it.
But the build succeeded.

However, the new firmware doesn't resolve the DNS.
The DNS of my provider is 62.251.0.6, my local lan is in the 10.0.0.x range and my gateway is 10.0.0.138.
I tried fixed ip-address: 10.0.0.118, netmask: 255.255.255.0, gateway: 10.0.0.138
and DHCP with gateway 10.0.0.138 but both configurations didn't succeed in getting the DNS resolved.

Any ideas?

- Harm
 



 
 

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #3 on: November 10, 2007, 01:23:05 PM »
Hi certeza,

   
The compiler MCC18 and a compiler an odd

Have no control type in the pointer,

And it needs to declare in advance the types to run sentence inline

In my case I have problems of RAM and save a little memory using the inline sentence.

Why you warns of a "warring"

But it is not a "error"


You may have a problem with the dnc.c original

If you add a modified version that works

Perfectly:

Code: [Select]
/*********************************************************************
 *
 *                  DNS Module for Modtronix TCP/IP Stack
 *
 *********************************************************************
 * FileName:        DNS.c
 * Dependencies:    UDP, ARP, Tick
 * Processor:       PIC18
 * Complier:        MPLAB C18 v2.10 or higher <br>
 *                  Microchip C30 v2.01 or higher
 *                  HITECH PICC-18 V8.35PL3 or higher
 * Company:         Microchip Technology, Inc.
 *
 * Software License Agreement
 *
 * The software supplied herewith by Modtronix Engineering is based on v2.20.04.01
 * of the Microchip TCP/IP stack. The original code base is owned by Microchip
 * Technology Incorporated (the Company), and is protected under applicable
 * copyright laws. The modifications are owned by Modtronix Engineering, and is
 * protected under applicable copyright laws. The software supplied herewith is
 * intended and supplied to you, the Company customer, for use solely and
 * exclusively on Microchip PICmicro Microcontroller based products manufactured
 * by Modtronix Engineering. The code may be modified and can be used free of charge
 * for non commercial and commercial applications. All rights are reserved. Any use
 * in violation of the foregoing restrictions may subject the user to criminal
 * sanctions under applicable laws, as well as to civil liability for the breach
 * of the terms and conditions of this license.
 *
 * THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS,
 * IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE
 * COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 ********************************************************************/
#define THIS_IS_DNS

#include "projdefs.h"
#include "net\checkcfg.h"
#include "net\dns.h"
#include "net\compiler.h"
#include "net\udp.h"
#include "net\tick.h"
#include "net\arp.h"
#include "net\arptsk.h"
#include "net\helpers.h"
#include "debug.h"

#if defined(STACK_USE_DNS)

/////////////////////////////////////////////////
//Debug defines
#define debugPutMsg(msgCode) debugPut2Bytes(0xE8, msgCode)
#define debugPutMsgRomStr(msgCode, strStr) debugMsgRomStr(0xE8, msgCode, msgStr)


#ifndef DNS_PORT
#define DNS_PORT        53
#endif

#ifndef DNS_TIMEOUT
#define DNS_TIMEOUT        (TICK_SECOND*2)
#endif


// ADD backdoor listing DNS resolve
#define DNS_BACKDOOR   (54153)

static BYTE *DNSHostName;
static enum
{
    DNS_HOME = 0,
    DNS_RESOLVE_ARP,
    DNS_OPEN_SOCKET,
    DNS_QUERY,
    DNS_GET_RESULT,
    DNS_DONE
} smDNS = DNS_DONE;

typedef struct _DNS_HEADER
{
    WORD_VAL TransactionID;
    WORD_VAL Flags;
    WORD_VAL Questions;
    WORD_VAL Answers;
    WORD_VAL AuthoritativeRecords;
    WORD_VAL AdditionalRecords;
} DNS_HEADER;

typedef struct _DNS_ANSWER_HEADER
{
    WORD_VAL    ResponseName;
    WORD_VAL    ResponseType;
    WORD_VAL    ResponseClass;
    DWORD_VAL    ResponseTTL;
    WORD_VAL    ResponseLen;
} DNS_ANSWER_HEADER;

static void DNSPutString(BYTE *String);
static void DNSGetString(BYTE *String);


/**
 * Call DNSIsResolved() until the host is resolved.
 * A UDP socket must be available before this function is called. It is freed
 * at the end of the resolution.  MAX_UDP_SOCKETS may need to be increased if
 * other modules use UDP sockets. You must not modify Hostname until
 * DNSIsResolved() returns TRUE.
 *
 * @preCondition        Stack is initialized()
 *
 * @param Hostname      Null terminated string specifying the host address to
 *                      resolve to an IP address.
 */
void DNSResolve(BYTE *Hostname)
{
    DNSHostName = Hostname;
    smDNS = DNS_HOME;
}


/**
 * Call DNSIsResolved() until the host is resolved.
 * You cannot start two DNS resolution proceedures concurrently.
 * You must not modify *Hostname until DNSIsResolved() returns TRUE.
 *
 * @preCondition        DNSResolve() was called.
 *
 * @param HostIP        4 byte IP address
 */
BOOL DNSIsResolved(IP_ADDR *HostIP)
{
    static UDP_SOCKET   MySocket;
    static NODE_INFO    Remote;
    static TICK         StartTime;
    BYTE                i;
    WORD_VAL            w;
    DNS_HEADER          DNSHeader;
    DNS_ANSWER_HEADER   DNSAnswerHeader;
    IP_ADDR             tmpIpAddr;

    switch(smDNS)
    {
        case DNS_HOME:

          //////////////  new code
          //
            Remote.IPAddr.v[0] = MY_DNS_BYTE1;
            Remote.IPAddr.v[1] = MY_DNS_BYTE2;
            Remote.IPAddr.v[2] = MY_DNS_BYTE3;
            Remote.IPAddr.v[3] = MY_DNS_BYTE4;
            ARPResolve(&Remote.IPAddr);


          //////////////  old code
          //
          //  tmpIpAddr.v[0] = MY_DNS_BYTE1;
          //  tmpIpAddr.v[1] = MY_DNS_BYTE2;
          //  tmpIpAddr.v[2] = MY_DNS_BYTE3;
          //  tmpIpAddr.v[3] = MY_DNS_BYTE4;
          //  ARPResolve(&tmpIpAddr);

            StartTime = TickGet();
            smDNS++;
            break;
        case DNS_RESOLVE_ARP:

           //  if(!ARPIsResolved(&tmpIpAddr, &Remote.MACAddr))  //old code

            if(!ARPIsResolved(&Remote.IpAddr, &Remote.MACAddr))  //new code
            {
                if(TickGet() - StartTime > DNS_TIMEOUT)
                {
                    smDNS--;
                }
                break;
            }
            //  Remote.IPAddr.Val = tmpIpAddr.Val;   //old code
            smDNS++;
            // No need to break, we can immediately start resolution

        case DNS_OPEN_SOCKET:


            // MySocket = UDPOpen(0, &Remote, DNS_PORT);   //old code


            MySocket = UDPOpen(DNS_BACKDOOR, &Remote, DNS_PORT);   // new code
            if(MySocket == INVALID_UDP_SOCKET) {
                #if (DEBUG_DNS >= LOG_ERROR)
                debugPutMsg(1); //@mxd:1:Could not open UDP socket
                #endif

                break;
            }

            smDNS++;
            // No need to break, we can immediately start resolution

        case DNS_QUERY:
            if(!UDPIsPutReady(MySocket))
                break;

            // Put DNS query here
            UDPPut(0x12);        // User chosen ID
            UDPPut(0x34);
            UDPPut(0x01);        // Standard query with recursion
            UDPPut(0x00);
            UDPPut(0x00);        // 0x0001 questions
            UDPPut(0x01);
            UDPPut(0x00);        // 0x0000 answers
            UDPPut(0x00);
            UDPPut(0x00);        // 0x0000 name server resource records
            UDPPut(0x00);
            UDPPut(0x00);        // 0x0000 additional records
            UDPPut(0x00);

            // Put hostname string to resolve
            DNSPutString(DNSHostName);

            UDPPut(0x00);        // Type: A (host address)
            UDPPut(0x01);
            UDPPut(0x00);        // Class: IN (Internet)
            UDPPut(0x01);

            UDPFlush();
            StartTime = TickGet();
            smDNS++;
            break;

        case DNS_GET_RESULT:
            if(!UDPIsGetReady(MySocket))
            {
                if(TickGet() - StartTime > DNS_TIMEOUT)
                {
                    smDNS--;
                }
                break;
            }

            // Retrieve the DNS header and de-big-endian it
            UDPGet(&DNSHeader.TransactionID.v[1]);
            UDPGet(&DNSHeader.TransactionID.v[0]);
            UDPGet(&DNSHeader.Flags.v[1]);
            UDPGet(&DNSHeader.Flags.v[0]);
            UDPGet(&DNSHeader.Questions.v[1]);
            UDPGet(&DNSHeader.Questions.v[0]);
            UDPGet(&DNSHeader.Answers.v[1]);
            UDPGet(&DNSHeader.Answers.v[0]);
            UDPGet(&DNSHeader.AuthoritativeRecords.v[1]);
            UDPGet(&DNSHeader.AuthoritativeRecords.v[0]);
            UDPGet(&DNSHeader.AdditionalRecords.v[1]);
            UDPGet(&DNSHeader.AdditionalRecords.v[0]);

            // Remove all questions
            while(DNSHeader.Questions.Val--)
            {
                DNSGetString(NULL);
                UDPGet(&w.v[1]);        // Question type
                UDPGet(&w.v[0]);
                UDPGet(&w.v[1]);        // Question class
                UDPGet(&w.v[0]);
            }

            // Scan through answers
            while(DNSHeader.Answers.Val--)
            {
                UDPGet(&DNSAnswerHeader.ResponseName.v[1]);        // Response name
                UDPGet(&DNSAnswerHeader.ResponseName.v[0]);
                UDPGet(&DNSAnswerHeader.ResponseType.v[1]);        // Response type
                UDPGet(&DNSAnswerHeader.ResponseType.v[0]);
                UDPGet(&DNSAnswerHeader.ResponseClass.v[1]);    // Response class
                UDPGet(&DNSAnswerHeader.ResponseClass.v[0]);
                UDPGet(&DNSAnswerHeader.ResponseTTL.v[3]);        // Time to live
                UDPGet(&DNSAnswerHeader.ResponseTTL.v[2]);
                UDPGet(&DNSAnswerHeader.ResponseTTL.v[1]);
                UDPGet(&DNSAnswerHeader.ResponseTTL.v[0]);
                UDPGet(&DNSAnswerHeader.ResponseLen.v[1]);        // Response length
                UDPGet(&DNSAnswerHeader.ResponseLen.v[0]);

                // Make sure that this is a 4 byte IP address, response type A, class 1
                // Check if this is Type A
                if(    DNSAnswerHeader.ResponseType.Val    == 0x0001 &&
                    DNSAnswerHeader.ResponseClass.Val    == 0x0001 && // Internet class
                    DNSAnswerHeader.ResponseLen.Val        == 0x0004)
                {
                    UDPGet(&HostIP->v[0]);
                    UDPGet(&HostIP->v[1]);
                    UDPGet(&HostIP->v[2]);
                    UDPGet(&HostIP->v[3]);
                    break;
                }
                else
                {
                    while(DNSAnswerHeader.ResponseLen.Val--)
                    {
                        UDPGet(&i);
                    }
                }
            }

            UDPDiscard();
            UDPClose(MySocket);
            MySocket = INVALID_UDP_SOCKET;
            smDNS++;
            // No need to break, we are done and need to return TRUE

        case DNS_DONE:
            return TRUE;
    }

    return FALSE;
}

static void DNSPutString(BYTE *String)
{
    BYTE *RightPtr;
    BYTE i;
    BYTE Len;

    RightPtr = String;

    while(1)
    {
        do
        {
            i = *RightPtr++;
        } while((i != 0x00) && (i != '.') && (i != '/'));

        // Put the length parameter
        Len = (BYTE)(RightPtr-String-1);
        UDPPut(Len);
        while(Len--)
        {
            UDPPut(*String++);
        }
        if(i == 0x00 || i == '/')
            break;

        // Skip over the '.' in the input string
        String++;
    }

    // Put the string terminator character
    UDPPut(0x00);
}

static void DNSGetString(BYTE *String)
{
    BYTE i;
    BYTE j;

    if(String == NULL)
    {
        UDPGet(&i);
        while(i)
        {
            while(i--)
            {
                UDPGet(&j);
            }
            UDPGet(&i);
        }
    }
    else
    {
        UDPGet(&i);
        while(i)
        {
            while(i--)
            {
                UDPGet(String);
                String++;
            }
            UDPGet(&i);
        }
    }
}


#endif    //#if defined(STACK_USE_DNS)





Remember to open the port of listening in your router

In this case the 54123 UDP


Please use a monitor network as Ethereal or Wireshark

I will advise Wireshark supports "tcpdump" instead ethereal not!

The result will be similar to that shown in the picture added:



I hope you serve.

Byee.
« Last Edit: November 10, 2007, 03:26:32 PM by niroblock »
do not make any questions, if you already have the answer!

certeza

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #4 on: November 11, 2007, 03:14:27 AM »
Niroblock,

Once again, thank you for your help.
I used your file dns.c and made the changes, and it worked!

One strange thing: I had to upload the new firmware 3 times and reset SBC65EC several times before it worked.
It is also clear that you need a tool like Wireshark to see what is happening.

I must say, this is all way above my head, but I am learning fast ;)

Now I can start working on the example code for the tcp client to retrieve a webpage from an external webserver.





certeza

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #5 on: November 11, 2007, 11:11:05 AM »
Niroblock,

I wrote a simple http client to retrieve data from my external webserver.
Dns works, tcp client works, but I cannot retrieve all the data from the
page www.certeza.nl/downloads/test.html. I can only get 92 bytes.

See the attached code.

Any idea why I cannot retrieve the whole content?


niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #6 on: November 11, 2007, 03:25:21 PM »
Hi Certeza,

The limit buffer for TCP connections is 1024 byte

Watch your projdefs.h


Code: (projdefs.h) [Select]

#if !defined(STACK_USE_SLIP)
    // The MAC_TX_BUFFER_COUNT must be equal to MAX_SOCKETS + 1
    // (for high priority messages), or else calls to TCPPut may
    // fail when multiple TCP sockets have data pending in the
    // output buffer that hasn't been acked.  Changing this value
    // is recommended only if the rammifications of doing so are
    // properly understood. 
    #if defined(NON_MCHP_MAC)
        #define MAC_TX_BUFFER_SIZE          (1024)
        #define MAC_TX_BUFFER_COUNT         (3)
    #else
        #define MAC_TX_BUFFER_SIZE          (576)
        #define MAC_TX_BUFFER_COUNT         (MAX_SOCKETS+1)
    #endif
#else

...


#define MAC_RX_BUFFER_SIZE              (MAC_TX_BUFFER_SIZE)



Has tried to change a class that I use the CHECK IP, this is okay

Your source code was partially well, but
You must improve your knowledge in the call pointers

I have amended the code, and now works perfectly:

Code: (rssfeed.c) [Select]
/*---------------------------------------------------------------------*\
|           ---[RSSFEED Module for Modtronix TCP/IP Stack]---
\----------------------------------------------------------------------
| Name:        rssfeed.c
| Author:      NiroBlock (Maurizio Spoto)
| Created:     28/07/2007
| Description: RSS
|
\----------------------------------------------------------------------*/
/*---------------------------------------------------------------------*\
|  Software License Agreement
|
|   The syntax of this code It is an integral part
|   of what stack of Modtronix TCP/IP Stack and has been developed
|   in harmony of the examples disclosed by Modtronix Engineering
|   As if that leaves only condition License:
|               Use only boards Modtronix Engineering
|
\----------------------------------------------------------------------*/
/*---------------------------------------------------------------------*\
|  File History
|
|
\----------------------------------------------------------------------*/

#include <string.h>

#include "projdefs.h"
#include "rssfeed.h"
#include "net\arptsk.h"
#include "net\arp.h"
#include "net\tcp.h"

#include "serint.h"
#include "net\tick.h"

int timeout2      = 0;                                               //watchdog for lost connection

BYTE tsecWaitRSS;

BYTE smRSS = RSS_HOME;         //index switch

TCP_SOCKET tcpSocketRSS = INVALID_SOCKET; 


unsigned char StartHeader2[]= {"GET "},                               
              EndHeader2[]=   {" HTTP/1.1"},                           
              UrlHeader2[]=   {"/downloads/test.html"},                //url request
              Arguments2[]=   {""},                                    //arguments
              HostRqst2[]=    {"Host: www.certeza.nl"},                //host update request
              AgentRqst2[]=   {"User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"}, //Modtronix Agent
              crlf2[]=       {0x0D,0x0A,0x00};                        // CR LF NULL
 
//--------------------------------------------------------------#public region

/*//////////////////////////////////////////////////////////////
>
>  [ RSSinit(void) ]--
>
>
*////////////////////////////////////////////////////////////////
void RSSinit(void)
{
   smRSS = RSS_SEND_ARP;
}

/*///////////////////////////////////////////////////////////////
>
>  [ RSSupdate(int sys) ]--
>
>  This function sends a HTTP GET request to the webserver.
>
>
*//////////////////////////////////////////////////////////////////
void doServerRequest(int sys, IP_ADDR *myip) 
{
     BYTE c;
     int i;
     NODE_INFO tcpServerRSS;
     
     tcpServerRSS.IPAddr=*myip;

     if(((++timeout2)>=25)||(sys==1)){             
              // debug
              //serPutByte('T');serPutByte('O');serPutByte('\r');serPutByte('\n');

              smRSS = RSS_SEND_ARP;
              TCPDisconnect(tcpSocketRSS);
              timeout2=0;
     }
     
     switch (smRSS) {
         case RSS_SEND_ARP:
             // debug
             //serPutByte('S');serPutByte('A');serPutByte('\r');serPutByte('\n');

             if (ARPIsTxReady()) {
                 // debug
                 //serPutByte('A');serPutByte('R');serPutByte('\r');serPutByte('\n');
                 tsecWaitRSS = TickGet8bitSec();
                 ARPResolve(&tcpServerRSS.IPAddr);
                 smRSS = RSS_WAIT_RESOLVE;
             }
             break;
         case RSS_WAIT_RESOLVE:
               // debug
               //serPutByte('W');serPutByte('R');serPutByte('\r');serPutByte('\n');
             if (ARPIsResolved(&tcpServerRSS.IPAddr, &tcpServerRSS.MACAddr)) {
                 smRSS = RSS_RESOLVED;
                 tcpSocketRSS = TCPConnect(&tcpServerRSS, RSS_PORT);
                 if (tcpSocketRSS == INVALID_SOCKET) {
                     //error code
                     // debug
                     //serPutByte('I');serPutByte('S');serPutByte('\r');serPutByte('\n');
                 }
             }
             else {
                 if (TickGetDiff8bitSec(tsecWaitRSS) >= 2) {
                     smRSS = RSS_SEND_ARP;
                 }
             }
             break;
         case RSS_RESOLVED:
                  // debug
                  //serPutByte('R');serPutByte('1');serPutByte('\r');serPutByte('\n');

             if (TCPIsConnected(tcpSocketRSS)) {
                    // debug
                    // serPutByte('R');serPutByte('2');serPutByte('\r');serPutByte('\n');

                 if (TCPIsPutReady(tcpSocketRSS)) {
                    //GET
                    TCPPutArray(tcpSocketRSS, StartHeader2, strlen(StartHeader2));
                    TCPPutArray(tcpSocketRSS, UrlHeader2, strlen(UrlHeader2));
//                    TCPPutArray(tcpSocketRSS, Arguments, strlen(Arguments));
                    TCPPutArray(tcpSocketRSS, EndHeader2, strlen(EndHeader2));                         
                    TCPPutArray(tcpSocketRSS, crlf2, strlen(crlf2));
                    //Host
                    TCPPutArray(tcpSocketRSS, HostRqst2, strlen(HostRqst2));                       
                    TCPPutArray(tcpSocketRSS, crlf2, strlen(crlf2));
                    //User-Agent
                    TCPPutArray(tcpSocketRSS, AgentRqst2, strlen(AgentRqst2));
                    TCPPutArray(tcpSocketRSS, crlf2, strlen(crlf2));                     
                    TCPPutArray(tcpSocketRSS, crlf2, strlen(crlf2));

                    //Send contents of transmit buffer, and free buffer
                    TCPFlush(tcpSocketRSS);

                    //Then open the port to hear the answer with function getRSSFeed
                    smRSS = RSS_QUERY;
                    // debug
                    // serPutByte('R');serPutByte('3');serPutByte('\r');serPutByte('\n');

                    timeout2=0;       //Always call the reset before changing state
                }
            }
            break;
         case RSS_QUERY:
                    // debug
                    //serPutByte('Q');serPutByte('1');serPutByte('\r');serPutByte('\n');

            break;
         case RSS_DONE:
             // debug
             //serPutByte('D');serPutByte('N');serPutByte('\r');serPutByte('\n');
                 
             TCPDisconnect(tcpSocketRSS);
             smRSS = RSS_HOME;             
             break;
         }
}


void walkmeRSS(void){
       int tc=0;         //total Byte
       int dc=0;         //Data Byte
       char totstr[]={"Total Byte Receive : "};
       char datstr[]={" Data Byte Receive : "};
       BOOL goTAG=FALSE; //flag TAG DATA
       BYTE c;
       if(smRSS==RSS_QUERY){
           if (TCPIsConnected(tcpSocketRSS)) {
               if (TCPIsGetReady(tcpSocketRSS)) { 

                       //Remove  "//CTRL"   if use TAG DATA <RSS></RSS>
                       while(TCPGet(tcpSocketRSS, &c)) {
                                tc++;                   //increment Total Byte counter

              //CTRL         if(goTAG){              //if data into TAG <RSS>
              //CTRL              if(c=='<')break;    //if pointer buffer in start end TAG '<' /RSS> exit while

                                     serPutByte(c);      //print to serial         
 
              //CTRL             dc++;                  //increment Data Byte counter
              //CTRL       }
              //CTRL       if(c=='>'){             //if pointer buffer in close TAG <RSS '>'   
              //CTRL              goTAG=TRUE;          //next byte if first byte data
              //CTRL      }

                        }
                        serPutString(crlf2);
                        serPutString(totstr);
                        serPutString( itoa(tc,10) );
                        serPutString(datstr);
                        serPutString( itoa(dc,10) );
                        serPutString(crlf2);
                        tc=0;dc=0;
                        //reset buffer
                        TCPDiscard(tcpSocketRSS);
                        smRSS = RSS_DONE;
               }
           }
       }
}


in your mxwebsrvr.c:

Code: (mxwebsrvr.c) [Select]

//inside funcition main


RSSinit();

...


while(1)
{

...
 
        //Blink SYSTEM LED every second.
        if (appcfgGetc(APPCFG_SYSFLAGS) & APPCFG_SYSFLAGS_BLINKB6) {
            if ( TickGetDiff8bit(t) >= ((TICK8)TICKS_PER_SECOND /(TICK8)2)) /// (TICK8)2
            {
                t = TickGet8bit();
                TRISB_RB6 = 0;
                LATB6 ^= 1;

                //your code resolve DNS
               
                //call rssfeed
                doServerRequest(0,&myipcra);
               
             }
 
            //If there are controls in data buffer TCP reception
            walkmeRSS();

  ...

}




I advise you to enter your information on TAG example

"<RSS></RSS>"

So you can only collect data without header.


Hopefully enough to learn how to properly manage your connections and your code.

byee
« Last Edit: November 11, 2007, 04:28:19 PM by niroblock »
do not make any questions, if you already have the answer!

certeza

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #7 on: November 13, 2007, 10:21:56 PM »
Yes, I now have a working application!

I had to change a few things, because we have to call the function walkmerss a few times
if the webpage is bigger than 1024 bytes.

How do I know when to stop calling the function?
Is it when tcpisconnected returns false or do I simply time out after a few seconds?

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #8 on: November 13, 2007, 11:26:08 PM »
hi Certeza,

The best way is to be hoped that the RSS webserver close the connection after submitting the webpage

It is wrong to use the method: if (tcpisconnected)

Byee.
do not make any questions, if you already have the answer!

certeza

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #9 on: December 03, 2007, 09:31:04 PM »
niroblock published an updated dns.c in this post
hat includes functionality to connect to servers outside
your local network.
I think that should be added to the stack.

Can someone have a look at it?



sparkcatcher

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #10 on: December 08, 2007, 10:43:05 PM »
 certeza:

The original DNS client always had the capability to connect to servers outside the local network.  Problem is that there is a bug in the code.

niroblock's solution, or workaround, will work most of the time, but he assigns the remote IP address before it has been verified, so it might overwrite a valid address and then have a subsequent dns resolve problem.  That's why the tempIP variable was used.

Here's a solution that has worked for me:

Old code:  (dns.c)

IP_ADDR             tmpIpAddr;

New Code:

static IP_ADDR     tmpIpAddr;

It other words, just declare the tmpIpAddr variable with a static.  It gets overwriten in a subsequant procedure and it's value changes from what it should be.

Hope this works for you and others.

By the way, I'm looking for a simple HTTP client, that takes up very little space (I'm working the the mx45 using the beta code that was derived from the 65 code).  It looks like your RSS feed http client is close, but it looks like it has some extra stuff in it.  I just want to request a simple page with less than 128 bytes on it.

If anyone can reccomend simple HTTP client that would be great, otherwise I'll go through the code that certeza and niroblock wrote.  Thanks for posting your code. 

best,
sparkcatcher,


niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #11 on: December 09, 2007, 08:57:09 AM »
Hi sparkcatcher,

Whether or not the use of a static type is correct

And the design of a temporary bridge before calling the host

My method simply result in a move to give a prospective BACKDOOR more separatist
Work IN / OUT of communications

Thanks for your contributions


   
HTTP client, used "certeza", is one of the easiest method of obtaining a result reliable and fast.

byee.
« Last Edit: December 09, 2007, 09:09:20 AM by niroblock »
do not make any questions, if you already have the answer!

sparkcatcher

  • Sr. Member
  • ****
  • Posts: 31
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #12 on: December 09, 2007, 06:28:11 PM »
niroblock:

The dns.c module is a bare skeleton.  If an address can't be resolved (old dns address, gateway down, etc) it just bounces back and forth between states and never exits.  It needs substantial modifications in order to be used in a commercial product.  But, once debugged,  it is a nice skeleton that works well if everything in the network is working like it is supposed to.

From your message I take it that the http client code posted above is free of errors and works well so I'll try that, and thanks to certeza for posting it.

regards,
sparkcatcher

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
Re: How to let SB65EC retrieve data from webserver outside local lan?
« Reply #13 on: December 10, 2007, 10:41:36 AM »
Hi sparkcatcher,

I say the same thing!

At no time did I say that the DNS module is not good!

In my view is a good code.

I just adapted to my commercial requirements.

It is useless to lose more time to talk about as simple as I DNS resolution, not you think?

Byee.
do not make any questions, if you already have the answer!