-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dweet.cpp
61 lines (46 loc) · 1.18 KB
/
Dweet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Dweet.h"
string Dweet::currentDateTime()
{
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf, sizeof(buf), "%Y-%m-%d\t%X", &tstruct);
return buf;
return string();
}
void Dweet::SendDweet()
{
thread thSendDweet([&]()
{
stringstream ssFaceName;
for (auto face : this->vFaceNames)
{
ssFaceName << face.first << " , ";
ssFaceName << " (" << face.second.getXCoord() << "," << face.second.getYCoord() << ") | ";
}
//Initialise IO Stream
iosockstream dweetStream("dweet.io:80");
//Assemble Get Request
dweetStream << "GET ";
dweetStream << "/dweet/for/" << this->dw_thingName << "?";
dweetStream << "CurrentDateTime=" << this->currentDateTime();
dweetStream << "&Faces=" << ssFaceName.str();
dweetStream << " TTP/1.0\r\n\r\n";
//Print result to console
while (dweetStream.peek() != EOF)
{
cout << (char)dweetStream.get();
}
//Clear Vectors and String Stream
ssFaceName.clear();
vFaceNames.clear();
});
}
void Dweet::AddFace(string& faceName, Coordinate& coord)
{
vFaceNames.push_back(pair<string, Coordinate>(faceName, coord));
}
Dweet::~Dweet()
{
}