[En-Nut-Discussion] NutTcpConnect error on GPRS Connection (MC35i)

Brett Abbott Brett.Abbott at digital-telemetry.com
Mon May 29 04:54:15 CEST 2006


Paolo

We've had both g18 and mc35i working well on the same network and 
identical code.

A couple of things to watch for.  You may find that the difference in 
modem will be due to handshaking and speed.  If you dont use hardware 
handshaking, buffer over run could be the issue.

I suggest trying to connect at a lower baud rate between nut and modem 
to determine if over the air baud rate is your issue - the mc35i is 
capable of higher speeds than the g18 over the air - this could result 
in more data coming through to the ethernut, even if the rs232 baud rate 
between modem and nut is the same.  Lowering the baud rate to 19200 or 
9600 may resolve this and force the modem to buffer better.

I note also you are atd*98#.  I dont know if this makes a difference, 
but we typically use:
atd*99***1#    This tells the modem to use the default IP interface for 
the specified APN, using the numbered CGD Context.,
 eg.

AT+CGDCONT=1,"IP","web.omnitel.it"
ATD*99***1#

where 1 is the named context.  (=1 and *1#)

Failing that, make sure your mc35i has the latest flash version.  Older 
versions of the flash didnt cope too well with some network operator 
conditions, especially if the modem was stationary.  You may need to 
check this with Siemens.

Cheers
Brett

paolo wrote:

>Hi all,
>
>I experimented a while with GPRS connection, using uart1 to connect my
>Ethernut 1.3 to a Motorola G18 Modem. After many trials, choosing the
>right Italian operator (Vodafone) leaded to a succesful PPP connection
>and I could connect to a server (www.google.com on port 80) and open a
>socket/ask for a page. 
>
>Now I changed my GPRS modem to Siemens MC35i: the modem seems to raise
>up PPP link correctly, I can access my DNS server to resolve google, but
>then I get error when I try to open a socket to server with instruction
>NutTcpConnect.
>
>This is my log:
>
>Wake UP...OK.             
>Connecting...done.                  
>
>Configure PPP...                
>[LCP-LOWERUP]             
>PPP<(20)[LCP-001(16)][CONFREQ][OPT(12)][ACCM=0x000A0000][MAGIC=0x7956341
>2]
>
>PPP>(29)[LCP-003(25)][CONFREQ][OPT(21)][ACCM=0x000A0000][PCOMP][ACOMP][M
>AGIC=0x3
>
>C8523FA][AUTH=0xC223]                     
>PPP<(12)[LCP-003(8)][CONFNAK][OPT(4)][AUTH=0xC023]
>
>PPP>(20)[LCP-001(16)][CONFACK][OPT(12)][ACCM=0x000A0000][MAGIC=0x7956341
>2]
>
>PPP>(28)[LCP-005(24)][CONFREQ][OPT(20)][ACCM=0x000A0000][PCOMP][ACOMP][M
>AGIC=0x3
>
>C8523FA][AUTH=0xC023]                     
>PPP<(28)[LCP-005(24)][CONFACK][OPT(20)][ACCM=0x000A0000][PCOMP][ACOMP][M
>AGIC=0x3
>
>C8523FA][AUTH=0xC023]                     
>PPP<(10)[PAP-003(6)][CONFREQ][OPT(2)]
>
>PPP>(9)[PAP-003(5)][CONFACK]                            
>[IPCP-LOWERUP]              
>PPP<(26)[IPCP-004(22)][CONFREQ][OPT(18)][ADDR=0.0.0.0][DNS1=0.0.0.0][DNS
>2=0.0.0.
>
>0]  
>PPP>(14)[IPCP-001(10)][CONFREQ][OPT(6)][ADDR=192.168.254.254]
>
>PPP<(14)[IPCP-001(10)][CONFACK][OPT(6)][ADDR=192.168.254.254]
>
>PPP<(26)[IPCP-004(22)][CONFREQ][OPT(18)][ADDR=0.0.0.0][DNS1=0.0.0.0][DNS
>2=0.0.0.
>
>0]  
>PPP>(14)[IPCP-004(10)][CONFREJ][OPT(6)][DNS2=0.0.0.0]
>
>PPP<(20)[IPCP-005(16)][CONFREQ][OPT(12)][ADDR=0.0.0.0][DNS1=0.0.0.0]
>
>PPP>(20)[IPCP-005(16)][CONFNAK][OPT(12)][ADDR=10.145.66.89][DNS1=83.224.
>65.134]
>
>PPP<(20)[IPCP-006(16)][CONFREQ][OPT(12)][ADDR=10.145.66.89][DNS1=83.224.
>65.134]
>
>PPP>(20)[IPCP-006(16)][CONFACK][OPT(12)][ADDR=10.145.66.89][DNS1=83.224.
>65.134]
>done   
>     Local IP: 10.145.66.89
>    Remote IP: 192.168.254.254
>  Primary DNS: 83.224.65.134
>Secondary DNS: 0.0.0.0
>NutIpRouteAdd restituisce 0
>call NutDnsGetHostByName to resolve www.google.com
>
>PPP<(64)
>PPP>(308)OK: il server www.google.com E' disponibile!
>Connecting 66.249.93.99:80
>
>PPP<(48)
>PPP<(48)
>PPP<(48)
>PPP<(48)
>PPP<(48)
>PPP<(48)
>PPP<(48)
>PPP<(48)
>PPP<(48)Bad news, www.google.com refuses the connection.(error 10060)
>Disconnecting 66.249.93.99:80
>
>
>I enclose my source code, wich is a mix between pppc.c and inetq.c
>examples:
>
>*!
> * \example pppc/pppc.c
> *
> * PPP client. Similar to the TCP server sample, but uses PPP over
>RS232.
> *
> * The default settings in this sample may be used to connect to a RAS
> * server of a Windows PC. When adding a similar modem script, it will
> * also work with a Linux PC nearly out of the box. At least you need
> * to change the PPPUSER and PPPPASS.
> *
> * \bug This sample works with ICCAVR (6.28 tested) only with debugging
> *      enabled.
> *
> * \bug Not working with ATmega103. Debug output needs to be removed.
> */
>#define INETSERVER  "www.google.com"
>#define INETSERVERPORT  80
>
>/*
> * The Nut/OS modem chat utility works similar to the the UNIX
> * chat script. This one is used to connect to a Windows PC
> * using a direct cable.
> */
>#define PPPCHAT     "TIMEOUT 15 '' AT OK AT&D2 OK
>AT+CGDCONT=1,\"IP\",\"web.omnitel.it\" OK ATD*98# CONNECT"
>
>/*
> * PPP device settings.
> */
>#define PPPDEV      devAhdlc1   /* Use HDLC driver. */
>//#define PPPDEV      devUart1    /* Use standard UART driver. */
>#define PPPCOM      "uart1"     /* Physical device name. */
>#define PPPSPEED    57600       /* Baudrate. */
>#define PPPRXTO     1000        /* Character receive timeout. */
>
>
>/*
> * Server input buffer size.
> */
>#define RXBUFFSIZE  8192
>
>
>
>#include <cfg/os.h>
>#include <dev/debug.h>
>//#include <dev/hd44780.h>
>#include <dev/ahdlcavr.h>
>#include <dev/uartavr.h>
>#include <dev/ppp.h>
>#include <dev/chat.h>
>
>#include <sys/version.h>
>#include <sys/heap.h>
>#include <sys/thread.h>
>#include <sys/timer.h>
>#include <sys/event.h>
>#include <sys/socket.h>
>
>#include <dev/board.h>
>#include "pppc.h"
>
>
>#include <sys/timer.h>
>
>#include <arpa/inet.h>
>#include <netdb.h>
>#include <net/if_var.h>
>#include <net/route.h>
>
>#ifdef NUTDEBUG
>#include <net/netdebug.h>
>#endif
>
>#include <stdlib.h>
>#include <string.h>
>#include <stdio.h>
>#include <io.h>
>#include <fcntl.h>
>
>#if defined(__IMAGECRAFT__)
>#define CC_STRING   "ICCAVR"
>#elif defined(__GNUC__)
>#define CC_STRING   "AVRGCC"
>#else
>#define CC_STRING   "Compiler unknown"
>#endif
>
>/*
> * Debug output device settings.
> */
>#ifdef __AVR_ENHANCED__
>//#define DBGDEV      devAhdlc0
>#define DBGDEV      devDebug0   /* Use debug driver. */
>//#define DBGDEV      devUart0    /* Use standard UART driver. */
>#define DBGCOM      "uart0"     /* Device name. */
>#define DBGSPEED    57600      /* Baudrate. */
>#endif
>
>/*
> * PPP client application entry.
> */
>int main(void)
>{
>    int pppcom;
>    PPPDCB *dcb;
>    u_long lctl;
>    int rc;
>	int i;
>	int PPP_loop;
>
>//	Variabili per il dialogo HTTP
>   	TCPSOCKET *sock;
>	u_long rip;
>	
>	FILE *stream;
>	 
>    /*
>     * Register our devices.
>     */
>#ifdef __AVR_ENHANCED__
>    NutRegisterDevice(&DBGDEV, 0, 0);	// devUart0 ovvero devDebug0
>#endif
>    NutRegisterDevice(&PPPDEV, 0, 0);	// devUart1 ovvero devAhdlc1
>    NutRegisterDevice(&devPpp, 0, 0);	// devPpp e' il nome del device
>implementato da dev\ppp.h
>
>    /*
>     * Open debug device for standard output.
>     */
>    if(freopen(DBGCOM, "w", stdout) == 0) {
>        for(;;);
>    }
>    /*
>     * Set debug output speed.
>     */
>#ifdef __AVR_ENHANCED__
>    lctl = DBGSPEED;
>    _ioctl(_fileno(stdout), UART_SETSPEED, &lctl);
>#endif
>
>    /*
>     * Open PPP device. Specify physical device, user and password.
>     * pppcom = _open("ppp:uart0/user/passwd", _O_RDWR | _O_BINARY);
>     */
>	printf("Open uart...");
>    
>	/* GPRS: apro ppp senza usernane e password	*/    	
>    if ((pppcom = _open("ppp:" PPPCOM "/" "/", _O_RDWR | _O_BINARY)) ==
>-1) {    	
>
>        printf("Failed to open " PPPCOM "\n");
>        for (;;);
>    }
>    puts("done");
>
>    /*
>     * Set PPP line speed.
>     */
>    lctl = PPPSPEED;
>    _ioctl(pppcom, UART_SETSPEED, &lctl);
>
>    /*
>     * The PPP driver doesn't set any receive timeout, but
>     * may require it.
>     */
>    lctl = PPPRXTO;
>    _ioctl(pppcom, UART_SETREADTIMEOUT, &lctl);
>
>#ifdef NUTDEBUG
>    /*
>     * Optionally enable PPP trace. 
>     */
>    NutTracePPP(stdout, 1); 	// 1: tracing enabled
>//    NutTraceTcp(stdout, 1);		
>//    NutTraceOs(stdout, 0);
>//    NutTraceHeap(stdout, 0);
>//    NutTracePPP(stdout, 0);
>    
>#endif
>
>    
>    /*
>     * TODO This delay may be removed. It is quite helpful during
>development.
>     */
>    NutSleep(1000);
>    
>    /*
>     * PPP connection loop.
>     */
>    PPP_loop = 1;
>	while (PPP_loop == 1) 
>	{
>        /*
>         * Connect using a chat script. We may also set any
>         * required hardware handshake line at this stage.
>         */
>
>        printf("Connecting...");
>        if ((rc = NutChat(pppcom, PPPCHAT)) != 0) {
>        	printf("no connect, reason = %d\n", rc);
>            continue;
>        }
>        puts("done.\r\n");
>
>
>        /*
>         * We are connected, configure our PPP network interface.
>         * This will initiate the PPP configuration negotiation
>         * and authentication with the server.
>         */
>        printf("Configure PPP...");
>        rc = NutNetIfConfig("ppp", 0, 0, 0);
>        if (rc != 0) {
>            puts("failed");
>            continue;
>            /*
>             * Optionally toggle DTR to hang up the modem.
>             */
>            continue;
>        }
>        puts("done");
>
>        /*
>         * Set name server and default route. Actually the PPP interface
>         * should do this, but the current release doesn't.
>         */
>        dcb = devPpp.dev_dcb;
>        NutDnsConfig2(0, 0, dcb->dcb_ip_dns1, dcb->dcb_ip_dns2);
>        i = NutIpRouteAdd(0, 0, dcb->dcb_remote_ip, &devPpp);
>
>        /*
>         * Display our IP settings.
>         */
>        printf("     Local IP: %s\n", inet_ntoa(dcb->dcb_local_ip));
>        printf("    Remote IP: %s\n", inet_ntoa(dcb->dcb_remote_ip));
>        printf("  Primary DNS: %s\n", inet_ntoa(dcb->dcb_ip_dns1));
>        printf("Secondary DNS: %s\n", inet_ntoa(dcb->dcb_ip_dns2));
>        printf("NutIpRouteAdd restituisce %d\n", i);
>
>		/*
>	     * Resolve hostname using DNS. (vedi esempio inetq.c)
>	     */
>    printf("chiamo NutDnsGetHostByName per risolvere %s\n", INETSERVER);
>	    i = -1; 
>	    if ((rip = NutDnsGetHostByName(INETSERVER)) != 0) {
>			printf("OK: il server %s E' disponibile!\n",
>INETSERVER);
>			i = 0;
>		} 
>		else 
>		printf("ERROR: il server %s non e' disponibile!\n",
>INETSERVER);
>
>		if (i == 0)
>		{
>	        /*
>	         * Now let's use native calls.
>	         */
>	        if ((sock = NutTcpCreateSocket()) != 0) {
>
>		        /*
>		         * Connect a HTTP server in the Internet.
>		         */
>        printf("Connecting %s:%u\r\n", inet_ntoa(rip), INETSERVERPORT);
>
>		        if (NutTcpConnect(sock, rip, INETSERVERPORT) ==
>0) 
>		        {
>           	printf("OK, %s connected.\r\nAssign stream...\r\n",
>INETSERVER);		        	
>	                /*
>	                 * Assign a stream to our connected socket.
>	                 */
>	                if ((stream = _fdopen((int) sock, "r+b")) != 0) 
>	                {
>					    for (;;)
>					    {
>					        NutSleep(100);
>					    }
>
>						fclose(stream);
>	                } 
>	                else 
>	                {
>		                printf("Creating stream device
>failed\n");
>					}
>               	
>				}
>				else 
>				{
>					i = NutTcpError(sock);
>printf("Bad news, %s refuses the connection.(error %d)\n", INETSERVER,
>i);
>            	}
>         	printf("Disconnecting %s:%u\n", inet_ntoa(rip),
>INETSERVERPORT);
>            	NutTcpCloseSocket(sock);
>
>	        } else printf ("Socket creation failed !\n");
>		} risolto
>
>		NutSleep(5000);
>
>		PPP_loop = 0;		
>    }	//	while (PPP_loop == 1)
>
>	printf("END PROGRAM.\n");
>    for (;;)
>    NutSleep(1000);
>}
>
>
>Can anybody help me ?
>Best regards,
>Paolo
>
>_______________________________________________
>En-Nut-Discussion mailing list
>En-Nut-Discussion at egnite.de
>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>
>
>  
>

-- 
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: Brett.Abbott at digital-telemetry.com
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860  Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------





More information about the En-Nut-Discussion mailing list