lib_Transmission_TCP_example

Dependencies:   lib_Transmission

Committer:
YSI
Date:
Wed Oct 06 09:20:05 2021 +0000
Revision:
0:bfe0a20512f3
Child:
1:b9a16f894120
up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
YSI 0:bfe0a20512f3 1 #include "main.h"
YSI 0:bfe0a20512f3 2
YSI 0:bfe0a20512f3 3 int main(void)
YSI 0:bfe0a20512f3 4 {
YSI 0:bfe0a20512f3 5 transmission.ip(true);
YSI 0:bfe0a20512f3 6 while(1) Led = transmission.recv();
YSI 0:bfe0a20512f3 7 }
YSI 0:bfe0a20512f3 8
YSI 0:bfe0a20512f3 9 void ethernet_up(void)
YSI 0:bfe0a20512f3 10 {
YSI 0:bfe0a20512f3 11 transmission.smtp("yannic.simon@u-psud.fr", transmission.ip().c_str(), "CONNECTION", transmission_processing("*IDN?").c_str());
YSI 0:bfe0a20512f3 12 char timeLogs[22] = {0};
YSI 0:bfe0a20512f3 13 time_t ntpTimeStamp = transmission.ntp();
YSI 0:bfe0a20512f3 14 if(ntpTimeStamp > 0) set_time(ntpTimeStamp);
YSI 0:bfe0a20512f3 15 strftime(timeLogs, 21, "%F;%T;", localtime(&ntpTimeStamp));
YSI 0:bfe0a20512f3 16 }
YSI 0:bfe0a20512f3 17
YSI 0:bfe0a20512f3 18 string transmission_processing(string cmd)
YSI 0:bfe0a20512f3 19 {
YSI 0:bfe0a20512f3 20 ostringstream ssend;
YSI 0:bfe0a20512f3 21 ssend << fixed;
YSI 0:bfe0a20512f3 22 ssend.precision(2);
YSI 0:bfe0a20512f3 23 if(cmd.empty());
YSI 0:bfe0a20512f3 24 else if(cmd == "*IDN?")
YSI 0:bfe0a20512f3 25 ssend << MBED_PROJECT << ", Mbed OS " << MBED_VERSION << ", Version dated, " << __DATE__ << ", " << __TIME__;
YSI 0:bfe0a20512f3 26 else if(cmd == "IP?")
YSI 0:bfe0a20512f3 27 ssend << "IP(" << transmission.ip() << ")";
YSI 0:bfe0a20512f3 28 else if(cmd == "IP:ALL?")
YSI 0:bfe0a20512f3 29 ssend << "IP(" << transmission.ip(transmission.ip()) << ")";
YSI 0:bfe0a20512f3 30 else if(cmd.find("HEAD /") != string::npos)
YSI 0:bfe0a20512f3 31 ssend << transmission.http.RETURN_OK << "Content-Type: text/html; charset=utf-8\r\nAccess-Control-Allow-Origin: *\r\n\r\n";
YSI 0:bfe0a20512f3 32 else if(cmd.find("GET / HTTP") != string::npos)
YSI 0:bfe0a20512f3 33 ssend << transmission.http.RETURN_OK << "Content-Type: text/html; charset=utf-8\r\nAccess-Control-Allow-Origin: *\r\n\r\n<!DOCTYPE html>\r\n<html>\r\n\t<head>\r\n\t\t<title>" << MBED_PROJECT << "</title>\r\n\t\t<meta http-equiv=refresh content=10>\r\n\t</head>\r\n\t<body style=background-color:dimgray>\r\n\t\t<center>\r\n\t\t\t<h1>" << MBED_PROJECT << "</h1>\r\n\t\t\t<p>" << time(NULL) << "</p>\r\n\t\t</center>\r\n\t</body>\r\n</html>";
YSI 0:bfe0a20512f3 34 else if(cmd.find("GET /FAVICON.ICO HTTP") != string::npos)
YSI 0:bfe0a20512f3 35 ssend << transmission.http.RETURN_OK << "Content-Type: image/svg+xml\r\nAccess-Control-Allow-Origin: *\r\n\r\n<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 100 100\" style=\"background-color:steelblue\" xmlns=\"http://www.w3.org/2000/svg\"><title>" << MBED_PROJECT << "</title><text x=\"0\" y=\"85\" textLength=\"100\" font-weight=\"bold\" font-size=\"110\" lengthAdjust=\"spacingAndGlyphs\" fill=\"white\" stroke=\"skyblue\">EL</text></svg>";
YSI 0:bfe0a20512f3 36 else if(cmd[cmd.size()-1] == '?')
YSI 0:bfe0a20512f3 37 ssend << "incorrect requeste [" << cmd << "]";
YSI 0:bfe0a20512f3 38 return ssend.str();
YSI 0:bfe0a20512f3 39 }