![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Backing up an unused program in case of future need
Diff: server.cpp
- Revision:
- 5:6226f3c566ef
- Parent:
- 2:06fa34661f19
- Child:
- 6:be97d38e0b01
diff -r e076884ef8bd -r 6226f3c566ef server.cpp --- a/server.cpp Tue May 03 09:23:26 2016 +0000 +++ b/server.cpp Wed May 11 16:42:35 2016 +0000 @@ -1,9 +1,10 @@ -#include "esp.h" -#include "at.h" -#include "io.h" -#include "log.h" -#include "time.h" -#include "wifi.h" +#include "esp.h" +#include "at.h" +#include "io.h" +#include "log.h" +#include "time.h" +#include "wifi.h" +#include "ds18b20.h" #define RECV_BUFFER_SIZE 1024 #define SEND_BUFFER_SIZE 256 #define SERVER_PORT 80 @@ -33,6 +34,26 @@ } return 0; } +static int addChunkF(int prevlen, char *fmt, ...) +{ + //Set up variable arguments + va_list argptr; + va_start(argptr, fmt); + + //Fill the buffer + int room = SEND_BUFFER_SIZE - prevlen; + int sent = vsnprintf(sendbuffer + prevlen, room, fmt, argptr); + if (sent > room) sent = room; + if (sent < 0) sent = 0; + + //Finish with variable arguments + va_end(argptr); + + //Return length + int len = prevlen + sent; + return len < SEND_BUFFER_SIZE ? len : SEND_BUFFER_SIZE; + +} static int addChunk(int prevlen, char *text) { @@ -125,9 +146,9 @@ lineToSendToId[id] += 1; break; case 2: - len = fillChunk("Version: "); - len = addChunk(len, AtEspVersion); - len = addChunk(len, "\r\n"); + len = 0; + len = addChunkF(len, "Version: %s<br/>\r\n", AtEspVersion); + len = addChunkF(len, "Temperature: %1.1f\r\n", DS18B20Value / 16.0); lineToSendToId[id] += 1; break; case 3: