Skip to content

Commit

Permalink
Fixed: missing os_sprintf %s
Browse files Browse the repository at this point in the history
  • Loading branch information
cskarai committed Oct 11, 2016
1 parent 491931b commit 1cd8363
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions web-server/web-server.c
Expand Up @@ -392,10 +392,16 @@ static int ICACHE_FLASH_ATTR WEB_handleMCUResponse(HttpdConnData *connData, CmdR
float f;
os_memcpy( &f, value, 4);

char intbuf[20];
os_sprintf(intbuf, "%f", f);
os_strcpy(jsonBuf + jsonPtr, intbuf);
jsonPtr += os_strlen(intbuf);
// os_sprintf doesn't support %f
int intPart = f;
int fracPart = (f - intPart) * 1000; // use 3 digit precision
if( fracPart < 0 ) // for negative numbers
fracPart = -fracPart;

char floatBuf[20];
os_sprintf(floatBuf, "%d.%03d", intPart, fracPart);
os_strcpy(jsonBuf + jsonPtr, floatBuf);
jsonPtr += os_strlen(floatBuf);
}
break;
case WEB_STRING:
Expand Down

0 comments on commit 1cd8363

Please sign in to comment.