Skip to content

Commit 7d8dc97

Browse files
authored
Merge pull request #4 from arduino-libraries/marqdevx-patch-1
Changed SimpleServer sketch name
2 parents e88abf2 + cc4e0c0 commit 7d8dc97

File tree

2 files changed

+170
-0
lines changed

2 files changed

+170
-0
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
#include <WiFi.h>
2+
#include "arduino_secrets.h"
3+
4+
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
5+
char ssid[] = SECRET_SSID; // your network SSID (name)
6+
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
7+
int keyIndex = 0; // your network key Index number (needed only for WEP)
8+
9+
int status = WL_IDLE_STATUS;
10+
11+
WiFiServer server(80);
12+
13+
void setup() {
14+
// put your setup code here, to run once:
15+
Serial.begin(9600);
16+
while (!Serial) {
17+
; // wait for serial port to connect. Needed for native USB port only
18+
}
19+
20+
Serial.println("Access Point Web Server");
21+
22+
pinMode(LEDR, OUTPUT);
23+
pinMode(LEDG, OUTPUT);
24+
pinMode(LEDB, OUTPUT);
25+
26+
// by default the local IP address of will be 192.168.3.1
27+
// you can override it with the following:
28+
// WiFi.config(IPAddress(10, 0, 0, 1));
29+
30+
// The AP needs the password be at least 8 characters long
31+
if(strlen(pass) < 8){
32+
Serial.println("Creating access point failed");
33+
Serial.println("The WiFi password must be at least 8 characters long");
34+
// don't continue
35+
while(true);
36+
}
37+
38+
// print the network name (SSID);
39+
Serial.print("Creating access point named: ");
40+
Serial.println(ssid);
41+
42+
//Create the Access point
43+
status = WiFi.beginAP(ssid, pass);
44+
if (status != WL_AP_LISTENING) {
45+
Serial.println("Creating access point failed");
46+
// don't continue
47+
while (true);
48+
}
49+
50+
// wait 10 seconds for connection:
51+
delay(10000);
52+
53+
// start the web server on port 80
54+
server.begin();
55+
56+
// you're connected now, so print out the status
57+
printWiFiStatus();
58+
59+
}
60+
61+
void loop() {
62+
63+
// compare the previous status to the current status
64+
if (status != WiFi.status()) {
65+
// it has changed update the variable
66+
status = WiFi.status();
67+
68+
if (status == WL_AP_CONNECTED) {
69+
// a device has connected to the AP
70+
Serial.println("Device connected to AP");
71+
} else {
72+
// a device has disconnected from the AP, and we are back in listening mode
73+
Serial.println("Device disconnected from AP");
74+
}
75+
}
76+
77+
WiFiClient client = server.available(); // listen for incoming clients
78+
79+
if (client) { // if you get a client,
80+
Serial.println("new client"); // print a message out the serial port
81+
String currentLine = ""; // make a String to hold incoming data from the client
82+
83+
while (client.connected()) { // loop while the client's connected
84+
85+
if (client.available()) { // if there's bytes to read from the client,
86+
char c = client.read(); // read a byte, then
87+
Serial.write(c); // print it out the serial monitor
88+
if (c == '\n') { // if the byte is a newline character
89+
90+
// if the current line is blank, you got two newline characters in a row.
91+
// that's the end of the client HTTP request, so send a response:
92+
if (currentLine.length() == 0) {
93+
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
94+
// and a content-type so the client knows what's coming, then a blank line:
95+
client.println("HTTP/1.1 200 OK");
96+
client.println("Content-type:text/html");
97+
client.println();
98+
99+
// the content of the HTTP response follows the header:
100+
client.print("<html><head>");
101+
client.print("<style>");
102+
client.print("* { font-family: sans-serif;}");
103+
client.print("body { padding: 2em; font-size: 2em; text-align: center;}");
104+
client.print("a { -webkit-appearance: button;-moz-appearance: button;appearance: button;text-decoration: none;color: initial; padding: 25px;} #red{color:red;} #green{color:green;} #blue{color:blue;}");
105+
client.print("</style></head>");
106+
client.print("<body><h1> LED CONTROLS </h1>");
107+
client.print("<h2><span id=\"red\">RED </span> LED </h2>");
108+
client.print("<a href=\"/Hr\">ON</a> <a href=\"/Lr\">OFF</a>");
109+
client.print("<h2> <span id=\"green\">GREEN</span> LED </h2>");
110+
client.print("<a href=\"/Hg\">ON</a> <a href=\"/Lg\">OFF</a>");
111+
client.print("<h2> <span id=\"blue\">BLUE</span> LED </h2>");
112+
client.print("<a href=\"/Hb\">ON</a> <a href=\"/Lb\">OFF</a>");
113+
client.print("</body></html>");
114+
115+
// The HTTP response ends with another blank line:
116+
client.println();
117+
// break out of the while loop:
118+
break;
119+
} else { // if you got a newline, then clear currentLine:
120+
currentLine = "";
121+
}
122+
} else if (c != '\r') { // if you got anything else but a carriage return character,
123+
currentLine += c; // add it to the end of the currentLine
124+
}
125+
126+
// Check to see if the client request was "GET /H" or "GET /L":
127+
if (currentLine.endsWith("GET /Hr")) {
128+
digitalWrite(LEDR, LOW); // GET /Hr turns the Red LED on
129+
}
130+
if (currentLine.endsWith("GET /Lr")) {
131+
digitalWrite(LEDR, HIGH); // GET /Lr turns the Red LED off
132+
}
133+
if (currentLine.endsWith("GET /Hg")) {
134+
digitalWrite(LEDG, LOW); // GET /Hg turns the Green LED on
135+
}
136+
if (currentLine.endsWith("GET /Lg")) {
137+
digitalWrite(LEDG, HIGH); // GET /Hg turns the Green LED on
138+
}
139+
if (currentLine.endsWith("GET /Hb")) {
140+
digitalWrite(LEDB, LOW); // GET /Hg turns the Green LED on
141+
}
142+
if (currentLine.endsWith("GET /Lb")) {
143+
digitalWrite(LEDB, HIGH); // GET /Hg turns the Green LED on
144+
}
145+
146+
}
147+
}
148+
// close the connection:
149+
client.stop();
150+
Serial.println("client disconnected");
151+
}
152+
153+
}
154+
155+
void printWiFiStatus() {
156+
// print the SSID of the network you're attached to:
157+
Serial.print("SSID: ");
158+
Serial.println(WiFi.SSID());
159+
160+
// print your WiFi shield's IP address:
161+
IPAddress ip = WiFi.localIP();
162+
Serial.print("IP Address: ");
163+
Serial.println(ip);
164+
165+
// print where to go in a browser:
166+
Serial.print("To see this page in action, open a browser to http://");
167+
Serial.println(ip);
168+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#define SECRET_SSID "PortentaAccessPoint"
2+
#define SECRET_PASS "123Qwerty"

0 commit comments

Comments
 (0)