Webduino Webserver crashing Spark Core

Hello hopefully someone can help me a bit here.

Trying to set up a simple server using https://github.com/m-mcgowan/Webduino to be able to send POST requests to the spark core.

I’m using the hello world example from github, and have added a POST if statement


 if (type == WebServer::POST){
 bool repeat;
 char name[16], value[16];
 
 do
{
/* readPOSTparam returns false when there are no more parameters
* to read from the input. We pass in buffers for it to store
* the name and value strings along with the length of those
* buffers. */
repeat = server.readPOSTparam(name, 16, value, 16);

} while (repeat);
 
}

but cannot for the life of me figure out how to get the name and value strings saved and then printed on the server webpage let alone get them saved to a Spark.variable.

For whatever reason my Spark core seems to be crashing when even adding a server.print() to the following, or *n = *name, they all crash the core.

/* Web_HelloWorld.pde - very simple Webduino example */
#include "application.h"
#include "WebServer.h"
/* This creates an instance of the webserver. By specifying a prefix
* of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 80);
/* commands are functions that get called by the webserver framework
* they can read any posted data from client, and they output to the
* server to send data back to the web browser. */


void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
/* this line sends the standard "we're all OK" headers back to the
browser */
server.httpSuccess();
/* if we're handling a GET or POST, we can output our data here.
For a HEAD request, we just stop after outputting headers. */

if (type != WebServer::HEAD)
{
/* this defines some HTML text in read-only memory aka PROGMEM.
* This is needed to avoid having the string copied to our limited
* amount of RAM. */
P(helloMsg) = "<h1>Hello, World!<form method='post'><input type='text' name='test'><input type='submit' value='Submit'></form></h1>";
/* this is a special form of print that outputs from PROGMEM */
server.printP(helloMsg);

}

 if (type == WebServer::POST){
 bool repeat;
 char name[16], value[16];
do
{
/* readPOSTparam returns false when there are no more parameters
* to read from the input. We pass in buffers for it to store
* the name and value strings along with the length of those
* buffers. */
repeat = server.readPOSTparam(name, 16, value, 16);

Here is where im trying to add server.print(name) and server.print(value), my main goal is to get them saved to new chars to be used elsewhere, n = name; just returns $ when printed elsewhere though.

The second this line is added when i go to the webpage and click submit the page shows what i expect but the core instantly crashes, i somehow managed to get it working once with the same code and no crashing…


server.print(name);

and the rest of the code


} while(repeat);

}

}
 
 
void setup()
{
    

/* setup our default command that will be run when the user accesses
* the root page on the server */
webserver.setDefaultCommand(&helloCmd);
/* run the same command if you try to load /index.html, a common
* default page name */
webserver.addCommand("index.html", &helloCmd);
/* start the webserver */
webserver.begin();

}
void loop()
{
char buff[64];
int len = 64;
/* process incoming connections one at a time forever */
webserver.processConnection(buff, &len);
}

I’m litterally at a standstill right now, this is the only REST webserver on github that actually works and i can POST to.

@xenoborg, can you post your full code cause I am not quite sure what you are trying to do. Are you compiling on the web IDE or locally? :smile:

That is the full code, its just Webserver.h and ccp from https://github.com/m-mcgowan/Webduino “ccp is blank though” along with my ino file above. Compiling on IDE everything checks out but everyway i can think of to grab name and value crashes the core for whatever reason.

All I need is for a device whos only capable method of communication is POST to periodically POST to the spark core over local connection and receive a 200 response ok, and then for the spark core to be able to grab the names and values POSTed and do stuff with it.

Full ino file again


/* Web_HelloWorld.pde - very simple Webduino example */
#include "application.h"
#include "WebServer.h"
/* This creates an instance of the webserver. By specifying a prefix
* of "", all pages will be at the root of the server. */
#define PREFIX ""
WebServer webserver(PREFIX, 80);
/* commands are functions that get called by the webserver framework
* they can read any posted data from client, and they output to the
* server to send data back to the web browser. */
char *n;

void helloCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
/* this line sends the standard "we're all OK" headers back to the
browser */
server.httpSuccess();
/* if we're handling a GET or POST, we can output our data here.
For a HEAD request, we just stop after outputting headers. */

if (type != WebServer::HEAD)
{
/* this defines some HTML text in read-only memory aka PROGMEM.
* This is needed to avoid having the string copied to our limited
* amount of RAM. */
P(helloMsg) = "<h1>Hello, World!<form method='post'><input type='text' name='test'><input type='submit' value='Submit'></form></h1>";
/* this is a special form of print that outputs from PROGMEM */
server.printP(helloMsg);

}

 if (type == WebServer::POST){
 bool repeat;
 char name[16], value[16];
do
{
/* readPOSTparam returns false when there are no more parameters
* to read from the input. We pass in buffers for it to store
* the name and value strings along with the length of those
* buffers. */
repeat = server.readPOSTparam(name, 16, value, 16);

n = name;
server.print(n);

} while(repeat);

}

}
 
 
void setup()
{
    

/* setup our default command that will be run when the user accesses
* the root page on the server */
webserver.setDefaultCommand(&helloCmd);
/* run the same command if you try to load /index.html, a common
* default page name */
webserver.addCommand("index.html", &helloCmd);
/* start the webserver */
webserver.begin();

}
void loop()
{
char buff[64];
int len = 64;
/* process incoming connections one at a time forever */
webserver.processConnection(buff, &len);
}