Dear All, looking for help to initiate API login of ESP8266 to RouterOS using Arduino IDE.. I grab this script from the internet but no success. Please help.
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
const char *ssid = "admin";
const char *pwd = "1234";
const char *username = "api";
const char *password = "45678";
void setup() {
Serial.begin(9600); //Serial connection
WiFi.begin(ssid, pwd); //WiFi connection
while (WiFi.status() != WL_CONNECTED) { //Wait for the WiFI connection completion
delay(500);
Serial.println("Waiting for connection");
}
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare object of class HTTPClient
http.begin("http://11.0.0.1/api/user/login"); //Specify request destination
http.addHeader("Content-Type", "text/plain"); //Specify content-type header
int httpCode = http.POST("username, password"); //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
} else {
Serial.println("Error in WiFi connection");
}
delay(30000); //Send a request every 30 seconds
}