-->
Page 1 of 1

Esp8266- Controling miltuple outputs of the ESP8266

PostPosted: Tue Feb 20, 2018 3:18 pm
by GeorgeEng
Hi all !
With my ESP8266 module I managed to control the pin 2 of it through a rudimental website .
My question is how can I make the out pin 3 of the ESP8266 as well to do the same. In other words how can I add an available output through my code so that I have two available outputs and control them through my website. I post my code to tell what should I change in order for that to happen.
Also what should amend to my code in order for the output 2 to be high as long as the button on the website is still pressed and not to be high when it is pressed once as it's now. If that it´s not the right group to post that kind of questions can you tell me please which is it ?

Thank you very much in advance


#include <ESP8266WiFi.h>
#include <aREST.h>
#include <aREST_UI.h>

// Create aREST instance
aREST_UI myRest = aREST_UI();




// WiFi parameters
const char* ssid = "TALKTALK580421";
const char* password = "W6D7JJ3U" ;

// The port to listen for incoming TCP connections

#define LISTEN_PORT 80

// Create an instance of the server
WiFiServer server(LISTEN_PORT);


void setup(void)
{
// Start Serial for debugging
Serial.begin(115200);

// Create a title for our webpage
myRest.title("LED Control");

// Create button to control pin 2
myRest.button(2);

// Give name and ID to device
myRest.set_id("1");
myRest.set_name("esp8266");

// Connect to the network and start the server
connectWifi();
}

void loop() {
restLoop(); //automatically handle the aRest functionality
}


boolean restLoop(){
WiFiClient client = server.available();

if (!client) { //check to see if the client is connected or not and return if not connected
return false;
}

while(!client.available()){ //wait for input from the client - note that this is a blocking operation
delay(1);
}

myRest.handle(client); //handle any requests from the client

return true; //and return
}

void connectWifi(){
Serial.print("Connecting to ");
Serial.println(ssid);

//Start the wifi subsystem
WiFi.begin(ssid, password);

//wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

//print connection IP upon success
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());

// Start the server
server.begin();
Serial.println("Server started");

Re: Esp8266- Controling miltuple outputs of the ESP8266

PostPosted: Tue Feb 20, 2018 7:52 pm
by rudy
Have you looked at where the code uses the first output and then duplicated it but with the second output? Have you read the documentation for the library that you are using?