Skip to content

Commit af5f7cc

Browse files
committed
Adding WiFiManager Example Sketch
1 parent 848e3ea commit af5f7cc

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* Adafruit IO Example Using WiFiManager
2+
*
3+
* This is a simple Adafruit feed subscribe example that uses
4+
* WiFiManager to handle setup of WiFi credentials and connecting
5+
* to the network instead of defining the WiFI SSID and password
6+
* explicitly in the code.
7+
*
8+
* To use this example, add your Adafruit IO Username and Key
9+
* and setup a feed called "myfeed". When you manually add data
10+
* to the feed on io.adafruit.com, you'll see that data written to
11+
* the serial output.
12+
*
13+
* Brad Black - 2022
14+
*
15+
*/
16+
17+
#include <WiFiManager.h>
18+
#include "AdafruitIO_WiFi.h"
19+
20+
char IO_USERNAME[64] = "my username";
21+
char IO_KEY[64] = "my key";
22+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, "", "");
23+
AdafruitIO_Feed *myfeed = io.feed("myfeed");
24+
25+
WiFiManager wifiManager;
26+
27+
void handleMessage(AdafruitIO_Data *data)
28+
{
29+
30+
Serial.print("received <- ");
31+
Serial.println(data->toString());
32+
33+
} // handleMessage
34+
35+
void setup()
36+
37+
{
38+
Serial.begin(115200); // Initialize serial port for debugging.
39+
delay(500);
40+
41+
// wifiManager.resetSettings(); //uncomment to reset the WiFi settings
42+
43+
wifiManager.setClass("invert"); // enable "dark mode" for the config portal
44+
wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds
45+
wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap
46+
47+
if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config
48+
{
49+
Serial.println("failed to connect and hit timeout");
50+
}
51+
else
52+
{
53+
// if you get here you have connected to the WiFi
54+
Serial.println("Connected to WiFi.");
55+
56+
Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY);
57+
io.connect();
58+
59+
myfeed->onMessage(handleMessage);
60+
61+
myfeed->get();
62+
63+
// wait for a connection
64+
65+
while ((io.status() < AIO_CONNECTED))
66+
{
67+
Serial.print(".");
68+
delay(500);
69+
}
70+
Serial.println("Connected to Adafruit IO.");
71+
}
72+
73+
} // setup()
74+
75+
void loop()
76+
{
77+
78+
io.run();
79+
80+
} // loop()

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ paragraph=Arduino library to access Adafruit IO using the Adafruit AirLift, ESP8
77
category=Communication
88
url=https://github.com/adafruit/Adafruit_IO_Arduino
99
architectures=*
10-
depends=Adafruit MQTT Library, ArduinoHttpClient, Adafruit Unified Sensor, Adafruit NeoPixel, DHT sensor library, Ethernet, Adafruit Si7021 Library, Adafruit SGP30 Sensor, Adafruit BME280 Library, Adafruit LIS3DH, Adafruit VEML6070 Library, ESP32Servo
10+
depends=Adafruit MQTT Library, ArduinoHttpClient, Adafruit Unified Sensor, Adafruit NeoPixel, DHT sensor library, Ethernet, Adafruit Si7021 Library, Adafruit SGP30 Sensor, Adafruit BME280 Library, Adafruit LIS3DH, Adafruit VEML6070 Library, ESP32Servo, WiFiManager

0 commit comments

Comments
 (0)