SoftAP HTTP Pages not compiling

Similar to Photon SoftAP Webserver not working, I’m having issues getting the SoftAP code to compile. Here is my current setup:

I copied the html and js declarations from the HTTP Soft Pages example and have them bundled in softap_http.h. This is the core application code, application.ino:

#pragma PARTICLE_NO_PREPROCESSOR

#include "Particle.h"
#include "softap_http.h"


// SoftAP
struct Page
{
    const char* url;
    const char* mime_type;
    const char* data;
};

Page myPages[] = {
     { "/index.html", "text/html", index_html },
     { "/rsa-utils/rsa.js", "application/javascript", rsa_js },
     { "/style.css", "text/css", style_css },
     { "/rsa-utils/rng.js", "application/javascript", rng_js },
     { "/rsa-utils/jsbn_2.js", "application/javascript", jsbn_2_js },
     { "/rsa-utils/jsbn_1.js", "application/javascript", jsbn_1_js },
     { "/script.js", "application/javascript", script_js },
     { "/rsa-utils/prng4.js", "application/javascript", prng4_js },
     { nullptr }
};

void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved)
{
    Serial.printlnf("handling page %s", url);

    if (strcmp(url,"/index")==0) {
        Serial.println("sending redirect");
        Header h("Location: /index.html\r\n");
        cb(cbArg, 0, 301, "text/plain", &h);
        return;
    }

    int8_t idx = 0;
    for (;;idx++) {
        Page& p = myPages[idx];
        if (!p.url) {
            idx = -1;
            break;
        }
        else if (strcmp(url, p.url)==0) {
            break;
        }
    }

    if (idx==-1) {
        cb(cbArg, 0, 404, nullptr, nullptr);
    }
    else {
        cb(cbArg, 0, 200, myPages[idx].mime_type, nullptr);
        result->write(myPages[idx].data);
    }
}

STARTUP(softap_set_application_page_handler(myPage, nullptr));

// Press SETUP for 3 seconds to make the Photon enter Listening mode
// Navigate to http://192.168.0.1 to setup Wi-Fi

// Include the rest of your application below,
// including your setup and loop functions

//

void setup() {
}



void loop() {
}

I’m getting the following error when I try to compile. I’ve tried compiling from the Particle Dev environment, as well as over the command line with particle compile photon .

src/application.cpp:13:30: error: 'ResponseCallback' has not been declared
 void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved);
                              ^
src/application.cpp:13:65: error: 'Reader' has not been declared
 void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved);
                                                                 ^
src/application.cpp:13:79: error: 'Writer' has not been declared
 void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved);
                                                                               ^
src/application.ino:32:30: error: 'ResponseCallback' has not been declared
 void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved)
                              ^
src/application.ino:32:65: error: 'Reader' has not been declared
 void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved)
                                                                 ^
src/application.ino:32:79: error: 'Writer' has not been declared
 void myPage(const char* url, ResponseCallback* cb, void* cbArg, Reader* body, Writer* result, void* reserved)
                                                                               ^
src/application.ino: In function 'void myPage(const char*, int*, void*, int*, int*, void*)':
src/application.ino:38:9: error: 'Header' was not declared in this scope
         Header h("Location: /index.html\r\n");
         ^
src/application.ino:39:42: error: 'h' was not declared in this scope
         cb(cbArg, 0, 301, "text/plain", &h);
                                          ^
src/application.ino:39:43: error: 'cb' cannot be used as a function
         cb(cbArg, 0, 301, "text/plain", &h);
                                           ^
src/application.ino:56:43: error: 'cb' cannot be used as a function
         cb(cbArg, 0, 404, nullptr, nullptr);
                                           ^
src/application.ino:59:58: error: 'cb' cannot be used as a function
         cb(cbArg, 0, 200, myPages[idx].mime_type, nullptr);
                                                          ^
src/application.ino:60:17: error: request for member 'write' in '* result', which is of non-class type 'int'
         result->write(myPages[idx].data);
                 ^
In file included from ../wiring/inc/spark_wiring_usbserial.h:34:0,
                 from ./inc/application.h:49,
                 from ./inc/Particle.h:5,
                 from src/application.cpp:3:
src/application.ino: In constructor 'startup0::startup0()':
src/application.ino:64:60: error: 'softap_set_application_page_handler' was not declared in this scope
 STARTUP(softap_set_application_page_handler(myPage, nullptr));
                                                            ^
../wiring/inc/spark_wiring_startup.h:27:37: note: in definition of macro 'STARTUP__'
     struct name##id {  name##id() { code; } };  static name##id __instance_##name##id;
                                     ^
../wiring/inc/spark_wiring_startup.h:21:23: note: in expansion of macro 'STARTUP_'
 #define STARTUP(code) STARTUP_(startup, __COUNTER__, code)
                       ^
src/application.ino:64:1: note: in expansion of macro 'STARTUP'
 STARTUP(softap_set_application_page_handler(myPage, nullptr));
 ^
../build/module.mk:267: recipe for target '../build/target/user/platform-6-msrc/application.o' failed
make[2]: Leaving directory '/firmware/user'
make[2]: *** [../build/target/user/platform-6-msrc/application.o] Error 1
../../../build/recurse.mk:11: recipe for target 'user' failed
make[1]: Leaving directory '/firmware/modules/photon/user-part'
make[1]: *** [user] Error 2
../build/recurse.mk:11: recipe for target 'modules/photon/user-part' failed
make: *** [modules/photon/user-part] Error 2
Compile a source file, or directory using the cloud compiler
Usage: particle compile [options] <deviceType> [files...]

Have you got #include <Particle.h> in your softap_http.h?
If you are using Web IDE you could also provide a snapshot link to your project so we could better focus the answers to your exact issue, without needing to guess and drill down on it if the first guesses are not the solution.

Thanks for the input, @ScruffR. I do have #include <Particle.h> in softap_http.h. I have also tried not including Particle in that file and I get the same error.

I wasn't using the Web IDE, but I just added it and am getting the same error. Here is the snapshot link

Hi @gemfarmer

The types that are missing in your compile are brought to the party by the softap_http.h header, so they should be there.

Are you sure you are compiling for a Photon? Those types are not available on an Electron or Core.

@bko I'm pretty sure that I'm compiling for a photon.I get the same errors when I run particle compile photon . with the Particle CLI, if that helps.

I'm a bit confused by this comment though:

As far as I can tell, the only declarations in softap_http.h are compressed html and js. ResponseCallback, Reader, Writer, etc. don't look like they are declared there. Or am I misunderstanding your comment?

Is softap_http.h a library that I'm mis-using? By adding my own softap_http.h am I overwriting the library?

Yes, see here:

1 Like

Thanks! That did it!

My confusion came from the softap-setup-page (below). It compresses files into a file labelled softap_http.h. I’ll have to make a PR to update the documentation there.

1 Like