-
Notifications
You must be signed in to change notification settings - Fork 0
/
wifi-module.ino
70 lines (58 loc) · 1.8 KB
/
wifi-module.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
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
const char* ssid = "wifiname";
const char* password = "wifipassword";
ESP8266WebServer server(80);
void setup()
{
Serial.begin(9600);
Serial.print("helow");
pinMode(2,OUTPUT);
digitalWrite(2,LOW);
Serial.print("Connecting to %s ");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
server.on("/",handleGenericArgs);
//server.on("/specificArgs",handleSpecificArgs);
server.begin();
Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str());
}
void loop()
{
server.handleClient();
}
// <-------------- get request format------------------>
//http://192.168.1.102/genericArgs?john=bro&greating=hello
void handleGenericArgs(){
String message = "Number of Args:";
message +=server.args(); // server.args gives you nuber of argument send
message+="\n";
// Serial.print("dsadadsa"+message);
String serialMessage = "";
for(int i=0;i <server.args();i++){
// message +="Arg no" +(String)i + "->";
// message +=server.argName(i) + ":";
// message +=server.arg(i) + "\n";
serialMessage +=server.arg(i);
// Serial.print("insdi loop");
}
// Serial.print("serialMessage: "+serialMessage);
// Serial.print("serialMessage: "+server.args());
serialMessage +="\n";
digitalWrite(2,HIGH);
if(!(Serial.print(serialMessage))){
String errorMessage = "Error on Serial Print to Arduino";
server.send(200,"text/plain",errorMessage);
}
else{
String errorMessage = serialMessage;
server.send(200,"text/plain",errorMessage);
}
digitalWrite(2,LOW);
server.send(200,"text/plain",message);
}