-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathesp8266_tuner_fw.ino
159 lines (136 loc) · 4.34 KB
/
esp8266_tuner_fw.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
const char* ssid = "HAM_NODE";
const char* password = "";
String frequency = String("");
String squelch = String("");
ESP8266WebServer server(80);
void writeString(String string);
float mapFl(int x, float in_min, float in_max, float out_min, float out_max);
const int led = 13;
void handleRoot() {
digitalWrite(led, 1);
server.send(200, "text/html", "<!DOCTYPE HTML><html><head><title>Ham tuner</title></head><body><form class=\"form-horizontal\" action=\"/submit\" method=\"post\">"
"<fieldset>"
"<!-- Form Name -->"
"<legend>Form Name</legend>"
"<!-- Text input-->"
"<div class=\"form-group\">"
"<label class=\"col-md-4 control-label\" for=\"frequency\">Frequency</label> "
"<div class=\"col-md-4\">"
"<input id=\"frequency\" name=\"frequency\" placeholder=\"e.g. 145.6000\" class=\"form-control input-md\" type=\"text\">"
"<span class=\"help-block\">Enter frequency</span> "
" </div>"
"</div>"
"<!-- Text input-->"
"<div class=\"form-group\">"
"<label class=\"col-md-4 control-label\" for=\"squelch\">Squelch level</label> "
"<div class=\"col-md-4\">"
"<input id=\"squelch\" name=\"squelch\" placeholder=\"e.g. 1\" class=\"form-control input-md\" type=\"text\">"
"<span class=\"help-block\">Enter squelch level between 0 to 7</span> "
"</div>"
"</div>"
"<!-- Button -->"
"<div class=\"form-group\">"
"<label class=\"col-md-4 control-label\" for=\"submit\"></label>"
"<div class=\"col-md-4\">"
"<button id=\"submit\" name=\"submit\" class=\"btn btn-primary\">Tune</button>"
"</div>"
"</div>"
"</fieldset>"
"</form></body></html>"
);
digitalWrite(led, 0);
}
void handleNotFound(){
digitalWrite(led, 1);
String message = "File Not Found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
digitalWrite(led, 0);
}
void handleSubmit(){
float floatFrequency;
char buffer[100];
if(server.args()>0){
if(server.hasArg("frequency")){
frequency = server.arg("frequency");
squelch = server.arg("squelch");
//floatFrequency = frequency.toFloat();
//floatFrequency = mapFl(floatFrequency, 1, 100, 144.000, 146.000);
//dtostrf(floatFrequency, 3, 3, buffer);
//Serial.println(buffer);
writeString("AT+DMOSETGROUP=1,"+frequency+","+frequency+",0000,"+squelch+",0000\r\n");
}
}
digitalWrite(led, 1);
String message;
String rx;
delay(100);
if(Serial.available()>0){
rx = Serial.readString();
}
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
message += rx + "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
digitalWrite(led, 0);
server.send(200, "text/html", message);
}
void setup(void){
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(9600);
IPAddress ip(192,168,1,35);
IPAddress subnet(255,255,255,0);
WiFi.softAP(ssid, password);
WiFi.softAPConfig(ip, ip, subnet);
Serial.println("");
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.softAPIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/submit", handleSubmit);
server.on("/inline", [](){
server.send(200, "text/plain", "this works as well");
});
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
void writeString(String string) { // Used to serially push out a String with Serial.write()
for (int i = 0; i < string.length(); i++)
{
Serial.write(string[i]); // Push each char 1 by 1 on each loop pass
}
}
float mapFl(int x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}