1
- /* **************************************************
2
- Adafruit MQTT Library PyPortal Adafruit IO SSL/TLS Example
1
+ /* ***************************************************************
2
+ Adafruit MQTT Library, Adafruit IO SSL/TLS Example for AirLift
3
3
4
4
Must use the latest version of nina-fw from:
5
5
https://github.com/adafruit/nina-fw
6
6
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
8
10
9
11
Adafruit invests time and resources providing this open source code,
10
12
please support Adafruit and open-source hardware by purchasing
11
13
products from Adafruit!
12
14
13
15
Written by Brent Rubell for Adafruit Industries.
14
16
MIT license, all text above must be included in any redistribution
15
- ****************************************************/
17
+ *******************************************************************/
18
+
16
19
#include < WiFiNINA.h>
17
20
#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
+
18
33
#include " Adafruit_MQTT.h"
19
34
#include " Adafruit_MQTT_Client.h"
20
35
21
36
/* ************************ WiFi Access Point *********************************/
22
37
23
38
#define WLAN_SSID " WLAN_SSID"
24
- #define WLAN_PASS " WLAN_PASSWORD "
39
+ #define WLAN_PASS " WIFI_PASSWORD "
25
40
int keyIndex = 0 ; // your network key Index number (needed only for WEP)
26
41
27
42
int status = WL_IDLE_STATUS;
@@ -59,13 +74,16 @@ void setup()
59
74
; // wait for serial port to connect. Needed for native USB port only
60
75
}
61
76
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)
64
84
{
65
85
Serial.println (" Communication with WiFi module failed!" );
66
- // don't continue
67
- while (true )
68
- ;
86
+ delay (1000 );
69
87
}
70
88
71
89
String fv = WiFi.firmwareVersion ();
@@ -74,17 +92,15 @@ void setup()
74
92
Serial.println (" Please upgrade the firmware" );
75
93
}
76
94
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
79
100
{
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:
83
101
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);
88
104
Serial.println (" Connected to wifi" );
89
105
printWiFiStatus ();
90
106
}
0 commit comments