Created
December 25, 2017 18:17
-
-
Save anonymous/9efac5924fe30b5ef02dcbcad6fdcc38 to your computer and use it in GitHub Desktop.
control ZTE MF283+ over UART with ESP8266
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <ESP8266WebServer.h> | |
#include "website_data.h" | |
ESP8266WebServer server(80); | |
const char* ssid = "SSID"; | |
const char* password = "PASSWORD"; | |
String html_data; | |
void handle_root() { | |
if(server.hasArg("band")) { | |
handle_band(); | |
} else { | |
html_data = common_header; | |
html_data = html_data + root_data; | |
html_data = html_data + common_footer; | |
server.send(200, "text/html", html_data); | |
} | |
} | |
void handle_band() { | |
int band = server.arg("band").toInt(); | |
Serial.println(); | |
Serial.print("echo \"AT+ZLOCKBAND="); | |
Serial.print(band); | |
Serial.println("\" > /dev/ttyUSB1"); | |
if( server.hasArg("reboot") ){ | |
Serial.println("reboot"); | |
} | |
handle_done(); | |
} | |
void handle_reboot(){ | |
Serial.println(); | |
Serial.println("reboot"); | |
handle_done(); | |
} | |
void handle_done(){ | |
html_data = common_header; | |
html_data = html_data + status_data; | |
html_data = html_data + common_footer; | |
server.send(200, "text/html", html_data); | |
} | |
// Initialize WiFi, web server and handles | |
void setup() { | |
Serial.begin(57600); | |
WiFi.mode(WIFI_STA); | |
WiFi.begin(ssid, password); | |
server.on("/", handle_root); | |
server.on("/reboot", handle_reboot); | |
server.begin(); | |
} | |
void loop() { | |
server.handleClient(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char* common_header = | |
"<html>" | |
"<head>" | |
"<title>ESP8266 WebGate Control</title>" | |
"</head>" | |
"<body>"; | |
const char* common_footer = | |
"</body>" | |
"</html>"; | |
const char* root_data = | |
"<h1>ESP8266 WebGate Control</h1>" | |
"<form action=\"/\" method=\"post\">" | |
"<input type=\"radio\" name=\"band\" value=\"20\">LTE 800 MHz<br />" | |
"<input type=\"radio\" name=\"band\" value=\"3\">LTE 1800 MHz<br />" | |
"<input type=\"radio\" name=\"band\" value=\"7\">LTE 2600 MHz<br />" | |
"<input type=\"radio\" name=\"band\" value=\"0\">automatic<br /><br />" | |
"<input type=\"checkbox\" name=\"reboot\" value=\"1\">reboot modem<br />" | |
"<input type=\"submit\" value=\"submit\"> <input type=\"reset\" value=\"reset\">" | |
"</form>"; | |
const char* status_data = | |
"<h2>command sent</h2>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment