Go Down

Topic: ESP8266 on Feather Huzzah: 2 GPIO pins work from webserver and the others don't (Read 430 times) previous topic - next topic

Sophi

Hello,
I am using a Feather Huzzah board from Adafruit. The goal is to turn all the GPIO on and off via a webpage.

The issue I need help with is that using the same HTML string, I am able to turn the GPIO0 and GPIO2 on/ off but none of the other GPIO pins. The Arduino pinout is equivalent to the ESP8266 Huzzah pinout.
I can use digitalWrite(12, HIGH) within the code to turn pin 12 on/off, but not via the webserver.

I followed this tutorial and ended up with a working connection over WiFi from PC to an ESP8266.

The GPIO buttons were made by running HTML through an HTML to string converter.
Code: [Select]
#ifndef header_h
#define header_h

String file1=
"<html>\r\n"
"<head>\r\n"
" <title>Drive</title>\r\n"
"</head>\r\n"
"<body>\r\n"
"<h2>Drive the car!</h2>\r\n"
"\r\n"

"<form action = \"/gpio0\" method=\"GET\">GPIO0 <input type=\"submit\" name=\"on\" value=\"ON\"/>&nbsp;<input type=\"submit\" name=\"off\" value=\"OFF\"/>&nbsp;</form>\r\n"
"<form action = \"/gpio2\" method=\"GET\">GPIO2<input type=\"submit\" name=\"on\" value=\"ON\"/>&nbsp;<input type=\"submit\" name=\"off\" value=\"OFF\"/>&nbsp;</form>\r\n"
"<form action = \"/gpio12\" method=\"GET\">GPIO12 <input type=\"submit\" name=\"on\" value=\"ON\"/>&nbsp;<input type=\"submit\" name=\"off\" value=\"OFF\"/>&nbsp;</form>\r\n"

"\r\n"
"</body>\r\n"
"</html>\r\n";

#endif


This is uploaded to the Arduino as an *.h file.

Here's the Arduino webserver
Code: [Select]
Instructions:
  - Update WiFi SSID and password as necessary.
  - Flash the sketch to the ESP8266 board
  - Install host software:
    - For Linux, install Avahi (http://avahi.org/).
    - For Windows, install Bonjour (http://www.apple.com/support/bonjour/).
    - For Mac OSX and iOS support is built in through Bonjour already.
  - Point your browser to http://esp8266.local, you should see a response.

 */

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include "ioControl.h"

const char* ssid = "S+O";
const char* password = "0000000000";

// multicast DNS responder
MDNSResponder mdns;

// TCP server at port 80 will respond to HTTP requests
WiFiServer server(80);
int PIN12;
void setup(void)

  pinMode(0,OUTPUT);//active high
  pinMode(1,OUTPUT);digitalWrite(1,HIGH); //active low
  pinMode(2,OUTPUT);//active high
  pinMode(4,OUTPUT);//active high
  pinMode(5,OUTPUT);
  pinMode(PIN12,OUTPUT);//active high
  pinMode(13,OUTPUT);//active high
  pinMode(14,OUTPUT);
  //pinMode(15,OUTPUT);//active high
  //digitalWrite(12,HIGH); //active low
  Serial.begin(115200);

  // Connect to WiFi network
  WiFi.begin(ssid, password);
  Serial.println(""); 
 
  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  // Set up mDNS responder:
  // - first argument is the domain name, in this example
  //   the fully-qualified domain name is "esp8266.local"
  // - second argument is the IP address to advertise
  //   we send our IP address on the WiFi network
  if (!mdns.begin("esp8266", WiFi.localIP())) {
    Serial.println("Error setting up MDNS responder!");
    while(1) {
      delay(1000);
    }
  }
 Serial.println("mDNS responder started");
 
  // Start TCP (HTTP) server
  server.begin();
  Serial.println("TCP server started");
  delay(2000);
  Serial.end();
 

}

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

  // 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) {
    return;
  }
  req = req.substring(addr_start + 1, addr_end);
  client.flush();
 
  String s;
  if (req == "/")
  {
    s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
    s += file1;
  }
 
  else if (req.indexOf("gpio0")!=-1)
  {
    if(req.indexOf("on")!=-1)
    digitalWrite(0,HIGH);
    else
    digitalWrite(0,LOW);
    s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
    s += file1;
  }

  else if (req.indexOf("gpio1")!=-1)
  {
    if(req.indexOf("on")!=-1)
    digitalWrite(1,LOW);
    else
    digitalWrite(1,HIGH);
    s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
    s += file1;
  }
 
 
  else if (req.indexOf("gpio2")!=-1)
  {
    if(req.indexOf("on")!=-1)
    digitalWrite(2,HIGH);
    else
    digitalWrite(2,LOW);
    s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
    s += file1;
  }
 
  else
  {
    s = "HTTP/1.1 404 Not Found\r\n\r\n";
  }
 
  while(s.length()>2000)
  {
   String dummy = s.substring(0,2000);
   client.print(dummy);
   s.replace(dummy,"");
  }
  client.print(s);
}

rw950431


You dont appear to have  specific code to match "gpio12".  The way its currently written the string "gpio12" will be matched by the code for gpio1 shown below and so gpio1 will be toggled instead.

Perhaps you should print out some diagnostics on the serial port to make sure you are parsing the response correctly?

 

Code: [Select]
else if (req.indexOf("gpio1")!=-1)
{
if(req.indexOf("on")!=-1)
digitalWrite(1,LOW);
else
digitalWrite(1,HIGH);
s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
s += file1;
}


According to https://learn.adafruit.com/adafruit-feather-huzzah-esp8266/pinouts GPIO1 is the serial port TX data pin so you probably dont want to be using that for IO unless you are really short of pins.

http://www.esp8266.com/wiki/doku.php?id=esp8266_gpio_pin_allocations is a nice drawing of the all GPIO pins along with thier limitations.

Go Up