I am using the following code to change the time value in a cgi function but the webserver stops working after i call the function. Any clues about why is this happening?
TIME_STRUCT MQX_time;
DATE_STRUCT DateStruct;
DateStruct.YEAR = year;
DateStruct.MONTH = month;
DateStruct.DAY = day;
DateStruct.HOUR = hour;
DateStruct.MINUTE = minute;
DateStruct.SECOND = second;
DateStruct.MILLISEC = millisec;
_time_from_date(&DateStruct, &MQX_time);//Convierte la fecha a tiempo MQX
_time_set (&MQX_time); //Actualiza el tiempo MQX con la fecha actual
_rtc_sync_with_mqx ( FALSE ); //Sincroniza RTC con MQX (MQX es la Fuente)
解決済! 解決策の投稿を見る。
I stopped messing with MQX_time and used another time structure. Things are going fine for now.
I can see any issue in your code. In this type of problem I would check task stack usage (in TAD) and eather increase it or try to save space on stack..
PetrL
I which task would you increase the stack?
If it is a task created into an MQX library, could you mention the file where I can define the stack?
For task stack, to increase the stack size, you can do that in task template list.
Use TAD, break the running code in the CGI handler and look in which task's context the handler is running. Increase the stack size for that task (or for interrupts).
Thank you for your answer, I have increased the stack size for http_server task (because it had the higher usage percentage)as well as for interrupt stack.
Problem is still present.
I dont think problem comes from stack overflow, I have tested my functions in other tasks and everything works fine.
Is there a restriction for changing the mqx time from a cgi function?
Yes, it looks like httpd sessions rely on actual MQX time. I guess this is good point of further improvement. As a workaround, please try to redefine macro in httpd_mqx.h like this:
#define HTTPD_GET_TIME(time) _time_get_elapsed(time)
I stopped messing with MQX_time and used another time structure. Things are going fine for now.
Thank you for your answer.
Everything works when the setTimeFromDate function is not called.
setTimeFromDate(ianio, imes, idia, ihora, iminuto, 0, 0);
void setTimeFromDate(uint_16 year, uint_16 month, uint_16 day, uint_16 hour,
uint_16 minute, uint_16 second, uint_16 millisec){
TIME_STRUCT MQX_time;
DATE_STRUCT DateStruct;
DateStruct.YEAR = year;
DateStruct.MONTH = month;
DateStruct.DAY = day;
DateStruct.HOUR = hour;
DateStruct.MINUTE = minute;
DateStruct.SECOND = second;
DateStruct.MILLISEC = millisec;
_time_from_date(&DateStruct, &MQX_time);//Convierte la fecha a tiempo MQX
_time_set (&MQX_time); //Actualiza el tiempo MQX con la fecha actual
_rtc_sync_with_mqx ( FALSE ); //Sincroniza RTC con MQX (MQX es la Fuente)
}
int cgi_modificar_tiempo(HTTPD_SESSION_STRUCT *session) {
uint_32 len = 0,index=0;
char hora[5], minuto[5], dia[5], mes[5], anio[5];
uint_32 ihora, iminuto, idia, imes, ianio;
boolean bParams = FALSE;
char buffer[100];
html_head(session->sock,"HVAC Settings response");
httpd_sendstr(session->sock, "<BODY>\n");
httpd_sendstr(session->sock, "<br><br>\n");
if (session->request.content_len) {
len = session->request.content_len;
len = httpd_read(session, buffer, (int)((len > sizeof(buffer)) ? sizeof(buffer) : len));
buffer[len] = 0;
session->request.content_len -= len;
len = 0;
if ( httpd_get_varval(session, buffer, "hora", hora, sizeof(hora)) &&
httpd_get_varval(session, buffer, "minuto", minuto, sizeof(minuto)) &&
httpd_get_varval(session, buffer, "dia", dia, sizeof(dia)) &&
httpd_get_varval(session, buffer, "mes", mes, sizeof(mes)) &&
httpd_get_varval(session, buffer, "anio", anio, sizeof(anio))
){
bParams = TRUE;
if( !PasswordOK() ){
rclave_ing = "Es necesario ingresar la palabra clave para utilizar esta funcion";
httpd_sendstr(session->sock,
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
"<html><head><title>MQX</title>"
"<meta http-equiv=\"REFRESH\" content=\"0;url=resultado.html\"></HEAD>"
"<BODY></BODY></HTML>");
}
else{
if ( (sscanf(hora, "%d", &ihora) == 1 ) && (sscanf(minuto, "%d", &iminuto) == 1 ) && (sscanf(dia, "%d", &idia) == 1 ) &&
(sscanf(mes, "%d", &imes) == 1 ) && (sscanf(anio, "%d", &ianio) == 1 ) ) {
setTimeFromDate(ianio, imes, idia, ihora, iminuto, 0, 0);
rclave_ing = "Se ha modificado la fecha correctamente";
httpd_sendstr(session->sock,
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
"<html><head><title>MQX</title>"
"<meta http-equiv=\"REFRESH\" content=\"0;url=resultado.html\"></HEAD>"
"<BODY></BODY></HTML>");
}
else{
bParams = FALSE;
}
}
}
}
if (!bParams) {
httpd_sendstr(session->sock, "No se recibieron los parametros<br>\n");
}
return session->request.content_len;
}
I have called the function setTimeFromDate(2009, 11, 23, 10, 30, 0, 0); with constant numbers
and the webserver stops working too.
Thank you.