1 /*==============================================================================
4 * You must configure your particular hardware. Follow the steps below.
6 * By default, StandardFirmataWiFi is configured as a TCP server, to configure
7 * as a TCP client, see STEP 2.
8 *============================================================================*/
11 // Uncomment / comment the appropriate set of includes for your hardware (OPTION A, B or C)
12 // Arduino MKR1000 or ESP8266 are enabled by default if compiling for either of those boards.
15 * OPTION A: Configure for Arduino MKR1000 or Arduino WiFi Shield 101
17 * This will configure StandardFirmataWiFi to use the WiFi101 library, which works with the
18 * Arduino WiFi101 shield and devices that have the WiFi101 chip built in (such as the MKR1000).
19 * It is compatible with 802.11 B/G/N networks.
21 * If you are using the MKR1000 board, continue on to STEP 2. If you are using the WiFi 101 shield,
22 * follow the instructions below.
24 * To enable for the WiFi 101 shield, uncomment the #define WIFI_101 below and verify the
25 * #define ARDUINO_WIFI_SHIELD is commented out for OPTION B.
27 * IMPORTANT: You must have the WiFI 101 library installed. To easily install this library, open
28 * the library manager via: Arduino IDE Menus: Sketch > Include Library > Manage Libraries > filter
29 * search for "WiFi101" > Select the result and click 'install'
33 //do not modify the following 11 lines
34 #if defined(ARDUINO_SAMD_MKR1000) && !defined(WIFI_101)
35 // automatically include if compiling for MRK1000
40 #include "utility/WiFiClientStream.h"
41 #include "utility/WiFiServerStream.h"
42 #define WIFI_LIB_INCLUDED
46 * OPTION B: Configure for legacy Arduino WiFi shield
48 * This will configure StandardFirmataWiFi to use the original WiFi library (deprecated) provided
49 * with the Arduino IDE. It is supported by the Arduino WiFi shield (a discontinued product) and
50 * is compatible with 802.11 B/G networks.
52 * To configure StandardFirmataWiFi to use the legacy Arduino WiFi shield
53 * leave the #define below uncommented and ensure #define WIFI_101 is commented out for OPTION A.
55 //#define ARDUINO_WIFI_SHIELD
57 //do not modify the following 10 lines
58 #ifdef ARDUINO_WIFI_SHIELD
60 #include "utility/WiFiClientStream.h"
61 #include "utility/WiFiServerStream.h"
62 #ifdef WIFI_LIB_INCLUDED
63 #define MULTIPLE_WIFI_LIB_INCLUDES
65 #define WIFI_LIB_INCLUDED
70 * OPTION C: Configure for ESP8266
72 * This will configure StandardFirmataWiFi to use the ESP8266WiFi library for boards
73 * with an ESP8266 chip. It is compatible with 802.11 B/G/N networks.
75 * The appropriate libraries are included automatically when compiling for the ESP8266 so
76 * continue on to STEP 2.
78 * IMPORTANT: You must have the esp8266 board support installed. To easily install this board see
79 * the instructions here: https://github.com/esp8266/Arduino#installing-with-boards-manager.
81 //do not modify the following 14 lines
83 // automatically include if compiling for ESP8266
87 #include <ESP8266WiFi.h>
88 #include "utility/WiFiClientStream.h"
89 #include "utility/WiFiServerStream.h"
90 #ifdef WIFI_LIB_INCLUDED
91 #define MULTIPLE_WIFI_LIB_INCLUDES
93 #define WIFI_LIB_INCLUDED
98 * OPTION D: Configure for HUZZAH
100 * HUZZAH with CC3000 is not yet supported, this will be added in a later revision to
101 * StandardFirmataWiFi.
102 * For HUZZAH with ESP8266 use ESP8266_WIFI.
105 //------------------------------
107 //------------------------------
108 //#define HUZZAH_WIFI
111 // STEP 2 [OPTIONAL for all boards and shields]
112 // If you want to setup you board as a TCP client, uncomment the following define and replace
113 // the IP address with the IP address of your server.
114 //#define SERVER_IP 10, 0, 0, 15
117 // STEP 3 [REQUIRED for all boards and shields]
118 // replace this with your wireless network SSID
119 char ssid[] = "your_network_name";
122 // STEP 4 [OPTIONAL for all boards and shields]
123 // If you want to use a static IP (v4) address, uncomment the line below. You can also change the IP.
124 // If the first line is commented out, the WiFi shield will attempt to get an IP from the DHCP server.
125 // If you are using a static IP with the ESP8266 then you must also uncomment the SUBNET and GATEWAY.
126 //#define STATIC_IP_ADDRESS 192,168,1,113
127 //#define SUBNET_MASK 255,255,255,0 // REQUIRED for ESP8266_WIFI, optional for others
128 //#define GATEWAY_IP_ADDRESS 0,0,0,0 // REQUIRED for ESP8266_WIFI, optional for others
131 // STEP 5 [REQUIRED for all boards and shields]
132 // define your port number here, you will need this to open a TCP connection to your Arduino
133 #define SERVER_PORT 3030
136 // STEP 6 [REQUIRED for all boards and shields]
137 // determine your network security type (OPTION A, B, or C). Option A is the most common, and the
141 * OPTION A: WPA / WPA2
143 * WPA is the most common network security type. A passphrase is required to connect to this type.
145 * To enable, leave #define WIFI_WPA_SECURITY uncommented below, set your wpa_passphrase value
146 * appropriately, and do not uncomment the #define values under options B and C
148 #define WIFI_WPA_SECURITY
150 #ifdef WIFI_WPA_SECURITY
151 char wpa_passphrase[] = "your_wpa_passphrase";
152 #endif //WIFI_WPA_SECURITY
158 * WEP is a less common (and regarded as less safe) security type. A WEP key and its associated
159 * index are required to connect to this type.
161 * To enable, Uncomment the #define below, set your wep_index and wep_key values appropriately,
162 * and verify the #define values under options A and C are commented out.
164 //#define WIFI_WEP_SECURITY
166 #ifdef WIFI_WEP_SECURITY
167 //The wep_index below is a zero-indexed value.
168 //Valid indices are [0-3], even if your router/gateway numbers your keys [1-4].
170 char wep_key[] = "your_wep_key";
171 #endif //WIFI_WEP_SECURITY
175 * OPTION C: Open network (no security)
177 * Open networks have no security, can be connected to by any device that knows the ssid, and are
180 * To enable, uncomment #define WIFI_NO_SECURITY below and verify the #define values
181 * under options A and B are commented out.
183 //#define WIFI_NO_SECURITY
185 /*==============================================================================
186 * CONFIGURATION ERROR CHECK (don't change anything here)
187 *============================================================================*/
189 #ifdef MULTIPLE_WIFI_LIB_INCLUDES
190 #error "you may not define more than one wifi device type in wifiConfig.h."
193 #ifndef WIFI_LIB_INCLUDED
194 #error "you must define a wifi device type in wifiConfig.h."
197 #if ((defined(WIFI_NO_SECURITY) && (defined(WIFI_WEP_SECURITY) || defined(WIFI_WPA_SECURITY))) || (defined(WIFI_WEP_SECURITY) && defined(WIFI_WPA_SECURITY)))
198 #error "you may not define more than one security type at the same time in wifiConfig.h."
199 #endif //WIFI_* security define check
201 #if !(defined(WIFI_NO_SECURITY) || defined(WIFI_WEP_SECURITY) || defined(WIFI_WPA_SECURITY))
202 #error "you must define a wifi security type in wifiConfig.h."
203 #endif //WIFI_* security define check
205 #if (defined(ESP8266_WIFI) && !(defined(WIFI_NO_SECURITY) || (defined(WIFI_WPA_SECURITY))))
206 #error "you must choose between WIFI_NO_SECURITY and WIFI_WPA_SECURITY"
209 /*==============================================================================
210 * WIFI STREAM (don't change anything here)
211 *============================================================================*/
214 WiFiClientStream stream(IPAddress(SERVER_IP), SERVER_PORT);
216 WiFiServerStream stream(SERVER_PORT);
219 /*==============================================================================
220 * PIN IGNORE MACROS (don't change anything here)
221 *============================================================================*/
223 #if defined(WIFI_101) && !defined(ARDUINO_SAMD_MKR1000)
224 // ignore SPI pins, pin 5 (reset WiFi101 shield), pin 7 (WiFi handshake) and pin 10 (WiFi SS)
225 // also don't ignore SS pin if it's not pin 10. Not needed for Arduino MKR1000.
226 #define IS_IGNORE_PIN(p) ((p) == 10 || (IS_PIN_SPI(p) && (p) != SS) || (p) == 5 || (p) == 7)
228 #elif defined(ARDUINO_WIFI_SHIELD) && defined(__AVR_ATmega32U4__)
229 // ignore SPI pins, pin 4 (SS for SD-Card on WiFi-shield), pin 7 (WiFi handshake) and pin 10 (WiFi SS)
230 // On Leonardo, pin 24 maps to D4 and pin 28 maps to D10
231 #define IS_IGNORE_PIN(p) ((IS_PIN_SPI(p) || (p) == 4) || (p) == 7 || (p) == 10 || (p) == 24 || (p) == 28)
233 #elif defined(ARDUINO_WIFI_SHIELD)
234 // ignore SPI pins, pin 4 (SS for SD-Card on WiFi-shield), pin 7 (WiFi handshake) and pin 10 (WiFi SS)
235 #define IS_IGNORE_PIN(p) ((IS_PIN_SPI(p) || (p) == 4) || (p) == 7 || (p) == 10)
237 #elif defined(ESP8266_WIFI) && defined(SERIAL_DEBUG)
238 #define IS_IGNORE_PIN(p) ((p) == 1)