8000 Functional update, host and service probes by hreintke · Pull Request #5653 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Functional update, host and service probes #5653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Feb 5, 2019
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5674603
Functional update, host and service probes
hreintke Jan 23, 2019
57c9ba4
Fix ServiceMonitor.ino warnings
hreintke Jan 23, 2019
168de73
Adding MDNSServiceQueryCallback functional
hreintke Jan 23, 2019
ab86859
DynamicServices Functional
hreintke Jan 24, 2019
8f8e90f
Fix ServiceMonitor to match latest MDNSServiceInfo
hreintke Jan 24, 2019
e3dee4f
Fix unused variable in LEAdns.h
hreintke Jan 24, 2019
b237160
mDNS_Clock.ino fix
hreintke Jan 24, 2019
6bb6e90
example restyle
d-a-v Jan 24, 2019
45fbbb9
Merge pull request #1 from d-a-v/FunctionalMDNS
hreintke Jan 24, 2019
b74735c
Merge branch 'master' into FunctionalMDNS
d-a-v Jan 24, 2019
516ed01
Merge branch 'master' into FunctionalMDNS
d-a-v Jan 24, 2019
639f097
Add keyValues and answerInfo
hreintke Jan 26, 2019
5da1832
Waring and formattin fix
hreintke Jan 26, 2019
249b325
Change struct MDNSServiceInfo { MDNSServiceInfo(MDNSResponder ...
hreintke Jan 26, 2019
db0d502
Make AnswerType user friendly
hreintke Jan 27, 2019
0ece474
Update ServiceInfo example
hreintke Jan 27, 2019
fd2cd67
Code cleanup
hreintke Jan 27, 2019
88f1547
AnswerType update, Astyle update servicemonitor
hreintke Jan 27, 2019
819a7e0
Update clock example to webserver
hreintke Jan 28, 2019
f667b56
Second typedef for probe callbacks
hreintke Jan 29, 2019
902f453
Merge branch 'master' into FunctionalMDNS
devyte Jan 31, 2019
7068938
Optimizations
hreintke Feb 1, 2019
772d633
Update callbacks to void
hreintke Feb 1, 2019
c189902
esp32 compatibility
hreintke Feb 1, 2019
8d3f912
std::map to const char*
hreintke Feb 3, 2019
603b659
Fix emplace_back call
hreintke Feb 4, 2019
e3f86d2
Change Dynamic callback to void(...)
hreintke Feb 4, 2019
0f0edb5
Add WiFi events reset() in close()
hreintke Feb 4, 2019
699656d
Merge branch 'master' into FunctionalMDNS
devyte Feb 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update clock example to webserver
  • Loading branch information
hreintke committed Jan 28, 2019
commit 819a7e09fdb97adb5bab0ed36fde8515faa4c66d
75 changes: 20 additions & 55 deletions libraries/ESP8266mDNS/examples/LEAmDNS/mDNS_Clock/mDNS_Clock.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <time.h>

/*
Expand Down Expand Up @@ -72,9 +73,8 @@ char* pcHostDomain = 0; // Negociated
bool bHostDomainConfirmed = false; // Flags the confirmation of the host domain
MDNSResponder::hMDNSService hMDNSService = 0; // The handle of the clock service in the MDNS responder

// TCP server at port 'SERVICE_PORT' will respond to HTTP requests
WiFiServer server(SERVICE_PORT);

// HTTP server at port 'SERVICE_PORT' will respond to HTTP requests
ESP8266WebServer server(SERVICE_PORT);

/*
getTimeString
Expand Down Expand Up @@ -194,59 +194,29 @@ bool hostProbeResult(String p_pcDomainName, bool p_bProbeResult) {
/*
handleHTTPClient
*/
void handleHTTPClient(WiFiClient& client) {
Serial.println("");
Serial.println("New client");

// Wait for data from client to become available
while (client.connected() && !client.available()) {
delay(1);
}

// Read the first line of HTTP request
String req = client.readStringUntil('\r');

// First line of HTTP request looks like "GET /path HTTP/1.1"
// Retrieve the "/path" part by finding the spaces
int addr_start = req.indexOf(' ');
int addr_end = req.indexOf(' ', addr_start + 1);
if (addr_start == -1 || addr_end == -1) {
Serial.print("Invalid request: ");
Serial.println(req);
return;
}
req = req.substring(addr_start + 1, addr_end);
Serial.print("Request: ");
Serial.println(req);
client.flush();
void handleHTTPRequest() {
Serial.println("");
Serial.println("HTTP Request");

// Get current time
time_t now = time(nullptr);;
struct tm timeinfo;
gmtime_r(&now, &timeinfo);

String s;
if (req == "/") {
IPAddress ip = WiFi.localIP();
String ipStr = String(ip[0]) + '.' + String(ip[1]) + '.' + String(ip[2]) + '.' + String(ip[3]);
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<!DOCTYPE HTML>\r\n<html>Hello from ";
s += WiFi.hostname() + " at " + ipStr;
// Simple addition of the current time
s += "\r\nCurrent time is: ";
s += getTimeString();
// done :-)
s += "</html>\r\n\r\n";
Serial.println("Sending 200");
} else {
s = "HTTP/1.1 404 Not Found\r\n\r\n";
Serial.println("Sending 404");
}
client.print(s);

Serial.println("Done with client");
s = "<!DOCTYPE HTML>\r\n<html>Hello from ";
s += WiFi.hostname() + " at " + WiFi.localIP().toString();
// Simple addition of the current time
s += "\r\nCurrent time is: ";
s += getTimeString();
// done :-)
s += "</html>\r\n\r\n";
Serial.println("Sending 200");
server.send(200, "text/html", s);
}


/*
setup
*/
Expand Down Expand Up @@ -284,27 +254,22 @@ void setup(void) {
}
Serial.println("MDNS responder started");

// Start TCP (HTTP) server
// Setup HTTP server
server.on("/", handleHTTPRequest);
server.begin();
Serial.println("TCP server started");
Serial.println("HTTP server started");
}


/*
loop
*/
void loop(void) {
// Check if a client has connected
WiFiClient client = server.available();
if (client) {
handleHTTPClient(client);
}

// Check if a request has come in
server.handleClient();
// Allow MDNS processing
MDNS.update();

// Update time (if needed)
//static unsigned long ulNextTimeUpdate = UPDATE_CYCLE;
static esp8266::polledTimeout::periodic timeout(UPDATE_CYCLE);
if (timeout.expired()) {

Expand Down
0