sending ESPEasy command triggered by GPIO

Redtape
Posts: 1
Joined: Wed Aug 02, 2017 7:41 am

sending ESPEasy command triggered by GPIO

Postby Redtape » Wed Aug 02, 2017 10:43 am

Hello, I have a couple sonoff modules and an ESP32 dev board with the 32wroom chip. The sonoffs are reprogrammed with ESPEasy and now have a simple task of switching a relay from on to off or vice versa. the ESP32 is set up as the access point to which the sonoff modules connect and as long as i am connected to the ESP32 module i can simply punch in the http command "http://192.168.0.179/control?cmd=event,TurnOn" (it varies a bit depending on the sonoff and desired command). my question lies within; my ESP32 was part of a 'Hackerboxes' kit and came with a tft lcd and circuit board containing capacitive touch pads.
I have been able to create a menu to show on the screen and included interaction from the capacitive touch pads to try to control the two sonoff modules. i have my code below and, though it is very sloppy and poorly commented, it works; i cannibalized from several different sources. how do i set it so that when i hit a capacitive touch pad, it triggers one of the sonoff modules?

Code: Select all

#include "WiFi.h"
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Adafruit_NeoPixel.h>
#include <HTTPClient.h>

// TFT Display Pins
#define TFT_CS    19
#define TFT_DC    22
#define TFT_MOSI  23
#define TFT_CLK   26
#define TFT_RST   21
#define TFT_MISO  25
int threshold = 40;

const char *ssid = "ESP32ap";
const char *password = "12345678";
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

WiFiServer server(80);

void setup()
{
    Serial.begin(115200);
    tft.begin();
    tft.setRotation(3); // rotate 3*(pi/2)
   
    delay(10);

    WiFi.softAP(ssid, password);
    for (int i; i<13; i++)

    server.begin();
    touchAttachInterrupt(12, gotTouch12, threshold);
    tft.fillScreen(ILI9341_BLACK);
    touchAttachInterrupt(13, gotTouch13, threshold);
    tft.fillScreen(ILI9341_BLACK);
    touchAttachInterrupt(14, gotTouch14, threshold);
    tft.fillScreen(ILI9341_BLACK);
    touchAttachInterrupt(15, gotTouch15, threshold);
    tft.fillScreen(ILI9341_BLACK);
    touchAttachInterrupt(27, gotTouch27, threshold);
    tft.fillScreen(ILI9341_BLACK);
    tft.setCursor(0, 0);
    tft.setTextColor(ILI9341_GREEN);
    tft.setTextSize(3);

    delay(1000);

}

int value = 0;
int selection = 0;
void loop(){
 WiFiClient client = server.available();   // listen for incoming clients
  int displaylines=13;
  
  while (displaylines > 0)
  {
    delay(1000); // Wait before scanning again
  }

  if (client) {                             // if you get a client,
    String currentLine = "";                // make a String to hold incoming data from the client
    while (client.connected()) {            // loop while the client's connected
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        if (c == '\n') {                    // if the byte is a newline character

          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println();

            // the content of the HTTP response follows the header:
            client.print("Click <a href=\"http://192.168.0.179/control?cmd=event,TurnOn\">here</a> turn the lights on<br>");
            client.print("Click <a href=\"http://192.168.0.128/control?cmd=event,TurnOn\">here</a> turn the fan on<br>");
            client.print("Click <a href=\"http://192.168.0.179/control?cmd=event,TurnOff\">here</a> turn the lights off<br>");
            client.print("Click <a href=\"http://192.168.0.128/control?cmd=event,TurnOff\">here</a> turn the fan off<br>");

            // The HTTP response ends with another blank line:
            client.println();
            // break out of the while loop:
            break;
          } else {    // if you got a newline, then clear currentLine:
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
  }
  tft.fillScreen(ILI9341_BLACK);
}
void gotTouch12()
{
/*  Serial.println("RIGHT\n");
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_RED);
  tft.println(" Sonoff Control");*/
}

void gotTouch13()
{
  
  Serial.println("DOWN\n");
  tft.setCursor(0, 0);
  tft.setTextSize(4);
  if (selection == 0 ){
  selection = (selection +1);
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" FAN ON");
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN Off");
  tft.println(" LIGHTS ON");
  tft.println(" LIGHTS Off");
  }
  else if (selection == 1 ){
  selection = (selection +1);
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN ON");
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" FAN Off");
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" LIGHTS ON");
  tft.println(" LIGHTS Off");
    
  }
  else if (selection == 2 ){
  selection = (selection +1);
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN ON");
  tft.println(" FAN Off");
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" LIGHTS ON");
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" LIGHTS Off");
    
  }
  else if (selection == 3 ){
  selection = 0;
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN ON");
  tft.println(" FAN Off");
  tft.println(" LIGHTS ON");
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" LIGHTS Off");
    
  }

}

void gotTouch14()
{

  Serial.println("UP\n");
  tft.setCursor(0, 0);
  if (selection == 0 ){
  selection = 3;
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" FAN ON");
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN Off");
  tft.println(" LIGHTS ON");
  tft.println(" LIGHTS Off");
  }
  else if (selection == 1 ){
  selection = (selection -1);
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN ON");
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" FAN Off");
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" LIGHTS ON");
  tft.println(" LIGHTS Off");
    
  }
  else if (selection == 2 ){
  selection = (selection -1);
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN ON");
  tft.println(" FAN Off");
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" LIGHTS ON");
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" LIGHTS Off");
    
  }
  else if (selection == 3 ){
  selection = (selection -1);
  tft.setTextColor(ILI9341_WHITE);
  tft.println(" FAN ON");
  tft.println(" FAN Off");
  tft.println(" LIGHTS ON");
  tft.setTextColor(ILI9341_BLUE);
  tft.println(" LIGHTS Off");
}
}
void gotTouch15()
{
  if (selection == 0) {
    selection = 0;
    // i need help doing the http thingy
  }
  else if (selection == 1){
    selection = 0;
    // i need help doing the http thingy
  }
  else if (selection ==2){
    selection = 0;
    // i need help doing the http thingy
  }
  else if (selection == 3){
    selection = 0;
    // i need help doing the http thingy
  }
}
void gotTouch27()
{
  /*Serial.println("LEFT\n");
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_YELLOW);
  tft.println(" Sonoff Control"); */
}
someone please point me in the right direction

Who is online

Users browsing this forum: Google [Bot] and 125 guests