netconn_write issue and sprintf issue esp32
Posted: Tue Feb 21, 2017 9:03 pm
I'm working on a webserver application and I'm print out a webpage with dynamic variables and can't seem to get it to work because of various issues.
In my first attempt, I tried writing out a page line by line with code that looked like this. The problem is, the text didn't render correctly on the webpage. Characters were out of order and it wasn't exactly how I sent it.
strcpy(strBuffer, "function updatePageID(){\n");
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
sprintf(strBuffer," document.getElementById('SRT').checked=%s;\n",http_util_truefalse_str_string(p->bEnableSRT));
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
strcpy(strBuffer, "}\n");
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
Next I tried creating a single buffer and that is giving a core dump. I took out the netconn_write and replaced it with the printf("%s", strBuffer); just to see if netconn had an issue. It still core dumps with the printf, there is a problem with the with the sprintf(
I'm hoping someone will look at this and have an idea on what I can try next.
char strBuffer [1024];
memset(strBuffer,0,(sizeof(strBuffer)));
strcpy(strBuffer, "function updatePageID(){\n");
sprintf(strBuffer + strlen(strBuffer)," document.getElementById('SRT').checked=%s;\n",http_util_truefalse_str_string(p->bEnableSRT));
strcpy(strBuffer + strlen(strBuffer), "}\n");
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
In my first attempt, I tried writing out a page line by line with code that looked like this. The problem is, the text didn't render correctly on the webpage. Characters were out of order and it wasn't exactly how I sent it.
strcpy(strBuffer, "function updatePageID(){\n");
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
sprintf(strBuffer," document.getElementById('SRT').checked=%s;\n",http_util_truefalse_str_string(p->bEnableSRT));
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
strcpy(strBuffer, "}\n");
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);
Next I tried creating a single buffer and that is giving a core dump. I took out the netconn_write and replaced it with the printf("%s", strBuffer); just to see if netconn had an issue. It still core dumps with the printf, there is a problem with the with the sprintf(
I'm hoping someone will look at this and have an idea on what I can try next.
char strBuffer [1024];
memset(strBuffer,0,(sizeof(strBuffer)));
strcpy(strBuffer, "function updatePageID(){\n");
sprintf(strBuffer + strlen(strBuffer)," document.getElementById('SRT').checked=%s;\n",http_util_truefalse_str_string(p->bEnableSRT));
strcpy(strBuffer + strlen(strBuffer), "}\n");
netconn_write(conn, strBuffer, sizeof(strBuffer)-1, NETCONN_NOCOPY);