tes

Dependencies:   NetServices mbed C027_Supports mbed-rpcx

Committer:
aldoao
Date:
Wed Sep 11 06:32:20 2019 +0000
Revision:
1:f7d9b0530b73
Parent:
0:64967b7043c2
tipe,1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
irsanjul 0:64967b7043c2 1 #include "RtuRpc.h"
irsanjul 0:64967b7043c2 2 #include "mbed.h"
irsanjul 0:64967b7043c2 3 #include <sstream>
irsanjul 0:64967b7043c2 4
irsanjul 0:64967b7043c2 5 extern Serial dbg;
irsanjul 0:64967b7043c2 6
irsanjul 0:64967b7043c2 7 RtuRpc::RtuRpc(std::string host)
irsanjul 0:64967b7043c2 8 {
irsanjul 0:64967b7043c2 9 hostAddr = host;
irsanjul 0:64967b7043c2 10 }
irsanjul 0:64967b7043c2 11
irsanjul 0:64967b7043c2 12 void RtuRpc::commitReading(const std::time_t &dt, int readingId, double value)
irsanjul 0:64967b7043c2 13 {
irsanjul 0:64967b7043c2 14 HTTPText dat;
irsanjul 0:64967b7043c2 15
irsanjul 0:64967b7043c2 16 std::tm * ptm = std::localtime(&dt);
irsanjul 0:64967b7043c2 17 char buffer[48];
irsanjul 0:64967b7043c2 18 std::strftime(buffer, 48, "%Y-%m-%d-%H:%M:%S", ptm);
irsanjul 0:64967b7043c2 19
irsanjul 0:64967b7043c2 20 char sent[50];
irsanjul 0:64967b7043c2 21 sprintf(sent,"%s/commitReading.php?w=%s&r=%d&v=%.2f", hostAddr.c_str(), buffer, readingId, value);
irsanjul 0:64967b7043c2 22
irsanjul 0:64967b7043c2 23 HTTPResult res = cl.get(sent, &dat);
irsanjul 0:64967b7043c2 24
irsanjul 0:64967b7043c2 25 if(res == HTTP_OK)
irsanjul 0:64967b7043c2 26 {
irsanjul 0:64967b7043c2 27 dbg.printf("HTTP_OK\r\n");
irsanjul 0:64967b7043c2 28 }
irsanjul 0:64967b7043c2 29 else
irsanjul 0:64967b7043c2 30 {
irsanjul 0:64967b7043c2 31 dbg.printf("Error %d\r\n", res);
irsanjul 0:64967b7043c2 32 }
irsanjul 0:64967b7043c2 33 }
irsanjul 0:64967b7043c2 34
irsanjul 0:64967b7043c2 35 void RtuRpc::commitEvent(const std::time_t &dt, int eventId, double value)
irsanjul 0:64967b7043c2 36 {
irsanjul 0:64967b7043c2 37 HTTPText dat;
irsanjul 0:64967b7043c2 38
irsanjul 0:64967b7043c2 39 std::tm * ptm = std::localtime(&dt);
irsanjul 0:64967b7043c2 40 char buffer[48];
irsanjul 0:64967b7043c2 41
irsanjul 0:64967b7043c2 42 std::strftime(buffer, 48, "%Y-%m-%d-%H:%M:%S", ptm);
irsanjul 0:64967b7043c2 43
irsanjul 0:64967b7043c2 44 char sent[50];
irsanjul 0:64967b7043c2 45 sprintf(sent,"%s/commitReading.php?w=%s&r=%d&v=%.2f", hostAddr.c_str(), buffer, eventId, value);
irsanjul 0:64967b7043c2 46
irsanjul 0:64967b7043c2 47 HTTPResult res = cl.get(sent, &dat);
irsanjul 0:64967b7043c2 48
irsanjul 0:64967b7043c2 49 if(res == HTTP_OK)
irsanjul 0:64967b7043c2 50 {
irsanjul 0:64967b7043c2 51 dbg.printf("HTTP_OK\r\n");
irsanjul 0:64967b7043c2 52 }
irsanjul 0:64967b7043c2 53 else
irsanjul 0:64967b7043c2 54 {
irsanjul 0:64967b7043c2 55 dbg.printf("Error %d\r\n", res);
irsanjul 0:64967b7043c2 56 }
irsanjul 0:64967b7043c2 57 }