From 1cd8363834ad4d0e1dcd0f0e0c23d8061cb87bb8 Mon Sep 17 00:00:00 2001 From: cskarai Date: Tue, 11 Oct 2016 07:58:42 +0200 Subject: [PATCH] Fixed: missing os_sprintf %s --- web-server/web-server.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/web-server/web-server.c b/web-server/web-server.c index bc8ffed..fd41486 100644 --- a/web-server/web-server.c +++ b/web-server/web-server.c @@ -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: