|
@@ -10,11 +10,15 @@
|
|
#include <ESP8266WiFi.h> // Include the Wi-Fi library
|
|
#include <ESP8266WiFi.h> // Include the Wi-Fi library
|
|
#include <ESP8266WiFiMulti.h> // Include the Wi-Fi-Multi library
|
|
#include <ESP8266WiFiMulti.h> // Include the Wi-Fi-Multi library
|
|
#include <ESP8266mDNS.h> // Include the mDNS library
|
|
#include <ESP8266mDNS.h> // Include the mDNS library
|
|
-
|
|
|
|
-ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
|
|
|
|
|
|
+#include <ESP8266WebServer.h> // Include the WebServer library
|
|
|
|
|
|
//Change the properties of the IoT device
|
|
//Change the properties of the IoT device
|
|
-const String DeviceName = "HDSv2-Demo"; //The name of this IoT device
|
|
|
|
|
|
+const String DeviceName = "HDSv2-Base"; //The name of this IoT device
|
|
|
|
+const int ListeningPort = 12110; //The port where this IoT device listen
|
|
|
|
+
|
|
|
|
+//Library Objects
|
|
|
|
+ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
|
|
|
|
+ESP8266WebServer server(ListeningPort); //Create an Web Server on the listening port
|
|
|
|
|
|
//Change the WiFi Settings
|
|
//Change the WiFi Settings
|
|
void WiFiConfig(){
|
|
void WiFiConfig(){
|
|
@@ -31,7 +35,7 @@ void MDNSDynamicServiceTxtCallback(const MDNSResponder::hMDNSService p_hService)
|
|
MDNS.addDynamicServiceTxt(p_hService, "protocol","hdsv2");
|
|
MDNS.addDynamicServiceTxt(p_hService, "protocol","hdsv2");
|
|
|
|
|
|
//Define the OEM written values
|
|
//Define the OEM written values
|
|
- MDNS.addDynamicServiceTxt(p_hService, "uuid","00000000-0000-0000-0000-000000000000");
|
|
|
|
|
|
+ MDNS.addDynamicServiceTxt(p_hService, "uuid",getMacAddress());
|
|
MDNS.addDynamicServiceTxt(p_hService, "model","Generic");
|
|
MDNS.addDynamicServiceTxt(p_hService, "model","Generic");
|
|
MDNS.addDynamicServiceTxt(p_hService, "vendor","HomeDynamic Project");
|
|
MDNS.addDynamicServiceTxt(p_hService, "vendor","HomeDynamic Project");
|
|
MDNS.addDynamicServiceTxt(p_hService, "version_minor","0.00");
|
|
MDNS.addDynamicServiceTxt(p_hService, "version_minor","0.00");
|
|
@@ -49,6 +53,7 @@ void setup() {
|
|
delay(10);
|
|
delay(10);
|
|
Serial.println('\n');
|
|
Serial.println('\n');
|
|
|
|
|
|
|
|
+ //Start WiFi Conenction Routines
|
|
WiFiConfig();
|
|
WiFiConfig();
|
|
|
|
|
|
Serial.println("Connecting ...");
|
|
Serial.println("Connecting ...");
|
|
@@ -61,7 +66,8 @@ void setup() {
|
|
Serial.println(WiFi.SSID());
|
|
Serial.println(WiFi.SSID());
|
|
Serial.print("IP address:\t");
|
|
Serial.print("IP address:\t");
|
|
Serial.println(WiFi.localIP());
|
|
Serial.println(WiFi.localIP());
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ //Startup MDNS Responder
|
|
MDNS.setHostProbeResultCallback(hostProbeResult);
|
|
MDNS.setHostProbeResultCallback(hostProbeResult);
|
|
|
|
|
|
if (!MDNS.begin(DeviceName)) { // Start the mDNS responder for esp8266.local
|
|
if (!MDNS.begin(DeviceName)) { // Start the mDNS responder for esp8266.local
|
|
@@ -69,10 +75,44 @@ void setup() {
|
|
}
|
|
}
|
|
|
|
|
|
//Advertise the port that you are using
|
|
//Advertise the port that you are using
|
|
- MDNS.addService("http", "tcp", 12110);
|
|
|
|
|
|
+ MDNS.addService("http", "tcp", ListeningPort);
|
|
Serial.println("mDNS responder started");
|
|
Serial.println("mDNS responder started");
|
|
|
|
+
|
|
|
|
+ //Startup the Web Server Endpoints
|
|
|
|
+ delay(100);
|
|
|
|
+ server.on("/", handle_index);
|
|
|
|
+ server.on("/status", handle_status);
|
|
|
|
+ server.on("/eps", handle_endpoints);
|
|
|
|
+
|
|
|
|
+ server.begin();
|
|
|
|
+ Serial.println("HTTP server started");
|
|
|
|
+ Serial.print("Listening on port: ");
|
|
|
|
+ Serial.println(ListeningPort);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//Handlers for Web Server
|
|
|
|
+void handle_index() {
|
|
|
|
+ server.send(200, "text/html", "index");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void handle_status() {
|
|
|
|
+ server.send(200, "application/json", "{\
|
|
|
|
+ \"power\":true,\
|
|
|
|
+ \"network\":true\
|
|
|
|
+}");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void handle_endpoints() {
|
|
|
|
+ server.send(200, "application/json", "[{\
|
|
|
|
+ \"Name\": \"Hello World\",\
|
|
|
|
+ \"Desc\":\"Print out Hello World in Serial\",\
|
|
|
|
+ \"Type\":\"none\"\
|
|
|
|
+ }]");
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+//Main Loop
|
|
void loop() {
|
|
void loop() {
|
|
|
|
+ server.handleClient();
|
|
MDNS.update();
|
|
MDNS.update();
|
|
}
|
|
}
|