Webbino
Webbino copied to clipboard
Ledcontrol in Sd card
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
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.
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
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.
Thanks for your work, it's a great project
This should be done with 3c51945bb3563f6d5beb0f7ef8b795707a5bf329, 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.
Hello!!
I have tested the modifications and it still does not work using the sd card, only work with flash
A quick test I did works instead. Can you please post your sketch?
@jmcastillejo: Make sure to associate the function with FileFuncAssoc rather than with FlashFileFuncAssoc as shown in the current LedControl version.
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'
Try something like:
FileFuncAssoc (indexAss, "/index.htm", indexFunc);
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 ();
}