Press virtual button on a local network homepage

Dear all,

I have a problem with a project I'm currently working on. The shadings in our house are controlled via a homepage in a local network which goes on my nerves because I have to switch between the WiFi's with my phone all the time. So I thought I could use my NodeMCU to controll the shadings, at first maybe just by using the serial monitor.

So far I can connect to the local network an the local homepage but I'm stuck at how to press the button (or actually image).

I have accessed the source code of the local hompage. I think what I need to do is telling the nodeMCU to execute the highlighted "onclick=set_request(id)" command. (see attachment)

Does anybody know an easy solution for my problem?

Thank you so much and kind regards
Alex

P.S.:
The code to access the homepage:

#include <WiFiClient.h>

#include <ESP8266WiFi.h>


const char *ssid =  "network";     // replace with your wifi ssid and wpa2 key
const char *pass =  "Password";

IPAddress server(192,168,48,10);

WiFiClient client;
 
void setup() 
{
       Serial.begin(9600);
       delay(10);
               
       Serial.println("Connecting to ");
       Serial.println(ssid); 
 
       WiFi.begin(ssid, pass); 
       while (WiFi.status() != WL_CONNECTED) 
          {
            delay(500);
            Serial.print(".");
          }
      Serial.println("");
      Serial.println("WiFi connected"); 
      Serial.println('\n');
      Serial.println("Connection established!");  
      Serial.print("IP address:\t");
      Serial.println(WiFi.localIP());         // Send 
      while(!client.connect(server, 80)){
        delay(500);
        Serial.print(".");
      }
  Serial.println();
  Serial.println("Connected");
}
 
void loop() 
{      
  
}

You will never be able to get the NodeMCU to press a button on a f**king picture.

Post TEXT AS TEXT.

You MIGHT be able to get the NodeMCU to perform the same action as if the user had clicked the button which triggered the onclick() method.

Hi,

PaulS:
You will never be able to get the NodeMCU to press a button on a f**king picture.

sorry, if I didn't express myself very well, I haven't much experience on this topic so far.

PaulS:
You MIGHT be able to get the NodeMCU to perform the same action as if the user had clicked the button which triggered the onclick() method.

Well, my question is how to do that?

I only have the screenshot available at the moment, but I can post the source code as text later on if that is of any help.

Thanks anyway and kind regards
Alex

I only have the screenshot available at the moment, but I can post the source code as text later on if that is of any help.

It will be necessary.

Hi,

I got a hint from somebody else how to solve my problem and it's working now. I wanted to share my solution with you, maybe it's useful for somebody else.

What I needed to do was using the software "Fiddler" to see what message is sent when I press the button. In my case a page "command.php" is called and the data "name=blind_1_up" is sent. Also the content type used in the code can be obtained with Fiddler.

Once I had this information was straight forward to use the NodeMCU for posting the request.

Best regards
Alex

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>


const char *ssid =  "SSID";     // replace with your wifi ssid and wpa2 key
const char *pass =  "****";

IPAddress server(192,168,82,10);


WiFiClient client;


void setup() {
  // put your setup code here, to run once:
       Serial.begin(115200);
       delay(10);
       
       WiFi.mode(WIFI_STA);
       
       Serial.println("Connecting to ");
       Serial.println(ssid); 
 
       WiFi.begin(ssid, pass); 
       while (WiFi.status() != WL_CONNECTED) 
          {
            delay(500);
            Serial.print(".");
          }
      Serial.println("");
      Serial.println("WiFi connected"); 
      Serial.println('\n');
      Serial.println("Connection established!");  
      Serial.print("IP address:\t");
      Serial.println(WiFi.localIP());         // Send 
  Serial.println();
  Serial.println("Connected");

}

void loop() {
  

  if (Serial.available()>0){
    Serial.read();
    HTTPClient http;
    http.begin("http://192.168.82.10/command.php");
    String postData = "name=blind_1_up" ;
    
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header
   
    int httpCode = http.POST(postData);   //Send the request
    String payload = http.getString();    //Get the response payload
   
    Serial.println(httpCode);   //Print HTTP return code
    Serial.println(payload);    //Print request response payload
   
    http.end();  //Close connection
    
  }
}
  

}
  if (Serial.available()==100){
    Serial.read();

Unless you have modified the HardwareSerial class, the buffer only holds 64 character, so available() will never return 100.

Why are you executing the rest of the code only if there are exactly 100 characters in the serial buffer?

Hi,

sorry, I somehow got this line wrong but edited it in my previous post. Of course it should be:

Serial.available()>0

that I cant send the request via the serial monitor.

Thanks
Alex