Last active
November 3, 2018 02:19
-
-
Save abachman/f1571715455dc7779fe43f988a4338c7 to your computer and use it in GitHub Desktop.
Troubleshooting IO with a very simple publish + subscribe sketch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adafruit IO Publish & Subscribe Example | |
// | |
// Adafruit invests time and resources providing this open source code. | |
// Please support Adafruit and open source hardware by purchasing | |
// products from Adafruit! | |
// | |
// Written by Todd Treece for Adafruit Industries | |
// Copyright (c) 2016 Adafruit Industries | |
// Licensed under the MIT license. | |
// | |
// All text above must be included in any redistribution. | |
/************************** Configuration ***********************************/ | |
#include "config.h" | |
// limit publishing speed | |
#define IO_LOOP_DELAY 5000 | |
unsigned long lastUpdate = 0; | |
// set up the 'counter' feed | |
AdafruitIO_Feed *counter = io.feed("counter"); | |
int count = 0; | |
void setup() { | |
Serial.begin(115200); | |
// start connecting, delay until connected | |
io.connect(); | |
counter->onMessage(handleMessage); | |
while(io.status() < AIO_CONNECTED) { | |
delay(500); | |
} | |
Serial.println("connected"); | |
} | |
void loop() { | |
io.run(); | |
if (millis() > (lastUpdate + IO_LOOP_DELAY)) { | |
Serial.println("publishing..."); | |
counter->save(count); | |
lastUpdate = millis(); | |
} | |
} | |
void handleMessage(AdafruitIO_Data *data) { | |
Serial.print("received <- "); | |
Serial.println(data->value()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adafruit IO Publish & Subscribe Example | |
// | |
// Adafruit invests time and resources providing this open source code. | |
// Please support Adafruit and open source hardware by purchasing | |
// products from Adafruit! | |
// | |
// Written by Todd Treece for Adafruit Industries | |
// Copyright (c) 2016 Adafruit Industries | |
// Licensed under the MIT license. | |
// | |
// All text above must be included in any redistribution. | |
/************************** Configuration ***********************************/ | |
#include "config.h" | |
// limit publishing speed | |
#define IO_LOOP_DELAY 5000 | |
unsigned long lastUpdate = 0; | |
// set up the 'counter' feed | |
AdafruitIO_Feed *counter = io.feed("counter"); | |
int count = 0; | |
void setup() { | |
Serial.begin(115200); | |
// start connecting, delay until connected | |
io.connect(); | |
counter->onMessage(handleMessage); | |
while(io.status() < AIO_CONNECTED) { | |
delay(500); | |
} | |
Serial.println("connected"); | |
} | |
void loop() { | |
io.run(); | |
if (millis() > (lastUpdate + IO_LOOP_DELAY)) { | |
Serial.println("publishing..."); | |
counter->save(count); | |
lastUpdate = millis(); | |
} | |
} | |
void handleMessage(AdafruitIO_Data *data) { | |
Serial.print("received <- "); | |
Serial.println(data->value()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AdafruitIO_WiFi.h" | |
#define IO_USERNAME "" | |
#define IO_KEY "" | |
#define WIFI_SSID "" | |
#define WIFI_PASS "" | |
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment