Skip to content

Commit 7ecba4e

Browse files
wifi updates
- Consolidate WiFi stream classes into single class - Remove unused WiFi stream classes - Fix ESP8266 serial output (needed flush) - Fix ESP8266 connection status issue - Automatically include WiFi lib for MKR1000 and ESP8266 - Simplify config error checking - Update instructions in wifiConfig.h - Do not ignore MKR1000 pins
1 parent 4799381 commit 7ecba4e

File tree

8 files changed

+140
-610
lines changed

8 files changed

+140
-610
lines changed

examples/StandardFirmataWiFi/StandardFirmataWiFi.ino

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Copyright (C) 2009 Shigeru Kobayashi. All rights reserved.
1414
Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved.
1515
Copyright (C) 2015-2016 Jesse Frush. All rights reserved.
16+
Copyright (C) 2016 Jens B. All rights reserved.
1617
1718
This library is free software; you can redistribute it and/or
1819
modify it under the terms of the GNU Lesser General Public
@@ -21,7 +22,7 @@
2122
2223
See file LICENSE.txt for further informations on licensing terms.
2324
24-
Last updated by Jeff Hoefs: January 10th, 2016
25+
Last updated by Jeff Hoefs: April 10th, 2016
2526
*/
2627

2728
/*
@@ -36,7 +37,7 @@
3637
- Arduino WiFi Shield (or clone)
3738
- Arduino WiFi Shield 101
3839
- Arduino MKR1000 board (built-in WiFi 101)
39-
- Adafruit HUZZAH CC3000 WiFi Shield (support coming soon)
40+
- ESP8266 WiFi board compatible with ESP8266 Arduino core
4041
4142
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
4243
configure your particular hardware.
@@ -45,6 +46,8 @@
4546
- WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
4647
1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
4748
https://github.com/arduino-libraries/WiFi101)
49+
- ESP8266 requires the Arduino ESP8266 core which can be obtained here:
50+
https://github.com/esp8266/Arduino
4851
4952
In order to use the WiFi Shield 101 with Firmata you will need a board with at least
5053
35k of Flash memory. This means you cannot use the WiFi Shield 101 with an Arduino Uno
@@ -74,11 +77,6 @@
7477
#include <Wire.h>
7578
#include <Firmata.h>
7679

77-
// I dont understand either
78-
void disableI2CPins();
79-
void enableI2CPins();
80-
void reportAnalogCallback(byte analogPin, int value);
81-
8280
/*
8381
* Uncomment the #define SERIAL_DEBUG line below to receive serial output messages relating to your
8482
* connection that may help in the event of connection issues. If defined, some boards may not begin
@@ -127,13 +125,9 @@ IPAddress local_ip(STATIC_IP_ADDRESS);
127125
#endif
128126
#ifdef SUBNET_MASK
129127
IPAddress subnet(SUBNET_MASK);
130-
#else
131-
IPAddress subnet(0,0,0,0);
132128
#endif
133129
#ifdef GATEWAY_IP_ADDRESS
134130
IPAddress gateway(GATEWAY_IP_ADDRESS);
135-
#else
136-
IPAddress gateway(0,0,0,0);
137131
#endif
138132

139133
int wifiConnectionAttemptCounter = 0;
@@ -896,13 +890,13 @@ void setup()
896890
#ifdef STATIC_IP_ADDRESS
897891
DEBUG_PRINT( "Using static IP: " );
898892
DEBUG_PRINTLN( local_ip );
899-
//you can also provide a static IP in the begin() functions, but this simplifies
900-
//ifdef logic in this sketch due to support for all different encryption types.
901-
#ifdef ESP8266_WIFI
893+
#ifdef ESP8266_WIFI
902894
stream.config( local_ip , gateway, subnet );
903-
#else
895+
#else
896+
// you can also provide a static IP in the begin() functions, but this simplifies
897+
// ifdef logic in this sketch due to support for all different encryption types.
904898
stream.config( local_ip );
905-
#endif
899+
#endif
906900
#else
907901
DEBUG_PRINTLN( "IP will be requested from DHCP ..." );
908902
#endif
@@ -968,7 +962,8 @@ void setup()
968962
|| 28 == i
969963
#endif //defined(__AVR_ATmega32U4__)
970964
) {
971-
#elif defined (WIFI_101)
965+
// don't ignore pins when using Wi-Fi 101 library with the MKR1000
966+
#elif defined (WIFI_101) && !defined(ARDUINO_SAMD_MKR1000)
972967
if (IS_IGNORE_WIFI101_SHIELD(i)) {
973968
#elif defined (HUZZAH_WIFI)
974969
// TODO

examples/StandardFirmataWiFi/wifiConfig.h

Lines changed: 80 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,67 @@
33
*
44
* You must configure your particular hardware. Follow the steps below.
55
*
6-
* Currently StandardFirmataWiFi is configured as a server. An option to
7-
* configure as a client may be added in the future.
6+
* Currently StandardFirmataWiFi is configured as a Wi-Fi server. An option to
7+
* configure as a Wi-Fi client will be added in the future.
88
*============================================================================*/
99

1010
// STEP 1 [REQUIRED]
1111
// Uncomment / comment the appropriate set of includes for your hardware (OPTION A, B or C)
1212
// Option A is enabled by default.
1313

1414
/*
15-
* OPTION A: Configure for Arduino WiFi shield
15+
* OPTION A: Configure for Arduino MKR1000 or Arduino WiFi Shield 101
1616
*
17-
* This will configure StandardFirmataWiFi to use the original WiFi library (deprecated) provided
18-
* with the Arduino IDE. It is supported by the Arduino WiFi shield (a discontinued product) and
19-
* is compatible with 802.11 B/G networks.
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.
20+
*
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.
2023
*
21-
* To configure StandardFirmataWiFi to use the Arduino WiFi shield
22-
* leave the #define below uncommented.
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.
26+
*
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'
2330
*/
24-
#define ARDUINO_WIFI_SHIELD
31+
//#define WIFI_101
2532

26-
//do not modify these next 5 lines
27-
#ifdef ARDUINO_WIFI_SHIELD
28-
#include <WiFi.h>
33+
//do not modify the following 10 lines
34+
#if defined(ARDUINO_SAMD_MKR1000) && !defined(WIFI_101)
35+
// automatically include if compiling for MRK1000
36+
#define WIFI_101
37+
#endif
38+
#ifdef WIFI_101
39+
#include <WiFi101.h>
2940
#include "utility/WiFiStream.h"
3041
WiFiStream stream;
42+
#define WIFI_LIB_INCLUDED
3143
#endif
3244

3345
/*
34-
* OPTION B: Configure for WiFi 101
35-
*
36-
* This will configure StandardFirmataWiFi to use the WiFi101 library, which works with the Arduino WiFi101
37-
* shield and devices that have the WiFi101 chip built in (such as the MKR1000). It is compatible
38-
* with 802.11 B/G/N networks.
46+
* OPTION B: Configure for legacy Arduino WiFi shield
3947
*
40-
* To enable, uncomment the #define WIFI_101 below and verify the #define values under
41-
* options A and C are commented out.
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.
4251
*
43-
* IMPORTANT: You must have the WiFI 101 library installed. To easily install this library, opent the library manager via:
44-
* Arduino IDE Menus: Sketch > Include Library > Manage Libraries > filter search for "WiFi101" > Select the result and click 'install'
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.
4554
*/
46-
//#define WIFI_101
55+
//#define ARDUINO_WIFI_SHIELD
4756

48-
//do not modify these next 5 lines
49-
#ifdef WIFI_101
50-
#include <WiFi101.h>
51-
#include "utility/WiFi101Stream.h"
57+
//do not modify the following 10 lines
58+
#ifdef ARDUINO_WIFI_SHIELD
59+
#include <WiFi.h>
60+
#include "utility/WiFiStream.h"
5261
WiFiStream stream;
62+
#ifdef WIFI_LIB_INCLUDED
63+
#define MULTIPLE_WIFI_LIB_INCLUDES
64+
#else
65+
#define WIFI_LIB_INCLUDED
66+
#endif
5367
#endif
5468

5569
/*
@@ -58,25 +72,33 @@ WiFiStream stream;
5872
* This will configure StandardFirmataWiFi to use the ESP8266WiFi library for boards
5973
* with an ESP8266 chip. It is compatible with 802.11 B/G/N networks.
6074
*
61-
* To enable, uncomment the #define ESP8266_WIFI below and verify the #define values under
62-
* options A and B are commented out.
75+
* The appropriate libraries are included automatically when compiling for the ESP8266 so
76+
* continue on to STEP 2.
6377
*
64-
* IMPORTANT: You must have the esp8266 board support installed. To easily install this board, open the board manager via:
65-
* Arduino IDE Menus: Tools > Board > Manage Boards > filter search for "esp8266" > Select the result and click 'install'
78+
* IMPORTANT: You must have the esp8266 board support installed. To easily install this board, open
79+
* see the instructions here: https://github.com/esp8266/Arduino#installing-with-boards-manager.
6680
*/
67-
//#define ESP8266_WIFI
68-
69-
//do not modify these next 5 lines
81+
//do not modify the following 14 lines
82+
#ifdef ESP8266
83+
// automatically include if compiling for ESP8266
84+
#define ESP8266_WIFI
85+
#endif
7086
#ifdef ESP8266_WIFI
7187
#include <ESP8266WiFi.h>
7288
#include "utility/WiFiStream.h"
7389
WiFiStream stream;
90+
#ifdef WIFI_LIB_INCLUDED
91+
#define MULTIPLE_WIFI_LIB_INCLUDES
92+
#else
93+
#define WIFI_LIB_INCLUDED
94+
#endif
7495
#endif
7596

7697
/*
7798
* OPTION D: Configure for HUZZAH
7899
*
79-
* HUZZAH with CC3000 is not yet supported, this will be added in a later revision to StandardFirmataWiFi.
100+
* HUZZAH with CC3000 is not yet supported, this will be added in a later revision to
101+
* StandardFirmataWiFi.
80102
* For HUZZAH with ESP8266 use ESP8266_WIFI.
81103
*/
82104

@@ -90,28 +112,32 @@ WiFiStream stream;
90112
// replace this with your wireless network SSID
91113
char ssid[] = "your_network_name";
92114

115+
93116
// STEP 3 [OPTIONAL for all boards and shields]
94-
// if you want to use a static IP (v4) address, uncomment the line below. You can also change the IP.
95-
// if the first line is commented out, the WiFi shield will attempt to get an IP from the DHCP server
96-
#define STATIC_IP_ADDRESS 192,168,1,113
97-
#define SUBNET_MASK 255,255,255,0 // REQUIRED for ESP8266_WIFI, ignored for others
98-
#define GATEWAY_IP_ADDRESS 0,0,0,0 // REQUIRED for ESP8266_WIFI, ignored for others
117+
// If you want to use a static IP (v4) address, uncomment the line below. You can also change the IP.
118+
// If the first line is commented out, the WiFi shield will attempt to get an IP from the DHCP server.
119+
// If you are using a static IP with the ESP8266 then you must also uncomment the SUBNET and GATEWAY.
120+
//#define STATIC_IP_ADDRESS 192,168,1,113
121+
//#define SUBNET_MASK 255,255,255,0 // REQUIRED for ESP8266_WIFI, optional for others
122+
//#define GATEWAY_IP_ADDRESS 0,0,0,0 // REQUIRED for ESP8266_WIFI, optional for others
123+
99124

100125
// STEP 4 [REQUIRED for all boards and shields]
101126
// define your port number here, you will need this to open a TCP connection to your Arduino
102127
#define SERVER_PORT 3030
103128

104-
// STEP 5 [REQUIRED for all boards and shields]
105-
// determine your network security type (OPTION A, B, or C). Option A is the most common, and the default.
106129

130+
// STEP 5 [REQUIRED for all boards and shields]
131+
// determine your network security type (OPTION A, B, or C). Option A is the most common, and the
132+
// default.
107133

108134
/*
109135
* OPTION A: WPA / WPA2
110136
*
111137
* WPA is the most common network security type. A passphrase is required to connect to this type.
112138
*
113-
* To enable, leave #define WIFI_WPA_SECURITY uncommented below, set your wpa_passphrase value appropriately,
114-
* and do not uncomment the #define values under options B and C
139+
* To enable, leave #define WIFI_WPA_SECURITY uncommented below, set your wpa_passphrase value
140+
* appropriately, and do not uncomment the #define values under options B and C
115141
*/
116142
#define WIFI_WPA_SECURITY
117143

@@ -123,11 +149,11 @@ char wpa_passphrase[] = "your_wpa_passphrase";
123149
/*
124150
* OPTION B: WEP
125151
*
126-
* WEP is a less common (and regarded as less safe) security type. A WEP key and its associated index are required
127-
* to connect to this type.
152+
* WEP is a less common (and regarded as less safe) security type. A WEP key and its associated
153+
* index are required to connect to this type.
128154
*
129-
* To enable, Uncomment the #define below, set your wep_index and wep_key values appropriately, and verify
130-
* the #define values under options A and C are commented out.
155+
* To enable, Uncomment the #define below, set your wep_index and wep_key values appropriately,
156+
* and verify the #define values under options A and C are commented out.
131157
*/
132158
//#define WIFI_WEP_SECURITY
133159

@@ -142,7 +168,8 @@ char wep_key[] = "your_wep_key";
142168
/*
143169
* OPTION C: Open network (no security)
144170
*
145-
* Open networks have no security, can be connected to by any device that knows the ssid, and are unsafe.
171+
* Open networks have no security, can be connected to by any device that knows the ssid, and are
172+
* unsafe.
146173
*
147174
* To enable, uncomment #define WIFI_NO_SECURITY below and verify the #define values
148175
* under options A and B are commented out.
@@ -153,11 +180,11 @@ char wep_key[] = "your_wep_key";
153180
* CONFIGURATION ERROR CHECK (don't change anything here)
154181
*============================================================================*/
155182

156-
#if ((defined(ARDUINO_WIFI_SHIELD) && (defined(WIFI_101) || defined(HUZZAH_WIFI))) || (defined(WIFI_101) && defined(HUZZAH_WIFI)) || (defined(WIFI_101) && defined(ESP8266_WIFI)) || (defined(ESP8266_WIFI) && defined(HUZZAH_WIFI)) || (defined(ESP8266_WIFI) && defined(ARDUINO_WIFI_SHIELD)))
183+
#ifdef MULTIPLE_WIFI_LIB_INCLUDES
157184
#error "you may not define more than one wifi device type in wifiConfig.h."
158-
#endif //WIFI device type check
185+
#endif
159186

160-
#if !(defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101) || defined(HUZZAH_WIFI) || defined(ESP8266_WIFI))
187+
#ifndef WIFI_LIB_INCLUDED
161188
#error "you must define a wifi device type in wifiConfig.h."
162189
#endif
163190

@@ -171,15 +198,15 @@ char wep_key[] = "your_wep_key";
171198

172199
#if (defined(ESP8266_WIFI) && !(defined(WIFI_NO_SECURITY) || (defined(WIFI_WPA_SECURITY))))
173200
#error "you must choose between WIFI_NO_SECURITY and WIFI_WPA_SECURITY"
174-
#endif
201+
#endif
175202

176203
/*==============================================================================
177204
* PIN IGNORE MACROS (don't change anything here)
178205
*============================================================================*/
179206

180207
// ignore SPI pins, pin 5 (reset WiFi101 shield), pin 7 (WiFi handshake) and pin 10 (WiFi SS)
181208
// also don't ignore SS pin if it's not pin 10
182-
// TODO - need to differentiate between Arduino WiFi1 101 Shield and Arduino MKR1000
209+
// Not needed for Arduino MKR1000.
183210
#define IS_IGNORE_WIFI101_SHIELD(p) ((p) == 10 || (IS_PIN_SPI(p) && (p) != SS) || (p) == 5 || (p) == 7)
184211

185212
// ignore SPI pins, pin 4 (SS for SD-Card on WiFi-shield), pin 7 (WiFi handshake) and pin 10 (WiFi SS)

utility/ESPWiFiStream.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)