Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions examples/StandardFirmataWiFi/StandardFirmataWiFi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
/*
README

StandardFirmataWiFi is a WiFi server application. You will need a Firmata client library with
a network transport in order to establish a connection with StandardFirmataWiFi.

To use StandardFirmataWiFi you will need to have one of the following
boards or shields:

Expand All @@ -38,6 +41,11 @@
Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
configure your particular hardware.

Dependencies:
- WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
https://github.com/arduino-libraries/WiFi101)

In order to use the WiFi Shield 101 with Firmata you will need a board with at least
35k of Flash memory. This means you cannot use the WiFi Shield 101 with an Arduino Uno
or any other ATmega328p-based microcontroller or with an Arduino Leonardo or other
Expand Down Expand Up @@ -99,7 +107,7 @@
*============================================================================*/

#ifdef STATIC_IP_ADDRESS
IPAddress local_ip(STATIC_IP_ADDRESS);
IPAddress local_ip(STATIC_IP_ADDRESS);
#endif

int wifiConnectionAttemptCounter = 0;
Expand Down Expand Up @@ -782,7 +790,7 @@ void systemResetCallback()

void printWifiStatus() {
#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
if( WiFi.status() != WL_CONNECTED )
if ( WiFi.status() != WL_CONNECTED )
{
DEBUG_PRINT( "WiFi connection failed. Status value: " );
DEBUG_PRINTLN( WiFi.status() );
Expand All @@ -797,15 +805,15 @@ void printWifiStatus() {
DEBUG_PRINTLN( WiFi.SSID() );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)

// print your WiFi shield's IP address:
// print your WiFi shield's IP address:
DEBUG_PRINT( "IP Address: " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
IPAddress ip = WiFi.localIP();
DEBUG_PRINTLN( ip );
#endif //defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)

// print the received signal strength:
// print the received signal strength:
DEBUG_PRINT( "signal strength (RSSI): " );

#if defined(ARDUINO_WIFI_SHIELD) || defined(WIFI_101)
Expand All @@ -823,7 +831,7 @@ void setup()
* WIFI SETUP
*/
DEBUG_BEGIN(9600);

/*
* This statement will clarify how a connection is being made
*/
Expand All @@ -834,7 +842,7 @@ void setup()
DEBUG_PRINTLN( "using the legacy WiFi library." );
#elif defined(HUZZAH_WIFI)
DEBUG_PRINTLN( "using the HUZZAH WiFi library." );
//else should never happen here as error-checking in wifiConfig.h will catch this
//else should never happen here as error-checking in wifiConfig.h will catch this
#endif //defined(WIFI_101)

/*
Expand All @@ -854,27 +862,28 @@ void setup()
* Configure WiFi security
*/
#if defined(WIFI_WEP_SECURITY)
while(wifiStatus != WL_CONNECTED) {
DEBUG_PRINT("Attempting to connect to WEP SSID: ");
while (wifiStatus != WL_CONNECTED) {
DEBUG_PRINT( "Attempting to connect to WEP SSID: " );
DEBUG_PRINTLN(ssid);
wifiStatus = stream.begin( ssid, wep_index, wep_key, SERVER_PORT );
delay(5000); // TODO - determine minimum delay
if (++wifiConnectionAttemptCounter > WIFI_MAX_CONN_ATTEMPTS) break;
}

#elif defined(WIFI_WPA_SECURITY)
while(wifiStatus != WL_CONNECTED) {
DEBUG_PRINT("Attempting to connect to WPA SSID: ");
while (wifiStatus != WL_CONNECTED) {
DEBUG_PRINT( "Attempting to connect to WPA SSID: " );
DEBUG_PRINTLN(ssid);
wifiStatus = stream.begin(ssid, wpa_passphrase, SERVER_PORT);
delay(5000); // TODO - determine minimum delay
if (++wifiConnectionAttemptCounter > WIFI_MAX_CONN_ATTEMPTS) break;
}

#else //OPEN network
DEBUG_PRINTLN( "Connecting to an open network ..." );
while(wifiStatus != WL_CONNECTED) {
wifiStatus = stream.begin( ssid, SERVER_PORT );
while (wifiStatus != WL_CONNECTED) {
DEBUG_PRINTLN( "Attempting to connect to open SSID: " );
DEBUG_PRINTLN(ssid);
wifiStatus = stream.begin(ssid, SERVER_PORT);
delay(5000); // TODO - determine minimum delay
if (++wifiConnectionAttemptCounter > WIFI_MAX_CONN_ATTEMPTS) break;
}
Expand Down Expand Up @@ -909,7 +918,7 @@ void setup()
|| 24 == i // On Leonardo, pin 24 maps to D4 and pin 28 maps to D10
|| 28 == i
#endif //defined(__AVR_ATmega32U4__)
) {
) {
#elif defined (WIFI_101)
if (IS_IGNORE_WIFI101_SHIELD(i)) {
#elif defined (HUZZAH_WIFI)
Expand All @@ -922,7 +931,7 @@ void setup()
}
}

//Set up controls for the Arduino WiFi Shield SS for the SD Card
//Set up controls for the Arduino WiFi Shield SS for the SD Card
#ifdef ARDUINO_WIFI_SHIELD
// Arduino WiFi, Arduino WiFi Shield and Arduino Yun all have SD SS wired to D4
pinMode(PIN_TO_DIGITAL(4), OUTPUT); // switch off SD card bypassing Firmata
Expand Down
22 changes: 12 additions & 10 deletions examples/StandardFirmataWiFi/wifiConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* WIFI CONFIGURATION
*
* You must configure your particular hardware. Follow the steps below.
*
* Currently StandardFirmataWiFi is configured as a server. An option to
* configure as a client may be added in the future.
*============================================================================*/

// STEP 1 [REQUIRED]
Expand All @@ -10,12 +13,12 @@

/*
* OPTION A: Configure for Arduino WiFi shield
*
*
* This will configure StandardFirmataWiFi to use the original WiFi library (deprecated) provided
* with the Arduino IDE. It is supported by the Arduino WiFi shield (a discontinued product) and
* is compatible with 802.11 B/G networks.
*
* To configure StandardFirmataWiFi to use the Arduino WiFi shield
* To configure StandardFirmataWiFi to use the Arduino WiFi shield
* leave the #define below uncommented.
*/
#define ARDUINO_WIFI_SHIELD
Expand All @@ -28,9 +31,9 @@ WiFiStream stream;

/*
* OPTION B: Configure for WiFi 101
*
*
* This will configure StandardFirmataWiFi to use the WiFi101 library, which works with the Arduino WiFi101
* shield and devices that have the WiFi101 chip built in (such as the MKR1000). It is compatible
* shield and devices that have the WiFi101 chip built in (such as the MKR1000). It is compatible
* with 802.11 B/G/N networks.
*
* To enable, uncomment the #define WIFI_101 below and verify the #define values under
Expand All @@ -49,7 +52,7 @@ WiFi101Stream stream;

/*
* OPTION C: Configure for HUZZAH
*
*
* HUZZAH is not yet supported, this will be added in a later revision to StandardFirmataWiFi
*/

Expand Down Expand Up @@ -78,9 +81,9 @@ char ssid[] = "your_network_name";

/*
* OPTION A: WPA / WPA2
*
*
* WPA is the most common network security type. A passphrase is required to connect to this type.
*
*
* To enable, leave #define WIFI_WPA_SECURITY uncommented below, set your wpa_passphrase value appropriately,
* and do not uncomment the #define values under options B and C
*/
Expand All @@ -95,7 +98,7 @@ char wpa_passphrase[] = "your_wpa_passphrase";
*
* WEP is a less common (and regarded as less safe) security type. A WEP key and its associated index are required
* to connect to this type.
*
*
* To enable, Uncomment the #define below, set your wep_index and wep_key values appropriately, and verify
* the #define values under options A and C are commented out.
*/
Expand All @@ -111,7 +114,7 @@ char wep_key[] = "your_wep_key";

/*
* OPTION C: Open network (no security)
*
*
* Open networks have no security, can be connected to by any device that knows the ssid, and are unsafe.
*
* To enable, uncomment #define WIFI_NO_SECURITY below and verify the #define values
Expand Down Expand Up @@ -150,4 +153,3 @@ char wep_key[] = "your_wep_key";

// ignore SPI pins, pin 4 (SS for SD-Card on WiFi-shield), pin 7 (WiFi handshake) and pin 10 (WiFi SS)
#define IS_IGNORE_WIFI_SHIELD(p) ((IS_PIN_SPI(p) || (p) == 4) || (p) == 7 || (p) == 10)

2 changes: 1 addition & 1 deletion utility/WiFi101Stream.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
* Implementation is in WiFi101Stream.h to avoid linker issues. Legacy WiFi and modern WiFi101 both define WiFiClass which
* will cause linker errors whenever Firmata.h is included.
*/
*/
Loading