Skip to content

Ledcontrol in Sd card #6

Open
Open
@jmcastillejo

Description

@jmcastillejo

I run the webbino server on a stm32 bluepill with an sdcard, but I can not get server requests to work. it works if I use flash storage, but not when I use storage on sdcard.

In the example ledcontrol the function ledToggle is called from this line:
const Page page01 PROGMEM = {index_html_name, index_html, index_html_len, ledToggle};

how do I call that function when I use sdcard storage?

Thank you

Activity

SukkoPera

SukkoPera commented on Apr 26, 2019

@SukkoPera
Owner

This is not supported at the moment, if I remember correctly. Functions can only be associated to pages stored in flash.

I am currently away, I will check better when I'm home, in a week or so.

qniens

qniens commented on Apr 26, 2019

@qniens
Contributor

A workaround is to make the following variable public instead of private
byte ethernetBuffer[MAX_URL_LEN + 16];
In WIZ5x00.h (or the interface you use) .
Then you can parse the GET request line yourself

SukkoPera

SukkoPera commented on Apr 26, 2019

@SukkoPera
Owner

Uhm, and where do you do that?

I don't think any hacks are necessary, this should be pretty straightforward to do with the last code refactoring I did. I will have a look at it ASAP.

jmcastillejo

jmcastillejo commented on Apr 26, 2019

@jmcastillejo
Author

Thanks for your work, it's a great project

SukkoPera

SukkoPera commented on May 16, 2019

@SukkoPera
Owner

This should be done with 3c51945, please check out the current master branch, test it and report.

See the LedControl example for the new method of associating functions to pages, this should work across all backends.

jmcastillejo

jmcastillejo commented on May 17, 2019

@jmcastillejo
Author

Hello!!

I have tested the modifications and it still does not work using the sd card, only work with flash

SukkoPera

SukkoPera commented on May 17, 2019

@SukkoPera
Owner

A quick test I did works instead. Can you please post your sketch?

SukkoPera

SukkoPera commented on May 17, 2019

@SukkoPera
Owner

@jmcastillejo: Make sure to associate the function with FileFuncAssoc rather than with FlashFileFuncAssoc as shown in the current LedControl version.

jmcastillejo

jmcastillejo commented on May 17, 2019

@jmcastillejo
Author

if I change the FlashFileFuncAssoc function by FileFuncAssoc I get the following error:

src / WebbinoCore / WebServer.h: 101: 60: note: in definition of macro 'FileFuncAssoc'

             const char REPTAG_FFA_VAR (var) [] PROGMEM = path; \

exit status 1
initializer fails to determine size of '_ffa_indexAss'

SukkoPera

SukkoPera commented on May 18, 2019

@SukkoPera
Owner

Try something like:

FileFuncAssoc (indexAss, "/index.htm", indexFunc);
jmcastillejo

jmcastillejo commented on May 18, 2019

@jmcastillejo
Author

With that it compiles well, it executes the function in the http request but the tags do not work, and in the chrome the save window appears as when entering the url. This is the sketch:

#include <Webbino.h>
#include <WebbinoInterfaces/WIZ5x00.h>

const byte ledPin = 1;
const byte LED_ACTIVE_LEVEL = HIGH;
boolean ledState = false;
const uint8_t SD_CS = PB12;   // chip select for sd

// Instantiate the WebServer and page storage
WebServer webserver;

SdStorage sdStorage;
NetworkInterfaceWIZ5x00 netint;

/******************************************************************************
 * PAGE FUNCTIONS                                                             *
 ******************************************************************************/

void led (HTTPRequestParser& request) {
	char *param;

	param = request.get_parameter (F("state"));
	if (strlen (param) > 0) {
		if (strcmp_P (param, PSTR ("on")) == 0) {
			ledState = true;
			digitalWrite (ledPin, LED_ACTIVE_LEVEL);

		} else {
			ledState = false;
			digitalWrite (ledPin, !LED_ACTIVE_LEVEL);
		}
	}
}

FileFuncAssoc (indexAss, "/index.htm", led);
FileFuncAssociationArray associations[] PROGMEM = {
  &indexAss,
  NULL
};

/******************************************************************************
 * DEFINITION OF TAGS                                                         *
 ******************************************************************************/

#define REP_BUFFER_LEN 32
char replaceBuffer[REP_BUFFER_LEN];
PString subBuffer (replaceBuffer, REP_BUFFER_LEN);

PString& onoff_checked (void *data) {
	boolean st = reinterpret_cast<int> (data);
	if (ledState == st) {
		subBuffer.print ("checked");
	}
	return subBuffer;
}

PString& _version (void *data __attribute__ ((unused))) {
	subBuffer.print (WEBBINO_VERSION);
	return subBuffer;
}

PString& evaluate_ip_src (void *data __attribute__ ((unused))) {
  subBuffer.print (Ethernet.localIP());
  return subBuffer;
}

// ReemplazoTag (nombretagarray, tabenlaweb, funcion);
EasyReplacementTag (tagestadoOn, ST_ON_CHK, onoff_checked, true);
EasyReplacementTag (tagestadoOff, ST_OFF_CHK, onoff_checked, false);
EasyReplacementTag (tagVersion, WEBBINO_VER, _version);
EasyReplacementTag (tagNetConfSrc, NET_CONF_SRC, evaluate_ip_src);

EasyReplacementTagArray tags[] PROGMEM = {
	&tagestadoOn,
	&tagestadoOff,
  &tagVersion,
  &tagNetConfSrc,
	NULL
};

void setup () {
  Serial.begin (115200);
  
  // Setup SPI 2 config for Sdcard connected in SPI2
  SPI_2.begin(); //Initialize the SPI_2 port.
  SPI_2.setBitOrder(MSBFIRST); // Set the SPI_2 bit order
  SPI_2.setDataMode(SPI_MODE0); //Set the  SPI_2 data mode 0
  SPI_2.setClockDivider(SPI_CLOCK_DIV16);  // Use a different speed to SPI 1
  pinMode(SD_CS, OUTPUT);

	Serial.println (F("Webserver " WEBBINO_VERSION));
//configuracion de red
  IPAddress ip (192,168,1,15);
  IPAddress dns (192,168,1,1);
  IPAddress gw (192,168,1,1);
  IPAddress mask (255,255,255,0);

  byte mac[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
  bool ok = netint.begin (mac, ip, dns, gw, mask);

	if (!ok) {
		Serial.println (F("Fallo inicializacion tarjeta Ethernet"));
    }
    else {
	  Serial.println (F("Interfaz de red configurado:"));
	  Serial.print (F("- IP: "));
	  Serial.println (netint.getIP ());
	  Serial.print (F("- Netmask: "));
	  Serial.println (netint.getNetmask ());
	  Serial.print (F("- Gateway: "));
  	Serial.println (netint.getGateway ());
		webserver.begin (netint);
		webserver.enableReplacementTags (tags);
   }
   if (!sdStorage.begin (SD_CS)) {
     Serial.println (F(" Fallo inicializacion tarjeta SD "));
      while (42)
        ;
    }
    webserver.addStorage (sdStorage);
    webserver.associateFunctions (associations);

	// Prepare pin
	digitalWrite (ledPin, !LED_ACTIVE_LEVEL);		// Off
	pinMode (ledPin, OUTPUT);

}

void loop () {
	webserver.loop ();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @SukkoPera@qniens@jmcastillejo

      Issue actions

        Ledcontrol in Sd card · Issue #6 · SukkoPera/Webbino