Author Topic: DynDNS Update Client for SBC68EC  (Read 2483 times)

niroblock

  • Hero Member
  • *****
  • Posts: 140
    • View Profile
DynDNS Update Client for SBC68EC
« on: September 10, 2007, 12:42:34 PM »
I have read many post in this forum, where the user asked like connecting itself and updating the DYNDNS.ORG service Dinamic DNS.

finally! I have been decided in publishing an example, of since one becomes.

1) to enter the Web www.dyndns.com

2) to create new account.

3) once activated the account to enter
   menu: “my Service”,
   to select “Host Service”,
   and to press on “add new host”,
   to introduce a name of host and
   to select a predetermined dominion
   example: homelinux.net
   to select checkbox “Wildcard”,
   the TTL to “60s”,
   and “To-record pointed to IP address”
   and already this!

4) now to modify the file “mxwebsrvv.c”


add this function:

Code: [Select]
///////////////////////////////////////////////////////////base 64 code
/*************************************************
*  encode Base 64 function!
*
*  special thanks a: Brad Conte
*
**************************************************/

unsigned char charset[]={"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"};

unsigned char revchar(char ch)
{
   if (ch >= 'A' && ch <= 'Z')
      ch -= 'A';
   else if (ch >= 'a' && ch <='z')
      ch = ch - 'a' + 26;
   else if (ch >= '0' && ch <='9')
      ch = ch - '0' + 52;
   else if (ch == '+')
      ch = 62;
   else if (ch == '/')
      ch = 63;
   return(ch);
}

int encode64(unsigned char in[], unsigned char out[], int len, int newline_flag)
{
   int idx,idx2,blks,left_over;
   // Since 3 input bytes = 4 output bytes, figure out how many even sets of 3 input bytes
   // there are and process those. Multiplying by the equivilent of 3/3 (int arithmetic)
   // will reduce a number to the lowest multiple of 3.
   blks = (len / 3) * 3;
   for (idx=0,idx2=0; idx < blks; idx += 3,idx2 += 4) {
      out[idx2] = charset[in[idx] >> 2];
      out[idx2+1] = charset[((in[idx] & 0x03) << 4) + (in[idx+1] >> 4)];
      out[idx2+2] = charset[((in[idx+1] & 0x0f) << 2) + (in[idx+2] >> 6)];
      out[idx2+3] = charset[in[idx+2] & 0x3F];
      // The offical standard requires insertion of a newline every 76 chars
      if (!(idx2 % 77) && newline_flag) {
         out[idx2+4] = '\n';
         idx2++;
      }
   }
   left_over = len % 3;
   if (left_over == 1) {
      out[idx2] = charset[in[idx] >> 2];
      out[idx2+1] = charset[(in[idx] & 0x03) << 4];
      out[idx2+2] = '=';
      out[idx2+3] = '=';
      idx2 += 4;
   }
   else if (left_over == 2) {
      out[idx2] = charset[in[idx] >> 2];
      out[idx2+1] = charset[((in[idx] & 0x03) << 4) + (in[idx+1] >> 4)];
      out[idx2+2] = charset[(in[idx+1] & 0x0F) << 2];
      out[idx2+3] = '=';
      idx2 += 4;
   }
   out[idx2] = '\0';
   return(idx2);
}


and this:

Code: [Select]
////////////////////////////////////////////////////this code import from TCP example by modtronix

//Timers
  TICK8  tsecWait = 0;           
  TICK16 tsecMsgSent = 0;

 //TCP State machine
  #define SM_TCP_SEND_ARP         0
  #define SM_TCP_WAIT_RESOLVE     1
  #define SM_TCP_RESOLVED         2
  #define SM_TCP_FINISHED         3

static BYTE smTcp = SM_TCP_SEND_ARP;   

static TCP_SOCKET tcpSocketUser = INVALID_SOCKET;   

void tcpSENDmsg(int sys,int net)
{
     int i;
     static int timeout=0;
     NODE_INFO tcpServerNode;
     
     if(net)
     {
        // this DNS RESOLVE of(members.dyndns.org)       !IMPORTAT! set in projdefs.h  "getway" with router value
        tcpServerNode.IPAddr.v[0] = 0x3F;   //63     
        tcpServerNode.IPAddr.v[1] = 0xD0;   //208
        tcpServerNode.IPAddr.v[2] = 0xC4;   //196
        tcpServerNode.IPAddr.v[3] = 0x60;   //96       
     }
     else
     {
       // this value for NETCAT listen
       tcpServerNode.IPAddr.v[0] = 0xC0;   //192
       tcpServerNode.IPAddr.v[1] = 0xA8;   //168
       tcpServerNode.IPAddr.v[2] = 0x00;   //0
       tcpServerNode.IPAddr.v[3] = 0xC2;   //194
     }
     

     if(((++timeout)>=10)||(sys)){             //5000ms x 10= 50 second
              smTcp = SM_TCP_SEND_ARP;
              TCPDisconnect(tcpSocketUser);
              timeout=0;
     }
     

   //  tcpSocketUser2 = INVALID_SOCKET;
 
         switch (smTcp) {
         case SM_TCP_SEND_ARP:
             if (ARPIsTxReady()) {
                 tsecWait = TickGet8bitSec();   //Remember when we sent last request
                 
                 //Send ARP request for given IP address
                 ARPResolve(&tcpServerNode.IPAddr);
                 
                 smTcp = SM_TCP_WAIT_RESOLVE;
             }
             break;
         case SM_TCP_WAIT_RESOLVE:
             //The IP address has been resolved, we now have the MAC address of the
             //node at 192.168.0.194
             if (ARPIsResolved(&tcpServerNode.IPAddr, &tcpServerNode.MACAddr)) {
                 //After calling TCPConnect(), we have to wait for a connection
                 //to be established. Stack will continuously try to connect!
                 smTcp = SM_TCP_RESOLVED;
 
                 //We can now connect, seeing that we have the remote server node
                 //info (MAC and IP address)
                 tcpSocketUser = TCPConnect(&tcpServerNode, 8245);
     
                 //An error occurred during the TCPListen() function
                 if (tcpSocketUser == INVALID_SOCKET) {
                     //Add user code here to take action if required!
                 }
             }
             //If not resolved after 2 seconds, send next request
             else {
                 if (TickGetDiff8bitSec(tsecWait) >= 2) {
                     smTcp = SM_TCP_SEND_ARP;
                 }
             }
             break;
         case SM_TCP_RESOLVED:
             //Connection has been established
             if (TCPIsConnected(tcpSocketUser)) {
                 //Checks if there is a transmit buffer ready for accepting data
                 if (TCPIsPutReady(tcpSocketUser)) {

                          //sequence send Header-Request

                          //GET
                          TCPPutArray(tcpSocketUser, StartHeader, strlen(StartHeader));
                          TCPPutArray(tcpSocketUser, UrlHeader, strlen(UrlHeader));
                          TCPPutArray(tcpSocketUser, HostAlias, strlen(HostAlias));
                          TCPPutArray(tcpSocketUser, EndHeader, strlen(EndHeader));                         
                          TCPPutArray(tcpSocketUser, crlf, strlen(crlf));
                          //Host
                          TCPPutArray(tcpSocketUser, HostRqst, strlen(HostRqst));                       
                          TCPPutArray(tcpSocketUser, crlf, strlen(crlf));
                          //Authorization
                          TCPPutArray(tcpSocketUser, AuthRqst, strlen(AuthRqst));
                          TCPPutArray(tcpSocketUser, B64UserPass, strlen(B64UserPass));                     
                          TCPPutArray(tcpSocketUser, crlf, strlen(crlf)); 
                          //User-Agent
                          TCPPutArray(tcpSocketUser, AgentRqst, strlen(AgentRqst));
                          TCPPutArray(tcpSocketUser, crlf, strlen(crlf));                     
                          TCPPutArray(tcpSocketUser, crlf, strlen(crlf));
                                             

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

                           timeout=0;   //reset lost connect timeout

                     }
                     

                  // smTcp = SM_TCP_FINISHED;    //Set to "message sent" state
                 
                     //Close connection if not needed anymore!
                  //   TCPDisconnect(tcpSocketUser);
                  // }

                 
                 //The TCP stack will continuously try and connect. It is up to the user to
                 //terminate the connection attempts if no connection is made after a
                 //certian time. The TCPDisconnect() function can be used to stop the
                 //stack from trying to connect.
                 
                 //TCPDisconnect();
                 //smTcp = SM_TCP_FINISHED;    //Set to "message sent" state
            }
            break;
         case SM_TCP_FINISHED:
            //Message sent state
             break;
         }
}


to add these declarations:

  by security problems the forum does not accept east code, to watch the drawing

in main function add this:

Code: [Select]

void main(void)
{
  static int tmrUC=0;    //timer for update request
  ....
 
  encode64(StrUserPass,B64UserPass,strlen(StrUserPass),0);    //encode Base64 "username:password"


and in main loop add this:

Code: [Select]
while(1)
{

  ...


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


                ///ADD THIS CODE
                if(++tmrUC==10){     //5000ms
                   tcpSENDmsg(0,1);  //call update request
                   tmrUC=0;              //reset timer
                }                   
 
            }
        }

...

}


and we already have our ClientUpdate for SBC68EC.

simple no? :wink:

it is possible to form this code: in order to send, data of configuration to the server dyndns.org

the service can be proven, with NETCAT.

until the next one!

« Last Edit: September 10, 2007, 12:57:33 PM by niroblock »
do not make any questions, if you already have the answer!