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?
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
}
}
}