Trouble with FORM SUBMIT

Discussion to talk about software related topics only.
Post Reply
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Trouble with FORM SUBMIT

Post by shockwave77598 »

Using release 2.9.2

What I'm trying to do is have a form with lots of number inputs. And when you hit Send, the webpage has the data for runtimes of the different parts. What I'm getting though is, when I press the Send button, the following happens:
***
The connection was reset

The connection to the server was reset while the page was loading.
***

Looking at the serial debug shows no sign that the Post Handler ever fired, even though I have it set up with SetNewPostHandler().

This is derived from the Mod5270 Factory Demo, which worked fine. What I'm trying to do is get the Forms to work, and it looks like nothing happens after the submit. No serial debug data appears and should if you even enter MyDoForm. Does anyone have an idea what I'm overlooking?

Code follows. Thanks in advance for all your help.

Allen

***
Main.cpp
/* Revision: 2.9.2 */

/******************************************************************************
* Copyright 1998-2019 NetBurner, Inc. ALL RIGHTS RESERVED
*
* Permission is hereby granted to purchasers of NetBurner Hardware to use or
* modify this computer program for any use as long as the resultant program
* is only executed on NetBurner provided hardware.
*
* No other rights to use this program or its derivatives in part or in
* whole are granted.
*
* It may be possible to license this or other NetBurner software for use on
* non-NetBurner Hardware. Contact sales@Netburner.com for more information.
*
* NetBurner makes no representation or warranties with respect to the
* performance of this computer program, and specifically disclaims any
* responsibility for any damages, special or consequential, connected with
* the use of this program.
*
* NetBurner
* 5405 Morehouse Dr.
* San Diego, CA 92121
* www.netburner.com
******************************************************************************/

/*------------------------------------------------------------------------------
* MOD5270 FACTORY DEMO PROGRAM
*----------------------------------------------------------------------------*/

#include <predef.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <ethernet.h>
#include <networkdebug.h>
#include <serial.h>
#include <taskmon.h>
#include <tcp.h>
#include <udp.h>
#include <sim5270.h>
#include <init.h>
#include <http.h>
#include "webfuncs.h"

extern int MyDoPost( int sock, char *url, char *pData, char *rxBuffer );

/*
* Diagnostic functions used in the command dispatcher.
*/
void dEnet( void );
void ShowArp( void );
void ShowCounter( void );
void DumpTcpDebug( void );
void EnableTcpDebug( WORD );


const char *AppName = "MOD5270 Rusty Race Tester";


extern "C"
{
void UserMain( void *pd );
void OSDumpTCBs( void );
}


/*
* Initialize the FTP server. The FTP server will allow a client to obtain
* time and date via the FTP protocol.
*/
void FTPServerInit( int prio );


/**
* This function pings the address given in the buffer.
*/
void ProcessPing( char *buffer )
{
IPADDR addr_to_ping;
char *cp = buffer;

while ( ( *cp ) && ( isspace( *cp ) ) ) // Trim leading white space
{
cp++;
}

if ( cp[0] ) // Get the address of use the default
{
addr_to_ping = AsciiToIp( cp );
}
else
{
addr_to_ping = EthernetIpGate;
}

iprintf( "\r\nPinging: " );
ShowIP( addr_to_ping );
iprintf( "\r\n" );

int rv = Ping( addr_to_ping, /* Id */ 1, /* Seq */ 1, /* Max Ticks */ 100 );

if ( rv == -1 )
{
iprintf( "Failed!\r\n" );
}
else
{
iprintf( "Response took %d ticks.\r\n", rv );
}
}


/**
* Used as part of a bring-up test in manufacturing.
*/
void DoManfTest( void )
{
int fd1 = OpenSerial( 1, 115200, 2, 8, eParityNone );
char buffer[10];
buffer[0] = ' ';

do
{
read( fd1, buffer, 1 );
write( fd1, buffer, 1 );
}
while ( buffer[0] != 'x' );

close( fd1 );
}


/**
* Display the Ethernet link status. This code is only valid in release builds
* because the network builds use Ethernet debugging.
*/
void ShowEthernetLinkStatus( void )
{
if ( EtherLink() )
{
iprintf( "Link Status: UP, " );

( EtherSpeed100() ) ?
iprintf( "100 Mb/s, " ):
iprintf( "10 Mb/s, " );

( EtherDuplex() ) ?
iprintf( "Full Duplex\r\n" ):
iprintf( "Half Duplex\r\n" );
}
else
{
iprintf( "Link Status: DOWN\r\n" );
}
}


/**
* Display debug menu.
*/
void DisplayMenu( void )
{
iprintf( "\r\n----- Main Menu -----\r\n" );
iprintf( "A - Show ARP Cache\r\n" );
iprintf( "C - Show Counters\r\n" );
iprintf( "E - Show Ethernet Registers\r\n" );

#ifdef UCOS_TASKLIST
iprintf( "H - Show Task Changes\r\n" );
#endif /* UCOS_TASKLIST */

iprintf( "I - Setup\r\n" );

#ifdef _DEBUG
iprintf( "L - Set Up Debug Log Enable(s)\r\n" );
#endif /* _DEBUG */

iprintf( "P - Ping (Example: \"P 192.168.1.1\")\r\n" );

#ifdef UCOS_STACKCHECK
iprintf( "S - Show OS Task Stack Info\r\n" );
iprintf( "U - Show OS Task Info\r\n" );
#endif /* UCOS_STACKCHECK */

#ifdef _DEBUG
iprintf( "T - DumpTcpDebug\r\n" );
#endif /* _DEBUG */

iprintf( "W - Show OS Seconds Counter\r\n" );
iprintf( "? - Display Menu\r\n" );

ShowEthernetLinkStatus();
iprintf("IP Address: %HI\r\n", EthernetIP);
}


/**
* Handle commands with a trivially simple command dispatcher.
*/
void ProcessCommand( char *buffer )
{
switch ( toupper( buffer[0] ) )
{
case 'A':
ShowArp();
break;
case 'C':
ShowCounters();
break;
case 'E':
dEnet();
break;

#ifdef UCOS_TASKLIST
case 'H':
ShowTaskList();
break;
#endif /* UCOS_TASKLIST */

case 'I':
SetupDialog();
break;

#ifdef _DEBUG
case 'L':
SetLogLevel();
break;
#endif /* _DEBUG */

case 'P':
ProcessPing( buffer + 1 );
break;
case '~':
DoManfTest();
break;

#ifdef UCOS_STACKCHECK
case 'U':
OSDumpTasks();
break;
case 'S':
OSDumpTCBStacks();
break;
#endif /* UCOS_STACKCHECK */

#ifdef _DEBUG
case 'T':
DumpTcpDebug();
break;
#endif /* _DEBUG */

case 'W':
iprintf( "Tick Count = 0x%lX = %ld (%ld seconds)\r\n", TimeTick,
TimeTick, ( TimeTick / TICKS_PER_SECOND ) );
break;
default: // '?'
DisplayMenu();
}
}

extern const char *default_page;

/**
* The main task.
*/
void UserMain( void *pd )
{
initWithWeb();

OSChangePrio( MAIN_PRIO ); // Set main task priority to the default (50)
EnableAutoUpdate(); // Enable NB application AutoUpdate support
StartHTTP(); // Start web server
default_page = "index.html";
EnableTaskMonitor();


/*
* The Initialize Network Debug functions are only valid when the application
* is compiled in debug mode, which can be detected with the preprocessor
* "#ifdef _DEBUG" definition. InitializeNetworkGDB() will tell the GDB
* setup on the NetBurner device to listen and then allow the application to
* run normally. InitializeNetworkGDB_and_Wait() will pause the application
* until the debugger connects.
*/
#ifdef _DEBUG
InitializeNetworkGDB();
//InitializeNetworkGDB_and_Wait();
#endif /* _DEBUG */

FTPServerInit( MAIN_PRIO - 2 ); // Start the FTP Server

// SetCallback(); // set the form callback function

iprintf( "%s\r\n", FirmwareVersion );
DisplayMenu();

char buffer[255];
buffer[0] = '\0';

while ( 1 )
{
if ( charavail() )
{
gets( buffer );
ProcessCommand( buffer );
buffer[0] = '\0';
}
}
}


webfuncs.cpp

/* Revision: 2.9.2 */

/******************************************************************************
* Copyright 1998-2019 NetBurner, Inc. ALL RIGHTS RESERVED
*
* Permission is hereby granted to purchasers of NetBurner Hardware to use or
* modify this computer program for any use as long as the resultant program
* is only executed on NetBurner provided hardware.
*
* No other rights to use this program or its derivatives in part or in
* whole are granted.
*
* It may be possible to license this or other NetBurner software for use on
* non-NetBurner Hardware. Contact sales@Netburner.com for more information.
*
* NetBurner makes no representation or warranties with respect to the
* performance of this computer program, and specifically disclaims any
* responsibility for any damages, special or consequential, connected with
* the use of this program.
*
* NetBurner
* 5405 Morehouse Dr.
* San Diego, CA 92121
* www.netburner.com
******************************************************************************/

/*------------------------------------------------------------------------------
* File: webfuncs.cpp
* Description: Dynamic web server content functions.
*----------------------------------------------------------------------------*/

#include <predef.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <tcp.h>
#include <udp.h>
#include <sim5270.h>
#include <http.h>
#include "webfuncs.h"


/*
* Functions linked to web FUNCTIONCALL tags.
*/
extern "C"
{

void DisplayFirmwareVersion( int sock, PCSTR url );
int MyDoPost( int sock, char *url, char *pData, char *rxBuffer );
void GetLastPost( int sock, PCSTR url );
}

void SetCallback()
{
SetNewPostHandler( MyDoPost );
}

// External references
char buffer[255];
char lastpost[255] = "NoData";
unsigned int Passcount = 0;
#define MAX_BUF_LEN 255
char textForm1[MAX_BUF_LEN];



void GetLastPost( int sock, PCSTR url )
{
sniprintf( buffer, 255, "<p> %s</p>", lastpost );
writestring( sock, buffer );
}

/*
* Display the factory demo application revision number and compilation date
* in index.htm.
*/
void DisplayFirmwareVersion( int sock, PCSTR url )
{
writestring( sock, FirmwareVersion );
}

int MyDoPost( int sock, char *url, char *pData, char *rxBuffer )
{
// Display the data passed in just for the purpose of this example
iprintf("----- Processing Post -----\r\n");
iprintf("Post URL: %s\r\n", url);
iprintf("Post Data: %s\r\n", pData);
strcpy(lastpost, pData);

/* Parse the url to determine which form was used. The item
* we are parsing for is defined by the HTML Form tag called
* "action". It can be any name, but in this example we are
* using it to tell us what web page the form was sent from.
* Note that httpstricmp() requires the search string to
* be in upper case, even if the action tag is lower case.
*/
if ( httpstricmp( url + 1, "r1" ) )
{
ExtractPostData( "r1", pData, textForm1, 256 );
iprintf("textForm1 set to: \"%s\"\r\n", textForm1 );
Passcount+=1;
// Tell the web browser to issue a GET request for the next page
RedirectResponse( sock, "form1.htm" );
}
else
{
NotFoundResponse( sock, url );
iprintf("We did not match any page\r\n");
RedirectResponse( sock, "form1.htm" );
}

return 1;
}
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Trouble with FORM SUBMIT

Post by pbreed »

Your SetCallback function call is commented out.
shockwave77598
Posts: 22
Joined: Sat May 27, 2017 10:38 am

Re: Trouble with FORM SUBMIT

Post by shockwave77598 »

*emails you a fine 20 year old scotch*

Pbreed, you are a gentleman and a scholar. That was the problem. I had other things causing issues and commented it out to simplify the problem to get it working. And yes, I forgot to plug it back in again.

Onward and upward! Thanks!
Post Reply