1- /* **************************************************
2- Adafruit MQTT Library PyPortal Adafruit IO SSL/TLS Example
1+ /* ***************************************************************
2+ Adafruit MQTT Library, Adafruit IO SSL/TLS Example for AirLift
33
44 Must use the latest version of nina-fw from:
55 https://github.com/adafruit/nina-fw
66
7- Adafruit PyPortal: https://www.adafruit.com/product/4116
7+ Works great with Adafruit AirLift ESP32 Co-Processors!
8+ --> https://www.adafruit.com/product/4201
9+ --> https://www.adafruit.com/product/4116
810
911 Adafruit invests time and resources providing this open source code,
1012 please support Adafruit and open-source hardware by purchasing
1113 products from Adafruit!
1214
1315 Written by Brent Rubell for Adafruit Industries.
1416 MIT license, all text above must be included in any redistribution
15- ****************************************************/
17+ *******************************************************************/
18+
1619#include < WiFiNINA.h>
1720#include < SPI.h>
21+
22+ // For AirLift Breakout/Wing/Shield: Configure the following to match the ESP32 Pins!
23+ #if !defined(SPIWIFI_SS)
24+ // Don't change the names of these #define's! they match the variant ones
25+ #define SPIWIFI SPI
26+ #define SPIWIFI_SS 11 // Chip select pin
27+ #define SPIWIFI_ACK 10 // a.k.a BUSY or READY pin
28+ #define ESP32_RESETN 9 // Reset pin
29+ #define ESP32_GPIO0 -1 // Not connected
30+ #define SET_PINS 1 // Pins were set using this IFNDEF
31+ #endif
32+
1833#include " Adafruit_MQTT.h"
1934#include " Adafruit_MQTT_Client.h"
2035
2136/* ************************ WiFi Access Point *********************************/
2237
2338#define WLAN_SSID " WLAN_SSID"
24- #define WLAN_PASS " WLAN_PASSWORD "
39+ #define WLAN_PASS " WIFI_PASSWORD "
2540int keyIndex = 0 ; // your network key Index number (needed only for WEP)
2641
2742int status = WL_IDLE_STATUS;
@@ -59,13 +74,16 @@ void setup()
5974 ; // wait for serial port to connect. Needed for native USB port only
6075 }
6176
62- // check for the WiFi module:
63- if (WiFi.status () == WL_NO_MODULE)
77+ // if the AirLift's pins were defined above...
78+ #ifdef SET_PINS
79+ WiFi.setPins (SPIWIFI_SS, SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
80+ #endif
81+
82+ // check for the wifi module
83+ while (WiFi.status () == WL_NO_MODULE)
6484 {
6585 Serial.println (" Communication with WiFi module failed!" );
66- // don't continue
67- while (true )
68- ;
86+ delay (1000 );
6987 }
7088
7189 String fv = WiFi.firmwareVersion ();
@@ -74,17 +92,15 @@ void setup()
7492 Serial.println (" Please upgrade the firmware" );
7593 }
7694
77- // attempt to connect to WiFi network:
78- while (status != WL_CONNECTED)
95+ // attempt to connect to Wifi network:
96+ Serial.print (" Attempting to connect to SSID: " );
97+ Serial.println (WLAN_SSID);
98+ // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
99+ do
79100 {
80- Serial.print (" Attempting to connect to WLAN_SSID: " );
81- Serial.println (WLAN_SSID);
82- // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
83101 status = WiFi.begin (WLAN_SSID, WLAN_PASS);
84-
85- // wait 10 seconds for connection:
86- delay (10000 );
87- }
102+ delay (100 ); // wait until connected
103+ } while (status != WL_CONNECTED);
88104 Serial.println (" Connected to wifi" );
89105 printWiFiStatus ();
90106}
0 commit comments