So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By L67GS
#92945 Hi, I've been lurking and just joined, I'm having a bit of trouble with input on GPIO 6 ,7,8,11 , for some reason it won't connect wifi when I choose those ports and 15 & 16 will allow a wifi connection when set up as input but don't work. Is this a known thing? I'm a 2 year C++ developer with experience programming PIC, and I frequently use SBC's for projects as well.

I'm using:
Linux
ESP12F
Arduino IDE
a programmer, not just a cable
C++ with curl to poll the URL

Code: Select all// Input on GPIO over wifi testing
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char *ssid = "ESP12Test";
const char *password = "00000000";

ESP8266WebServer server(80);
// Just a test message.  Go to http://192.168.4.1 to see it.
void handleRoot() {
  //Do not Remove handleRoot
}
// ESP12F Testing working inputs: 0,1,2,3,4,5,9,10,12,13,14
// ESP12F Tested NOT working inputs 15,16
// ESP12F NOT allowing wifi connection as inputs 6,7,8,11
void setup(){
  delay(1000);
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  server.on("/", handleRoot);
  server.begin();
  pinMode(1, INPUT_PULLUP);

}
void loop(){
  if (digitalRead(1) == HIGH) {
    server.handleClient();
    server.send(200, "text/html", "1");
  }
  else {
    server.handleClient();
    server.send(200, "text/html", "0");
  }
}


Any suggestions?
User avatar
By L67GS
#92961 Apologies for the near identical posts, it takes a while to get approved and I didn't think the first one went through.

Pins 15 & 16 on ESP12F cannot do internal pull up, need to do it externally and they work, 6, 7, 8, & 11 are for internal communication and cannot be used. In all 13 GPIO pins are useable. For other noobs finding this, here's the sample program I cobbled together from samples to do soft AP and input.

Code: Select all //ESP12F Input on GPIO over wifi testing
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
const char *ssid = "ESP12Test";
const char *password = "sidangel";

ESP8266WebServer server(80);
// Just a test message.  Go to http://192.168.4.1 to see it.
void handleRoot() {
  //Do not Remove handleRoot
}
/*
 ESP12F Inputs
  Testing working inputs: 0,1,2,3,4,5,9,10,12,13,14
  Tested working inputs need External pullup: 15,16
  RESERVED FOR DATA: 6,7,8,11
*/
void setup(){
  delay(1000);
  Serial.begin(115200);
  WiFi.softAP(ssid, password);
  IPAddress myIP = WiFi.softAPIP();
  server.on("/", handleRoot);
  server.begin();
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, INPUT_PULLUP);
  pinMode(14, INPUT_PULLUP);
  pinMode(15, INPUT); // need external pullup
  pinMode(16, INPUT); // need external pullup

}
void loop(){
  if(digitalRead(0) == LOW) {
    server.handleClient();
    server.send(200, "text/html", "0");
    delay(250);
  }
  else if(digitalRead(1) == LOW){
    server.handleClient();
    server.send(200, "text/html", "1");
    delay(250);
  }
  else if(digitalRead(2) == LOW){
    server.handleClient();
    server.send(200, "text/html", "2");
    delay(250);
  }
  else if(digitalRead(3) == LOW){
    server.handleClient();
    server.send(200, "text/html", "3");
    delay(250);
  }
    else if(digitalRead(4) == LOW){
    server.handleClient();
    server.send(200, "text/html", "4");
    delay(250);
  }
  else if(digitalRead(5) == LOW){
    server.handleClient();
    server.send(200, "text/html", "5");
    delay(250);
  }
  else if(digitalRead(9) == LOW){
    server.handleClient();
    server.send(200, "text/html", "9");
    delay(250);
  }
  else if(digitalRead(10) == LOW){
    server.handleClient();
    server.send(200, "text/html", "10");
    delay(250);
  }
  else if(digitalRead(12) == LOW){
    server.handleClient();
    server.send(200, "text/html", "12");
    delay(250);
  }
  else if(digitalRead(13) == LOW){
    server.handleClient();
    server.send(200, "text/html", "13");
    delay(250);
  }
  else if(digitalRead(14) == LOW){
    server.handleClient();
    server.send(200, "text/html", "14");
    delay(250);
  }
  else if(digitalRead(15) == LOW){
    server.handleClient();
    server.send(200, "text/html", "15");
    delay(250);
  }
  else if(digitalRead(16) == LOW){
    server.handleClient();
    server.send(200, "text/html", "16");
    delay(250);
  }
  else{
    server.handleClient();
    server.send(200, "text/html", "No Pins Are Toggled");
    delay(250);
  }
}


On the C++/curl side I went long since cpr.h gave me fits. Here's a test program for the PC/Linux side in C++, it's not all mine but the first two functions should do nearly everything one could need to get GPIO input status over wifi:

Code: Select all// compile string: g++ -o curl curl.cpp -lcurl
#include <iostream>
#include <curl/curl.h>
#include <string>
using namespace std;
string responses = "0";
bool var0 = 0, var1 = 0;;

size_t writeFunction(void* ptr, size_t size, size_t nmemb, std::string* data){
   data->append((char*)ptr, size * nmemb);
    return size * nmemb;
}

string getinfo(){
   string data;
   curl_global_init(CURL_GLOBAL_DEFAULT);
   auto curl = curl_easy_init();
   if(curl) {
      curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.4.1");
      curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
      curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L);
      curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
      string response_string;
      string header_string;
      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeFunction);
      curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
      curl_easy_setopt(curl, CURLOPT_HEADERDATA, &header_string);
      curl_easy_perform(curl);
      data = response_string;
      curl_easy_cleanup(curl);
      curl_global_cleanup();
      curl = NULL;
   }   
   return data;
}

int main(){
   while(responses != "17"){
      responses = getinfo();
      if(responses != "none"){
         std::cout << "Pin " << responses << " is LOW" << "\n";
      }
   }
}
User avatar
By L67GS
#92975
QuickFix wrote:You might find this article interesting reading material. :idea:


Thank You for the link I actually figured it out but due to the lag when posting here waiting for approval my next post wasn't available. While I appreciate the absence of spam it would serve this community better to simply appoint MODS to police the forum and remove offensive material rather than taking days to show every post.