- Wed Dec 01, 2021 10:03 pm
#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";
}
}
}