SNode.C
Loading...
Searching...
No Matches
warema-jalousien.cpp File Reference
Include dependency graph for warema-jalousien.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static std::map< std::string, std::string > jalousien
 
static std::map< std::string, std::string > actions = {{"open", "up"}, {"close", "down"}, {"stop", "stop"}}
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 45 of file warema-jalousien.cpp.

45 {
46 WebApp::init(argc, argv);
47
48 legacy::in::WebApp webApp("werema");
49
50 // tls::WebApp wa;
51
52 webApp.get("/jalousien/:id", [] APPLICATION(req, res) {
53 VLOG(1) << "Param: " << req->param("id");
54 VLOG(1) << "Qurey: " << req->query("action");
55
56 std::string arguments = "aircontrol -t " + jalousien[req->param("id")] + "_" + actions[req->query("action")];
57
58 int ret = system(arguments.c_str());
59 ret = (ret >> 8) & 0xFF;
60 /* ret:
61 Bits 15-8 = Exit code.
62 Bit 7 = 1 if a core dump was produced.
63 Bits 6-0 = Signal number that killed the process.
64 */
65
66 switch (ret) {
67 case 0:
68 res->status(200).send("OK: " + arguments);
69 break;
70 case 127:
71 res->status(404).send("ERROR not found: " + arguments);
72 break;
73 }
74 });
75
76 webApp.use([] APPLICATION(req, res) {
77 res->status(404).send("No Jalousie specified");
78 });
79
80 webApp.listen(8080,
81 [instanceName = webApp.getConfig().getInstanceName()](const legacy::in::WebApp::SocketAddress& socketAddress,
82 const core::socket::State& state) {
83 switch (state) {
85 VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'";
86 break;
88 VLOG(1) << instanceName << ": disabled";
89 break;
91 LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
92 break;
94 LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what();
95 break;
96 }
97 });
98
99 return WebApp::start();
100}
#define APPLICATION(req, res)
Definition Router.h:45
static constexpr int DISABLED
Definition State.h:34
static constexpr int ERROR
Definition State.h:35
static constexpr int FATAL
Definition State.h:36
static constexpr int OK
Definition State.h:33
typename Server::SocketAddress SocketAddress
Definition WebAppT.h:48
static void init(int argc, char *argv[])
Definition WebApp.cpp:34
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
Definition WebApp.cpp:38
static std::map< std::string, std::string > jalousien
static std::map< std::string, std::string > actions

References express::WebApp::init(), and express::WebApp::start().

Here is the call graph for this function:

Variable Documentation

◆ actions

static std::map< std::string, std::string > actions = {{"open", "up"}, {"close", "down"}, {"stop", "stop"}}
static

Definition at line 43 of file warema-jalousien.cpp.

43{{"open", "up"}, {"close", "down"}, {"stop", "stop"}};

◆ jalousien

static std::map< std::string, std::string > jalousien
static
Initial value:
= {{"kueche", "kueche"},
{"strasse", "strasse"},
{"esstisch", "esstisch"},
{"balkon", "balkon"},
{"schlafzimmer", "schlafzimmer"},
{"arbeitszimmer", "arbeitszimmer"},
{"comfort", "komfort"},
{"all", "alle"}}

Definition at line 34 of file warema-jalousien.cpp.

34 {{"kueche", "kueche"},
35 {"strasse", "strasse"},
36 {"esstisch", "esstisch"},
37 {"balkon", "balkon"},
38 {"schlafzimmer", "schlafzimmer"},
39 {"arbeitszimmer", "arbeitszimmer"},
40 {"comfort", "komfort"},
41 {"all", "alle"}};