Utils Boards  1.0.2
Utility functions and macros to uniform the usage of the WiFi and I2C across different boards
UtilsBoards.h
Go to the documentation of this file.
1 #ifndef _UtilsBoards_h_
2 #define _UtilsBoards_h_
3 
4 #ifdef ARDUINO_TTGO_LoRa32_V1
5  // ESP32 – TTGO LoRa32-OLED V1
6  #define BOARD_TYPE_1
7  #define BOARD_FAMILY "ESP32"
8  #define BOARD_NAME "ESP32 – TTGO LoRa32-OLED V1"
9 
10  #else
11  #ifdef ARDUINO_TTGO_T1
12  // ESP32 – TTGO T1
13  #define BOARD_TYPE_2
14  #define BOARD_FAMILY "ESP32"
15  #define BOARD_NAME "ESP32 – TTGO T1"
16 
17  #else
18  #ifdef ARDUINO_ESP32_DEV
19  // ESP32 – DOIT ESP32 DEVKIT V1
20  #define BOARD_TYPE_3
21  #define BOARD_FAMILY "ESP32"
22  #define BOARD_NAME "ESP32 – DOIT DEVKIT V1"
23 
24  #else
25  #ifdef ARDUINO_ESP8266_WEMOS_D1MINI
26  // ESP8266 – LOLIN (WEMOS) D1 R2 & mini
27  #define BOARD_TYPE_4
28  #define BOARD_FAMILY "ESP8266"
29  #define BOARD_NAME "ESP8266 – LOLIN (WEMOS) D1 R2"
30 
31  #else
32  #ifdef ARDUINO_ESP8266_GENERIC
33  // ESP8266 – Generic
34  #define BOARD_TYPE_5
35  #define BOARD_FAMILY "ESP8266"
36  #define BOARD_NAME "Generic ESP8266"
37 
38  #else
39  // None of the above boards
40  #define BOARD_TYPE_6
41  #define BOARD_FAMILY "Unknown"
42  #define BOARD_NAME "Unknown"
43  #endif
44  #endif
45  #endif
46  #endif
47 #endif
48 
49 #ifdef BOARD_TYPE_1 // ESP32 – TTGO LoRa32-OLED V1
50  #include <WiFi.h>
51  #include <WiFiMulti.h>
52  #include <ESPmDNS.h>
53 
54  #include <AsyncTCP.h>
55 
56  #include <SPIFFS.h>
57 
58  // Internal led pin
59  #define LED_INTERNAL_PIN 2
60 
61  // I2C pins
62  #define SDA 21
63  #define SCL 22
64 #endif
65 
66 #ifdef BOARD_TYPE_2 // ESP32 – TTGO T1
67  #include <WiFi.h>
68  #include <WiFiMulti.h>
69  #include <ESPmDNS.h>
70 
71  #include <AsyncTCP.h>
72 
73  #include <SPIFFS.h>
74 
75  // Internal led pin
76  #define LED_INTERNAL_PIN 22
77 
78  // I2C pins
79  #define SDA 21
80  #define SCL 22
81 #endif
82 
83 #ifdef BOARD_TYPE_3 // ESP32 – DOIT ESP32 DEVKIT V1
84  #include <WiFi.h>
85  #include <WiFiMulti.h>
86  #include <ESPmDNS.h>
87 
88  #include <AsyncTCP.h>
89 
90  #include <SPIFFS.h>
91 
92  // Internal led pin
93  #define LED_INTERNAL_PIN 2
94 
95  // I2C pins
96  #define SDA 21
97  #define SCL 22
98 #endif
99 
100 #ifdef BOARD_TYPE_4 // ESP8266 – LOLIN (WEMOS) D1 R2 & mini
101  #include <ESP8266WiFi.h>
102  #include <ESP8266WiFiMulti.h>
103  #include <ESP8266mDNS.h>
104 
105  #include <ESPAsyncTCP.h>
106 
107  #include <FS.h>
108 
109  // Internal led pin
110  #define LED_INTERNAL_PIN 2
111 
112  // I2C pins
113  #define SDA 19
114  #define SCL 20
115 
116  typedef ESP8266WiFiMulti WiFiMulti;
117 #endif
118 
119 #ifdef BOARD_TYPE_5 // ESP8266 – Generic
120  #include <ESP8266WiFi.h>
121  #include <ESP8266WiFiMulti.h>
122  #include <ESP8266mDNS.h>
123 
124  #include <ESPAsyncTCP.h>
125 
126  #include <FS.h>
127 
128  typedef ESP8266WiFiMulti WiFiMulti;
129 
130  // Internal led pin
131  #define LED_INTERNAL_PIN 1
132 
133  // I2C pins
134  #define SDA 0
135  #define SCL 2
136 #endif
137 
138 #ifdef BOARD_TYPE_6 // Other Boards
139 
140  // Internal led pin
141  #define LED_INTERNAL_PIN 1
142 
143  typedef void WiFiMulti;
144 #endif
145 
146 #include <Print.h>
147 
157 typedef struct {
158  const char* ssid;
159  const char* password;
161 
168 #define internalLedOn() digitalWrite( LED_INTERNAL_PIN, LOW )
169 
176 #define internalLedOff() digitalWrite( LED_INTERNAL_PIN, HIGH )
177 
184 void initInternalLed();
185 
195 void blinkInternalLed(int onTime, int offTime);
196 
205 void showBoardType(Print& pr=Serial);
206 
232 bool initWiFi(
233  const char* ssid,
234  const char* password,
235  const bool resetIfNoWiFi=true,
236  const bool blinkInternal=false,
237  const char* hostName=NULL,
238  Print& pr=Serial);
239 
265 bool initWiFi(
266  PtrWiFiMultiEntry creds,
267  int sizeOfCreds,
268  const bool resetIfNoWiFi=true,
269  const bool blinkInternal=false,
270  const char* hostName=NULL,
271  Print& pr=Serial);
272 
273 #endif // _UtilsBoards_h_
blinkInternalLed
void blinkInternalLed(int onTime, int offTime)
Blink the internal LED of the board.
Definition: UtilsBoards.cpp:23
initInternalLed
void initInternalLed()
Initialize the internal LED.
Definition: UtilsBoards.cpp:30
WiFiMultiEntry
Struct to hold the WiFi credentials.
Definition: UtilsBoards.h:157
WiFiMultiEntry::ssid
const char * ssid
Definition: UtilsBoards.h:158
WiFiMulti
void WiFiMulti
Definition: UtilsBoards.h:143
PtrWiFiMultiEntry
struct WiFiMultiEntry * PtrWiFiMultiEntry
showBoardType
void showBoardType(Print &pr=Serial)
Show the board name.
Definition: UtilsBoards.cpp:18
initWiFi
bool initWiFi(const char *ssid, const char *password, const bool resetIfNoWiFi=true, const bool blinkInternal=false, const char *hostName=NULL, Print &pr=Serial)
Initialize the WiFi.
Definition: UtilsBoards.cpp:66
WiFiMultiEntry::password
const char * password
Definition: UtilsBoards.h:159