2
2
MDNS WiFi Web Server
3
3
4
4
A simple web server that shows the value of the analog input pins,
5
- and exposes itself on the MDNS name 'winc1500 .local'.
5
+ and exposes itself on the MDNS name 'wifi101 .local'.
6
6
7
7
On Linux (like Ubuntu 15.04) or OSX you can access the web page
8
- on the device in a browser at 'http://winc1500 .local/'.
8
+ on the device in a browser at 'http://wifi101 .local/'.
9
9
10
10
On Windows you'll first need to install the Bonjour Printer Services
11
11
from:
12
12
https://support.apple.com/kb/dl999?locale=en_US
13
- Then you can access the device in a browser at 'http://winc1500 .local/'.
13
+ Then you can access the device in a browser at 'http://wifi101 .local/'.
14
14
15
15
This example is written for a network using WPA encryption. For
16
16
WEP or WPA, change the Wifi.begin() call accordingly.
29
29
*/
30
30
31
31
#include < SPI.h>
32
- #include < Adafruit_WINC1500.h>
33
- #include < Adafruit_WINC1500MDNS.h>
34
-
35
- // Define the MDNS name that the board will respond to:
36
- #define MDNS_NAME " winc1500"
37
- // Note that the actual MDNS name will have '.local' after
38
- // the name above, so "winc1500" will be accessible on
39
- // the MDNS name "winc1500.local".
40
-
41
- // Define the WINC1500 board connections below.
42
- // If you're following the Adafruit WINC1500 board
43
- // guide you don't need to modify these:
44
- #define WINC_CS 8
45
- #define WINC_IRQ 7
46
- #define WINC_RST 4
47
- #define WINC_EN 2 // or, tie EN to VCC and comment this out
48
- // The SPI pins of the WINC1500 (SCK, MOSI, MISO) should be
49
- // connected to the hardware SPI port of the Arduino.
50
- // On an Uno or compatible these are SCK = #13, MISO = #12, MOSI = #11.
51
- // On an Arduino Zero use the 6-pin ICSP header, see:
52
- // https://www.arduino.cc/en/Reference/SPI
53
-
54
- // Setup the WINC1500 connection with the pins above and the default hardware SPI.
55
- Adafruit_WINC1500 WiFi (WINC_CS, WINC_IRQ, WINC_RST);
56
-
57
- // Or just use hardware SPI (SCK/MOSI/MISO) and defaults, SS -> #10, INT -> #7, RST -> #5, EN -> 3-5V
58
- // Adafruit_WINC1500 WiFi;
32
+ #include < WiFi101.h>
33
+ #include < WifiMdns.h>
59
34
60
35
char ssid[] = " yourNetwork" ; // your network SSID (name)
61
36
char pass[] = " secretPassword" ; // your network password
62
37
int keyIndex = 0 ; // your network key Index number (needed only for WEP)
63
38
39
+ char mdnsName[] = " wifi101" ; // the MDNS name that the board will respond to
40
+ // Note that the actual MDNS name will have '.local' after
41
+ // the name above, so "wifi101" will be accessible on
42
+ // the MDNS name "wifi101.local".
43
+
64
44
int status = WL_IDLE_STATUS;
65
45
66
46
// Create a MDNS responder to listen and respond to MDNS name requests.
67
- MDNSResponder mdns (&WiFi); // Need to pass in a reference to the WiFi class above.
47
+ MDNSResponder mdns;
68
48
69
- Adafruit_WINC1500Server server (80 );
49
+ WiFiServer server (80 );
70
50
71
51
void setup () {
72
- #ifdef WINC_EN
73
- pinMode (WINC_EN, OUTPUT);
74
- digitalWrite (WINC_EN, HIGH);
75
- #endif
76
-
77
52
// Initialize serial and wait for port to open:
78
53
Serial.begin (9600 );
79
54
while (!Serial) {
@@ -105,13 +80,13 @@ void setup() {
105
80
// Setup the MDNS responder to listen to the configured name.
106
81
// NOTE: You _must_ call this _after_ connecting to the WiFi network and
107
82
// being assigned an IP address.
108
- if (!mdns.begin (MDNS_NAME )) {
83
+ if (!mdns.begin (mdnsName )) {
109
84
Serial.println (" Failed to start MDNS responder!" );
110
85
while (1 );
111
86
}
112
87
113
88
Serial.print (" Server listening at http://" );
114
- Serial.print (MDNS_NAME );
89
+ Serial.print (mdnsName );
115
90
Serial.println (" .local/" );
116
91
}
117
92
@@ -122,7 +97,7 @@ void loop() {
122
97
mdns.update ();
123
98
124
99
// listen for incoming clients
125
- Adafruit_WINC1500Client client = server.available ();
100
+ WiFiClient client = server.available ();
126
101
if (client) {
127
102
Serial.println (" new client" );
128
103
// an http request ends with a blank line
0 commit comments