Wow.. ESP8266 is amazing. It is cheap and has many functions. I didnt know esp has AP mode. I am trying project using exp8266. I will watch your code and improve this. Thank you for sharing good implement.
thanks Hugues, i will use the code as a base for a "flexible" IOT sensoring system (kWh, Water, weather, etc...) for my domoticz server. The flexible means you can configurate all the static parameter with the web-interface. your code gives me the basic that i need. it's all about web interactions with the IO. later on i shall publish it on RUclips John
Wow..
ESP8266 is amazing.
It is cheap and has many functions.
I didnt know esp has AP mode.
I am trying project using exp8266.
I will watch your code and improve this.
Thank you for sharing good implement.
Nice piece of code, can you make it available as text file? thnx
#include
#include
#include Servo myservo; // create servo object to control a servo
const char *ssid = "Hugues";
const char *password = "";
String t = "OFF";
int servopin=4;
int valclic=60;
int valinit=40;ESP8266WebServer server ( 80 );String getPage(){
String page = "";
page += "ESP8266 Remote Servo Control";
page += " body { background-color: #fffff; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }";
page += "ESP8266 Remote DX80 Control";
page += "DX80 status : ";
page += t;
page +="";
page +="";
//page += "";
//page += "ON";
//page += "OFF";
//page += "";
page +="Choose a DX80 action: ";
page +="TURN ON";
page +=" ";
page +="TURN OFF";
page +="";
page += "";
return page;
}
void handleRoot(){
if ( server.hasArg("DX80") ) {
handleSubmit();
} else {
server.send ( 200, "text/html", getPage() );
}
}void handleSubmit() {
// Actualise le GPIO / Update GPIO
String DX80Value;
DX80Value = server.arg("DX80");
Serial.print("Set DX80 to:"); Serial.println(DX80Value);
if ( DX80Value == "1" ) {
myservo.write(valclic); // sets the servo position according to the scaled value
delay(100);
myservo.write(valinit);
delay(100);
myservo.write(valclic);
delay(100);
myservo.write(valinit);
delay(100);
t = "On";
server.send ( 200, "text/html", getPage() );
} else if ( DX80Value == "0" ) {
myservo.write(valclic);
delay(100);
myservo.write(valinit);
delay(100);
t = "Off";
server.send ( 200, "text/html", getPage() );
} else {
Serial.println("Error DX80 Value");
}
}void setup() {
myservo.write(valinit); // sets the servo position according to the scaled value
Serial.begin(115200);
Serial.println();
Serial.print("Configuring access point...");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
myservo.attach(servopin); // attaches the servo on GIO2 to the servo object
delay(1000);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
Serial.print("Server MAC address: ");
Serial.println(WiFi.softAPmacAddress()); // On branche la fonction qui gère la premiere page / link to the function that manage launch page
server.on ( "/", handleRoot ); server.begin();
Serial.println ( "HTTP server started" );
}void loop() {
server.handleClient();
}
thanks Hugues,
i will use the code as a base for a "flexible" IOT sensoring system (kWh, Water, weather, etc...) for my domoticz server.
The flexible means you can configurate all the static parameter with the web-interface.
your code gives me the basic that i need. it's all about web interactions with the IO.
later on i shall publish it on RUclips
John
Nice, yes post your results!