我有 esp8266 设备向服务器发送数据。它连接 wifi 路由器 (D-Link DWR921) 以访问互联网。几天来,它工作得很好,但是 wifi 路由器卡住了,没有互联网连接,所以我必须手动重启。
无线路由器设置是基于网络的,它有软按钮来重启。
我有想法,如果我通过发送 HTTP 请求将按钮替换为其他,那么我可以在我的 ESP8266 中发挥作用(如果可能的话)
然后我使用网络浏览器检查元素按钮,
名为 system_reboot() 的重启按钮调用函数
然后我下载所有的 .html 和 .js 文件,并搜索 system_reboot(),
function system_reboot(){
var value = 1;
if( win.confirm(global_lang["login1"]["information"],global_lang["system_popup"]["reboot_dialog"],function (r){
if(r){systemApi_reboot(value);}
})){
}else{return;}
}
function systemApi_reboot(value) {
/* Get auth Id */
cpApi_get_authId();
var post_data={"CfgType":"reboot_reset","cmd": "reboot","authID":auth_id};
var request = $.ajax({
url: "/webpost.cgi",
type: "POST",
data: JSON.stringify(post_data),
dataType: "json"
});
request.done(function( responseData,textStatus, jqXHR ) {
clearCookies();
alert(global_lang['alerts_set']['restart_success']);
var path = "index.html";
ProhibitionClick();
defaultRedirect(120,path,value);
});
request.fail(function( jqXHR, textStatus, errorThrown) {
});
request.always(function(responseData,textStatus, jqXHR ) {
});
}
function cpApi_get_authId() {
loginApi_check_auth();
var request = $.ajax({
url: "/data.ria?token=1",
type: "GET",
dataType: "text",
async: false
});
request.done(function( responseData,textStatus, jqXHR ) {
auth_id = responseData;
});
request.fail(function( jqXHR, textStatus, errorThrown) {
});
request.always(function(responseData,textStatus, jqXHR ) {
});
}
function loginApi_check_auth() {
if (getCookie("qSessId") == null ) {
alert(global_lang['login1']['session-logout']);
window.location = "index.html";
return;
} else {
var request = $.ajax({
url: "login.cgi",
type: "POST",
data: { "check_valid" : "qSessId="+getCookie("qSessId")},
dataType: "json"
});
request.done(function( responseData,textStatus, jqXHR ) {
if(responseData.login_fail){
clearCookies();
alert(global_lang['login1']['session-logout']);
window.location = "index.html";
return;
}
/* Login is failed */
if(jqXHR.status == 401) {
clearCookies();
window.location = "index.html";
return;
}
/* ReSet the timeout cookie as per latest timeout
Note: This happens when you refresh the control panel page and we need to revaidate the cookie
*/
var date = new Date();
date.setTime(date.getTime() + (24 * 60 * 179 * 1000));
var expires = ";expires=" + date.toGMTString();
document.cookie ="DWRLOGGEDTIMEOUT="+179+expires;
global_AuthTimeout = 179;
global_authDefaulTimeout = ui_config["login_timeout"];
});
request.fail(function( jqXHR, textStatus, errorThrown) {
clearCookies();
alert(global_lang['login1']['session-logout']);
window.location = "index.html";
return;
});
request.always(function( responseData,textStatus, jqXHR ) {
});
}
}
function getCookie(c_name)
{
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1)
{
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1)
{
c_value = null;
}
else
{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1)
{
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
所有相关的功能,我的问题,是否可以发送 HTTP(ajax)请求来重启路由器?以及如何做到这一点?我很困惑......