2222
2323 See file LICENSE.txt for further informations on licensing terms.
2424
25- Last updated by Jeff Hoefs: April 17th , 2016
25+ Last updated by Jeff Hoefs: April 24th , 2016
2626*/
2727
2828/*
3636
3737 - Arduino WiFi Shield (or clone)
3838 - Arduino WiFi Shield 101
39- - Arduino MKR1000 board (built-in WiFi 101)
39+ - Arduino MKR1000 board
4040 - ESP8266 WiFi board compatible with ESP8266 Arduino core
4141
4242 Follow the instructions in the wifiConfig.h file (wifiConfig.h tab in Arduino IDE) to
4646 - WiFi Shield 101 requires version 0.7.0 or higher of the WiFi101 library (available in Arduino
4747 1.6.8 or higher, or update the library via the Arduino Library Manager or clone from source:
4848 https://github.com/arduino-libraries/WiFi101)
49- - ESP8266 requires the Arduino ESP8266 core which can be obtained here:
49+ - ESP8266 requires the Arduino ESP8266 core v2.1.0 or higher which can be obtained here:
5050 https://github.com/esp8266/Arduino
5151
5252 In order to use the WiFi Shield 101 with Firmata you will need a board with at least 35k of Flash
@@ -308,7 +308,7 @@ void checkDigitalInputs(void)
308308}
309309
310310// -----------------------------------------------------------------------------
311- // function forward declarations
311+ // function forward declarations for xtensa compiler (ESP8266)
312312void enableI2CPins ();
313313void disableI2CPins ();
314314void reportAnalogCallback (byte analogPin, int value);
@@ -832,9 +832,9 @@ void systemResetCallback()
832832
833833/*
834834 * Called when a TCP connection is either connected or disconnected.
835- * TODO - figure out why the callback is not being called when using ESP8266 as a TCP server and
836- * why only connect is called when using ESP8266 as a TCP client. In both cases the actual
837- * connection is working but not reported via the callback.
835+ * TODO:
836+ * - report connected or reconnected state to host (to be added to protocol)
837+ * - report current state to host (to be added to protocol)
838838 */
839839void hostConnectionCallback (byte state)
840840{
@@ -883,43 +883,30 @@ void printWifiStatus() {
883883 * Additional pins may also need to be ignored depending on the particular board or
884884 * shield in use.
885885 */
886- void ignoreWiFiPins ()
886+ void ignorePins ()
887887{
888+ #ifdef IS_IGNORE_PIN
888889 for (byte i = 0 ; i < TOTAL_PINS; i++) {
889- #if defined(ARDUINO_WIFI_SHIELD)
890- if (IS_IGNORE_WIFI_SHIELD (i)
891- #if defined(__AVR_ATmega32U4__)
892- || 24 == i // On Leonardo, pin 24 maps to D4 and pin 28 maps to D10
893- || 28 == i
894- #endif // defined(__AVR_ATmega32U4__)
895- ) {
896- // don't ignore pins when using Wi-Fi 101 library with the MKR1000
897- #elif defined (WIFI_101) && !defined(ARDUINO_SAMD_MKR1000)
898- if (IS_IGNORE_WIFI101_SHIELD (i)) {
899- #elif defined (HUZZAH_WIFI)
900- // TODO
901- if (false ) {
902- #else
903- if (false ) {
904- #endif
890+ if (IS_IGNORE_PIN (i)) {
905891 Firmata.setPinMode (i, PIN_MODE_IGNORE);
906892 }
907893 }
894+ #endif
908895
909896 // Set up controls for the Arduino WiFi Shield SS for the SD Card
910897#ifdef ARDUINO_WIFI_SHIELD
911- // Arduino WiFi, Arduino WiFi Shield and Arduino Yun all have SD SS wired to D4
898+ // Arduino WiFi Shield has SD SS wired to D4
912899 pinMode (PIN_TO_DIGITAL (4 ), OUTPUT); // switch off SD card bypassing Firmata
913900 digitalWrite (PIN_TO_DIGITAL (4 ), HIGH); // SS is active low;
914901
915902#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
916903 pinMode (PIN_TO_DIGITAL (53 ), OUTPUT); // configure hardware SS as output on MEGA
917- #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
904+ #endif // defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
918905
919- #endif // ARDUINO_WIFI_SHIELD
906+ #endif // ARDUINO_WIFI_SHIELD
920907}
921908
922- void initWiFi ()
909+ void initTransport ()
923910{
924911 // This statement will clarify how a connection is being made
925912 DEBUG_PRINT ( " StandardFirmataWiFi will attempt a WiFi connection " );
@@ -967,11 +954,7 @@ void initWiFi()
967954#endif // defined(WIFI_WEP_SECURITY)
968955 DEBUG_PRINTLN ( " WiFi setup done" );
969956
970- // Wait for connection to access point to be established. This is necessary for ESP8266
971- // or we won't have a connection state once printWiFiStatus() is called and the state
972- // will be reported as disconnected. We don't want to wait until the TCP connection is
973- // established before calling printWiFiStatus() because printing the IP address upon
974- // connection with the access point is useful when using DHCP
957+ // Wait for connection to access point to be established.
975958 while (WiFi.status () != WL_CONNECTED && ++connectionAttempts <= MAX_CONN_ATTEMPTS) {
976959 delay (500 );
977960 DEBUG_PRINT (" ." );
@@ -991,7 +974,7 @@ void initFirmata()
991974 Firmata.attach (START_SYSEX, sysexCallback);
992975 Firmata.attach (SYSTEM_RESET, systemResetCallback);
993976
994- ignoreWiFiPins ();
977+ ignorePins ();
995978
996979 // Initialize Firmata to use the WiFi stream object as the transport.
997980 Firmata.begin (stream);
@@ -1002,7 +985,7 @@ void setup()
1002985{
1003986 DEBUG_BEGIN (9600 );
1004987
1005- initWiFi ();
988+ initTransport ();
1006989
1007990 initFirmata ();
1008991}
0 commit comments