|
@@ -15,6 +15,12 @@
|
|
const String DeviceName = "HDsv2-Test"; //The name of this IoT device
|
|
const String DeviceName = "HDsv2-Test"; //The name of this IoT device
|
|
const int ListeningPort = 12110; //The port where this IoT device listen
|
|
const int ListeningPort = 12110; //The port where this IoT device listen
|
|
|
|
|
|
|
|
+//Runtime values
|
|
|
|
+String stringInput = "default";
|
|
|
|
+int integerInput = 0;
|
|
|
|
+float floatInput = 2.5;
|
|
|
|
+bool booleanInput = true;
|
|
|
|
+
|
|
//Library Objects
|
|
//Library Objects
|
|
ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
|
|
ESP8266WiFiMulti wifiMulti; // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'
|
|
ESP8266WebServer server(ListeningPort); //Create an Web Server on the listening port
|
|
ESP8266WebServer server(ListeningPort); //Create an Web Server on the listening port
|
|
@@ -102,6 +108,7 @@ void handle_index() {
|
|
void handle_string() {
|
|
void handle_string() {
|
|
String value = server.arg("value");
|
|
String value = server.arg("value");
|
|
Serial.println(value);
|
|
Serial.println(value);
|
|
|
|
+ stringInput = value;
|
|
//Use value (String) to do something
|
|
//Use value (String) to do something
|
|
server.send(200, "text/html", "OK");
|
|
server.send(200, "text/html", "OK");
|
|
}
|
|
}
|
|
@@ -110,14 +117,16 @@ void handle_integer() {
|
|
String value = server.arg("value");
|
|
String value = server.arg("value");
|
|
int number = value.toInt();
|
|
int number = value.toInt();
|
|
Serial.println(number);
|
|
Serial.println(number);
|
|
|
|
+ integerInput = number;
|
|
//Use number (int) to do something
|
|
//Use number (int) to do something
|
|
server.send(200, "text/html", "OK");
|
|
server.send(200, "text/html", "OK");
|
|
}
|
|
}
|
|
|
|
|
|
void handle_float() {
|
|
void handle_float() {
|
|
String value = server.arg("value");
|
|
String value = server.arg("value");
|
|
- int floatNumber = value.toFloat();
|
|
|
|
|
|
+ float floatNumber = value.toFloat();
|
|
Serial.println(floatNumber);
|
|
Serial.println(floatNumber);
|
|
|
|
+ floatInput = floatNumber;
|
|
//Use floatNumber to do something else
|
|
//Use floatNumber to do something else
|
|
server.send(200, "text/html", "OK");
|
|
server.send(200, "text/html", "OK");
|
|
}
|
|
}
|
|
@@ -132,6 +141,8 @@ void handle_bool() {
|
|
Serial.println("False");
|
|
Serial.println("False");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ booleanInput = result;
|
|
|
|
+
|
|
//Use result to do something else
|
|
//Use result to do something else
|
|
server.send(200, "text/html", "OK");
|
|
server.send(200, "text/html", "OK");
|
|
}
|
|
}
|
|
@@ -144,12 +155,16 @@ void handle_output() {
|
|
//This function return the status of the current device.
|
|
//This function return the status of the current device.
|
|
//If the name of status matches one of the input endpoints, the value will be used as auto fill
|
|
//If the name of status matches one of the input endpoints, the value will be used as auto fill
|
|
void handle_status() {
|
|
void handle_status() {
|
|
|
|
+ String boolValue = "true";
|
|
|
|
+ if (booleanInput == false){
|
|
|
|
+ boolValue = "false";
|
|
|
|
+ }
|
|
server.send(200, "application/json", "{\
|
|
server.send(200, "application/json", "{\
|
|
\"Global Status\":\"It is working\",\
|
|
\"Global Status\":\"It is working\",\
|
|
- \"String Input\":\"default value\",\
|
|
|
|
- \"Integer Input\":8,\
|
|
|
|
- \"Float Input\":4.5,\
|
|
|
|
- \"Boolean Input\":true\
|
|
|
|
|
|
+ \"String Input\":\"" + stringInput + "\",\
|
|
|
|
+ \"Integer Input\":" + String(integerInput) + ",\
|
|
|
|
+ \"Float Input\":" + String(floatInput, 2) + ",\
|
|
|
|
+ \"Boolean Input\":" + boolValue + "\
|
|
}");
|
|
}");
|
|
}
|
|
}
|
|
|
|
|