huohuoh
Dependencies: NetServices mbed C027_Supports mbed-rpcx
Diff: RtuRpc.cpp
- Revision:
- 0:64967b7043c2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RtuRpc.cpp Tue Aug 06 12:59:05 2019 +0000 @@ -0,0 +1,57 @@ +#include "RtuRpc.h" +#include "mbed.h" +#include <sstream> + +extern Serial dbg; + +RtuRpc::RtuRpc(std::string host) +{ + hostAddr = host; +} + +void RtuRpc::commitReading(const std::time_t &dt, int readingId, double value) +{ + HTTPText dat; + + std::tm * ptm = std::localtime(&dt); + char buffer[48]; + std::strftime(buffer, 48, "%Y-%m-%d-%H:%M:%S", ptm); + + char sent[50]; + sprintf(sent,"%s/commitReading.php?w=%s&r=%d&v=%.2f", hostAddr.c_str(), buffer, readingId, value); + + HTTPResult res = cl.get(sent, &dat); + + if(res == HTTP_OK) + { + dbg.printf("HTTP_OK\r\n"); + } + else + { + dbg.printf("Error %d\r\n", res); + } +} + +void RtuRpc::commitEvent(const std::time_t &dt, int eventId, double value) +{ + HTTPText dat; + + std::tm * ptm = std::localtime(&dt); + char buffer[48]; + + std::strftime(buffer, 48, "%Y-%m-%d-%H:%M:%S", ptm); + + char sent[50]; + sprintf(sent,"%s/commitReading.php?w=%s&r=%d&v=%.2f", hostAddr.c_str(), buffer, eventId, value); + + HTTPResult res = cl.get(sent, &dat); + + if(res == HTTP_OK) + { + dbg.printf("HTTP_OK\r\n"); + } + else + { + dbg.printf("Error %d\r\n", res); + } +}