Skip to content

Commit f9751a6

Browse files
committed
Example for self managed WiFi
1 parent 9f441b1 commit f9751a6

File tree

2 files changed

+156
-0
lines changed

2 files changed

+156
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Adafruit IO Publish Example with Independent WINC1500 WiFi
2+
//
3+
// Same as the adafruitio_00_publish example, except with WIFI_SSID set to ""
4+
// so your sketch needs to manage the WiFi connection independently. Don't
5+
// follow this example unless you need to handle the WiFi independently!!!
6+
//
7+
// Adafruit invests time and resources providing this open source code.
8+
// Please support Adafruit and open source hardware by purchasing
9+
// products from Adafruit!
10+
//
11+
// Written by Todd Treece for Adafruit Industries
12+
// Copyright (c) 2016 Adafruit Industries
13+
// Licensed under the MIT license.
14+
//
15+
// All text above must be included in any redistribution.
16+
17+
/************************** Configuration ***********************************/
18+
19+
// edit the config.h tab and enter your Adafruit IO credentials
20+
// and any additional configuration needed for WiFi, cellular,
21+
// or ethernet clients.
22+
#include "config.h"
23+
24+
/************************ Example Starts Here *******************************/
25+
26+
// this int will hold the current count for our sketch
27+
int count = 0;
28+
29+
// set up the 'counter' feed
30+
AdafruitIO_Feed *counter = io.feed("counter");
31+
32+
void setup() {
33+
34+
// start the serial connection
35+
Serial.begin(115200);
36+
37+
// wait for serial monitor to open
38+
while(! Serial);
39+
40+
// Board specific self start WiFi network code goes here
41+
WiFi.disconnect();
42+
delay(300);
43+
WiFi.setPins(8, 7, 4, 2); // Adafruit M0 Feather WINC1500
44+
if (WiFi.status() == WL_NO_SHIELD) Serial.println("No WINC1500 Module Detected!");
45+
WiFi.begin(SELF_SSID, WIFI_PASS);
46+
while(WiFi.status() != WL_CONNECTED) {
47+
Serial.print("+");
48+
delay(50);
49+
}
50+
51+
Serial.print("Connecting to Adafruit IO");
52+
53+
// connect to io.adafruit.com
54+
io.connect();
55+
56+
// wait for a connection
57+
while(io.status() < AIO_CONNECTED) {
58+
Serial.print(".");
59+
delay(500);
60+
}
61+
62+
// we are connected
63+
Serial.println();
64+
Serial.println(io.statusText());
65+
66+
}
67+
68+
void loop() {
69+
70+
// io.run(); is required for all sketches.
71+
// it should always be present at the top of your loop
72+
// function. it keeps the client connected to
73+
// io.adafruit.com, and processes any incoming data.
74+
io.run();
75+
76+
// save count to the 'counter' feed on Adafruit IO
77+
Serial.print("sending -> ");
78+
Serial.println(count);
79+
counter->save(count);
80+
81+
// increment the count by 1
82+
count++;
83+
84+
// Adafruit IO is rate limited for publishing, so a delay is required in
85+
// between feed->save events. In this example, we will wait three seconds
86+
// (1000 milliseconds == 1 second) during each loop.
87+
delay(3000);
88+
89+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/************************ Adafruit IO Config *******************************/
2+
3+
// visit io.adafruit.com if you need to create an account,
4+
// or if you need your Adafruit IO key.
5+
#define IO_USERNAME "your_username"
6+
#define IO_KEY "your_key"
7+
8+
/******************************* WIFI **************************************/
9+
10+
// the AdafruitIO_WiFi client will work with the following boards:
11+
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
12+
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
13+
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
14+
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
15+
// - Feather WICED -> https://www.adafruit.com/products/3056
16+
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
17+
// - Adafruit Metro M4 Express AirLift Lite -> https://www.adafruit.com/product/4000
18+
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
19+
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
20+
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
21+
22+
#define WIFI_SSID "" // if "" then you must self connect to WiFi
23+
#define WIFI_PASS "your_pass"
24+
#define SELF_SSID "your_ssid" // an SSID for self connected WiFi
25+
26+
// uncomment the following line if you are using airlift
27+
// #define USE_AIRLIFT
28+
29+
// uncomment the following line if you are using winc1500
30+
#define USE_WINC1500
31+
32+
// comment out the following lines if you are using fona or ethernet
33+
#include "AdafruitIO_WiFi.h"
34+
35+
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE)
36+
// Configure the pins used for the ESP32 connection
37+
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
38+
// Don't change the names of these #define's! they match the variant ones
39+
#define SPIWIFI SPI
40+
#define SPIWIFI_SS 10 // Chip select pin
41+
#define NINA_ACK 9 // a.k.a BUSY or READY pin
42+
#define NINA_RESETN 6 // Reset pin
43+
#define NINA_GPIO0 -1 // Not connected
44+
#endif
45+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
46+
#else
47+
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
48+
#endif
49+
/******************************* FONA **************************************/
50+
51+
// the AdafruitIO_FONA client will work with the following boards:
52+
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
53+
54+
// uncomment the following two lines for 32u4 FONA,
55+
// and comment out the AdafruitIO_WiFi client in the WIFI section
56+
// #include "AdafruitIO_FONA.h"
57+
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
58+
59+
/**************************** ETHERNET ************************************/
60+
61+
// the AdafruitIO_Ethernet client will work with the following boards:
62+
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
63+
64+
// uncomment the following two lines for ethernet,
65+
// and comment out the AdafruitIO_WiFi client in the WIFI section
66+
// #include "AdafruitIO_Ethernet.h"
67+
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);

0 commit comments

Comments
 (0)