Compare commits
No commits in common. "master" and "test-travis" have entirely different histories.
master
...
test-travi
127 changed files with 2844 additions and 8424 deletions
47
.github/workflows/githubci.yml
vendored
47
.github/workflows/githubci.yml
vendored
|
|
@ -1,47 +0,0 @@
|
|||
name: Arduino Library CI
|
||||
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
arduino-platform: ["esp8266", "esp32",
|
||||
"pyportal", "metro_m4_airliftlite",
|
||||
"picow_rp2040_tinyusb"]
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/setup-python@v4
|
||||
with:
|
||||
python-version: '3.x'
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
repository: adafruit/ci-arduino
|
||||
path: ci
|
||||
|
||||
- name: pre-install
|
||||
run: bash ci/actions_install.sh
|
||||
|
||||
|
||||
# manually install WiFi and HTTPClient
|
||||
- name: extra libraries
|
||||
run: |
|
||||
git clone --quiet https://github.com/adafruit/WiFiNINA.git /home/runner/Arduino/libraries/WiFiNINA
|
||||
rm -rf /home/runner/Arduino/libraries/ArduinoHttpClient
|
||||
git clone --quiet https://github.com/arduino-libraries/ArduinoHttpClient.git /home/runner/Arduino/libraries/ArduinoHttpClient
|
||||
|
||||
- name: test platforms
|
||||
run: python3 ci/build_platform.py ${{ matrix.arduino-platform }}
|
||||
|
||||
- name: clang
|
||||
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
|
||||
|
||||
- name: doxygen
|
||||
env:
|
||||
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
|
||||
PRETTYNAME : "Adafruit IO Arduino Library"
|
||||
run: bash ci/doxy_gen_and_deploy.sh src
|
||||
9
.gitignore
vendored
9
.gitignore
vendored
|
|
@ -7,13 +7,6 @@
|
|||
# platformio (testing)
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.travis.yml
|
||||
platformio.ini
|
||||
.tests
|
||||
|
||||
# visual studio code
|
||||
.vscode
|
||||
|
||||
# Our handy .gitignore for automation ease
|
||||
Doxyfile*
|
||||
doxygen_sqlite3.db
|
||||
html
|
||||
|
|
|
|||
79
.tests/AdafruitIO_Data/AdafruitIO_Data.ino
Normal file
79
.tests/AdafruitIO_Data/AdafruitIO_Data.ino
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#include <ArduinoTap.h>
|
||||
#include "AdafruitIO_Data.h"
|
||||
|
||||
AdafruitIO_Data *data = new AdafruitIO_Data();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while(! Serial);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
delay(5000);
|
||||
|
||||
plan(8);
|
||||
|
||||
char bad_csv[] = "xxxxx";
|
||||
char good_csv[] = "12.120,42.331427,-83.045754,233";
|
||||
|
||||
nok(
|
||||
data->setCSV(bad_csv),
|
||||
"invalid CSV doesn't parse"
|
||||
);
|
||||
|
||||
ok(
|
||||
data->setCSV(good_csv),
|
||||
"valid CSV parses"
|
||||
);
|
||||
|
||||
ok(
|
||||
compareChar("12.120", data->value()),
|
||||
"char value match"
|
||||
);
|
||||
|
||||
ok(
|
||||
(12 == data->toInt()),
|
||||
"int value match"
|
||||
);
|
||||
|
||||
ok(
|
||||
compareDouble(12.12, data->toDouble()),
|
||||
"double value match"
|
||||
);
|
||||
|
||||
ok(
|
||||
compareDouble(42.331427, data->lat()),
|
||||
"lat match"
|
||||
);
|
||||
|
||||
ok(
|
||||
compareDouble(-83.045754, data->lon()),
|
||||
"lon match"
|
||||
);
|
||||
|
||||
ok(
|
||||
compareDouble(233, data->ele()),
|
||||
"ele match"
|
||||
);
|
||||
|
||||
done_testing();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool compareDouble(double a, double b)
|
||||
{
|
||||
#ifdef __AVR__
|
||||
return abs(a-b) < 0.00001;
|
||||
#else
|
||||
return abs(a-b) < 0.000001;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool compareChar(char *a, char *b)
|
||||
{
|
||||
return strcmp(a,b) == 0;
|
||||
}
|
||||
|
||||
34
.tests/pub_sub/config.template
Normal file
34
.tests/pub_sub/config.template
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
#define IO_USERNAME "${io_username}"
|
||||
#define IO_KEY "${io_key}"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
#define WIFI_SSID "${wifi_ssid}"
|
||||
#define WIFI_PASS "${wifi_pass}"
|
||||
|
||||
<%
|
||||
if (["ESP8266", "M0_WINC1500", "WICED", "MKR1000"].contains(platform)) {
|
||||
println '#include "AdafruitIO_WiFi.h"'
|
||||
println 'AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);'
|
||||
}
|
||||
%>
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
<%
|
||||
if (["FONA_32U4"].contains(platform)) {
|
||||
println '#include "AdafruitIO_FONA.h"'
|
||||
println 'AdafruitIO_FONA io(IO_USERNAME, IO_KEY);'
|
||||
}
|
||||
%>
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
<%
|
||||
if (["M0_ETHERNETWING"].contains(platform)) {
|
||||
println '#include "AdafruitIO_Ethernet.h"'
|
||||
println 'AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);'
|
||||
}
|
||||
%>
|
||||
47
.tests/pub_sub/pub_sub.ino
Normal file
47
.tests/pub_sub/pub_sub.ino
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
#include <ArduinoTap.h>
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
AdafruitIO_Feed *pubsub = io.feed("pubsub");
|
||||
char time[] = __TIME__;
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
delay(3000);
|
||||
|
||||
plan(2);
|
||||
|
||||
io.connect();
|
||||
pubsub->onMessage(handleMessage);
|
||||
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
delay(500);
|
||||
}
|
||||
|
||||
ok(io.status() > AIO_CONNECTED, "connected to IO");
|
||||
ok(pubsub->save(time), "sent message");
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
io.run();
|
||||
}
|
||||
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
ok(compareChar(time, data->value()), "message received");
|
||||
done_testing();
|
||||
}
|
||||
|
||||
|
||||
bool compareChar(char *a, char *b)
|
||||
{
|
||||
return strcmp(a,b) == 0;
|
||||
}
|
||||
|
||||
8
Jenkinsfile
vendored
8
Jenkinsfile
vendored
|
|
@ -1,6 +1,6 @@
|
|||
arduino {
|
||||
verify = false
|
||||
platforms = ["esp8266:esp8266", "esp32:esp32", "adafruit:avr", "arduino:samd", "adafruit:samd"]
|
||||
libraries = ["Adafruit MQTT Library", "Adafruit FONA Library", "Ethernet", "WiFi101"]
|
||||
boards = ["ESP8266", "M0_WINC1500", "WICED", "MKR1000", "M0_ETHERNETWING", "FONA_32U4", "ESP32"]
|
||||
}
|
||||
platforms = ["esp8266:esp8266", "adafruit:avr", "arduino:samd", "adafruit:samd"]
|
||||
libraries = ["Adafruit MQTT Library", "Adafruit FONA Library", "Ethernet2", "WiFi101"]
|
||||
boards = ["ESP8266", "M0_WINC1500", "WICED", "MKR1000", "M0_ETHERNETWING", "FONA_32U4"]
|
||||
}
|
||||
|
|
|
|||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-2021 Adafruit Industries
|
||||
Copyright (c) 2015-2016 Adafruit Industries
|
||||
Authors: Tony DiCola, Todd Treece
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
|
|||
21
README.md
21
README.md
|
|
@ -1,25 +1,16 @@
|
|||
# Adafruit IO Arduino Library
|
||||
|
||||
[](https://github.com/adafruit/Adafruit_IO_Arduino/actions)[](http://adafruit.github.io/Adafruit_IO_Arduino/html/index.html)
|
||||
[](https://adafruit-io-arduino.readthedocs.io/en/latest/) [](https://travis-ci.org/adafruit/Adafruit_IO_Arduino) [](https://discord.gg/nBQh6qu)
|
||||
|
||||
[](https://adafru.it/discord)
|
||||
|
||||

|
||||
This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing)
|
||||
|
||||
This library provides a simple device independent interface for interacting with [Adafruit IO](https://io.adafruit.com) using Arduino. It allows you to switch between WiFi (ESP8266, ESP32, ESP32-S2, ESP32-S3, ESP32-C3, RP2040, Airlift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing).
|
||||
|
||||
## Documentation
|
||||
|
||||
The Doxygen documentation is automatically generated from the source files
|
||||
in this repository, and documents the API exposed by this library.
|
||||
|
||||
- [API Documentation](https://adafruit.github.io/Adafruit_IO_Arduino/) (automatically generated via doxygen from source)
|
||||
Documentation including installation, configuration and usage for this library is found on [the Adafruit IO Arduino ReadTheDocs pages](https://adafruit-io-arduino.readthedocs.io/en/latest/).
|
||||
|
||||
## License
|
||||
Copyright (c) 2018 [Adafruit Industries](https://adafruit.com). Licensed under the [MIT license](/LICENSE?raw=true).
|
||||
|
||||
This open source code is licensed under the MIT license (see [LICENSE](LICENSE)
|
||||
for details).
|
||||
|
||||
Adafruit invests time and resources providing this open source code, please
|
||||
support Adafruit and open-source hardware by purchasing products from
|
||||
[Adafruit](https://www.adafruit.com)!
|
||||
[Adafruit](https://adafruit.com) invests time and resources providing this open source code.
|
||||
Please support Adafruit and open-source hardware by purchasing products from [Adafruit](https://adafruit.com).
|
||||
|
|
|
|||
BIN
docs/_static/favicon.png
vendored
Normal file
BIN
docs/_static/favicon.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 697 B |
8
docs/api.rst
Normal file
8
docs/api.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
|
||||
.. If you created a package, create one automodule per module in the package.
|
||||
|
||||
.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py)
|
||||
.. use this format as the module name: "adafruit_foo.foo"
|
||||
|
||||
.. automodule:: adafruit io arduino
|
||||
:members:
|
||||
32
docs/compatibility.rst
Normal file
32
docs/compatibility.rst
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
=============
|
||||
Compatibility
|
||||
=============
|
||||
Last tested with library `v2.7.4` on 06/18/2018 for ESP8266, ESP32 and M0 WiFi Targets
|
||||
|
||||
Previously tested on all targets using v2.0.0 on 08/10/2016.
|
||||
|
||||
|
||||
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| Example | ESP8266 | ESP82 | M0 WiFi | WICED | Ethernet* | FONA 32u4 | MKR1000 |
|
||||
+======================+=========+=======+=========+=======+===========+===========+=========+
|
||||
| 00_publish | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 01_subscribe | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 02_pubsub | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 03_multiple_feeds | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 04_location | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 05_type_conversion | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 06_digital_in | ✓ | ✓ | ✓ | ✓ | ? | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 07_digital_out | ✓ | ✓ | ✓ | ✓ | ? | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 08_analog_in | ✓ | ✓ | ✓ | ✓ | ? | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
| 09_analog_out | ✓ | ✓ | ✓ | ✓ | ? | ✓ | ? |
|
||||
+----------------------+---------+-------+---------+-------+-----------+-----------+---------+
|
||||
153
docs/conf.py
Normal file
153
docs/conf.py
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('..'))
|
||||
|
||||
# -- General configuration ------------------------------------------------
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be
|
||||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
|
||||
# ones.
|
||||
extensions = [
|
||||
'sphinx.ext.autodoc',
|
||||
'sphinx.ext.intersphinx',
|
||||
'sphinx.ext.napoleon',
|
||||
'sphinx.ext.todo',
|
||||
]
|
||||
|
||||
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'Adafruit IO Arduino Library'
|
||||
copyright = u'2018 ToddTreece,abachman,tdicola,jwcooper,ladyada'
|
||||
author = u'ToddTreece,abachman,tdicola,jwcooper,ladyada'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'2.7'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'2.7.4'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#
|
||||
# This is also used if you do content translation via gettext catalogs.
|
||||
# Usually you set "language" from the command line for these cases.
|
||||
#language = C
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
# This patterns also effect to html_static_path and html_extra_path
|
||||
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all
|
||||
# documents.
|
||||
#
|
||||
default_role = "any"
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#
|
||||
add_function_parentheses = True
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# If true, `todo` and `todoList` produce output, else they produce nothing.
|
||||
todo_include_todos = False
|
||||
|
||||
# If this is True, todo emits a warning for each TODO entries. The default is False.
|
||||
todo_emit_warnings = True
|
||||
|
||||
napoleon_numpy_docstring = False
|
||||
|
||||
# -- Options for HTML output ----------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
#
|
||||
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
|
||||
|
||||
if not on_rtd: # only import and set the theme if we're building docs locally
|
||||
try:
|
||||
import sphinx_rtd_theme
|
||||
html_theme = 'sphinx_rtd_theme'
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
|
||||
except:
|
||||
html_theme = 'default'
|
||||
html_theme_path = ['.']
|
||||
else:
|
||||
html_theme_path = ['.']
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# The name of an image file (relative to this directory) to use as a favicon of
|
||||
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#
|
||||
html_favicon = '_static/favicon.ico'
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'Adafruit io arduinoLibrarydoc'
|
||||
|
||||
# -- Options for LaTeX output ---------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#
|
||||
# 'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#
|
||||
# 'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#
|
||||
# 'preamble': '',
|
||||
|
||||
# Latex figure (float) alignment
|
||||
#
|
||||
# 'figure_align': 'htbp',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title,
|
||||
# author, documentclass [howto, manual, or own class]).
|
||||
latex_documents = [
|
||||
(master_doc, 'Adafruit IO ArduinoLibrary.tex', u'Adafruit IO Arduino Library Documentation',
|
||||
author, 'manual'),
|
||||
]
|
||||
|
||||
# -- Options for manual page output ---------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
(master_doc, 'Adafruit IO Arduinolibrary', u'Adafruit IO Arduino Library Documentation',
|
||||
[author], 1)
|
||||
]
|
||||
|
||||
# -- Options for Texinfo output -------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
(master_doc, 'Adafruit IO ArduinoLibrary', u' Adafruit IO Arduino Library Documentation',
|
||||
author, 'Adafruit IO ArduinoLibrary', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
65
docs/dependencies.rst
Normal file
65
docs/dependencies.rst
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
Dependencies
|
||||
------------
|
||||
|
||||
This library requires the latest version of the `Arduino IDE <https://www.arduino.cc/en/Main/Software>`_ (tested with v1.6.10).
|
||||
|
||||
Adafruit Feather HUZZAH ESP8266 & Adafruit HUZZAH ESP8266 Breakout
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Latest version of the `ESP8266 Arduino Core <https://github.com/esp8266/Arduino#installing-with-boards-manager>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `Arduino HTTP Client Library <https://github.com/arduino-libraries/ArduinoHttpClient>`_
|
||||
|
||||
Adafruit Feather HUZZAH32 (ESP32)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Latest version of the `ESP32 Arduino Core <https://github.com/espressif/arduino-esp32#using-through-arduino-ide>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `Arduino HTTP Client Library <https://github.com/arduino-libraries/ArduinoHttpClient>`_
|
||||
|
||||
|
||||
Adafruit Feather M0 WiFi with ATWINC1500
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
* Latest version of the `Arduino SAMD Arduino Core <https://github.com/arduino/ArduinoCore-samd>`_
|
||||
* Latest version of the `Adafruit SAMD Arduino Core <https://github.com/adafruit/ArduinoCore-samd>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `WiFi101 Library <https://github.com/arduino-libraries/WiFi101>`_
|
||||
* Latest version of the `Arduino HTTP Client Library <https://github.com/arduino-libraries/ArduinoHttpClient>`_
|
||||
|
||||
You will also need to add the SSL certificate for *io.adafruit.com* using `the guide on the Adafruit Learning System. <https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/updating-ssl-certificates>`_
|
||||
|
||||
|
||||
Arduino MKR1000
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Latest version of the `Arduino SAMD Arduino Core <https://github.com/arduino/ArduinoCore-samd>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `WiFi101 Library <https://github.com/arduino-libraries/WiFi101>`_
|
||||
* Latest version of the `Arduino HTTP Client Library <https://github.com/arduino-libraries/ArduinoHttpClient>`_
|
||||
|
||||
You will also need to add the SSL certificate for *io.adafruit.com* using the MKR1000 SSL utility.
|
||||
|
||||
Adafruit WICED Feather WiFi
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Latest version of the `Adafruit WICED Arduino Core <https://github.com/adafruit/Adafruit_WICED_Arduino>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `Arduino HTTP Client Library <https://github.com/arduino-libraries/ArduinoHttpClient>`_
|
||||
|
||||
|
||||
Adafruit Feather 32u4 FONA
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
* Latest version of the `Adafruit AVR Arduino Core <https://github.com/adafruit/Adafruit_Arduino_Boards>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `Adafruit FONA Library <https://github.com/adafruit/Adafruit_FONA>`_
|
||||
|
||||
|
||||
Adafruit Ethernet FeatherWing
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The Ethernet FeatherWing will also require a 32u4, M0, or ESP8266 based Feather. Any Arduino cores
|
||||
required by the host Feather board will also be required.
|
||||
|
||||
* Latest version of the `Adafruit Ethernet2 Library <https://github.com/adafruit/Ethernet2>`_
|
||||
* Latest version of the `Adafruit MQTT Library <https://github.com/adafruit/Adafruit_MQTT_Library>`_
|
||||
* Latest version of the `Arduino HTTP Client Library <https://github.com/arduino-libraries/ArduinoHttpClient>`_
|
||||
8
docs/examples.rst
Normal file
8
docs/examples.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
Examples
|
||||
---------
|
||||
.. image:: https://cdn-learn.adafruit.com/assets/assets/000/025/083/original/adafruit_io_P1040260.gif?1448317883
|
||||
|
||||
|
||||
Examples for this repository are found in the */examples* folder of this repository.
|
||||
|
||||
They're also fully illustrated and documented on the `Adafruit IO Basics Series on the Adafruit Learning System <https://learn.adafruit.com/series/adafruit-io-basics>`_
|
||||
27
docs/index.rst
Normal file
27
docs/index.rst
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
.. include:: ../README.rst
|
||||
|
||||
Adafruit IO Arduino Library
|
||||
---------------------------
|
||||
This library provides a simple device independent interface for interacting with Adafruit IO using Arduino.
|
||||
It allows you to switch beween WiFi (ESP8266, M0 WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing)
|
||||
with only a two line change in your sketch.
|
||||
|
||||
|
||||
.. toctree::
|
||||
:titlesonly:
|
||||
:maxdepth: 5
|
||||
|
||||
dependencies
|
||||
usage
|
||||
examples
|
||||
compatibility
|
||||
|
||||
|
||||
.. toctree::
|
||||
:caption: Other Links
|
||||
|
||||
Adafruit IO Support Forum <https://forums.adafruit.com/viewforum.php?f=56>
|
||||
Discord Chat <https://adafru.it/discord>
|
||||
Adafruit Learning System <https://learn.adafruit.com>
|
||||
Adafruit Blog <https://blog.adafruit.com>
|
||||
Adafruit Store <https://www.adafruit.com>
|
||||
80
docs/usage.rst
Normal file
80
docs/usage.rst
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
Usage
|
||||
------
|
||||
|
||||
The included examples sketches will walk you through all of the features of the library.
|
||||
They can be used on all platforms, but they default to WiFi. To change between platforms,
|
||||
you will need to change two lines of code in the `config.h` tab of the example.
|
||||
It is recommended that you start with one of the Adafruit WiFi feathers before
|
||||
moving on to cellular or ethernet.
|
||||
|
||||
For all examples, you will need to set `IO_USERNAME` and `IO_KEY` in the `config.h` tab.
|
||||
|
||||
The following sections demonstrate how to switch between WiFi, cellular, and ethernet.
|
||||
|
||||
WiFi (ESP8266, M0 WINC1500, WICED)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
If you are using the included examples, you do not need to change anything for the Adafruit WiFi Feathers.
|
||||
All WiFi based Feathers (ESP8266, M0 WiFi, WICED) will work with the examples out of the box.
|
||||
|
||||
You will need to add your WiFi information to the `WIFI_SSID` and `WIFI_PASS` defines in the `config.h` tab.
|
||||
|
||||
Cellular (32u4 FONA)
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
For FONA, you will only need to change from the default WiFi constructor to the FONA specific constructor in the `config.h` tab.
|
||||
The rest of the sketch remains the same.
|
||||
|
||||
You will need to comment out these WiFi lines in `config.h`:
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
|
||||
and uncomment the FONA lines in `config.h`:
|
||||
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include "AdafruitIO_FONA.h"
|
||||
AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
If your carrier requires APN info, you can set it by adding a call to `io.setAPN()` after `io.connect()` in the `setup()` function of the sketch.
|
||||
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
io.setAPN(F("your_apn"), F("your_apn_user"), F("your_apn_pass"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Ethernet (Ethernet FeatherWing)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
For Ethernet, you will only need to change from the default WiFi constructor to the Ethernet specific constructor in the `config.h` tab.
|
||||
The rest of the sketch remains the same.
|
||||
|
||||
You will need to comment out these WiFi lines in `config.h`:
|
||||
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
|
||||
and uncomment the Ethernet lines in `config.h`:
|
||||
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include "AdafruitIO_Ethernet.h"
|
||||
AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,53 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define SPIWIFI_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define ESP32_RESETN 6 // Reset pin
|
||||
#define ESP32_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -59,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -67,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -30,14 +30,9 @@ void setup() {
|
|||
|
||||
// set up led pin as an analog output
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
|
||||
// New ESP32 LEDC API
|
||||
ledcAttach(LED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution
|
||||
#else
|
||||
// Legacy ESP32 LEDC API
|
||||
ledcAttachPin(LED_PIN, 1);
|
||||
ledcSetup(1, 1200, 8);
|
||||
#endif
|
||||
// ESP32 pinMode()
|
||||
ledcAttachPin(LED_PIN, 1);
|
||||
ledcSetup(1, 1200, 8);
|
||||
#else
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
#endif
|
||||
|
|
@ -92,6 +87,12 @@ void handleMessage(AdafruitIO_Data *data) {
|
|||
Serial.print("received <- ");
|
||||
Serial.println(reading);
|
||||
|
||||
|
||||
// write the current 'reading' to the led
|
||||
analogWrite(LED_PIN, reading);
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWrite(1, reading); // ESP32 analogWrite()
|
||||
#else
|
||||
analogWrite(LED_PIN, reading);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -37,9 +37,6 @@ void setup() {
|
|||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
group->onMessage("count-1", one);
|
||||
group->onMessage("count-2", two);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
|
|
@ -72,22 +69,8 @@ void loop() {
|
|||
// increment the count_1 by 1
|
||||
count_1 += 1;
|
||||
// increment the count_2 by 2
|
||||
count_2 += 2;
|
||||
count_2 *= 2;
|
||||
|
||||
// wait four seconds (1000 milliseconds == 1 second)
|
||||
delay(4000);
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter-1' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter-1 feed in the setup() function above.
|
||||
void one(AdafruitIO_Data *data) {
|
||||
// do nothing!
|
||||
}
|
||||
|
||||
// this function is called whenever a 'counter-2' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter-2 feed in the setup() function above.
|
||||
void two(AdafruitIO_Data *data) {
|
||||
// do nothing!
|
||||
}
|
||||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
// products from Adafruit!
|
||||
//
|
||||
// Written by Todd Treece for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Copyright (c) 2016 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
|
@ -47,8 +47,6 @@ void setup() {
|
|||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// force IO to update our MQTT subscription with the current values of all feeds
|
||||
group->get();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -39,20 +39,14 @@ void setup() {
|
|||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32) // ESP32 pinMode
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
|
||||
// New ESP32 LEDC API
|
||||
ledcAttach(RED_PIN, 12000, 8); // 12 kHz PWM, 8-bit resolution
|
||||
ledcAttach(GREEN_PIN, 12000, 8);
|
||||
ledcAttach(BLUE_PIN, 12000, 8);
|
||||
#else
|
||||
// Legacy ESP32 LEDC API
|
||||
ledcAttachPin(RED_PIN, 1);
|
||||
ledcAttachPin(GREEN_PIN, 2);
|
||||
ledcAttachPin(BLUE_PIN, 3);
|
||||
ledcSetup(1, 12000, 8);
|
||||
ledcSetup(2, 12000, 8);
|
||||
ledcSetup(3, 12000, 8);
|
||||
#endif
|
||||
// assign rgb pins to channels
|
||||
ledcAttachPin(RED_PIN, 1);
|
||||
ledcAttachPin(GREEN_PIN, 2);
|
||||
ledcAttachPin(BLUE_PIN, 3);
|
||||
// init. channels
|
||||
ledcSetup(1, 12000, 8);
|
||||
ledcSetup(2, 12000, 8);
|
||||
ledcSetup(3, 12000, 8);
|
||||
#else
|
||||
pinMode(RED_PIN, OUTPUT);
|
||||
pinMode(GREEN_PIN, OUTPUT);
|
||||
|
|
@ -114,7 +108,14 @@ void handleMessage(AdafruitIO_Data *data) {
|
|||
Serial.println(data->value());
|
||||
|
||||
// invert RGB values for common anode LEDs
|
||||
analogWrite(RED_PIN, 255 - data->toRed());
|
||||
analogWrite(GREEN_PIN, 255 - data->toGreen());
|
||||
analogWrite(BLUE_PIN, 255 - data->toBlue());
|
||||
#if defined(ARDUINO_ARCH_ESP32) // ESP32 analogWrite
|
||||
ledcWrite(1, 255 - data->toRed());
|
||||
ledcWrite(2, 255 - data->toGreen());
|
||||
ledcWrite(3, 255 - data->toBlue());
|
||||
#else
|
||||
analogWrite(RED_PIN, 255 - data->toRed());
|
||||
analogWrite(GREEN_PIN, 255 - data->toGreen());
|
||||
analogWrite(BLUE_PIN, 255 - data->toBlue());
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -2,55 +2,25 @@
|
|||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
// comment out the following two lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
|
||||
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
|
|
@ -61,6 +31,7 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
|
|
@ -69,4 +40,4 @@ AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
|||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
// Adafruit IO Time Topic Subscription 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 Adam Bachman, Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// set up the 'time/seconds' topic
|
||||
AdafruitIO_Time *seconds = io.time(AIO_TIME_SECONDS);
|
||||
|
||||
// set up the 'time/milliseconds' topic
|
||||
AdafruitIO_Time *msecs = io.time(AIO_TIME_MILLIS);
|
||||
|
||||
// set up the 'time/ISO-8601' topic
|
||||
AdafruitIO_Time *iso = io.time(AIO_TIME_ISO);
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
|
||||
// start MQTT connection to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// attach message handler for the seconds feed
|
||||
seconds->onMessage(handleSecs);
|
||||
|
||||
// attach a message handler for the msecs feed
|
||||
msecs->onMessage(handleMillis);
|
||||
|
||||
// attach a message handler for the ISO feed
|
||||
iso->onMessage(handleISO);
|
||||
|
||||
// wait for an MQTT connection
|
||||
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
|
||||
// method to check on MQTT connection status specifically
|
||||
while(io.mqttStatus() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
// Because this sketch isn't publishing, we don't need
|
||||
// a delay() in the main program loop.
|
||||
|
||||
}
|
||||
|
||||
|
||||
// message handler for the seconds feed
|
||||
void handleSecs(char *data, uint16_t len) {
|
||||
Serial.print("Seconds Feed: ");
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
|
||||
// message handler for the milliseconds feed
|
||||
void handleMillis(char *data, uint16_t len) {
|
||||
Serial.print("Millis Feed: ");
|
||||
Serial.println(data);
|
||||
}
|
||||
|
||||
|
||||
// message handler for the ISO-8601 feed
|
||||
void handleISO(char *data, uint16_t len) {
|
||||
Serial.print("ISO Feed: ");
|
||||
Serial.println(data);
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
// Adafruit IO Device Information
|
||||
// desc: Displays Device, WiFi, and Adafruit IO connection information
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
// device mac address
|
||||
byte mac[6];
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO...");
|
||||
|
||||
// connect to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Device Info
|
||||
Serial.println("----DEVICE INFO----");
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC Address: ");
|
||||
for(int i=0;i<6;i++) {
|
||||
Serial.print(mac[i], HEX);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
// Network Info
|
||||
Serial.println("----ROUTER INFO----");
|
||||
Serial.print("WIFI SSID: ");
|
||||
Serial.println(WIFI_SSID);
|
||||
Serial.print("WIFI Pass: ");
|
||||
Serial.println(WIFI_PASS);
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("RSSI:");
|
||||
Serial.println(rssi);
|
||||
|
||||
// Adafruit IO Info
|
||||
Serial.println("----ADAFRUIT IO INFO----");
|
||||
Serial.print("IO User: ");
|
||||
Serial.println(IO_USERNAME);
|
||||
Serial.print("IO Key: ");
|
||||
Serial.println(IO_KEY);
|
||||
Serial.print("IO Status: ");
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop(){
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
// Adafruit IO DeepSleep Example (HUZZAH8266)
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
#define DEEPSLEEP_DURATION 20e6
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while (!Serial);
|
||||
Serial.println("Adafruit IO + DeepSleep");
|
||||
|
||||
// connect to the Adafruit IO Library
|
||||
connectAIO();
|
||||
|
||||
// set up and write to deepsleep feed
|
||||
feedWrite();
|
||||
|
||||
// let's go back to sleep for DEEPSLEEP_DURATION seconds...
|
||||
Serial.println("sleeping...");
|
||||
// Put the Huzzah into deepsleep for DEEPSLEEP_DURATION
|
||||
// NOTE: Make sure Pin 16 is connected to RST
|
||||
#if defined(ESP8266)
|
||||
ESP.deepSleep(1000000 * 2);
|
||||
#else
|
||||
Serial.println("This example is not compatible with your hardware.");
|
||||
#endif
|
||||
}
|
||||
|
||||
// NOOP
|
||||
void loop() {
|
||||
}
|
||||
|
||||
|
||||
void feedWrite(){
|
||||
// set up `deepsleep` feed
|
||||
AdafruitIO_Feed *deepsleep = io.feed("deepsleep");
|
||||
Serial.println("sending value to feed 'deepsleep");
|
||||
// send data to deepsleep feed
|
||||
deepsleep->save(1);
|
||||
// write data to AIO
|
||||
io.run();
|
||||
}
|
||||
void connectAIO() {
|
||||
Serial.println("Connecting to Adafruit IO...");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
// Adafruit IO Shared Feeds Write Example
|
||||
// desc: Example of writing a button value to a shared feed.
|
||||
//
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// digital pin 5
|
||||
#define BUTTON_PIN 5
|
||||
|
||||
// the Adafruit IO username of whomever owns the feed
|
||||
#define FEED_OWNER "AIO_FEED_OWNER"
|
||||
|
||||
// set up a shared feed between you and the FEED_OWNER
|
||||
// make sure you have both read AND write access to this feed
|
||||
AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER);
|
||||
|
||||
// button state
|
||||
bool current = false;
|
||||
bool last = false;
|
||||
|
||||
void setup() {
|
||||
|
||||
// set button pin as an input
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
// grab the current state of the button.
|
||||
// we have to flip the logic because we are
|
||||
// using a pullup resistor.
|
||||
if(digitalRead(BUTTON_PIN) == LOW)
|
||||
current = true;
|
||||
else
|
||||
current = false;
|
||||
|
||||
// return if the value hasn't changed
|
||||
if(current == last)
|
||||
return;
|
||||
|
||||
// save the current state to the 'sharedFeed' feed on adafruit io
|
||||
Serial.print("sending button -> ");
|
||||
Serial.println(current);
|
||||
sharedFeed->save(current);
|
||||
|
||||
// store last button state
|
||||
last = current;
|
||||
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
// Adafruit IO Feed Reading
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-feeds/sharing-a-feed
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// the Adafruit IO username of whomever owns the feed
|
||||
#define FEED_OWNER "AIO_FEED_OWNER"
|
||||
|
||||
// set up the `sharedFeed`
|
||||
AdafruitIO_Feed *sharedFeed = io.feed("FEED-NAME", FEED_OWNER);
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'sharedFeed' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
sharedFeed->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
sharedFeed->get();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever an 'sharedFeed' feed message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the 'digital' feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toInt());
|
||||
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,190 +0,0 @@
|
|||
// Adafruit IO Environmental Data Logger
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-air-quality-monitor
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Adafruit IO Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/**************************** Sensor Configuration ***************************************/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_BME280.h>
|
||||
#include "Adafruit_VEML6070.h"
|
||||
#include "Adafruit_SGP30.h"
|
||||
|
||||
// BME280 Sensor Definitions
|
||||
#define BME_SCK 13
|
||||
#define BME_MISO 12
|
||||
#define BME_MOSI 11
|
||||
#define BME_CS 10
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
// Instanciate the sensors
|
||||
Adafruit_BME280 bme;
|
||||
Adafruit_VEML6070 uv = Adafruit_VEML6070();
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
/**************************** Example ***************************************/
|
||||
// Delay between sensor reads, in seconds
|
||||
#define READ_DELAY 10
|
||||
|
||||
// DHT22 Data
|
||||
int temperatureReading;
|
||||
int pressureReading;
|
||||
|
||||
// SGP30 Data
|
||||
int tvocReading = 0;
|
||||
int ecO2Reading = 0;
|
||||
|
||||
// BME280 Data
|
||||
int altitudeReading = 0;
|
||||
int humidityReading = 0;
|
||||
|
||||
// VEML6070 Data
|
||||
int uvReading = 0;
|
||||
|
||||
// set up the feeds for the BME280
|
||||
AdafruitIO_Feed *temperatureFeed = io.feed("temperature");
|
||||
AdafruitIO_Feed *humidityFeed = io.feed("humidity");
|
||||
AdafruitIO_Feed *pressureFeed = io.feed("pressure");
|
||||
AdafruitIO_Feed *altitudeFeed = io.feed("altitude");
|
||||
|
||||
// set up feed for the VEML6070
|
||||
AdafruitIO_Feed *uvFeed = io.feed("uv");
|
||||
|
||||
// set up feeds for the SGP30
|
||||
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
|
||||
AdafruitIO_Feed *ecO2Feed = io.feed("ecO2");
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(9600);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("Adafruit IO Environmental Logger");
|
||||
|
||||
// set up BME280
|
||||
setupBME280();
|
||||
// set up SGP30
|
||||
setupSGP30();
|
||||
// setup VEML6070
|
||||
uv.begin(VEML6070_1_T);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
Serial.println("Reading Sensors...");
|
||||
|
||||
// Read the temperature from the BME280
|
||||
temperatureReading = bme.readTemperature();
|
||||
|
||||
// convert from celsius to degrees fahrenheit
|
||||
temperatureReading = temperatureReading * 1.8 + 32;
|
||||
|
||||
Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F");
|
||||
|
||||
// Read the pressure from the BME280
|
||||
pressureReading = bme.readPressure() / 100.0F;
|
||||
Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa");
|
||||
|
||||
// Read the altitude from the BME280
|
||||
altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
||||
Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m");
|
||||
|
||||
// Read the humidity from the BME280
|
||||
humidityReading = bme.readHumidity();
|
||||
Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%");
|
||||
|
||||
// VEML6070
|
||||
uvReading = uv.readUV();
|
||||
Serial.print("UV Light Level: "); Serial.println(uvReading);
|
||||
|
||||
if(! sgp.IAQmeasure()){
|
||||
tvocReading = -1;
|
||||
ecO2Reading = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
tvocReading = sgp.TVOC;
|
||||
ecO2Reading = sgp.eCO2;
|
||||
}
|
||||
|
||||
Serial.print("TVOC: "); Serial.print(tvocReading); Serial.print(" ppb\t");
|
||||
Serial.print("eCO2: "); Serial.print(ecO2Reading); Serial.println(" ppm");
|
||||
|
||||
// send data to Adafruit IO feeds
|
||||
temperatureFeed->save(temperatureReading);
|
||||
humidityFeed->save(humidityReading);
|
||||
altitudeFeed->save(altitudeReading);
|
||||
pressureFeed->save(pressureReading);
|
||||
uvFeed->save(uvReading);
|
||||
ecO2Feed->save(ecO2Reading);
|
||||
tvocFeed->save(tvocReading);
|
||||
|
||||
// delay the polled loop
|
||||
delay(READ_DELAY * 1000);
|
||||
}
|
||||
|
||||
// Set up the SGP30 sensor
|
||||
void setupSGP30() {
|
||||
if (!sgp.begin())
|
||||
{
|
||||
Serial.println("Sensor not found :(");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Found SGP30 serial #");
|
||||
Serial.print(sgp.serialnumber[0], HEX);
|
||||
Serial.print(sgp.serialnumber[1], HEX);
|
||||
Serial.println(sgp.serialnumber[2], HEX);
|
||||
|
||||
// If you previously calibrated the sensor in this environment,
|
||||
// you can assign it to self-calibrate (replace the values with your baselines):
|
||||
// sgp.setIAQBaseline(0x8E68, 0x8F41);
|
||||
}
|
||||
|
||||
// Set up the BME280 sensor
|
||||
void setupBME280() {
|
||||
bool status;
|
||||
status = bme.begin();
|
||||
if (!status)
|
||||
{
|
||||
Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("BME Sensor is set up!");
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
// Adafruit IO IFTTT Example - Gmailbox
|
||||
// Tutorial Link: https://learn.adafruit.com/gmailbox
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
// Import Servo Libraries
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32Servo Library (https://github.com/madhephaestus/ESP32Servo)
|
||||
// installation: library manager -> search -> "ESP32Servo"
|
||||
#include <ESP32Servo.h>
|
||||
#else
|
||||
#include <Servo.h>
|
||||
#endif
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// pin used to control the servo
|
||||
#define SERVO_PIN 14
|
||||
|
||||
// Flag's up position, in degrees
|
||||
#define FLAG_UP 0
|
||||
|
||||
// Flag's down position, in degrees
|
||||
#define FLAG_DOWN 180
|
||||
|
||||
// How long to hold the flag up, in seconds
|
||||
#define FLAG_DELAY 2
|
||||
|
||||
// create an instance of the servo class
|
||||
Servo servo;
|
||||
|
||||
// set up the 'servo' feed
|
||||
AdafruitIO_Feed *gmail_feed = io.feed("gmail");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("IFTTT Gmailbox");
|
||||
|
||||
// tell the servo class which pin we are using
|
||||
servo.attach(SERVO_PIN);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'servo' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
gmail_feed->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
gmail_feed->get();
|
||||
|
||||
// write flag to down position
|
||||
servo.write(FLAG_DOWN);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever a 'gmail' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the gmail feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.println("You've got mail!");
|
||||
servo.write(FLAG_UP);
|
||||
// wait FLAG_DELAY seconds
|
||||
delay(FLAG_DELAY * 1000);
|
||||
servo.write(FLAG_DOWN);
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define SPIWIFI_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define ESP32_RESETN 6 // Reset pin
|
||||
#define ESP32_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
// Adafruit IO Time Tracking Cube
|
||||
// Tutorial Link: https://learn.adafruit.com/time-tracking-cube
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2019 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_LIS3DH.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
// Prop-Maker Wing
|
||||
#define NEOPIXEL_PIN 2
|
||||
#define POWER_PIN 15
|
||||
|
||||
// Used for Pizeo
|
||||
#define PIEZO_PIN 0
|
||||
|
||||
// # of Pixels Attached
|
||||
#define NUM_PIXELS 8
|
||||
|
||||
// Adafruit_LIS3DH Setup
|
||||
Adafruit_LIS3DH lis = Adafruit_LIS3DH();
|
||||
|
||||
// NeoPixel Setup
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
// Set up the 'cubeTask' feed
|
||||
AdafruitIO_Feed *cubetask = io.feed("cubetask");
|
||||
|
||||
/* Time Tracking Cube States
|
||||
* 1: Cube Tilted Left
|
||||
* 2: Cube Tilted Right
|
||||
* 3: Cube Neutral, Top
|
||||
*/
|
||||
int cubeState = 0;
|
||||
|
||||
// Previous cube orientation state
|
||||
int prvCubeState = 0;
|
||||
|
||||
// Tasks (change these to what you're currently working on)
|
||||
String taskOne = "Write Learn Guide";
|
||||
String taskTwo = "Write Code";
|
||||
|
||||
// Adafruit IO sending delay, in seconds
|
||||
int sendDelay = 0.5;
|
||||
|
||||
// Time-Keeping
|
||||
unsigned long currentTime;
|
||||
unsigned long prevTime;
|
||||
int seconds = 0;
|
||||
int minutes = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// start the serial connection
|
||||
Serial.begin(9600);
|
||||
// wait for serial monitor to open
|
||||
while (!Serial)
|
||||
;
|
||||
Serial.println("Adafruit IO Time Tracking Cube");
|
||||
|
||||
// disabling low-power mode on the prop-maker wing
|
||||
pinMode(POWER_PIN, OUTPUT);
|
||||
digitalWrite(POWER_PIN, HIGH);
|
||||
|
||||
// Initialize LIS3DH
|
||||
if (!lis.begin(0x18))
|
||||
{
|
||||
Serial.println("Couldnt start");
|
||||
while (1)
|
||||
;
|
||||
}
|
||||
Serial.println("LIS3DH found!");
|
||||
lis.setRange(LIS3DH_RANGE_4_G);
|
||||
|
||||
// Initialize NeoPixel Strip
|
||||
strip.begin();
|
||||
Serial.println("Pixels init'd");
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// wait for a connection
|
||||
while (io.status() < AIO_CONNECTED)
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
}
|
||||
|
||||
void updateTime()
|
||||
{
|
||||
// grab the current time from millis()
|
||||
currentTime = millis() / 1000;
|
||||
seconds = currentTime - prevTime;
|
||||
// increase mins.
|
||||
if (seconds == 60)
|
||||
{
|
||||
prevTime = currentTime;
|
||||
minutes++;
|
||||
}
|
||||
}
|
||||
|
||||
void updatePixels(uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
for (int p = 0; p < NUM_PIXELS; p++)
|
||||
{
|
||||
strip.setPixelColor(p, red, green, blue);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
// Update the timer
|
||||
updateTime();
|
||||
|
||||
// Get a normalized sensor reading
|
||||
sensors_event_t event;
|
||||
lis.getEvent(&event);
|
||||
|
||||
// Detect cube face orientation
|
||||
if (event.acceleration.x > 9 && event.acceleration.x < 10)
|
||||
{
|
||||
//Serial.println("Cube TILTED: Left");
|
||||
cubeState = 1;
|
||||
}
|
||||
else if (event.acceleration.x < -9)
|
||||
{
|
||||
//Serial.println("Cube TILTED: Right");
|
||||
cubeState = 2;
|
||||
}
|
||||
else if (event.acceleration.y < 0 && event.acceleration.y > -1)
|
||||
{
|
||||
cubeState = 3;
|
||||
}
|
||||
else
|
||||
{ // orientation not specified
|
||||
//Serial.println("Cube Idle...");
|
||||
}
|
||||
|
||||
// return if the orientation hasn't changed
|
||||
if (cubeState == prvCubeState)
|
||||
return;
|
||||
|
||||
// Send to Adafruit IO based off of the orientation of the cube
|
||||
switch (cubeState)
|
||||
{
|
||||
case 1:
|
||||
Serial.println("Switching to Task 1");
|
||||
// update the neopixel strip
|
||||
updatePixels(50, 0, 0);
|
||||
|
||||
// play a sound
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWriteTone(PIEZO_PIN, 650);
|
||||
#else
|
||||
tone(PIEZO_PIN, 650, 300);
|
||||
#endif
|
||||
|
||||
Serial.print("Sending to Adafruit IO -> ");
|
||||
Serial.println(taskTwo);
|
||||
cubetask->save(taskTwo, minutes);
|
||||
// reset the timer
|
||||
minutes = 0;
|
||||
break;
|
||||
case 2:
|
||||
Serial.println("Switching to Task 2");
|
||||
// update the neopixel strip
|
||||
updatePixels(0, 50, 0);
|
||||
|
||||
// play a sound
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWriteTone(PIEZO_PIN, 850);
|
||||
#else
|
||||
tone(PIEZO_PIN, 850, 300);
|
||||
#endif
|
||||
|
||||
Serial.print("Sending to Adafruit IO -> ");
|
||||
Serial.println(taskOne);
|
||||
cubetask->save(taskOne, minutes);
|
||||
// reset the timer
|
||||
minutes = 0;
|
||||
break;
|
||||
case 3:
|
||||
updatePixels(0, 0, 50);
|
||||
|
||||
// play a sound
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
ledcWriteTone(PIEZO_PIN, 950);
|
||||
#else
|
||||
tone(PIEZO_PIN, 950, 300);
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// save cube state
|
||||
prvCubeState = cubeState;
|
||||
|
||||
// Delay the send to Adafruit IO
|
||||
delay(sendDelay * 1000);
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
// Adafruit IO Schedule Trigger Example
|
||||
// Tutorial Link: https://learn.adafruit.com/adafruit-io-basics-scheduled-triggers/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2020 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
|
||||
// Relay is connected to PyPortal's D3 connector
|
||||
#define RELAY_POWER_PIN 3
|
||||
|
||||
// Set up the 'relay feed'
|
||||
AdafruitIO_Feed *relay = io.feed("relay");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
|
||||
// connect to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the 'relay' feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io
|
||||
relay->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// Get the last known value from the feed
|
||||
relay->get();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever an 'relay' feed message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the 'relay' feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
|
||||
Serial.print("feed received new data <- ");
|
||||
Serial.println(data->toChar());
|
||||
|
||||
// Check to see if the morning scheduled trigger has executed
|
||||
if (strcmp(data->toChar(), "1") == 0) {
|
||||
Serial.println("Turning lights ON");
|
||||
digitalWrite(RELAY_POWER_PIN, HIGH);
|
||||
}
|
||||
// Check to see if the evening scheduled trigger has executed
|
||||
else if (strcmp(data->toChar(), "0") == 0) {
|
||||
Serial.println("Turning lights OFF");
|
||||
digitalWrite(RELAY_POWER_PIN, LOW);
|
||||
}
|
||||
else {
|
||||
Serial.println("Unexpected data received from Adafruit IO");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define SPIWIFI_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define ESP32_RESETN 6 // Reset pin
|
||||
#define ESP32_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,116 +0,0 @@
|
|||
// Adafruit IO Publish & Subscribe, Digital Input and Output 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
|
||||
// Modified by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2020 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// Button Pin
|
||||
#define BUTTON_PIN 0
|
||||
|
||||
// LED Pin
|
||||
#define LED_PIN LED_BUILTIN
|
||||
|
||||
// button state
|
||||
bool btn_state = false;
|
||||
bool prv_btn_state = false;
|
||||
|
||||
// set up the 'led' feed
|
||||
AdafruitIO_Feed *led = io.feed("led");
|
||||
|
||||
// set up the 'button' feed
|
||||
AdafruitIO_Feed *button = io.feed("button");
|
||||
|
||||
void setup() {
|
||||
|
||||
// set button pin as an input
|
||||
pinMode(BUTTON_PIN, INPUT);
|
||||
|
||||
// set LED pin as an output
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
|
||||
// connect to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// set up a message handler for the count feed.
|
||||
// the handleMessage function (defined below)
|
||||
// will be called whenever a message is
|
||||
// received from adafruit io.
|
||||
led->onMessage(handleMessage);
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
led->get();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
// grab the btn_state state of the button.
|
||||
if(digitalRead(BUTTON_PIN) == LOW)
|
||||
btn_state = false;
|
||||
else
|
||||
btn_state = true;
|
||||
|
||||
// return if the btn state hasn't changed
|
||||
if(btn_state == prv_btn_state)
|
||||
return;
|
||||
|
||||
// save the btn_state state to the 'button' feed on adafruit io
|
||||
Serial.print("sending button -> "); Serial.println(btn_state);
|
||||
button->save(btn_state);
|
||||
|
||||
// store last button state
|
||||
prv_btn_state = btn_state;
|
||||
|
||||
}
|
||||
|
||||
// this function is called whenever a 'led' message
|
||||
// is received from Adafruit IO. it was attached to
|
||||
// the counter feed in the setup() function above.
|
||||
void handleMessage(AdafruitIO_Data *data) {
|
||||
Serial.print("received <- ");
|
||||
|
||||
if(data->toPinLevel() == HIGH)
|
||||
Serial.println("HIGH");
|
||||
else
|
||||
Serial.println("LOW");
|
||||
|
||||
digitalWrite(LED_PIN, data->toPinLevel());
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define SPIWIFI_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define ESP32_RESETN 6 // Reset pin
|
||||
#define ESP32_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
SPIWIFI_ACK, ESP32_RESETN, ESP32_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/* Adafruit IO Example Using WiFiManager
|
||||
*
|
||||
* This is a simple Adafruit feed subscribe example that uses
|
||||
* WiFiManager to handle setup of WiFi credentials and connecting
|
||||
* to the network instead of defining the WiFI SSID and password
|
||||
* explicitly in the code.
|
||||
*
|
||||
* To use this example, add your Adafruit IO Username and Key
|
||||
* and setup a feed called "myfeed". When you manually add data
|
||||
* to the feed on io.adafruit.com, you'll see that data written to
|
||||
* the serial output.
|
||||
*
|
||||
* Brad Black - 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFiManager.h>
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
char IO_USERNAME[64] = "my username";
|
||||
char IO_KEY[64] = "my key";
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, "", "");
|
||||
AdafruitIO_Feed *myfeed = io.feed("myfeed");
|
||||
|
||||
WiFiManager wifiManager;
|
||||
|
||||
void handleMessage(AdafruitIO_Data *data)
|
||||
{
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toString());
|
||||
|
||||
} // handleMessage
|
||||
|
||||
void setup()
|
||||
|
||||
{
|
||||
Serial.begin(115200); // Initialize serial port for debugging.
|
||||
delay(500);
|
||||
|
||||
// wifiManager.resetSettings(); //uncomment to reset the WiFi settings
|
||||
|
||||
wifiManager.setClass("invert"); // enable "dark mode" for the config portal
|
||||
wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds
|
||||
wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap
|
||||
|
||||
if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config
|
||||
{
|
||||
Serial.println("failed to connect and hit timeout");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you get here you have connected to the WiFi
|
||||
Serial.println("Connected to WiFi.");
|
||||
|
||||
Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY);
|
||||
io.connect();
|
||||
|
||||
myfeed->onMessage(handleMessage);
|
||||
|
||||
myfeed->get();
|
||||
|
||||
// wait for a connection
|
||||
|
||||
while ((io.status() < AIO_CONNECTED))
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("Connected to Adafruit IO.");
|
||||
}
|
||||
|
||||
} // setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
io.run();
|
||||
|
||||
} // loop()
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1,192 +0,0 @@
|
|||
/* Adafruit IO Example Using WiFiManager with Custom Adafruit IO parameters
|
||||
*
|
||||
* This is a simple Adafruit feed subscribe example that uses
|
||||
* WiFiManager to handle setup of WiFi credentials and connecting
|
||||
* to the network instead of defining the WiFI SSID and password
|
||||
* explicitly in the code.
|
||||
*
|
||||
* In addition, this example allows you to enter your Adafruit IO username and key
|
||||
* as customer parameters in WiFiManager so that they do not need to be coded into
|
||||
* the sketch.
|
||||
*
|
||||
* This is useful if you want to create projects and share them with others that
|
||||
* may use them on a different WiFi network and use a different Adafruit IO account
|
||||
* for IOT integrations such as collecting sensor data or voice command integration via
|
||||
* IFFT.
|
||||
*
|
||||
* To use this example, setup a feed called "myfeed". When the ESP8266 or ESP32
|
||||
* microcontroller starts, join the "WiFi Setup" SSID and you should be presented
|
||||
* with the config portal. If the config portal does not automatically start you
|
||||
* can browse to http://192.168.4.1 to access it
|
||||
*
|
||||
* Select the SSID and enter the password for WiFi Access in the config portal.
|
||||
* Enter your Adafruit IO username and key in the config portal and select "Save".
|
||||
*
|
||||
* When you manually add data to the feed on io.adafruit.com, you'll see
|
||||
* that data written to the serial output.
|
||||
*
|
||||
* Brad Black - 2022
|
||||
*
|
||||
*/
|
||||
|
||||
#include <WiFiManager.h>
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
#include <ArduinoJson.h>
|
||||
#include <LittleFS.h>
|
||||
|
||||
char IO_USERNAME[64] = "";
|
||||
char IO_KEY[64] = "";
|
||||
|
||||
static uint8_t objStorage[sizeof(AdafruitIO_WiFi)]; // RAM for the object
|
||||
AdafruitIO_WiFi *io; // a pointer to the object, once it's constructed
|
||||
|
||||
// create WiFiManager object and define our custom parameters
|
||||
|
||||
WiFiManager wifiManager;
|
||||
WiFiManagerParameter custom_IO_USERNAME("iouser", "Adafruit IO Username", IO_USERNAME, 60);
|
||||
WiFiManagerParameter custom_IO_KEY("iokey", "Adafruit IO Key", IO_KEY, 60);
|
||||
|
||||
void handleMessage(AdafruitIO_Data *data)
|
||||
{
|
||||
|
||||
Serial.print("received <- ");
|
||||
Serial.println(data->toString());
|
||||
|
||||
} // handleMessage
|
||||
|
||||
// callback notifying us of the need to save config
|
||||
void saveConfigCallback()
|
||||
{
|
||||
|
||||
Serial.println("Saving new config");
|
||||
|
||||
strcpy(IO_USERNAME, custom_IO_USERNAME.getValue());
|
||||
strcpy(IO_KEY, custom_IO_KEY.getValue());
|
||||
|
||||
DynamicJsonDocument json(256);
|
||||
|
||||
json["IO_KEY"] = IO_KEY;
|
||||
json["IO_USERNAME"] = IO_USERNAME;
|
||||
|
||||
File configFile = LittleFS.open("/config.json", "w");
|
||||
if (!configFile)
|
||||
{
|
||||
Serial.println("Failed to open config file for writing");
|
||||
}
|
||||
|
||||
serializeJson(json, Serial);
|
||||
|
||||
serializeJson(json, configFile);
|
||||
|
||||
configFile.close();
|
||||
} // end save
|
||||
|
||||
void readParamsFromFS()
|
||||
{
|
||||
if (LittleFS.begin())
|
||||
{
|
||||
|
||||
if (LittleFS.exists("/config.json"))
|
||||
{
|
||||
// file exists, reading and loading
|
||||
Serial.println("Reading config file");
|
||||
|
||||
File configFile = LittleFS.open("/config.json", "r");
|
||||
if (configFile)
|
||||
{
|
||||
size_t size = configFile.size();
|
||||
// Allocate a buffer to store contents of the file.
|
||||
std::unique_ptr<char[]> buf(new char[size]);
|
||||
|
||||
configFile.readBytes(buf.get(), size);
|
||||
|
||||
DynamicJsonDocument json(256);
|
||||
auto deserializeError = deserializeJson(json, buf.get());
|
||||
serializeJson(json, Serial);
|
||||
Serial.println();
|
||||
if (!deserializeError)
|
||||
{
|
||||
|
||||
if (json.containsKey("IO_USERNAME"))
|
||||
strcpy(IO_USERNAME, json["IO_USERNAME"]);
|
||||
if (json.containsKey("IO_KEY"))
|
||||
strcpy(IO_KEY, json["IO_KEY"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Failed to load json config");
|
||||
}
|
||||
configFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Serial.println("Failed to mount FS");
|
||||
}
|
||||
}
|
||||
}
|
||||
void setup()
|
||||
|
||||
{
|
||||
Serial.begin(115200); // Initialize serial port for debugging.
|
||||
delay(500);
|
||||
WiFi.begin();
|
||||
|
||||
readParamsFromFS(); // get parameters from file system
|
||||
|
||||
//wifiManager.resetSettings(); //uncomment to reset the WiFi settings
|
||||
|
||||
wifiManager.setClass("invert"); // enable "dark mode" for the config portal
|
||||
wifiManager.setConfigPortalTimeout(120); // auto close configportal after n seconds
|
||||
wifiManager.setAPClientCheck(true); // avoid timeout if client connected to softap
|
||||
|
||||
wifiManager.addParameter(&custom_IO_USERNAME); // set custom paraeter for IO username
|
||||
wifiManager.addParameter(&custom_IO_KEY); // set custom parameter for IO key
|
||||
|
||||
custom_IO_KEY.setValue(IO_KEY, 64); // set custom parameter value
|
||||
custom_IO_USERNAME.setValue(IO_USERNAME, 64); // set custom parameter value
|
||||
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback); // set config save notify callback
|
||||
|
||||
if (!wifiManager.autoConnect("WiFi Setup")) // connect to wifi with existing setting or start config
|
||||
{
|
||||
Serial.println("Failed to connect and hit timeout");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if you get here you have connected to the WiFi
|
||||
Serial.println("Connected to WiFi.");
|
||||
|
||||
// connect to Adafruit IO
|
||||
|
||||
io = new (objStorage) AdafruitIO_WiFi(IO_USERNAME, IO_KEY, "", "");
|
||||
|
||||
Serial.printf("Connecting to Adafruit IO with User: %s Key: %s.\n", IO_USERNAME, IO_KEY);
|
||||
|
||||
io->connect();
|
||||
|
||||
AdafruitIO_Feed *myfeed = io->feed("myfeed");
|
||||
|
||||
myfeed->onMessage(handleMessage);
|
||||
|
||||
myfeed->get();
|
||||
|
||||
// wait for a connection
|
||||
|
||||
while ((io->status() < AIO_CONNECTED))
|
||||
{
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.println("Connected to Adafruit IO.");
|
||||
}
|
||||
|
||||
} // setup()
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
io->run();
|
||||
|
||||
} // loop()
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,305 +0,0 @@
|
|||
// Adafruit IO House: Security System
|
||||
//
|
||||
// Learn Guide: https://learn.adafruit.com/adafruit-io-home-security
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
// include the NeoPixel library
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
// include the SGP30 library
|
||||
#include <Wire.h>
|
||||
#include "Adafruit_SGP30.h"
|
||||
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// delay the main `io.run()` loop
|
||||
#define LOOP_DELAY 3000
|
||||
// delay for each sensor send to adafruit io
|
||||
#define SENSOR_DELAY 1000
|
||||
|
||||
// PIR sensor input pin
|
||||
#define pirPin 13
|
||||
// reed switch input pin
|
||||
#define doorPin 2
|
||||
// piezo (alarm) buzzer
|
||||
#define piezoPin 14
|
||||
|
||||
/**** Time Setup ****/
|
||||
// set the hour to start at
|
||||
int startingHour = 1;
|
||||
// set the second to start at
|
||||
int seconds = 56;
|
||||
// set the minutes to start at
|
||||
int minutes = 56;
|
||||
// set the hour at which the motion alarm should trigger
|
||||
int alarmHour = 16;
|
||||
|
||||
unsigned long currentTime = 0;
|
||||
unsigned long prevTime = 0;
|
||||
int currentHour = startingHour;
|
||||
|
||||
|
||||
/*********NeoPixel Setup*********/
|
||||
// pin the NeoPixel strip and jewel are connected to
|
||||
#define NEOPIXEL_PIN 12
|
||||
// amount of neopixels on the NeoPixel strip
|
||||
#define STRIP_PIXEL_COUNT 60
|
||||
#define JEWEL_PIXEL_COUNT 7
|
||||
// type of neopixels used by the NeoPixel strip and jewel.
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
// init. neoPixel Strip
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, NEOPIXEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// sketch starts assuming no motion is detected
|
||||
int pirState = LOW;
|
||||
// sketch starts assuming the the door is closed
|
||||
int doorState = LOW;
|
||||
// alarm state
|
||||
bool isAlarm = false;
|
||||
// variable for reading the pin status
|
||||
int pirRead = 0;
|
||||
// SGP30 Sensor Object
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
/*** Adafruit IO Feed Setup ***/
|
||||
// 'indoor-lights' feed
|
||||
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
|
||||
// `outdoor-lights` feed
|
||||
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
|
||||
// `front-door` feed
|
||||
AdafruitIO_Feed *frontDoor = io.feed("front-door");
|
||||
// `motion-detector` feed
|
||||
AdafruitIO_Feed *motionFeed = io.feed("motion-detector");
|
||||
// `home-alarm` feed
|
||||
AdafruitIO_Feed *homeAlarm = io.feed("home-alarm");
|
||||
// 'tvoc' feed
|
||||
AdafruitIO_Feed *tvocFeed = io.feed("tvoc");
|
||||
// 'eco2' feed
|
||||
AdafruitIO_Feed *eco2Feed = io.feed("eco2");
|
||||
|
||||
void setup() {
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
Serial.println("Adafruit IO Home: Security");
|
||||
|
||||
Serial.println("Connecting to Adafruit IO");
|
||||
// start MQTT connection to io.adafruit.com
|
||||
io.connect();
|
||||
|
||||
// attach a message handler for the `home-alarm` feed
|
||||
homeAlarm->onMessage(handleAlarm);
|
||||
// subscribe to lighting feeds and register message handlers
|
||||
indoorLights->onMessage(indoorLightHandler);
|
||||
outdoorLights->onMessage(outdoorLightHandler);
|
||||
|
||||
// wait for an MQTT connection
|
||||
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
|
||||
// method to check on MQTT connection status specifically
|
||||
while(io.mqttStatus() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// declare PIR sensor as input
|
||||
pinMode(pirPin, INPUT);
|
||||
// declare reed switch as input
|
||||
pinMode(doorPin, INPUT);
|
||||
// set up the SGP30 sensor
|
||||
setupSGP30();
|
||||
// init the neopixel strip and set to `off`
|
||||
strip.begin();
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
getTime();
|
||||
Serial.println("* read door sensor...");
|
||||
readDoorSensor();
|
||||
Serial.println("* read motion detector");
|
||||
readPIR();
|
||||
Serial.println("* reading SGP30...");
|
||||
readSGP30();
|
||||
|
||||
// check if the alarm toggle is armed from the dashboard
|
||||
if (isAlarm == true) {
|
||||
if (doorState == HIGH || (currentHour>alarmHour && pirState == HIGH)) {
|
||||
playAlarmAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void playAlarmAnimation() {
|
||||
// plays the alarm piezo buzzer and turn on/off neopixels
|
||||
Serial.println("ALARM TRIGGERED!");
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// ESP32 doesn't use native tone() function
|
||||
ledcWriteTone(piezoPin, 220);
|
||||
#else
|
||||
tone(piezoPin, 220, 2);
|
||||
#endif
|
||||
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, 255, 0, 0);
|
||||
}
|
||||
strip.show();
|
||||
delay(500);
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, 0, 0, 0);
|
||||
}
|
||||
strip.show();
|
||||
}
|
||||
|
||||
void readDoorSensor() {
|
||||
// reads the status of the front door and sends to adafruit io
|
||||
doorState = digitalRead(doorPin);
|
||||
if (doorState == LOW) {
|
||||
Serial.println("* Door Closed");
|
||||
frontDoor->save(1);
|
||||
} else {
|
||||
Serial.println("* Door Open");
|
||||
frontDoor->save(3);
|
||||
}
|
||||
delay(SENSOR_DELAY);
|
||||
}
|
||||
|
||||
void readPIR() {
|
||||
// check if motion is detected in front of the home
|
||||
pirRead = digitalRead(pirPin);
|
||||
if (pirRead == HIGH) {
|
||||
if (pirState == LOW) {
|
||||
// we have just turned on
|
||||
Serial.println("* Motion detected in front of home!");
|
||||
motionFeed->save(3);
|
||||
pirState = HIGH;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pirState == HIGH) {
|
||||
Serial.println("* Motion ended.");
|
||||
motionFeed->save(0);
|
||||
pirState = LOW;
|
||||
}
|
||||
}
|
||||
delay(SENSOR_DELAY);
|
||||
}
|
||||
|
||||
void readSGP30() {
|
||||
// reads the SGP30 sensor and sends data to Adafruit IO
|
||||
if (! sgp.IAQmeasure()) {
|
||||
Serial.println("Measurement failed");
|
||||
return;
|
||||
}
|
||||
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
|
||||
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
|
||||
tvocFeed->save(int(sgp.TVOC));
|
||||
delay(SENSOR_DELAY/2);
|
||||
eco2Feed->save(int(sgp.eCO2));
|
||||
delay(SENSOR_DELAY/2);
|
||||
}
|
||||
|
||||
/*** MQTT messageHandlers ***/
|
||||
void handleAlarm(AdafruitIO_Data *data) {
|
||||
// handle the alarm toggle on the Adafruit IO Dashboard
|
||||
String toggleValue = data->toString();
|
||||
Serial.print("> rcv alarm: ");
|
||||
Serial.println(toggleValue);
|
||||
if(toggleValue == String("ON")) {
|
||||
Serial.println("* Alarm Set: ON");
|
||||
isAlarm = true;
|
||||
} else {
|
||||
Serial.println("* Alarm Set: OFF");
|
||||
isAlarm = false;
|
||||
}
|
||||
}
|
||||
|
||||
// handles the indoor light colorpicker on the Adafruit IO Dashboard
|
||||
void indoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> indoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
long color = data->toNeoPixel();
|
||||
// set the color of each NeoPixel in the jewel
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel jewel to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
||||
// handles the outdoor light colorpicker on the Adafruit IO Dashboard
|
||||
void outdoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> outdoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
long color = data->toNeoPixel();
|
||||
// set the color of each NeoPixel in the strip
|
||||
for(int i=JEWEL_PIXEL_COUNT; i<STRIP_PIXEL_COUNT+JEWEL_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel strip to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
||||
|
||||
void setupSGP30(){
|
||||
// sets up the SGP30 Sensor
|
||||
if (! sgp.begin()) {
|
||||
Serial.println("Sensor not found :(");
|
||||
while (1);
|
||||
}
|
||||
Serial.print("Found SGP30 serial #");
|
||||
Serial.print(sgp.serialnumber[0], HEX);
|
||||
Serial.print(sgp.serialnumber[1], HEX);
|
||||
Serial.println(sgp.serialnumber[2], HEX);
|
||||
}
|
||||
|
||||
void getTime() {
|
||||
currentTime = millis()/1000;
|
||||
seconds = currentTime - prevTime;
|
||||
|
||||
if (seconds == 60) {
|
||||
prevTime = currentTime;
|
||||
minutes += 1;
|
||||
}
|
||||
if (minutes == 60) {
|
||||
minutes = 0;
|
||||
currentHour += 1;
|
||||
}
|
||||
if (currentHour == 24) {
|
||||
currentHour = 0;
|
||||
}
|
||||
|
||||
Serial.print("Time:");
|
||||
Serial.print(currentHour);
|
||||
Serial.print(":");
|
||||
Serial.print(minutes);
|
||||
Serial.print(":");
|
||||
Serial.println(seconds);
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/************************ Adafruit IO Config *******************************/
|
||||
|
||||
// visit io.adafruit.com if you need to create an account,
|
||||
// or if you need your Adafruit IO key.
|
||||
#define IO_USERNAME "your_username"
|
||||
#define IO_KEY "your_key"
|
||||
|
||||
/******************************* WIFI **************************************/
|
||||
|
||||
// the AdafruitIO_WiFi client will work with the following boards:
|
||||
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
|
||||
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
|
||||
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
|
||||
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
|
||||
// - Feather WICED -> https://www.adafruit.com/products/3056
|
||||
// - Adafruit PyPortal -> https://www.adafruit.com/product/4116
|
||||
// - Adafruit Metro M4 Express AirLift Lite ->
|
||||
// https://www.adafruit.com/product/4000
|
||||
// - Adafruit AirLift Breakout -> https://www.adafruit.com/product/4201
|
||||
// - Adafruit AirLift Shield -> https://www.adafruit.com/product/4285
|
||||
// - Adafruit AirLift FeatherWing -> https://www.adafruit.com/product/4264
|
||||
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASS "your_pass"
|
||||
|
||||
// uncomment the following line if you are using airlift
|
||||
// #define USE_AIRLIFT
|
||||
|
||||
// uncomment the following line if you are using winc1500
|
||||
// #define USE_WINC1500
|
||||
|
||||
// uncomment the following line if you are using mrk1010 or nano 33 iot
|
||||
// #define ARDUINO_SAMD_MKR1010
|
||||
|
||||
// comment out the following lines if you are using fona or ethernet
|
||||
#include "AdafruitIO_WiFi.h"
|
||||
|
||||
#if defined(USE_AIRLIFT) || defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || \
|
||||
defined(ADAFRUIT_PYPORTAL)
|
||||
// Configure the pins used for the ESP32 connection
|
||||
#if !defined(SPIWIFI_SS) // if the wifi definition isnt in the board variant
|
||||
// Don't change the names of these #define's! they match the variant ones
|
||||
#define SPIWIFI SPI
|
||||
#define SPIWIFI_SS 10 // Chip select pin
|
||||
#define NINA_ACK 9 // a.k.a BUSY or READY pin
|
||||
#define NINA_RESETN 6 // Reset pin
|
||||
#define NINA_GPIO0 -1 // Not connected
|
||||
#endif
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS,
|
||||
NINA_ACK, NINA_RESETN, NINA_GPIO0, &SPIWIFI);
|
||||
#else
|
||||
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
|
||||
#endif
|
||||
/******************************* FONA **************************************/
|
||||
|
||||
// the AdafruitIO_FONA client will work with the following boards:
|
||||
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
|
||||
|
||||
// uncomment the following two lines for 32u4 FONA,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_FONA.h"
|
||||
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
|
||||
|
||||
/**************************** ETHERNET ************************************/
|
||||
|
||||
// the AdafruitIO_Ethernet client will work with the following boards:
|
||||
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
|
||||
|
||||
// uncomment the following two lines for ethernet,
|
||||
// and comment out the AdafruitIO_WiFi client in the WIFI section
|
||||
// #include "AdafruitIO_Ethernet.h"
|
||||
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
|
||||
|
|
@ -1,156 +0,0 @@
|
|||
// Adafruit IO House: Lights and Temperature
|
||||
//
|
||||
// Learn Guide: https://learn.adafruit.com/adafruit-io-house-lights-and-temperature
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Written by Brent Rubell for Adafruit Industries
|
||||
// Copyright (c) 2018 Adafruit Industries
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
|
||||
/************************** Configuration ***********************************/
|
||||
|
||||
// edit the config.h tab and enter your Adafruit IO credentials
|
||||
// and any additional configuration needed for WiFi, cellular,
|
||||
// or ethernet clients.
|
||||
#include "config.h"
|
||||
|
||||
// include the NeoPixel library
|
||||
#include "Adafruit_NeoPixel.h"
|
||||
|
||||
// include the si7021 library
|
||||
#include "Adafruit_Si7021.h"
|
||||
/************************ Example Starts Here *******************************/
|
||||
|
||||
// pin the NeoPixel strip is connected to
|
||||
#define STRIP_PIN 12
|
||||
// pin the NeoPixel Jewel is connected to
|
||||
#define JEWEL_PIN 2
|
||||
|
||||
// amount of neopixels on the NeoPixel strip
|
||||
#define STRIP_PIXEL_COUNT 34
|
||||
// amount of neopixels on the NeoPixel jewel
|
||||
#define JEWEL_PIXEL_COUNT 7
|
||||
|
||||
// type of neopixels used by the NeoPixel strip and jewel.
|
||||
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800
|
||||
|
||||
// main loop() delay, in seconds
|
||||
#define TEMP_DELAY 7
|
||||
|
||||
// Temperature and Humidity: Si7021 Sensor
|
||||
int temperatureData;
|
||||
int humidityData;
|
||||
|
||||
// initalize neopixel strip
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE);
|
||||
// initalize neopixel jewel
|
||||
Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE);
|
||||
|
||||
// initalize the sensor object
|
||||
Adafruit_Si7021 sensor = Adafruit_Si7021();
|
||||
|
||||
// set up the Adafruit IO feeds
|
||||
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
|
||||
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
|
||||
AdafruitIO_Feed *humidity = io.feed("humidity");
|
||||
AdafruitIO_Feed *temperature = io.feed("temperature");
|
||||
|
||||
void setup() {
|
||||
|
||||
// start the serial connection
|
||||
Serial.begin(115200);
|
||||
|
||||
// wait for serial monitor to open
|
||||
while(! Serial);
|
||||
|
||||
// connect to io.adafruit.com
|
||||
Serial.print("Connecting to Adafruit IO");
|
||||
io.connect();
|
||||
|
||||
// subscribe to lighting feeds and register message handlers
|
||||
indoorLights->onMessage(indoorLightHandler);
|
||||
outdoorLights->onMessage(outdoorLightHandler);
|
||||
|
||||
|
||||
// wait for a connection
|
||||
while(io.status() < AIO_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// we are connected
|
||||
Serial.println();
|
||||
Serial.println(io.statusText());
|
||||
|
||||
// initalize the Si7021 sensor
|
||||
if (!sensor.begin()) {
|
||||
Serial.println("Did not find Si7021 sensor!");
|
||||
while (true);
|
||||
}
|
||||
Serial.println("Si7021 sensor set up!");
|
||||
|
||||
// initalize the neopixel strip and jewel.
|
||||
strip.begin();
|
||||
jewel.begin();
|
||||
|
||||
// set all neopixels on the strip and jewel to `off`.
|
||||
strip.show();
|
||||
jewel.show();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// io.run(); is required for all sketches.
|
||||
// it should always be present at the top of your loop
|
||||
// function. it keeps the client connected to
|
||||
// io.adafruit.com, and processes any incoming data.
|
||||
io.run();
|
||||
|
||||
temperatureData = sensor.readTemperature() * 1.8 + 32;
|
||||
humidityData = sensor.readHumidity();
|
||||
|
||||
|
||||
Serial.print("-> Sending Temperature to Adafruit IO: ");
|
||||
Serial.println(temperatureData);
|
||||
Serial.print("-> Sending Humidity to Adafruit IO: ");
|
||||
Serial.println(humidityData);
|
||||
|
||||
// send the state of the feed to adafruit io
|
||||
temperature->save(temperatureData);
|
||||
humidity->save(humidityData);
|
||||
|
||||
// delay the loop to avoid flooding Adafruit IO
|
||||
delay(1000*TEMP_DELAY);
|
||||
}
|
||||
|
||||
void indoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> indoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
// set the color of each NeoPixel in the jewel
|
||||
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
|
||||
jewel.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel jewel to the new color
|
||||
jewel.show();
|
||||
}
|
||||
|
||||
void outdoorLightHandler(AdafruitIO_Data *data) {
|
||||
Serial.print("-> outdoor light HEX: ");
|
||||
Serial.println(data->value());
|
||||
|
||||
long color = data->toNeoPixel();
|
||||
|
||||
// set the color of each NeoPixel in the strip
|
||||
for(int i=0; i<STRIP_PIXEL_COUNT; ++i) {
|
||||
strip.setPixelColor(i, color);
|
||||
}
|
||||
// 'set' the neopixel strip to the new color
|
||||
strip.show();
|
||||
}
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
name=Adafruit IO Arduino
|
||||
version=4.3.2
|
||||
version=2.7.4
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <adafruitio@adafruit.com>
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library to access Adafruit IO.
|
||||
paragraph=Arduino library to access Adafruit IO using WiFi, ethernet, or cellular.
|
||||
paragraph=Arduino library to access Adafruit IO using the Adafruit ESP8266, M0 WINC1500, WICED, MKR1000, Ethernet, or FONA hardware.
|
||||
category=Communication
|
||||
url=https://github.com/adafruit/Adafruit_IO_Arduino
|
||||
architectures=*
|
||||
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, ArduinoJson
|
||||
|
|
|
|||
|
|
@ -1,50 +1,18 @@
|
|||
/*!
|
||||
* @file AdafruitIO.cpp
|
||||
*
|
||||
* @mainpage Adafruit IO Arduino Client Library
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* This is the documentation for the Adafruit IO Arduino library. This library
|
||||
* provides a simple device independent interface for interacting with Adafruit
|
||||
* IO using Arduino. It allows you to switch between WiFi (ESP8266, ESP32,
|
||||
* AirLift, WINC1500, & WICED), Cellular (32u4 FONA), and Ethernet (Ethernet
|
||||
* FeatherWing)
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* @section dependencies Dependencies
|
||||
*
|
||||
* This library depends on <a
|
||||
* href="https://github.com/arduino-libraries/ArduinoHttpClient">
|
||||
* ArduinoHTTPClient</a> and <a
|
||||
* href="https://github.com/adafruit/Adafruit_MQTT_Library"> Adafruit MQTT
|
||||
* Library</a> being present on your system. Please make sure you have installed
|
||||
* the latest version before using this library.
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "AdafruitIO.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instantiate the AIO object.
|
||||
@param user
|
||||
A pointer to a constant AIO user name.
|
||||
@param key
|
||||
A pointer to a constant key for the user name.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO::AdafruitIO(const char *user, const char *key) {
|
||||
AdafruitIO::AdafruitIO(const char *user, const char *key)
|
||||
{
|
||||
_mqtt = 0;
|
||||
_http = 0;
|
||||
_username = user;
|
||||
|
|
@ -59,21 +27,77 @@ AdafruitIO::AdafruitIO(const char *user, const char *key) {
|
|||
_init();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialize the AIO object.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO::_init() {
|
||||
void errorCallback(char *err, uint16_t len)
|
||||
{
|
||||
AIO_ERROR_PRINTLN();
|
||||
AIO_ERROR_PRINT("ERROR: ");
|
||||
AIO_ERROR_PRINTLN(err);
|
||||
AIO_ERROR_PRINTLN();
|
||||
}
|
||||
|
||||
void AdafruitIO::connect()
|
||||
{
|
||||
|
||||
AIO_DEBUG_PRINTLN("AdafruitIO::connect()");
|
||||
|
||||
if(_err_sub) {
|
||||
// setup error sub
|
||||
_err_sub = new Adafruit_MQTT_Subscribe(_mqtt, _err_topic);
|
||||
_mqtt->subscribe(_err_sub);
|
||||
_err_sub->setCallback(errorCallback);
|
||||
}
|
||||
|
||||
if(_throttle_sub) {
|
||||
// setup throttle sub
|
||||
_throttle_sub = new Adafruit_MQTT_Subscribe(_mqtt, _throttle_topic);
|
||||
_mqtt->subscribe(_throttle_sub);
|
||||
_throttle_sub->setCallback(errorCallback);
|
||||
}
|
||||
|
||||
_connect();
|
||||
|
||||
}
|
||||
|
||||
AdafruitIO::~AdafruitIO()
|
||||
{
|
||||
if(_err_topic)
|
||||
free(_err_topic);
|
||||
|
||||
if(_throttle_topic)
|
||||
free(_throttle_topic);
|
||||
|
||||
if(_err_sub)
|
||||
delete _err_sub;
|
||||
|
||||
if(_throttle_sub)
|
||||
delete _throttle_sub;
|
||||
}
|
||||
|
||||
AdafruitIO_Feed* AdafruitIO::feed(const char* name)
|
||||
{
|
||||
return new AdafruitIO_Feed(this, name);
|
||||
}
|
||||
|
||||
AdafruitIO_Group* AdafruitIO::group(const char* name)
|
||||
{
|
||||
return new AdafruitIO_Group(this, name);
|
||||
}
|
||||
|
||||
AdafruitIO_Dashboard* AdafruitIO::dashboard(const char* name)
|
||||
{
|
||||
return new AdafruitIO_Dashboard(this, name);
|
||||
}
|
||||
|
||||
void AdafruitIO::_init()
|
||||
{
|
||||
|
||||
// we have never pinged, so set last ping to now
|
||||
_last_ping = millis();
|
||||
|
||||
// dynamically allocate memory for err topic
|
||||
_err_topic = (char *)malloc(
|
||||
sizeof(char) * (strlen(_username) + strlen(AIO_ERROR_TOPIC) + 1));
|
||||
_err_topic = (char *)malloc(sizeof(char) * (strlen(_username) + strlen(AIO_ERROR_TOPIC) + 1));
|
||||
|
||||
if (_err_topic) {
|
||||
if(_err_topic) {
|
||||
|
||||
// build error topic
|
||||
strcpy(_err_topic, _username);
|
||||
|
|
@ -83,13 +107,13 @@ void AdafruitIO::_init() {
|
|||
|
||||
// malloc failed
|
||||
_err_topic = 0;
|
||||
|
||||
}
|
||||
|
||||
// dynamically allocate memory for throttle topic
|
||||
_throttle_topic = (char *)malloc(
|
||||
sizeof(char) * (strlen(_username) + strlen(AIO_THROTTLE_TOPIC) + 1));
|
||||
_throttle_topic = (char *)malloc(sizeof(char) * (strlen(_username) + strlen(AIO_THROTTLE_TOPIC) + 1));
|
||||
|
||||
if (_throttle_topic) {
|
||||
if(_throttle_topic) {
|
||||
|
||||
// build throttle topic
|
||||
strcpy(_throttle_topic, _username);
|
||||
|
|
@ -99,265 +123,61 @@ void AdafruitIO::_init() {
|
|||
|
||||
// malloc failed
|
||||
_throttle_topic = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const __FlashStringHelper* AdafruitIO::statusText()
|
||||
{
|
||||
switch(_status) {
|
||||
|
||||
// CONNECTING
|
||||
case AIO_IDLE: return F("Idle. Waiting for connect to be called...");
|
||||
case AIO_NET_DISCONNECTED: return F("Network disconnected.");
|
||||
case AIO_DISCONNECTED: return F("Disconnected from Adafruit IO.");
|
||||
|
||||
// FAILURE
|
||||
case AIO_NET_CONNECT_FAILED: return F("Network connection failed.");
|
||||
case AIO_CONNECT_FAILED: return F("Adafruit IO connection failed.");
|
||||
case AIO_FINGERPRINT_INVALID: return F("Adafruit IO SSL fingerprint verification failed.");
|
||||
case AIO_AUTH_FAILED: return F("Adafruit IO authentication failed.");
|
||||
|
||||
// SUCCESS
|
||||
case AIO_NET_CONNECTED: return F("Network connected.");
|
||||
case AIO_CONNECTED: return F("Adafruit IO connected.");
|
||||
case AIO_CONNECTED_INSECURE: return F("Adafruit IO connected. **THIS CONNECTION IS INSECURE** SSL/TLS not supported for this platform.");
|
||||
case AIO_FINGERPRINT_UNSUPPORTED: return F("Adafruit IO connected over SSL/TLS. Fingerprint verification unsupported.");
|
||||
case AIO_FINGERPRINT_VALID: return F("Adafruit IO connected over SSL/TLS. Fingerprint valid.");
|
||||
|
||||
default: return F("Unknown status code");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Destructor to end the AIO object.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO::~AdafruitIO() {
|
||||
if (_err_topic)
|
||||
free(_err_topic);
|
||||
|
||||
if (_throttle_topic)
|
||||
free(_throttle_topic);
|
||||
|
||||
if (_err_sub)
|
||||
delete _err_sub;
|
||||
|
||||
if (_throttle_sub)
|
||||
delete _throttle_sub;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Prints errors
|
||||
@param err
|
||||
An error string to print.
|
||||
@param len
|
||||
The length of the error string.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void errorCallback(char *err, uint16_t len) {
|
||||
AIO_ERROR_PRINTLN();
|
||||
AIO_ERROR_PRINT("ERROR: ");
|
||||
AIO_ERROR_PRINTLN(err);
|
||||
AIO_ERROR_PRINTLN();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Connects to AIO, setting up using parameters set when the
|
||||
class is instantiated.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO::connect() {
|
||||
|
||||
AIO_DEBUG_PRINTLN("AdafruitIO::connect()");
|
||||
|
||||
_last_mqtt_connect = 0; // need to start over fresh
|
||||
_status = AIO_IDLE;
|
||||
_last_ping = 0;
|
||||
|
||||
if (_err_sub) {
|
||||
// setup error sub
|
||||
_err_sub = new Adafruit_MQTT_Subscribe(_mqtt, _err_topic);
|
||||
_mqtt->subscribe(_err_sub);
|
||||
_err_sub->setCallback(errorCallback);
|
||||
}
|
||||
|
||||
if (_throttle_sub) {
|
||||
// setup throttle sub
|
||||
_throttle_sub = new Adafruit_MQTT_Subscribe(_mqtt, _throttle_topic);
|
||||
_mqtt->subscribe(_throttle_sub);
|
||||
_throttle_sub->setCallback(errorCallback);
|
||||
}
|
||||
|
||||
_connect();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnects from WiFi.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO::wifi_disconnect() {
|
||||
|
||||
AIO_DEBUG_PRINTLN("AdafruitIO::wifi_disconnect()");
|
||||
|
||||
_disconnect();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Create a new AIO feed.
|
||||
@param name
|
||||
The AIO name of the feed.
|
||||
@return A pointer to the feed.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Feed *AdafruitIO::feed(const char *name) {
|
||||
return new AdafruitIO_Feed(this, name);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Create a new AIO feed.
|
||||
@param name
|
||||
The AIO name of the feed.
|
||||
@param owner
|
||||
The AIO name of the user that owns the feed, if not the current
|
||||
user.
|
||||
@return A pointer to the feed.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Feed *AdafruitIO::feed(const char *name, const char *owner) {
|
||||
return new AdafruitIO_Feed(this, name, owner);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Create a new AIO time.
|
||||
@param format
|
||||
A format specifier.
|
||||
@return A pointer to the time.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Time *AdafruitIO::time(aio_time_format_t format) {
|
||||
return new AdafruitIO_Time(this, format);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Create a new AIO group.
|
||||
@param name
|
||||
The AIO name of the group.
|
||||
@return A pointer to the group.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Group *AdafruitIO::group(const char *name) {
|
||||
return new AdafruitIO_Group(this, name);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Create a new AIO dashboard.
|
||||
@param name
|
||||
The AIO name of the dashboard.
|
||||
@return A pointer to the dashboard.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Dashboard *AdafruitIO::dashboard(const char *name) {
|
||||
return new AdafruitIO_Dashboard(this, name);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Provide status explanation strings.
|
||||
@return A pointer to the status string, _status. _status is the AIO status
|
||||
value
|
||||
*/
|
||||
/**************************************************************************/
|
||||
const __FlashStringHelper *AdafruitIO::statusText() {
|
||||
switch (_status) {
|
||||
|
||||
// CONNECTING
|
||||
case AIO_IDLE:
|
||||
return F("Idle. Waiting for connect to be called...");
|
||||
case AIO_NET_DISCONNECTED:
|
||||
return F("Network disconnected.");
|
||||
case AIO_DISCONNECTED:
|
||||
return F("Disconnected from Adafruit IO.");
|
||||
|
||||
// FAILURE
|
||||
case AIO_NET_CONNECT_FAILED:
|
||||
return F("Network connection failed.");
|
||||
case AIO_CONNECT_FAILED:
|
||||
return F("Adafruit IO connection failed.");
|
||||
case AIO_FINGERPRINT_INVALID:
|
||||
return F("Adafruit IO SSL fingerprint verification failed.");
|
||||
case AIO_AUTH_FAILED:
|
||||
return F("Adafruit IO authentication failed.");
|
||||
|
||||
// SUCCESS
|
||||
case AIO_NET_CONNECTED:
|
||||
return F("Network connected.");
|
||||
case AIO_CONNECTED:
|
||||
return F("Adafruit IO connected.");
|
||||
case AIO_CONNECTED_INSECURE:
|
||||
return F("Adafruit IO connected. **THIS CONNECTION IS INSECURE** SSL/TLS "
|
||||
"not supported for this platform.");
|
||||
case AIO_FINGERPRINT_UNSUPPORTED:
|
||||
return F("Adafruit IO connected over SSL/TLS. Fingerprint verification "
|
||||
"unsupported.");
|
||||
case AIO_FINGERPRINT_VALID:
|
||||
return F("Adafruit IO connected over SSL/TLS. Fingerprint valid.");
|
||||
|
||||
default:
|
||||
return F("Unknown status code");
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Must be called frequently to keep AIO connections alive. When
|
||||
called with no arguments run() will try to repair MQTT and WiFi
|
||||
connections before returning. To avoid potentially long timeout
|
||||
delays, sketches can use the busywait_ms and fail_fast arguments
|
||||
to return an imperfect status quickly. The calling sketch will
|
||||
then need to respond appropriately to that status.
|
||||
@param busywait_ms
|
||||
The packet read timeout, optional.
|
||||
@param fail_fast
|
||||
Set true to skip retries and return with status immediately,
|
||||
optional.
|
||||
@return AIO status value
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aio_status_t AdafruitIO::run(uint16_t busywait_ms, bool fail_fast) {
|
||||
uint32_t timeStart = millis();
|
||||
if (status() < AIO_NET_CONNECTED) { // If we aren't network connected...
|
||||
if (fail_fast)
|
||||
return status(); // return status and fail quickly
|
||||
else { // or try to reconnect from the start
|
||||
AIO_ERROR_PRINT("run() connection failed -- retrying");
|
||||
unsigned long started = millis();
|
||||
connect();
|
||||
// wait for a full AIO connection then carry on
|
||||
while (status() < AIO_CONNECTED) {
|
||||
// or return an error if the reconnection times out
|
||||
if (millis() - started > AIO_NET_CONNECTION_TIMEOUT)
|
||||
return status();
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdafruitIO::run(uint16_t busywait_ms)
|
||||
{
|
||||
// loop until we have a connection
|
||||
// mqttStatus() will try to reconnect before returning
|
||||
while (mqttStatus(fail_fast) != AIO_CONNECTED &&
|
||||
millis() - timeStart < AIO_MQTT_CONNECTION_TIMEOUT) {
|
||||
}
|
||||
if (mqttStatus(fail_fast) != AIO_CONNECTED)
|
||||
return status();
|
||||
while(mqttStatus() != AIO_CONNECTED){}
|
||||
|
||||
if (busywait_ms > 0)
|
||||
if(busywait_ms > 0)
|
||||
_packetread_timeout = busywait_ms;
|
||||
|
||||
_mqtt->processPackets(_packetread_timeout);
|
||||
|
||||
// ping to keep connection alive if needed
|
||||
if (millis() > (_last_ping + AIO_PING_INTERVAL)) {
|
||||
if(millis() > (_last_ping + AIO_PING_INTERVAL)) {
|
||||
_mqtt->ping();
|
||||
_last_ping = millis();
|
||||
}
|
||||
return status();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Status check.
|
||||
@return An AIO status value. Lower values represent poorer connection
|
||||
status.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aio_status_t AdafruitIO::status() {
|
||||
aio_status_t AdafruitIO::status()
|
||||
{
|
||||
aio_status_t net_status = networkStatus();
|
||||
|
||||
// if we aren't connected, return network status
|
||||
if (net_status != AIO_NET_CONNECTED) {
|
||||
if(net_status != AIO_NET_CONNECTED) {
|
||||
_status = net_status;
|
||||
return _status;
|
||||
}
|
||||
|
|
@ -367,45 +187,26 @@ aio_status_t AdafruitIO::status() {
|
|||
return _status;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Identify the board.
|
||||
@return A board ID
|
||||
*/
|
||||
/**************************************************************************/
|
||||
char *AdafruitIO::boardID() { return AdafruitIO_Board::id(); }
|
||||
char* AdafruitIO::boardID()
|
||||
{
|
||||
return AdafruitIO_Board::id();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Identify the board type.
|
||||
@return A board type
|
||||
*/
|
||||
/**************************************************************************/
|
||||
const char *AdafruitIO::boardType() { return AdafruitIO_Board::type(); }
|
||||
const char* AdafruitIO::boardType()
|
||||
{
|
||||
return AdafruitIO_Board::type();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Identify the software version.
|
||||
@return A pointer to a version number string.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
char *AdafruitIO::version() {
|
||||
sprintf(_version, "%d.%d.%d", ADAFRUITIO_VERSION_MAJOR,
|
||||
ADAFRUITIO_VERSION_MINOR, ADAFRUITIO_VERSION_PATCH);
|
||||
char* AdafruitIO::version()
|
||||
{
|
||||
sprintf(_version, "%d.%d.%d", ADAFRUITIO_VERSION_MAJOR, ADAFRUITIO_VERSION_MINOR, ADAFRUITIO_VERSION_PATCH);
|
||||
return _version;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Identify the user agent.
|
||||
@return A pointer to a user agent string.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
char *AdafruitIO::userAgent() {
|
||||
if (!_user_agent) {
|
||||
_user_agent =
|
||||
(char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) +
|
||||
strlen(connectionType()) + 24));
|
||||
char* AdafruitIO::userAgent()
|
||||
{
|
||||
if(!_user_agent) {
|
||||
_user_agent = (char *)malloc(sizeof(char) * (strlen(version()) + strlen(boardType()) + strlen(connectionType()) + 24));
|
||||
strcpy(_user_agent, "AdafruitIO-Arduino/");
|
||||
strcat(_user_agent, version());
|
||||
strcat(_user_agent, " (");
|
||||
|
|
@ -417,50 +218,35 @@ char *AdafruitIO::userAgent() {
|
|||
return _user_agent;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Checks connection status with Adafruit IO's MQTT broker.
|
||||
@param fail_fast
|
||||
Set true to skip retries and return with status immediately.
|
||||
@return True if connected, otherwise False.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aio_status_t AdafruitIO::mqttStatus(bool fail_fast) {
|
||||
aio_status_t AdafruitIO::mqttStatus()
|
||||
{
|
||||
// if the connection failed,
|
||||
// return so we don't hammer IO
|
||||
if (_status == AIO_CONNECT_FAILED) {
|
||||
if(_status == AIO_CONNECT_FAILED)
|
||||
{
|
||||
AIO_ERROR_PRINT("mqttStatus() failed to connect");
|
||||
AIO_ERROR_PRINTLN(_mqtt->connectErrorString(_status));
|
||||
return _status;
|
||||
}
|
||||
|
||||
if (_mqtt->connected())
|
||||
if(_mqtt->connected())
|
||||
return AIO_CONNECTED;
|
||||
|
||||
// prevent fast reconnect attempts, except for the first time through
|
||||
if (_last_mqtt_connect == 0 ||
|
||||
millis() - _last_mqtt_connect > AIO_THROTTLE_RECONNECT_INTERVAL) {
|
||||
_last_mqtt_connect = millis();
|
||||
switch (_mqtt->connect(_username, _key)) {
|
||||
switch(_mqtt->connect(_username, _key)) {
|
||||
case 0:
|
||||
return AIO_CONNECTED;
|
||||
case 1: // invalid mqtt protocol
|
||||
case 2: // client id rejected
|
||||
case 4: // malformed user/pass
|
||||
case 5: // unauthorized
|
||||
case 1: // invalid mqtt protocol
|
||||
case 2: // client id rejected
|
||||
case 4: // malformed user/pass
|
||||
case 5: // unauthorized
|
||||
return AIO_CONNECT_FAILED;
|
||||
case 3: // mqtt service unavailable
|
||||
case 6: // throttled
|
||||
case 7: // banned -> all MQTT bans are temporary, so eventual retry is
|
||||
// permitted
|
||||
// delay to prevent fast reconnects and fast returns (backward
|
||||
// compatibility)
|
||||
if (!fail_fast)
|
||||
delay(AIO_THROTTLE_RECONNECT_INTERVAL);
|
||||
case 3: // mqtt service unavailable
|
||||
case 6: // throttled
|
||||
case 7: // banned -> all MQTT bans are temporary, so eventual retry is permitted
|
||||
// delay to prevent fast reconnects
|
||||
delay(AIO_THROTTLE_RECONNECT_INTERVAL);
|
||||
return AIO_DISCONNECTED;
|
||||
default:
|
||||
return AIO_DISCONNECTED;
|
||||
}
|
||||
}
|
||||
return AIO_DISCONNECTED;
|
||||
}
|
||||
|
|
|
|||
192
src/AdafruitIO.h
192
src/AdafruitIO.h
|
|
@ -1,174 +1,96 @@
|
|||
/*!
|
||||
* @file AdafruitIO.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_H
|
||||
#define ADAFRUITIO_H
|
||||
|
||||
#include "AdafruitIO_Dashboard.h"
|
||||
#include "AdafruitIO_Data.h"
|
||||
#include "Arduino.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "AdafruitIO_Feed.h"
|
||||
#include "AdafruitIO_Group.h"
|
||||
#include "AdafruitIO_Time.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Arduino.h"
|
||||
#include "AdafruitIO_Dashboard.h"
|
||||
#include "AdafruitIO_Data.h"
|
||||
#include "ArduinoHttpClient.h"
|
||||
#include "util/AdafruitIO_Board.h"
|
||||
|
||||
#ifndef ADAFRUIT_MQTT_VERSION_MAJOR
|
||||
#error \
|
||||
"This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
|
||||
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
|
||||
#endif
|
||||
|
||||
#if ADAFRUIT_MQTT_VERSION_MAJOR == 1 && ADAFRUIT_MQTT_VERSION_MINOR < 0
|
||||
#error \
|
||||
"This sketch requires Adafruit MQTT Library v1.0.0 or higher. Please install or upgrade using the Library Manager."
|
||||
#if ADAFRUIT_MQTT_VERSION_MAJOR == 0 && ADAFRUIT_MQTT_VERSION_MINOR < 17
|
||||
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
|
||||
#endif
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with Adafruit IO
|
||||
*/
|
||||
/**************************************************************************/
|
||||
|
||||
class AdafruitIO {
|
||||
/**
|
||||
* @brief AdafruitIO_Feed addition.
|
||||
* @relates AdafruitIO_Feed
|
||||
*/
|
||||
|
||||
friend class AdafruitIO_Feed;
|
||||
|
||||
/**
|
||||
* @brief AdafruitIO_Group addition.
|
||||
* @relates AdafruitIO_Group
|
||||
*/
|
||||
friend class AdafruitIO_Group;
|
||||
|
||||
/**
|
||||
* @brief AdafruitIO_Dashboard addition.
|
||||
* @relates AdafruitIO_Dashboard
|
||||
*/
|
||||
friend class AdafruitIO_Dashboard;
|
||||
|
||||
/**
|
||||
* @brief AdafruitIO_Block addition.
|
||||
* @relates AdafruitIO_Block
|
||||
*/
|
||||
friend class AdafruitIO_Block;
|
||||
|
||||
/**
|
||||
* @brief AdafruitIO_Time addition.
|
||||
* @relates AdafruitIO_Time
|
||||
*/
|
||||
friend class AdafruitIO_Time;
|
||||
public:
|
||||
AdafruitIO(const char *user, const char *key);
|
||||
virtual ~AdafruitIO();
|
||||
|
||||
public:
|
||||
AdafruitIO(const char *user, const char *key);
|
||||
virtual ~AdafruitIO();
|
||||
void connect();
|
||||
|
||||
void connect();
|
||||
void wifi_disconnect();
|
||||
aio_status_t run(uint16_t busywait_ms = 0, bool fail_fast = false);
|
||||
void run(uint16_t busywait_ms = 0);
|
||||
|
||||
AdafruitIO_Feed *feed(const char *name);
|
||||
AdafruitIO_Feed *feed(const char *name, const char *owner);
|
||||
AdafruitIO_Group *group(const char *name);
|
||||
AdafruitIO_Dashboard *dashboard(const char *name);
|
||||
AdafruitIO_Time *time(aio_time_format_t format);
|
||||
AdafruitIO_Feed* feed(const char *name);
|
||||
AdafruitIO_Group* group(const char *name);
|
||||
AdafruitIO_Dashboard* dashboard(const char *name);
|
||||
|
||||
const __FlashStringHelper *statusText();
|
||||
const __FlashStringHelper* statusText();
|
||||
|
||||
aio_status_t status();
|
||||
/********************************************************************/
|
||||
/*!
|
||||
@brief Returns network module status.
|
||||
@return 0
|
||||
*/
|
||||
/*******************************************************************/
|
||||
virtual aio_status_t networkStatus() = 0;
|
||||
aio_status_t status();
|
||||
virtual aio_status_t networkStatus() = 0;
|
||||
aio_status_t mqttStatus();
|
||||
|
||||
/********************************************************************/
|
||||
/*!
|
||||
@brief Returns MQTT connection status.
|
||||
*/
|
||||
/*******************************************************************/
|
||||
aio_status_t mqttStatus(bool fail_fast = false);
|
||||
char* boardID();
|
||||
const char* boardType();
|
||||
char* version();
|
||||
char* userAgent();
|
||||
virtual const char* connectionType() = 0;
|
||||
|
||||
char *boardID();
|
||||
const char *boardType();
|
||||
char *version();
|
||||
char *userAgent();
|
||||
protected:
|
||||
virtual void _connect() = 0;
|
||||
aio_status_t _status = AIO_IDLE;
|
||||
uint32_t _last_ping = 0;
|
||||
|
||||
/********************************************************************/
|
||||
/*!
|
||||
@brief Returns the Adafruit IO network module connection type.
|
||||
@return 0
|
||||
*/
|
||||
/*******************************************************************/
|
||||
virtual const char *connectionType() = 0;
|
||||
Adafruit_MQTT *_mqtt;
|
||||
HttpClient *_http;
|
||||
|
||||
protected:
|
||||
/********************************************************************/
|
||||
/*!
|
||||
@brief Establishes a connection with the Adafruit IO MQTT broker.
|
||||
@return 0
|
||||
*/
|
||||
/*******************************************************************/
|
||||
virtual void _connect() = 0;
|
||||
char _version[10];
|
||||
|
||||
/******************************************************/
|
||||
/*!
|
||||
@brief Disconnects from the Adafruit IO MQTT broker.
|
||||
@return 0
|
||||
*/
|
||||
/*****************************************************/
|
||||
virtual void _disconnect() = 0;
|
||||
const char *_host = "io.adafruit.com";
|
||||
uint16_t _mqtt_port = 8883;
|
||||
uint16_t _http_port = 443;
|
||||
|
||||
aio_status_t _status = AIO_IDLE; /*!< Adafruit IO Connection Status */
|
||||
uint32_t _last_ping =
|
||||
0; /*!< Previous time when client pinged Adafruit IO, in milliseconds */
|
||||
uint32_t _last_mqtt_connect = 0; /*!< Previous time when client connected to
|
||||
Adafruit IO, in milliseconds */
|
||||
uint16_t _packetread_timeout;
|
||||
|
||||
Adafruit_MQTT *_mqtt; /*!< Reference to Adafruit_MQTT, _mqtt. */
|
||||
HttpClient *_http; /*!< Reference to HTTPClient, _http */
|
||||
const char *_username;
|
||||
const char *_key;
|
||||
|
||||
char _version[10]; /*!< Adafruit IO Arduino library version */
|
||||
char *_err_topic;
|
||||
char *_throttle_topic;
|
||||
char *_user_agent;
|
||||
|
||||
const char *_host = "io.adafruit.com"; /*!< Adafruit IO URL */
|
||||
uint16_t _mqtt_port = 8883; /*!< Adafruit IO MQTT SSL port */
|
||||
uint16_t _mqtt_eth_port =
|
||||
1883; /*!< Adafruit IO MQTT insecure port, used by ethernet clients. */
|
||||
uint16_t _http_port = 443; /*!< Adafruit IO HTTP SSL port */
|
||||
Adafruit_MQTT_Subscribe *_err_sub;
|
||||
Adafruit_MQTT_Subscribe *_throttle_sub;
|
||||
|
||||
uint16_t _packetread_timeout; /*!< Maximum amount of time to wait before
|
||||
processing packets. */
|
||||
private:
|
||||
void _init();
|
||||
|
||||
const char *_username; /*!< Adafruit IO Username. */
|
||||
const char *_key; /*!< Adafruit IO Key. */
|
||||
|
||||
char *_err_topic; /*!< Adafruit IO MQTT error message topic. */
|
||||
char *_throttle_topic; /*!< Adafruit IO MQTT throttle message topic. */
|
||||
char *_user_agent; /*!< Identifies the Adafruit IO client. */
|
||||
|
||||
Adafruit_MQTT_Subscribe
|
||||
*_err_sub; /*!< Subscription to Adafruit IO Error topic. */
|
||||
Adafruit_MQTT_Subscribe
|
||||
*_throttle_sub; /*!< Subscription to Adafruit IO Throttle topic. */
|
||||
|
||||
private:
|
||||
void _init();
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_H
|
||||
|
|
|
|||
|
|
@ -1,45 +1,27 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Dashboard.cpp
|
||||
*
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "AdafruitIO_Dashboard.h"
|
||||
#include "AdafruitIO.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets Adafruit IO Dashboard instance.
|
||||
@param *io
|
||||
Reference to Adafruit IO class.
|
||||
@param *n
|
||||
Valid username string.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Dashboard::AdafruitIO_Dashboard(AdafruitIO *io, const char *n) {
|
||||
AdafruitIO_Dashboard::AdafruitIO_Dashboard(AdafruitIO *io, const char *n)
|
||||
{
|
||||
_io = io;
|
||||
name = n;
|
||||
}
|
||||
|
||||
AdafruitIO_Dashboard::~AdafruitIO_Dashboard() {}
|
||||
AdafruitIO_Dashboard::~AdafruitIO_Dashboard(){}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Checks if Adafruit IO Dashboard exists.
|
||||
https://io.adafruit.com/api/docs/#return-dashboard
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Dashboard::exists() {
|
||||
bool AdafruitIO_Dashboard::exists()
|
||||
{
|
||||
String url = "/api/v2/";
|
||||
url += _io->_username;
|
||||
url += "/dashboards/";
|
||||
|
|
@ -56,14 +38,8 @@ bool AdafruitIO_Dashboard::exists() {
|
|||
return status == 200;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new dashboard.
|
||||
https://io.adafruit.com/api/docs/#create-a-dashboard
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Dashboard::create() {
|
||||
bool AdafruitIO_Dashboard::create()
|
||||
{
|
||||
String url = "/api/v2/";
|
||||
url += _io->_username;
|
||||
url += "/dashboards";
|
||||
|
|
@ -93,142 +69,60 @@ bool AdafruitIO_Dashboard::create() {
|
|||
return status == 201;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Returns the dashboard owner.
|
||||
@return Adafruit IO username.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
const char *AdafruitIO_Dashboard::user() { return _io->_username; }
|
||||
const char* AdafruitIO_Dashboard::user() {
|
||||
return _io->_username;
|
||||
}
|
||||
|
||||
AdafruitIO *AdafruitIO_Dashboard::io() { return _io; }
|
||||
AdafruitIO* AdafruitIO_Dashboard::io() {
|
||||
return _io;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new toggle block element on a dashboard connected
|
||||
to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Toggle block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ToggleBlock *AdafruitIO_Dashboard::addToggleBlock(AdafruitIO_Feed *feed) {
|
||||
ToggleBlock* AdafruitIO_Dashboard::addToggleBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new ToggleBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new momentary block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Momentary block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
MomentaryBlock *AdafruitIO_Dashboard::addMomentaryBlock(AdafruitIO_Feed *feed) {
|
||||
MomentaryBlock* AdafruitIO_Dashboard::addMomentaryBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new MomentaryBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new slider block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Slider block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
SliderBlock *AdafruitIO_Dashboard::addSliderBlock(AdafruitIO_Feed *feed) {
|
||||
SliderBlock* AdafruitIO_Dashboard::addSliderBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new SliderBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new gauge block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Gauge block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GaugeBlock *AdafruitIO_Dashboard::addGaugeBlock(AdafruitIO_Feed *feed) {
|
||||
GaugeBlock* AdafruitIO_Dashboard::addGaugeBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new GaugeBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new momentary block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Text block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
TextBlock *AdafruitIO_Dashboard::addTextBlock(AdafruitIO_Feed *feed) {
|
||||
TextBlock* AdafruitIO_Dashboard::addTextBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new TextBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new chart block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Chart block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ChartBlock *AdafruitIO_Dashboard::addChartBlock(AdafruitIO_Feed *feed) {
|
||||
ChartBlock* AdafruitIO_Dashboard::addChartBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new ChartBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new color block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Color block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ColorBlock *AdafruitIO_Dashboard::addColorBlock(AdafruitIO_Feed *feed) {
|
||||
ColorBlock* AdafruitIO_Dashboard::addColorBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new ColorBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new map block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Map block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
MapBlock *AdafruitIO_Dashboard::addMapBlock(AdafruitIO_Feed *feed) {
|
||||
MapBlock* AdafruitIO_Dashboard::addMapBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new MapBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new stream block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Stream block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
StreamBlock *AdafruitIO_Dashboard::addStreamBlock(AdafruitIO_Feed *feed) {
|
||||
StreamBlock* AdafruitIO_Dashboard::addStreamBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new StreamBlock(this, feed);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new image block element on a dashboard
|
||||
connected to provided feed.
|
||||
@param *feed
|
||||
Reference to an Adafruit IO feed.
|
||||
@return Image block dashboard element.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ImageBlock *AdafruitIO_Dashboard::addImageBlock(AdafruitIO_Feed *feed) {
|
||||
ImageBlock* AdafruitIO_Dashboard::addImageBlock(AdafruitIO_Feed *feed)
|
||||
{
|
||||
return new ImageBlock(this, feed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,76 +1,62 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Dashboard.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_DASHBOARD_H
|
||||
#define ADAFRUITIO_DASHBOARD_H
|
||||
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "Arduino.h"
|
||||
#include "blocks/ChartBlock.h"
|
||||
#include "blocks/ColorBlock.h"
|
||||
#include "blocks/GaugeBlock.h"
|
||||
#include "blocks/ImageBlock.h"
|
||||
#include "blocks/MapBlock.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "blocks/ToggleBlock.h"
|
||||
#include "blocks/MomentaryBlock.h"
|
||||
#include "blocks/SliderBlock.h"
|
||||
#include "blocks/StreamBlock.h"
|
||||
#include "blocks/GaugeBlock.h"
|
||||
#include "blocks/TextBlock.h"
|
||||
#include "blocks/ToggleBlock.h"
|
||||
#include "blocks/ChartBlock.h"
|
||||
#include "blocks/ColorBlock.h"
|
||||
#include "blocks/MapBlock.h"
|
||||
#include "blocks/StreamBlock.h"
|
||||
#include "blocks/ImageBlock.h"
|
||||
|
||||
// forward declaration
|
||||
class AdafruitIO;
|
||||
class AdafruitIO_Feed;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with Adafruit IO Dashboards.
|
||||
https://io.adafruit.com/api/docs/#dashboards
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_Dashboard {
|
||||
|
||||
public:
|
||||
AdafruitIO_Dashboard(AdafruitIO *io, const char *name);
|
||||
~AdafruitIO_Dashboard();
|
||||
public:
|
||||
AdafruitIO_Dashboard(AdafruitIO *io, const char *name);
|
||||
~AdafruitIO_Dashboard();
|
||||
|
||||
const char *name; /*!< Dashboard name. */
|
||||
const char *user(); /*!< Dashboard owner's Adafruit IO username. */
|
||||
const char* name;
|
||||
const char* user();
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates an instance of AdafruitIO.
|
||||
@return True
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO *io();
|
||||
AdafruitIO* io();
|
||||
|
||||
bool exists();
|
||||
bool create();
|
||||
bool exists();
|
||||
bool create();
|
||||
|
||||
ToggleBlock *addToggleBlock(AdafruitIO_Feed *feed);
|
||||
MomentaryBlock *addMomentaryBlock(AdafruitIO_Feed *feed);
|
||||
SliderBlock *addSliderBlock(AdafruitIO_Feed *feed);
|
||||
GaugeBlock *addGaugeBlock(AdafruitIO_Feed *feed);
|
||||
TextBlock *addTextBlock(AdafruitIO_Feed *feed);
|
||||
ChartBlock *addChartBlock(AdafruitIO_Feed *feed);
|
||||
ColorBlock *addColorBlock(AdafruitIO_Feed *feed);
|
||||
MapBlock *addMapBlock(AdafruitIO_Feed *feed);
|
||||
StreamBlock *addStreamBlock(AdafruitIO_Feed *feed);
|
||||
ImageBlock *addImageBlock(AdafruitIO_Feed *feed);
|
||||
ToggleBlock* addToggleBlock(AdafruitIO_Feed *feed);
|
||||
MomentaryBlock* addMomentaryBlock(AdafruitIO_Feed *feed);
|
||||
SliderBlock* addSliderBlock(AdafruitIO_Feed *feed);
|
||||
GaugeBlock* addGaugeBlock(AdafruitIO_Feed *feed);
|
||||
TextBlock* addTextBlock(AdafruitIO_Feed *feed);
|
||||
ChartBlock* addChartBlock(AdafruitIO_Feed *feed);
|
||||
ColorBlock* addColorBlock(AdafruitIO_Feed *feed);
|
||||
MapBlock* addMapBlock(AdafruitIO_Feed *feed);
|
||||
StreamBlock* addStreamBlock(AdafruitIO_Feed *feed);
|
||||
ImageBlock* addImageBlock(AdafruitIO_Feed *feed);
|
||||
|
||||
private:
|
||||
AdafruitIO *_io;
|
||||
|
||||
private:
|
||||
AdafruitIO *_io; /*!< Reference to Adafruit IO client */
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_DASHBOARD_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,106 +1,96 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Data.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece, Adam Bachman
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_DATA_H
|
||||
#define ADAFRUITIO_DATA_H
|
||||
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "Arduino.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
|
||||
// forward decl
|
||||
class AdafruitIO_Feed;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with Adafruit IO Data Records.
|
||||
https://io.adafruit.com/api/docs/#data
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_Data {
|
||||
|
||||
public:
|
||||
AdafruitIO_Data();
|
||||
AdafruitIO_Data(AdafruitIO_Feed *f);
|
||||
AdafruitIO_Data(AdafruitIO_Feed *f, char *csv);
|
||||
AdafruitIO_Data(AdafruitIO_Feed *f, const char *csv);
|
||||
AdafruitIO_Data(const char *f);
|
||||
AdafruitIO_Data(const char *f, char *csv);
|
||||
public:
|
||||
AdafruitIO_Data();
|
||||
AdafruitIO_Data(AdafruitIO_Feed *f);
|
||||
AdafruitIO_Data(AdafruitIO_Feed *f, char *csv);
|
||||
AdafruitIO_Data(AdafruitIO_Feed *f, const char *csv);
|
||||
AdafruitIO_Data(const char *f);
|
||||
AdafruitIO_Data(const char *f, char *csv);
|
||||
|
||||
bool setCSV(char *csv);
|
||||
bool setCSV(const char *csv);
|
||||
bool setCSV(char *csv);
|
||||
bool setCSV(const char *csv);
|
||||
|
||||
void setLocation(double lat, double lon, double ele = 0);
|
||||
void setLocation(double lat, double lon, double ele=0);
|
||||
|
||||
void setValue(const char *value, double lat = 0, double lon = 0,
|
||||
double ele = 0);
|
||||
void setValue(char *value, double lat = 0, double lon = 0, double ele = 0);
|
||||
void setValue(bool value, double lat = 0, double lon = 0, double ele = 0);
|
||||
void setValue(String value, double lat = 0, double lon = 0, double ele = 0);
|
||||
void setValue(int value, double lat = 0, double lon = 0, double ele = 0);
|
||||
void setValue(unsigned int value, double lat = 0, double lon = 0,
|
||||
double ele = 0);
|
||||
void setValue(long value, double lat = 0, double lon = 0, double ele = 0);
|
||||
void setValue(unsigned long value, double lat = 0, double lon = 0,
|
||||
double ele = 0);
|
||||
void setValue(float value, double lat = 0, double lon = 0, double ele = 0,
|
||||
int precision = 6);
|
||||
void setValue(double value, double lat = 0, double lon = 0, double ele = 0,
|
||||
int precision = 6);
|
||||
void setValue(const char *value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(char *value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(bool value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(String value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(int value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(unsigned int value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(long value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(unsigned long value, double lat=0, double lon=0, double ele=0);
|
||||
void setValue(float value, double lat=0, double lon=0, double ele=0, int precision=6);
|
||||
void setValue(double value, double lat=0, double lon=0, double ele=0, int precision=6);
|
||||
|
||||
char *feedName();
|
||||
char* feedName();
|
||||
|
||||
char *value();
|
||||
char *toChar();
|
||||
String toString();
|
||||
char* value();
|
||||
char* toChar();
|
||||
String toString();
|
||||
|
||||
bool toBool();
|
||||
bool isTrue();
|
||||
bool isFalse();
|
||||
bool toBool();
|
||||
bool isTrue();
|
||||
bool isFalse();
|
||||
|
||||
int toInt();
|
||||
int toPinLevel();
|
||||
unsigned int toUnsignedInt();
|
||||
int toInt();
|
||||
int toPinLevel();
|
||||
unsigned int toUnsignedInt();
|
||||
|
||||
double toDouble();
|
||||
float toFloat();
|
||||
double toDouble();
|
||||
float toFloat();
|
||||
|
||||
long toLong();
|
||||
unsigned long toUnsignedLong();
|
||||
long toLong();
|
||||
unsigned long toUnsignedLong();
|
||||
|
||||
int toRed();
|
||||
int toGreen();
|
||||
int toBlue();
|
||||
long toNeoPixel();
|
||||
int toRed();
|
||||
int toGreen();
|
||||
int toBlue();
|
||||
long toNeoPixel();
|
||||
|
||||
char *toCSV();
|
||||
char *charFromDouble(double d, int precision = 6);
|
||||
char* toCSV();
|
||||
char* charFromDouble(double d, int precision=6);
|
||||
|
||||
double lat();
|
||||
double lon();
|
||||
double ele();
|
||||
double lat();
|
||||
double lon();
|
||||
double ele();
|
||||
|
||||
AdafruitIO_Data *next_data; /*!< next data value in Adafruit IO data record */
|
||||
AdafruitIO_Data *next_data;
|
||||
|
||||
private:
|
||||
char _feed[AIO_FEED_NAME_LENGTH];
|
||||
private:
|
||||
|
||||
char _csv[AIO_CSV_LENGTH];
|
||||
char _value[AIO_DATA_LENGTH];
|
||||
char _feed[AIO_FEED_NAME_LENGTH];
|
||||
|
||||
double _lat, _lon, _ele;
|
||||
char _csv[AIO_CSV_LENGTH];
|
||||
char _value[AIO_DATA_LENGTH];
|
||||
|
||||
double _lat,
|
||||
_lon,
|
||||
_ele;
|
||||
|
||||
bool _parseCSV();
|
||||
|
||||
bool _parseCSV();
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_DATA_H
|
||||
|
|
|
|||
|
|
@ -1,169 +1,107 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Definitions.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_DEFINITIONS_H_
|
||||
#define ADAFRUITIO_DEFINITIONS_H_
|
||||
|
||||
#define ADAFRUITIO_VERSION_MAJOR 4 ///< Adafruit IO Arduino Major Semvar
|
||||
#define ADAFRUITIO_VERSION_MINOR 2 ///< Adafruit IO Arduino Minor Semvar
|
||||
#define ADAFRUITIO_VERSION_PATCH 1 ///< Adafruit IO Arduino Patch Semvar
|
||||
#define ADAFRUITIO_VERSION_MAJOR 2
|
||||
#define ADAFRUITIO_VERSION_MINOR 6
|
||||
#define ADAFRUITIO_VERSION_PATCH 0
|
||||
|
||||
// forward declaration
|
||||
class AdafruitIO_Data;
|
||||
|
||||
typedef void (*AdafruitIODataCallbackType)(
|
||||
AdafruitIO_Data *data); /*!< Data callback type */
|
||||
typedef void (*AdafruitIODataCallbackType)(AdafruitIO_Data *data);
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class that contains methods for Adafruit IO MQTT callbacks.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIOGroupCallback {
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up MQTT Group callbacks.
|
||||
@param f
|
||||
Valid Adafruit IO feed key.
|
||||
@param cb
|
||||
Adafruit IO MQTT callback.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIOGroupCallback(const char *f, AdafruitIODataCallbackType cb) {
|
||||
feed = f;
|
||||
dataCallback = cb;
|
||||
next_cb = 0;
|
||||
}
|
||||
public:
|
||||
AdafruitIOGroupCallback(const char *f, AdafruitIODataCallbackType cb) {
|
||||
feed = f;
|
||||
dataCallback = cb;
|
||||
next_cb = 0;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up MQTT Group callbacks.
|
||||
@param cb
|
||||
Adafruit IO MQTT callback.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIOGroupCallback(AdafruitIODataCallbackType cb) {
|
||||
feed = 0;
|
||||
dataCallback = cb;
|
||||
next_cb = 0;
|
||||
}
|
||||
AdafruitIOGroupCallback(AdafruitIODataCallbackType cb) {
|
||||
feed = 0;
|
||||
dataCallback = cb;
|
||||
next_cb = 0;
|
||||
}
|
||||
|
||||
const char *feed;
|
||||
AdafruitIODataCallbackType dataCallback;
|
||||
AdafruitIOGroupCallback *next_cb;
|
||||
|
||||
const char *feed; /*!< Adafruit IO feed name. */
|
||||
AdafruitIODataCallbackType
|
||||
dataCallback; /*!< data carried by an AdafruitIOGroupCallback. */
|
||||
AdafruitIOGroupCallback *next_cb; /*!< Next callback number. */
|
||||
};
|
||||
|
||||
// Uncomment/comment to turn on/off debug output messages.
|
||||
// #define AIO_DEBUG
|
||||
// Uncomment/comment to turn on/off error output
|
||||
// #define AIO_ERROR
|
||||
#define AIO_DEBUG
|
||||
// uncomment/comment to turn on/off error output
|
||||
#define AIO_ERROR
|
||||
|
||||
// note: if you're using something like Zero or Due, change the below to
|
||||
// SerialUSB
|
||||
#define AIO_PRINTER Serial ///< Where debug messages will be printed
|
||||
// where debug messages will be printed
|
||||
#define AIO_PRINTER Serial
|
||||
// If using something like Zero or Due, change the above to SerialUSB
|
||||
|
||||
// Define actual debug output functions when necessary.
|
||||
#ifdef AIO_DEBUG
|
||||
#define AIO_DEBUG_PRINT(...) \
|
||||
{ AIO_PRINTER.print(__VA_ARGS__); } ///< Prints debug output.
|
||||
#define AIO_DEBUG_PRINTLN(...) \
|
||||
{ AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from debug output.
|
||||
#define AIO_DEBUG_PRINT(...) { AIO_PRINTER.print(__VA_ARGS__); }
|
||||
#define AIO_DEBUG_PRINTLN(...) { AIO_PRINTER.println(__VA_ARGS__); }
|
||||
#else
|
||||
#define AIO_DEBUG_PRINT(...) \
|
||||
{} ///< Prints debug output
|
||||
#define AIO_DEBUG_PRINTLN(...) \
|
||||
{} ///< Prints line from debug output.
|
||||
#define AIO_DEBUG_PRINT(...) {}
|
||||
#define AIO_DEBUG_PRINTLN(...) {}
|
||||
#endif
|
||||
|
||||
// Define actual error output functions when necessary.
|
||||
#ifdef AIO_ERROR
|
||||
#define AIO_ERROR_PRINT(...) \
|
||||
{ AIO_PRINTER.print(__VA_ARGS__); } ///< Prints error output
|
||||
#define AIO_ERROR_PRINTLN(...) \
|
||||
{ AIO_PRINTER.println(__VA_ARGS__); } ///< Prints line from error output
|
||||
#define AIO_ERROR_PRINT(...) { AIO_PRINTER.print(__VA_ARGS__); }
|
||||
#define AIO_ERROR_PRINTLN(...) { AIO_PRINTER.println(__VA_ARGS__); }
|
||||
#else
|
||||
#define AIO_ERROR_PRINT(...) \
|
||||
{} ///< Prints error output.
|
||||
#define AIO_ERROR_PRINTLN(...) \
|
||||
{} ///< Prints line from error output.
|
||||
#define AIO_ERROR_PRINT(...) {}
|
||||
#define AIO_ERROR_PRINTLN(...) {}
|
||||
#endif
|
||||
|
||||
#define AIO_PING_INTERVAL 60000 ///< Adafruit IO Ping Interval, in milliseconds
|
||||
#define AIO_THROTTLE_RECONNECT_INTERVAL \
|
||||
60000 ///< Time to wait between re-connecting to Adafruit IO after throttled
|
||||
#define AIO_MQTT_CONNECTION_TIMEOUT \
|
||||
60000 ///< Time to wait for a successful reconnection after MQTT disconnect
|
||||
#define AIO_NET_CONNECTION_TIMEOUT \
|
||||
60000 ///< Time to wait for a successful reconnection after network disconnect
|
||||
#define AIO_NET_DISCONNECT_WAIT \
|
||||
300 ///< Time to wait for a net disconnect to take effect
|
||||
#define AIO_PING_INTERVAL 60000
|
||||
#define AIO_THROTTLE_RECONNECT_INTERVAL 60000
|
||||
|
||||
#define AIO_ERROR_TOPIC "/errors" ///< Adafruit IO Error MQTT Topic
|
||||
#define AIO_THROTTLE_TOPIC "/throttle" ///< Adafruit IO Throttle MQTT Topic
|
||||
#define AIO_ERROR_TOPIC "/errors"
|
||||
#define AIO_THROTTLE_TOPIC "/throttle"
|
||||
|
||||
// latest fingerprint can be generated with
|
||||
// echo | openssl s_client -connect io.adafruit.com:443 | openssl x509
|
||||
// -fingerprint -noout
|
||||
#define AIO_SSL_FINGERPRINT \
|
||||
"47 D2 CB 14 DF 38 97 59 C6 65 1A 1F 3E 00 1E 53 CC A5 17 E0" ///< Latest
|
||||
///< Adafruit IO
|
||||
///< SSL
|
||||
///< Fingerprint
|
||||
// echo | openssl s_client -connect io.adafruit.com:443 |& openssl x509 -fingerprint -noout
|
||||
#define AIO_SSL_FINGERPRINT "77 00 54 2D DA E7 D8 03 27 31 23 99 EB 27 DB CB A5 4C 57 18"
|
||||
|
||||
#define AIO_FEED_NAME_LENGTH \
|
||||
258 ///< Maximum length of an Adafruit IO Feed: Name; 128 + 1 + 128 for the
|
||||
///< group, a dot, and actual feed name.
|
||||
#define AIO_FEED_NAME_LENGTH 20
|
||||
#define AIO_DATA_LENGTH 45
|
||||
#define AIO_CSV_LENGTH 150
|
||||
|
||||
#define AIO_DATA_LENGTH \
|
||||
45 ///< Maximum length of data sent/recieved from Adafruit IO
|
||||
#define AIO_CSV_LENGTH \
|
||||
AIO_FEED_NAME_LENGTH + \
|
||||
4 ///< Maximum comma-separated-value length from Adafruit IO
|
||||
|
||||
/** aio_status_t offers 13 status states */
|
||||
typedef enum {
|
||||
|
||||
AIO_IDLE = 0, // Waiting for connection establishement
|
||||
AIO_NET_DISCONNECTED = 1, // Network disconnected
|
||||
AIO_DISCONNECTED = 2, // Disconnected from Adafruit IO
|
||||
AIO_FINGERPRINT_UNKOWN = 3, // Unknown AIO_SSL_FINGERPRINT
|
||||
// CONNECTING
|
||||
AIO_IDLE = 0,
|
||||
AIO_NET_DISCONNECTED = 1,
|
||||
AIO_DISCONNECTED = 2,
|
||||
AIO_FINGERPRINT_UNKOWN = 3,
|
||||
|
||||
AIO_NET_CONNECT_FAILED = 10, // Failed to connect to network
|
||||
AIO_CONNECT_FAILED = 11, // Failed to connect to Adafruit IO
|
||||
AIO_FINGERPRINT_INVALID = 12, // Unknown AIO_SSL_FINGERPRINT
|
||||
AIO_AUTH_FAILED = 13, // Invalid Adafruit IO login credentials provided.
|
||||
AIO_SSID_INVALID =
|
||||
14, // SSID is "" or otherwise invalid, connection not attempted
|
||||
// FAILURE
|
||||
AIO_NET_CONNECT_FAILED = 10,
|
||||
AIO_CONNECT_FAILED = 11,
|
||||
AIO_FINGERPRINT_INVALID = 12,
|
||||
AIO_AUTH_FAILED = 13,
|
||||
|
||||
AIO_NET_CONNECTED = 20, // Connected to Adafruit IO
|
||||
AIO_CONNECTED = 21, // Connected to network
|
||||
AIO_CONNECTED_INSECURE = 22, // Insecurely (non-SSL) connected to network
|
||||
AIO_FINGERPRINT_UNSUPPORTED = 23, // Unsupported AIO_SSL_FINGERPRINT
|
||||
AIO_FINGERPRINT_VALID = 24 // Valid AIO_SSL_FINGERPRINT
|
||||
// SUCCESS
|
||||
AIO_NET_CONNECTED = 20,
|
||||
AIO_CONNECTED = 21,
|
||||
AIO_CONNECTED_INSECURE = 22,
|
||||
AIO_FINGERPRINT_UNSUPPORTED = 23,
|
||||
AIO_FINGERPRINT_VALID = 24
|
||||
|
||||
} aio_status_t;
|
||||
|
||||
/** Three different types of MQTT time feeds from IO */
|
||||
typedef enum {
|
||||
|
||||
AIO_TIME_SECONDS = 0, // Seconds MQTT feed
|
||||
AIO_TIME_MILLIS = 1, // Milisecond MQTT feed
|
||||
AIO_TIME_ISO = 2 // ISO8601 MQTT Feed
|
||||
|
||||
} aio_time_format_t;
|
||||
|
||||
#endif /* ADAFRUITIO_DEFINITIONS_H_ */
|
||||
|
|
|
|||
|
|
@ -1,114 +1,68 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Ethernet.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_ETHERNET_H
|
||||
#define ADAFRUITIO_ETHERNET_H
|
||||
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
#include "Arduino.h"
|
||||
#include <SPI.h>
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
|
||||
#include <Dhcp.h>
|
||||
#include <Dns.h>
|
||||
#include <Ethernet.h>
|
||||
#include <Ethernet2.h>
|
||||
#include <EthernetClient.h>
|
||||
#include <Dns.h>
|
||||
#include <Dhcp.h>
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interfacing with the Adafruit Ethernet FeatherWing
|
||||
*/
|
||||
/**************************************************************************/
|
||||
// all logic in .h to avoid auto compile
|
||||
class AdafruitIO_Ethernet : public AdafruitIO {
|
||||
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Instanciates an Adafruit Ethernet FeatherWing.
|
||||
@param *user
|
||||
Reference to a valid Adafruit IO Username.
|
||||
@param *key
|
||||
Reference to a valid Adafruit IO Key.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Ethernet(const char *user, const char *key)
|
||||
: AdafruitIO(user, key) {
|
||||
_client = new EthernetClient();
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_eth_port, _username,
|
||||
_key);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Checks the connection status between the Ethernet
|
||||
FeatherWing and Adafruit IO
|
||||
@return True if connected to Adafruit IO, otherwise False.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aio_status_t networkStatus() {
|
||||
if (_status == AIO_NET_CONNECTED)
|
||||
return _status;
|
||||
|
||||
_connect();
|
||||
return _status;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Defines network module type.
|
||||
@return String "ethernet_wing"
|
||||
*/
|
||||
/**************************************************************************/
|
||||
const char *connectionType() { return "ethernet_wing"; }
|
||||
|
||||
protected:
|
||||
byte _mac[6] = {0xDE, 0xAD, 0xBE,
|
||||
0xEF, 0xFE, 0xED}; /*!< Ethernet FeatherWing MAC Address */
|
||||
|
||||
EthernetClient *_client; /*!< Reference to EthernetClient, _client */
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Attempts to connect Ethernet FeatherWing to Adafruit IO
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _connect() {
|
||||
if (Ethernet.begin(_mac) == 0) {
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
|
||||
AIO_DEBUG_PRINTLN("Ethernet FeatherWing not found! Please recheck "
|
||||
"wiring connections.");
|
||||
while (true)
|
||||
delay(1); // do nothing, no point running without Ethernet hardware
|
||||
}
|
||||
} else {
|
||||
_status = AIO_NET_CONNECTED;
|
||||
public:
|
||||
AdafruitIO_Ethernet(const char *user, const char *key):AdafruitIO(user, key)
|
||||
{
|
||||
_client = new EthernetClient();
|
||||
_mqtt = new Adafruit_MQTT_Client(_client, _host, _mqtt_port);
|
||||
_http = new HttpClient(*_client, _host, _http_port);
|
||||
}
|
||||
|
||||
aio_status_t networkStatus()
|
||||
{
|
||||
if(_status == AIO_NET_CONNECTED)
|
||||
return _status;
|
||||
|
||||
_connect();
|
||||
return _status;
|
||||
}
|
||||
|
||||
const char* connectionType()
|
||||
{
|
||||
return "ethernet_wing";
|
||||
}
|
||||
|
||||
protected:
|
||||
byte _mac[6] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
|
||||
uint16_t _port = 1883;
|
||||
|
||||
EthernetClient *_client;
|
||||
|
||||
void _connect()
|
||||
{
|
||||
if(Ethernet.begin(_mac) == 0)
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
else
|
||||
_status = AIO_NET_CONNECTED;
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnect the ethernet connection.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _disconnect() {
|
||||
_client->stop();
|
||||
delay(AIO_NET_DISCONNECT_WAIT);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_ETHERNET_H
|
||||
|
|
|
|||
|
|
@ -12,129 +12,82 @@
|
|||
#ifndef ADAFRUITIO_FONA_H
|
||||
#define ADAFRUITIO_FONA_H
|
||||
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_FONA.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_FONA.h"
|
||||
#include "Arduino.h"
|
||||
#include <SoftwareSerial.h>
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_FONA.h"
|
||||
#include "AdafruitIO.h"
|
||||
#include "Adafruit_MQTT_FONA.h"
|
||||
|
||||
#define FONA_RX 9
|
||||
#define FONA_TX 8
|
||||
#define FONA_RX 9
|
||||
#define FONA_TX 8
|
||||
#define FONA_RST 4
|
||||
#define FONA_RI 7
|
||||
#define FONA_RI 7
|
||||
#define FONA_BAUD 4800
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interfacing with an Adafruit FONA Ceullar Module
|
||||
*/
|
||||
/**************************************************************************/
|
||||
// all logic in .h to avoid auto compile
|
||||
class AdafruitIO_FONA : public AdafruitIO {
|
||||
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initializes a new AdafruitIO_FONA instance.
|
||||
@param user
|
||||
GRPS APN username
|
||||
@param key
|
||||
GPRS APN password
|
||||
public:
|
||||
AdafruitIO_FONA(const char *user, const char *key):AdafruitIO(user, key)
|
||||
{
|
||||
_serial = new SoftwareSerial(FONA_TX, FONA_RX);
|
||||
_fona = new Adafruit_FONA(FONA_RST);
|
||||
_mqtt = new Adafruit_MQTT_FONA(_fona, _host, _mqtt_port);
|
||||
_packetread_timeout = 500;
|
||||
}
|
||||
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_FONA(const char *user, const char *key) : AdafruitIO(user, key) {
|
||||
_serial = new SoftwareSerial(FONA_TX, FONA_RX);
|
||||
_fona = new Adafruit_FONA(FONA_RST);
|
||||
_mqtt = new Adafruit_MQTT_FONA(_fona, _host, _mqtt_port);
|
||||
_packetread_timeout = 500;
|
||||
}
|
||||
void setAPN(FONAFlashStringPtr apn, FONAFlashStringPtr username=0, FONAFlashStringPtr password=0)
|
||||
{
|
||||
_fona->setGPRSNetworkSettings(apn, username, password);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets Adafruit Fona APN name
|
||||
@param apn
|
||||
GPRS APN name.
|
||||
@param username
|
||||
GPRS APN username.
|
||||
@param password
|
||||
GRPS APN password.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void setAPN(FONAFlashStringPtr apn, FONAFlashStringPtr username = 0,
|
||||
FONAFlashStringPtr password = 0) {
|
||||
_fona->setGPRSNetworkSettings(apn, username, password);
|
||||
}
|
||||
aio_status_t AdafruitIO_FONA::networkStatus()
|
||||
{
|
||||
// return if in a failed state
|
||||
if(_status == AIO_NET_CONNECT_FAILED)
|
||||
return _status;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Returns network connection status.
|
||||
@return Adafruit IO Network status, aio_status_t
|
||||
*/
|
||||
/**************************************************************************/
|
||||
aio_status_t AdafruitIO_FONA::networkStatus() {
|
||||
// return if in a failed state
|
||||
if (_status == AIO_NET_CONNECT_FAILED)
|
||||
return _status;
|
||||
// if we are connected, return
|
||||
if(_fona->GPRSstate())
|
||||
return AIO_NET_CONNECTED;
|
||||
|
||||
// if we are connected, return
|
||||
if (_fona->GPRSstate())
|
||||
// wait for connection to network
|
||||
if(_fona->getNetworkStatus() != 1)
|
||||
return AIO_NET_DISCONNECTED;
|
||||
|
||||
_fona->enableGPRS(true);
|
||||
return AIO_NET_CONNECTED;
|
||||
|
||||
// wait for connection to network
|
||||
if (_fona->getNetworkStatus() != 1)
|
||||
return AIO_NET_DISCONNECTED;
|
||||
|
||||
_fona->enableGPRS(true);
|
||||
return AIO_NET_CONNECTED;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Returns network module type.
|
||||
@return Network module name, "fona"
|
||||
*/
|
||||
/**************************************************************************/
|
||||
const char *connectionType() { return "fona"; }
|
||||
|
||||
protected:
|
||||
uint16_t _mqtt_port = 1883; /*!< Adafruit IO insecure MQTT port. */
|
||||
|
||||
SoftwareSerial *_serial; /*!< an instance of SoftwareSerial. */
|
||||
Adafruit_FONA *_fona; /*!< an instance of Adafruit_FONA. */
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Establishes a connection to Adafruit IO.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _connect() {
|
||||
// set software serial baud rate
|
||||
_serial->begin(FONA_BAUD);
|
||||
|
||||
// if fona can't be found, bail
|
||||
if (!_fona->begin(*_serial)) {
|
||||
_status = AIO_NET_CONNECT_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
// disable cme error reporting
|
||||
_serial->println("AT+CMEE=2");
|
||||
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Disconnects from Adafruit IO and the cellular network.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void _disconnect() {
|
||||
if (!_fona->enableGPRS(false)) {
|
||||
AIO_DEBUG_PRINTLN("Failed to turn off GPRS.");
|
||||
const char* connectionType()
|
||||
{
|
||||
return "fona";
|
||||
}
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint16_t _mqtt_port = 1883;
|
||||
|
||||
SoftwareSerial *_serial;
|
||||
Adafruit_FONA *_fona;
|
||||
|
||||
void _connect()
|
||||
{
|
||||
// set software serial baud rate
|
||||
_serial->begin(FONA_BAUD);
|
||||
|
||||
// if fona can't be found, bail
|
||||
if(! _fona->begin(*_serial)) {
|
||||
_status = AIO_NET_CONNECT_FAILED;
|
||||
return;
|
||||
}
|
||||
|
||||
// disable cme error reporting
|
||||
_serial->println("AT+CMEE=2");
|
||||
|
||||
_status = AIO_NET_DISCONNECTED;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_FONA_H
|
||||
|
|
|
|||
|
|
@ -1,297 +1,122 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Feed.cpp
|
||||
*
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece, Adam Bachman
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "AdafruitIO_Feed.h"
|
||||
#include "AdafruitIO.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new instance of an Adafruit IO Feed.
|
||||
@param *io
|
||||
Reference to AdafruitIO.
|
||||
@param *n
|
||||
Valid feed name.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n)
|
||||
: AdafruitIO_MQTT() {
|
||||
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n):AdafruitIO_MQTT()
|
||||
{
|
||||
_io = io;
|
||||
name = n;
|
||||
owner = _io->_username;
|
||||
_sub = 0;
|
||||
_pub = 0;
|
||||
_get_pub = 0;
|
||||
_dataCallback = 0;
|
||||
|
||||
_init();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new instance of an Adafruit IO Feed.
|
||||
@param *io
|
||||
Reference to AdafruitIO.
|
||||
@param *n
|
||||
Valid feed name.
|
||||
@param *un
|
||||
Feed owner's Adafruit IO username.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n, const char *un)
|
||||
: AdafruitIO_MQTT() {
|
||||
_io = io;
|
||||
name = n;
|
||||
owner = un;
|
||||
|
||||
_init();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adafruit IO Feed destructor.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Feed::~AdafruitIO_Feed() {
|
||||
if (_sub)
|
||||
AdafruitIO_Feed::~AdafruitIO_Feed()
|
||||
{
|
||||
if(_sub)
|
||||
delete _sub;
|
||||
|
||||
if (_pub)
|
||||
if(_pub)
|
||||
delete _pub;
|
||||
|
||||
if (_get_pub)
|
||||
delete _get_pub;
|
||||
if(_get_pub)
|
||||
delete _pub;
|
||||
|
||||
if (data)
|
||||
if(data)
|
||||
delete data;
|
||||
|
||||
if (_topic)
|
||||
if(_topic)
|
||||
free(_topic);
|
||||
|
||||
if (_get_topic)
|
||||
free(_get_topic);
|
||||
|
||||
if (_feed_url)
|
||||
if(_feed_url)
|
||||
free(_feed_url);
|
||||
|
||||
if (_create_url)
|
||||
if(_create_url)
|
||||
free(_create_url);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new onMessage callback.
|
||||
@param cb
|
||||
Adafruit IO callback.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Feed::onMessage(AdafruitIODataCallbackType cb) {
|
||||
void AdafruitIO_Feed::onMessage(AdafruitIODataCallbackType cb)
|
||||
{
|
||||
_dataCallback = cb;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(char *value, double lat, double lon, double ele) {
|
||||
bool AdafruitIO_Feed::save(char *value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(bool value, double lat, double lon, double ele) {
|
||||
bool AdafruitIO_Feed::save(bool value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(String value, double lat, double lon, double ele) {
|
||||
bool AdafruitIO_Feed::save(String value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(int value, double lat, double lon, double ele) {
|
||||
bool AdafruitIO_Feed::save(int value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(unsigned int value, double lat, double lon,
|
||||
double ele) {
|
||||
bool AdafruitIO_Feed::save(unsigned int value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(long value, double lat, double lon, double ele) {
|
||||
bool AdafruitIO_Feed::save(long value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(unsigned long value, double lat, double lon,
|
||||
double ele) {
|
||||
bool AdafruitIO_Feed::save(unsigned long value, double lat, double lon, double ele)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@param precision
|
||||
Desired amount of decimal precision.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(float value, double lat, double lon, double ele,
|
||||
int precision) {
|
||||
bool AdafruitIO_Feed::save(float value, double lat, double lon, double ele, int precision)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele, precision);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates Adafruit IO Feed.
|
||||
@param value
|
||||
Value to publish to feed.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
@param precision
|
||||
Desired amount of decimal precision.
|
||||
@return True if data successfully published to feed, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele,
|
||||
int precision) {
|
||||
bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele, int precision)
|
||||
{
|
||||
data->setValue(value, lat, lon, ele, precision);
|
||||
return _pub->publish(data->toCSV());
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/*!
|
||||
@brief Publishes a null character to an Adafruit IO /get topic.
|
||||
https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/****************************************************************************/
|
||||
bool AdafruitIO_Feed::get() { return _get_pub->publish("\0"); }
|
||||
bool AdafruitIO_Feed::get()
|
||||
{
|
||||
return _get_pub->publish("\0");
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/*!
|
||||
@brief Checks if Adafruit IO Feed exists and belongs to username.
|
||||
https://io.adafruit.com/api/docs/#get-feed
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/****************************************************************************/
|
||||
bool AdafruitIO_Feed::exists() {
|
||||
bool AdafruitIO_Feed::exists()
|
||||
{
|
||||
_io->_http->beginRequest();
|
||||
_io->_http->get(_feed_url);
|
||||
_io->_http->sendHeader("X-AIO-Key", _io->_key);
|
||||
|
|
@ -303,14 +128,8 @@ bool AdafruitIO_Feed::exists() {
|
|||
return status == 200;
|
||||
}
|
||||
|
||||
/**************************************************************/
|
||||
/*!
|
||||
@brief Creates a new Adafruit IO Feed
|
||||
https://io.adafruit.com/api/docs/#create-feed
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/*************************************************************/
|
||||
bool AdafruitIO_Feed::create() {
|
||||
bool AdafruitIO_Feed::create()
|
||||
{
|
||||
String body = "name=";
|
||||
body += name;
|
||||
|
||||
|
|
@ -336,17 +155,11 @@ bool AdafruitIO_Feed::create() {
|
|||
return status == 201;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*!
|
||||
@brief Retrieves the most recent value published to a feed.
|
||||
https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic
|
||||
@return NULL
|
||||
*/
|
||||
/*****************************************************************************/
|
||||
AdafruitIO_Data *AdafruitIO_Feed::lastValue() {
|
||||
AdafruitIO_Data* AdafruitIO_Feed::lastValue()
|
||||
{
|
||||
// 15 extra for api path, 12 for /data/retain, 1 for null
|
||||
String url = "/api/v2/";
|
||||
url += owner;
|
||||
url += _io->_username;
|
||||
url += "/feeds/";
|
||||
url += name;
|
||||
url += "/data/retain";
|
||||
|
|
@ -368,8 +181,6 @@ AdafruitIO_Data *AdafruitIO_Feed::lastValue() {
|
|||
return new AdafruitIO_Data(this, body.c_str());
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
} else {
|
||||
|
||||
AIO_ERROR_PRINT("error retrieving lastValue, status: ");
|
||||
|
|
@ -378,90 +189,57 @@ AdafruitIO_Data *AdafruitIO_Feed::lastValue() {
|
|||
AIO_ERROR_PRINTLN(_io->_http->responseBody());
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets Adafruit IO feed location metadata.
|
||||
@param lat
|
||||
Latitude metadata.
|
||||
@param lon
|
||||
Longitudinal metadata.
|
||||
@param ele
|
||||
Elevation metadata.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Feed::setLocation(double lat, double lon, double ele) {
|
||||
void AdafruitIO_Feed::setLocation(double lat, double lon, double ele)
|
||||
{
|
||||
data->setLocation(lat, lon, ele);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Calls _datacallback if new data is avaliable on feed.
|
||||
@param val
|
||||
Value to publish to Adafruit IO feed.
|
||||
@param len
|
||||
Feed length.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Feed::subCallback(char *val, uint16_t len) {
|
||||
void AdafruitIO_Feed::subCallback(char *val, uint16_t len)
|
||||
{
|
||||
data->setCSV(val);
|
||||
|
||||
// call callback with data
|
||||
if (_dataCallback)
|
||||
if(_dataCallback)
|
||||
_dataCallback(data);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialize MQTT topics and REST URLs for Adafruit IO feeds.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Feed::_init() {
|
||||
_sub = 0;
|
||||
_pub = 0;
|
||||
_get_pub = 0;
|
||||
_dataCallback = 0;
|
||||
void AdafruitIO_Feed::_init()
|
||||
{
|
||||
|
||||
// dynamically allocate memory for mqtt topic and REST URLs
|
||||
_topic = (char *)malloc(
|
||||
sizeof(char) * (strlen(owner) + strlen(name) +
|
||||
8)); // 8 extra chars for /f/, /csv & null termination
|
||||
_get_topic = (char *)malloc(
|
||||
sizeof(char) *
|
||||
(strlen(owner) + strlen(name) +
|
||||
12)); // 12 extra chars for /f/, /csv/get & null termination
|
||||
_feed_url =
|
||||
(char *)malloc(sizeof(char) * (strlen(owner) + strlen(name) +
|
||||
16)); // 16 extra for api path & null term
|
||||
_create_url = (char *)malloc(
|
||||
sizeof(char) * (strlen(owner) + 15)); // 15 extra for api path & null term
|
||||
_topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 8)); // 8 extra chars for /f/, /csv & null termination
|
||||
_get_topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 12)); // 12 extra chars for /f/, /csv/get & null termination
|
||||
_feed_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 16)); // 16 extra for api path & null term
|
||||
_create_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + 15)); // 15 extra for api path & null term
|
||||
|
||||
// init feed data
|
||||
data = new AdafruitIO_Data(this);
|
||||
|
||||
if (_topic && _create_url && _feed_url) {
|
||||
if(_topic && _create_url && _feed_url) {
|
||||
|
||||
// build topic string
|
||||
strcpy(_topic, owner);
|
||||
strcpy(_topic, _io->_username);
|
||||
strcat(_topic, "/f/");
|
||||
strcat(_topic, name);
|
||||
strcat(_topic, "/csv");
|
||||
|
||||
// build feed url string
|
||||
strcpy(_feed_url, "/api/v2/");
|
||||
strcat(_feed_url, owner);
|
||||
strcat(_feed_url, _io->_username);
|
||||
strcat(_feed_url, "/feeds/");
|
||||
strcat(_feed_url, name);
|
||||
|
||||
// build create url string
|
||||
strcpy(_create_url, "/api/v2/");
|
||||
strcat(_create_url, owner);
|
||||
strcat(_create_url, _io->_username);
|
||||
strcat(_create_url, "/feeds");
|
||||
|
||||
// build /get topic string
|
||||
strcpy(_get_topic, owner);
|
||||
strcpy(_get_topic, _io->_username);
|
||||
strcat(_get_topic, "/f/");
|
||||
strcat(_get_topic, name);
|
||||
strcat(_get_topic, "/csv/get");
|
||||
|
|
@ -478,12 +256,13 @@ void AdafruitIO_Feed::_init() {
|
|||
|
||||
// malloc failed
|
||||
_topic = 0;
|
||||
_get_topic = 0;
|
||||
_create_url = 0;
|
||||
_feed_url = 0;
|
||||
_sub = 0;
|
||||
_pub = 0;
|
||||
_get_pub = 0;
|
||||
data = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,90 +1,74 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Feed.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece, Adam Bachman
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_FEED_H
|
||||
#define ADAFRUITIO_FEED_H
|
||||
|
||||
#include "AdafruitIO_Data.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "AdafruitIO_MQTT.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Arduino.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "AdafruitIO_Data.h"
|
||||
#include "AdafruitIO_MQTT.h"
|
||||
|
||||
// forward declaration
|
||||
class AdafruitIO;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class that provides methods for interfacing with
|
||||
Adafruit IO feed topics.
|
||||
https://io.adafruit.com/api/docs/mqtt.html#mqtt-topics
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_Feed : public AdafruitIO_MQTT {
|
||||
|
||||
public:
|
||||
AdafruitIO_Feed(AdafruitIO *io, const char *name);
|
||||
AdafruitIO_Feed(AdafruitIO *io, const char *name, const char *owner);
|
||||
public:
|
||||
AdafruitIO_Feed(AdafruitIO *io, const char *name);
|
||||
~AdafruitIO_Feed();
|
||||
|
||||
~AdafruitIO_Feed();
|
||||
bool save(char *value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(bool value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(String value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(int value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(unsigned int value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(long value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(unsigned long value, double lat=0, double lon=0, double ele=0);
|
||||
bool save(float value, double lat=0, double lon=0, double ele=0, int precision=6);
|
||||
bool save(double value, double lat=0, double lon=0, double ele=0, int precision=6);
|
||||
|
||||
bool save(char *value, double lat = 0, double lon = 0, double ele = 0);
|
||||
bool save(bool value, double lat = 0, double lon = 0, double ele = 0);
|
||||
bool save(String value, double lat = 0, double lon = 0, double ele = 0);
|
||||
bool save(int value, double lat = 0, double lon = 0, double ele = 0);
|
||||
bool save(unsigned int value, double lat = 0, double lon = 0, double ele = 0);
|
||||
bool save(long value, double lat = 0, double lon = 0, double ele = 0);
|
||||
bool save(unsigned long value, double lat = 0, double lon = 0,
|
||||
double ele = 0);
|
||||
bool save(float value, double lat = 0, double lon = 0, double ele = 0,
|
||||
int precision = 6);
|
||||
bool save(double value, double lat = 0, double lon = 0, double ele = 0,
|
||||
int precision = 6);
|
||||
bool get();
|
||||
|
||||
bool get();
|
||||
bool exists();
|
||||
bool create();
|
||||
|
||||
bool exists();
|
||||
bool create();
|
||||
void setLocation(double lat, double lon, double ele=0);
|
||||
|
||||
void setLocation(double lat, double lon, double ele = 0);
|
||||
void onMessage(AdafruitIODataCallbackType cb);
|
||||
void subCallback(char *val, uint16_t len);
|
||||
|
||||
void onMessage(AdafruitIODataCallbackType cb);
|
||||
void subCallback(char *val, uint16_t len);
|
||||
const char *name;
|
||||
|
||||
const char *name; /*!< Adafruit IO feed name. */
|
||||
const char *owner; /*!< Adafruit IO feed owner. */
|
||||
AdafruitIO_Data *lastValue();
|
||||
AdafruitIO_Data *data;
|
||||
|
||||
AdafruitIO_Data *lastValue(); /*!< Last value sent to Adafruit IO feed. */
|
||||
AdafruitIO_Data *data; /*!< Adafruit IO feed data record. */
|
||||
private:
|
||||
AdafruitIODataCallbackType _dataCallback;
|
||||
|
||||
private:
|
||||
AdafruitIODataCallbackType
|
||||
_dataCallback; /*!< Callback from onMessage containing data. */
|
||||
void _init();
|
||||
|
||||
void _init();
|
||||
char *_topic;
|
||||
char *_get_topic;
|
||||
char *_create_url;
|
||||
char *_feed_url;
|
||||
|
||||
char *_topic; /*!< MQTT Topic URL */
|
||||
char *_get_topic; /*!< /get topic string */
|
||||
char *_create_url; /*!< create URL string */
|
||||
char *_feed_url; /*!< feed URL string */
|
||||
Adafruit_MQTT_Subscribe *_sub;
|
||||
Adafruit_MQTT_Publish *_pub;
|
||||
Adafruit_MQTT_Publish *_get_pub;
|
||||
|
||||
Adafruit_MQTT_Subscribe *_sub; /*!< MQTT subscription for _topic. */
|
||||
Adafruit_MQTT_Publish *_pub; /*!< MQTT publish for _topic. */
|
||||
Adafruit_MQTT_Publish *_get_pub; /*!< MQTT publish to _get_topic. */
|
||||
AdafruitIO *_io;
|
||||
AdafruitIO_Data *_data;
|
||||
|
||||
AdafruitIO *_io; /*!< An instance of AdafruitIO. */
|
||||
AdafruitIO_Data *_data; /*!< An instance of AdafruitIO_Data. */
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_FEED_H
|
||||
|
|
|
|||
|
|
@ -1,206 +1,104 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Group.cpp
|
||||
*
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Author: Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "AdafruitIO_Group.h"
|
||||
#include "AdafruitIO.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new instance of an Adafruit IO Group.
|
||||
@param *io
|
||||
Reference to AdafruitIO.
|
||||
@param *n
|
||||
Valid group name.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Group::AdafruitIO_Group(AdafruitIO *io, const char *n)
|
||||
: AdafruitIO_MQTT() {
|
||||
AdafruitIO_Group::AdafruitIO_Group(AdafruitIO *io, const char *n):AdafruitIO_MQTT()
|
||||
{
|
||||
_io = io;
|
||||
name = n;
|
||||
owner = _io->_username;
|
||||
|
||||
_init();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adafruit IO Group destructor.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Group::~AdafruitIO_Group() {
|
||||
if (_sub)
|
||||
AdafruitIO_Group::~AdafruitIO_Group()
|
||||
{
|
||||
if(_sub)
|
||||
delete _sub;
|
||||
|
||||
if (_pub)
|
||||
if(_pub)
|
||||
delete _pub;
|
||||
|
||||
if (_get_pub)
|
||||
delete _get_pub;
|
||||
|
||||
if (data)
|
||||
if(data)
|
||||
delete data;
|
||||
|
||||
if (_topic)
|
||||
if(_topic)
|
||||
free(_topic);
|
||||
|
||||
if (_get_topic)
|
||||
free(_get_topic);
|
||||
|
||||
if (_group_url)
|
||||
if(_group_url)
|
||||
free(_group_url);
|
||||
|
||||
if (_create_url)
|
||||
if(_create_url)
|
||||
free(_create_url);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, char *value) {
|
||||
void AdafruitIO_Group::set(const char *feed, char *value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, bool value) {
|
||||
void AdafruitIO_Group::set(const char *feed, bool value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, String value) {
|
||||
void AdafruitIO_Group::set(const char *feed, String value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, int value) {
|
||||
void AdafruitIO_Group::set(const char *feed, int value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, unsigned int value) {
|
||||
void AdafruitIO_Group::set(const char *feed, unsigned int value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, long value) {
|
||||
void AdafruitIO_Group::set(const char *feed, long value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, unsigned long value) {
|
||||
void AdafruitIO_Group::set(const char *feed, unsigned long value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, float value) {
|
||||
void AdafruitIO_Group::set(const char *feed, float value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets value of Adafruit IO Group.
|
||||
@param feed
|
||||
Adafruit IO feed name.
|
||||
@param value
|
||||
Adafruit IO feed value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::set(const char *feed, double value) {
|
||||
void AdafruitIO_Group::set(const char *feed, double value)
|
||||
{
|
||||
AdafruitIO_Data *f = getFeed(feed);
|
||||
f->setValue(value);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Updates value of Adafruit IO Group.
|
||||
@return True if successfully published to group, False if data is
|
||||
NULL or if unable to successfully publish data to group.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Group::save() {
|
||||
bool AdafruitIO_Group::save()
|
||||
{
|
||||
|
||||
if (data == NULL)
|
||||
if(data == NULL)
|
||||
return false;
|
||||
|
||||
char csv[150];
|
||||
|
|
@ -208,7 +106,7 @@ bool AdafruitIO_Group::save() {
|
|||
|
||||
strcpy(csv, "");
|
||||
|
||||
while (cur_data != NULL) {
|
||||
while(cur_data != NULL) {
|
||||
|
||||
strcat(csv, cur_data->feedName());
|
||||
strcat(csv, ",");
|
||||
|
|
@ -216,224 +114,175 @@ bool AdafruitIO_Group::save() {
|
|||
strcat(csv, "\n");
|
||||
|
||||
cur_data = cur_data->next_data;
|
||||
|
||||
}
|
||||
|
||||
return _pub->publish(csv);
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Publishes null value ("\0") to Adafruit IO Group
|
||||
https://io.adafruit.com/api/docs/mqtt.html#retained-values
|
||||
@return True if successfully published to group, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Group::get() { return _get_pub->publish("\0"); }
|
||||
AdafruitIO_Data* AdafruitIO_Group::getFeed(const char *feed)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Obtains data from feed within group.
|
||||
@param feed
|
||||
Existing Adafruit IO Feed.
|
||||
@return cur_data Data from feed within group
|
||||
data Adafruit IO Feed does not exist in group. Data is
|
||||
the value of a generated feed, feed, within group.
|
||||
NULL If unable to return data.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Data *AdafruitIO_Group::getFeed(const char *feed) {
|
||||
if (data == NULL) {
|
||||
if(data == NULL) {
|
||||
data = new AdafruitIO_Data(feed);
|
||||
return data;
|
||||
}
|
||||
|
||||
AdafruitIO_Data *cur_data = data;
|
||||
|
||||
while (cur_data != NULL) {
|
||||
while(cur_data != NULL) {
|
||||
|
||||
if (strcmp(cur_data->feedName(), feed) == 0) {
|
||||
if(strcmp(cur_data->feedName(), feed) == 0) {
|
||||
return cur_data;
|
||||
}
|
||||
|
||||
if (!cur_data->next_data) {
|
||||
if(! cur_data->next_data) {
|
||||
cur_data->next_data = new AdafruitIO_Data(feed);
|
||||
return cur_data->next_data;
|
||||
}
|
||||
|
||||
cur_data = cur_data->next_data;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up Adafruit IO callback to monitor incoming
|
||||
new data in group.
|
||||
@param cb
|
||||
An function to be called if group receives new data.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb) {
|
||||
if (_groupCallback == NULL) {
|
||||
void AdafruitIO_Group::onMessage(AdafruitIODataCallbackType cb)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if(_groupCallback == NULL) {
|
||||
_groupCallback = new AdafruitIOGroupCallback(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
AdafruitIOGroupCallback *cur_cb = _groupCallback;
|
||||
|
||||
while (cur_cb != NULL) {
|
||||
while(cur_cb != NULL) {
|
||||
|
||||
if (!cur_cb->next_cb) {
|
||||
if(! cur_cb->next_cb) {
|
||||
cur_cb->next_cb = new AdafruitIOGroupCallback(cb);
|
||||
return;
|
||||
}
|
||||
|
||||
cur_cb = cur_cb->next_cb;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up Adafruit IO callback to monitor incoming
|
||||
new data in group's feed, feed.
|
||||
@param feed
|
||||
An Adafruit IO Feed within Group.
|
||||
@param cb
|
||||
An function to be called if group receives new data.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::onMessage(const char *feed,
|
||||
AdafruitIODataCallbackType cb) {
|
||||
if (_groupCallback == NULL) {
|
||||
void AdafruitIO_Group::onMessage(const char *feed, AdafruitIODataCallbackType cb)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if(_groupCallback == NULL) {
|
||||
_groupCallback = new AdafruitIOGroupCallback(feed, cb);
|
||||
return;
|
||||
}
|
||||
|
||||
AdafruitIOGroupCallback *cur_cb = _groupCallback;
|
||||
|
||||
while (cur_cb != NULL) {
|
||||
while(cur_cb != NULL) {
|
||||
|
||||
if (strcmp(cur_cb->feed, feed) == 0) {
|
||||
if(strcmp(cur_cb->feed, feed) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cur_cb->next_cb) {
|
||||
if(! cur_cb->next_cb) {
|
||||
cur_cb->next_cb = new AdafruitIOGroupCallback(feed, cb);
|
||||
return;
|
||||
}
|
||||
|
||||
cur_cb = cur_cb->next_cb;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Adafruit IO Group subscription function callback.
|
||||
@param d
|
||||
Name of feed within group.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::call(AdafruitIO_Data *d) {
|
||||
// uint8_t i;
|
||||
void AdafruitIO_Group::call(AdafruitIO_Data *d)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if (_groupCallback == NULL) {
|
||||
if(_groupCallback == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdafruitIOGroupCallback *cur_cb = _groupCallback;
|
||||
|
||||
while (cur_cb) {
|
||||
while(cur_cb) {
|
||||
|
||||
if (cur_cb->feed == NULL || strcmp(cur_cb->feed, d->feedName()) == 0) {
|
||||
if(strcmp(cur_cb->feed, d->feedName()) == 0 || cur_cb->feed == NULL) {
|
||||
cur_cb->dataCallback(d);
|
||||
}
|
||||
|
||||
cur_cb = cur_cb->next_cb;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Checks for new value within Adafruit IO group.
|
||||
@param val
|
||||
Value to send to Adafruit IO group.
|
||||
@param len
|
||||
Length of Adafruit IO value.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::subCallback(char *val, uint16_t len) {
|
||||
void AdafruitIO_Group::subCallback(char *val, uint16_t len)
|
||||
{
|
||||
|
||||
char *line;
|
||||
char *name;
|
||||
char *value;
|
||||
|
||||
if (_groupCallback == NULL)
|
||||
if(_groupCallback == NULL)
|
||||
return;
|
||||
|
||||
while ((line = strtok_r(val, "\n", &val)) != NULL) {
|
||||
while((line = strtok_r(val, "\n", &val)) != NULL) {
|
||||
|
||||
name = strtok_r(line, ",", &line);
|
||||
|
||||
// couldn't grab name from line, move on
|
||||
if (!name)
|
||||
if(! name)
|
||||
continue;
|
||||
|
||||
// don't handle location for now
|
||||
if (strcmp(name, "location") == 0)
|
||||
if(strcmp(name, "location") == 0)
|
||||
continue;
|
||||
|
||||
value = strtok_r(line, ",", &line);
|
||||
|
||||
// no value? move on
|
||||
if (!value)
|
||||
if(! value)
|
||||
continue;
|
||||
|
||||
AdafruitIO_Data *feed = getFeed(name);
|
||||
|
||||
// we couldn't get the data, move on
|
||||
if (!feed)
|
||||
if(! feed)
|
||||
continue;
|
||||
|
||||
feed->setValue(value);
|
||||
call(feed);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up locational metadata.
|
||||
@param lat
|
||||
Desired latitude.
|
||||
@param lon
|
||||
Desired longitude.
|
||||
@param ele
|
||||
Desired elevation.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::setLocation(double lat, double lon, double ele) {
|
||||
// uint8_t i;
|
||||
void AdafruitIO_Group::setLocation(double lat, double lon, double ele)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
if (data == NULL) {
|
||||
if(data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
AdafruitIO_Data *cur_data = data;
|
||||
|
||||
while (cur_data) {
|
||||
while(cur_data) {
|
||||
cur_data->setLocation(lat, lon, ele);
|
||||
cur_data = cur_data->next_data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Checks if Adafruit IO Group exists.
|
||||
https://io.adafruit.com/api/docs/#get-group
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Group::exists() {
|
||||
bool AdafruitIO_Group::exists()
|
||||
{
|
||||
_io->_http->beginRequest();
|
||||
_io->_http->get(_group_url);
|
||||
_io->_http->sendHeader("X-AIO-Key", _io->_key);
|
||||
|
|
@ -444,14 +293,8 @@ bool AdafruitIO_Group::exists() {
|
|||
return status == 200;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates new Adafruit IO Group.
|
||||
https://io.adafruit.com/api/docs/#create-group
|
||||
@return True if successful, otherwise False.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Group::create() {
|
||||
bool AdafruitIO_Group::create()
|
||||
{
|
||||
String body = "name=";
|
||||
body += name;
|
||||
|
||||
|
|
@ -476,58 +319,38 @@ bool AdafruitIO_Group::create() {
|
|||
return status == 201;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initialize MQTT topics and REST URLs for Adafruit IO groups.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Group::_init() {
|
||||
void AdafruitIO_Group::_init()
|
||||
{
|
||||
|
||||
// dynamically allocate memory for mqtt topic and REST URLs
|
||||
_topic = (char *)malloc(
|
||||
sizeof(char) * (strlen(owner) + strlen(name) +
|
||||
8)); // 8 extra chars for /g/, /csv & null termination
|
||||
_get_topic = (char *)malloc(
|
||||
sizeof(char) *
|
||||
(strlen(owner) + strlen(name) +
|
||||
12)); // 12 extra chars for /f/, /csv/get & null termination
|
||||
_group_url =
|
||||
(char *)malloc(sizeof(char) * (strlen(owner) + strlen(name) +
|
||||
16)); // 16 extra for api path & null term
|
||||
_create_url = (char *)malloc(
|
||||
sizeof(char) * (strlen(owner) + 15)); // 15 extra for api path & null term
|
||||
_topic = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 8)); // 8 extra chars for /g/, /csv & null termination
|
||||
_group_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + strlen(name) + 16)); // 16 extra for api path & null term
|
||||
_create_url = (char *) malloc(sizeof(char) * (strlen(_io->_username) + 15)); // 15 extra for api path & null term
|
||||
|
||||
data = 0;
|
||||
|
||||
if (_topic && _create_url && _group_url) {
|
||||
if(_topic && _create_url && _group_url) {
|
||||
|
||||
// build topic string
|
||||
strcpy(_topic, owner);
|
||||
strcpy(_topic, _io->_username);
|
||||
strcat(_topic, "/g/");
|
||||
strcat(_topic, name);
|
||||
strcat(_topic, "/csv");
|
||||
|
||||
// build feed url string
|
||||
strcpy(_group_url, "/api/v2/");
|
||||
strcat(_group_url, owner);
|
||||
strcat(_group_url, _io->_username);
|
||||
strcat(_group_url, "/groups/");
|
||||
strcat(_group_url, name);
|
||||
|
||||
// build create url string
|
||||
strcpy(_create_url, "/api/v2/");
|
||||
strcat(_create_url, owner);
|
||||
strcat(_create_url, _io->_username);
|
||||
strcat(_create_url, "/groups");
|
||||
|
||||
// build /get topic string
|
||||
strcpy(_get_topic, owner);
|
||||
strcat(_get_topic, "/g/");
|
||||
strcat(_get_topic, name);
|
||||
strcat(_get_topic, "/csv/get");
|
||||
|
||||
// setup subscription
|
||||
_sub = new Adafruit_MQTT_Subscribe(_io->_mqtt, _topic);
|
||||
_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _topic);
|
||||
_get_pub = new Adafruit_MQTT_Publish(_io->_mqtt, _get_topic);
|
||||
_io->_mqtt->subscribe(_sub);
|
||||
|
||||
_sub->setCallback(this, &AdafruitIO_MQTT::subCallback);
|
||||
|
|
@ -536,11 +359,11 @@ void AdafruitIO_Group::_init() {
|
|||
|
||||
// malloc failed
|
||||
_topic = 0;
|
||||
_get_topic = 0;
|
||||
_create_url = 0;
|
||||
_group_url = 0;
|
||||
_sub = 0;
|
||||
_pub = 0;
|
||||
_get_pub = 0;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,74 +12,66 @@
|
|||
#ifndef ADAFRUITIO_GROUP_H
|
||||
#define ADAFRUITIO_GROUP_H
|
||||
|
||||
#include "AdafruitIO_Data.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "AdafruitIO_MQTT.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Arduino.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "AdafruitIO_Data.h"
|
||||
#include "AdafruitIO_MQTT.h"
|
||||
|
||||
// forward declaration
|
||||
class AdafruitIO;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with Adafruit IO Grouped Feeds
|
||||
https://io.adafruit.com/api/docs/mqtt.html#group-topics
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_Group : public AdafruitIO_MQTT {
|
||||
|
||||
public:
|
||||
AdafruitIO_Group(AdafruitIO *io, const char *name);
|
||||
~AdafruitIO_Group();
|
||||
public:
|
||||
AdafruitIO_Group(AdafruitIO *io, const char *name);
|
||||
~AdafruitIO_Group();
|
||||
|
||||
void set(const char *feed, char *value);
|
||||
void set(const char *feed, bool value);
|
||||
void set(const char *feed, String value);
|
||||
void set(const char *feed, int value);
|
||||
void set(const char *feed, unsigned int value);
|
||||
void set(const char *feed, long value);
|
||||
void set(const char *feed, unsigned long value);
|
||||
void set(const char *feed, float value);
|
||||
void set(const char *feed, double value);
|
||||
void set(const char *feed, char *value);
|
||||
void set(const char *feed, bool value);
|
||||
void set(const char *feed, String value);
|
||||
void set(const char *feed, int value);
|
||||
void set(const char *feed, unsigned int value);
|
||||
void set(const char *feed, long value);
|
||||
void set(const char *feed, unsigned long value);
|
||||
void set(const char *feed, float value);
|
||||
void set(const char *feed, double value);
|
||||
|
||||
bool save();
|
||||
bool get();
|
||||
bool save();
|
||||
|
||||
void setLocation(double lat = 0, double lon = 0, double ele = 0);
|
||||
void setLocation(double lat=0, double lon=0, double ele=0);
|
||||
|
||||
bool exists();
|
||||
bool create();
|
||||
bool exists();
|
||||
bool create();
|
||||
|
||||
void onMessage(AdafruitIODataCallbackType cb);
|
||||
void onMessage(const char *feed, AdafruitIODataCallbackType cb);
|
||||
void onMessage(AdafruitIODataCallbackType cb);
|
||||
void onMessage(const char *feed, AdafruitIODataCallbackType cb);
|
||||
|
||||
void subCallback(char *val, uint16_t len);
|
||||
void call(AdafruitIO_Data *d);
|
||||
void subCallback(char *val, uint16_t len);
|
||||
void call(AdafruitIO_Data *d);
|
||||
|
||||
const char *name; /*!< Adafruit IO group name. */
|
||||
const char *owner; /*!< Adafruit IO username of group owner. */
|
||||
const char *name;
|
||||
|
||||
AdafruitIO_Data *data; /*!< Adafruit IO data record. */
|
||||
AdafruitIO_Data *getFeed(const char *feed);
|
||||
AdafruitIO_Data *data;
|
||||
AdafruitIO_Data* getFeed(const char *feed);
|
||||
|
||||
private:
|
||||
void _init();
|
||||
private:
|
||||
void _init();
|
||||
|
||||
char *_topic; /*!< MQTT topic URL.. */
|
||||
char *_get_topic; /*!< /get topic string. */
|
||||
char *_create_url; /*!< Create URL string. */
|
||||
char *_group_url; /*!< Group URL string. */
|
||||
char *_topic;
|
||||
char *_create_url;
|
||||
char *_group_url;
|
||||
|
||||
Adafruit_MQTT_Subscribe *_sub; /*!< MQTT subscription for _topic. */
|
||||
Adafruit_MQTT_Publish *_pub; /*!< MQTT publish for _topic. */
|
||||
Adafruit_MQTT_Publish *_get_pub; /*!< MQTT publish to _get_topic. */
|
||||
Adafruit_MQTT_Subscribe *_sub;
|
||||
Adafruit_MQTT_Publish *_pub;
|
||||
|
||||
AdafruitIO *_io; /*!< An instance of AdafruitIO. */
|
||||
AdafruitIOGroupCallback *_groupCallback =
|
||||
NULL; /*!< An instance of AdafruitIOGroupCallback */
|
||||
AdafruitIO *_io;
|
||||
AdafruitIOGroupCallback *_groupCallback;
|
||||
|
||||
double _lat,
|
||||
_lon,
|
||||
_ele;
|
||||
|
||||
double _lat, _lon, _ele; /*!< latitude, longitude, elevation metadata. */
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_GROUP_H
|
||||
#endif // ADAFRUITIO_GROUP_H
|
||||
|
|
|
|||
|
|
@ -1,42 +1,25 @@
|
|||
/*!
|
||||
* @file AdafruitIO_MQTT.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_MQTT_H
|
||||
#define ADAFRUITIO_MQTT_H
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class that contains MQTT subscription callbacks.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_MQTT {
|
||||
|
||||
public:
|
||||
AdafruitIO_MQTT() {}
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates an instance of a MQTT subscription callback.
|
||||
@param val
|
||||
Value from the MQTT subscription callback.
|
||||
@param len
|
||||
Length of returned value.
|
||||
@return True
|
||||
*/
|
||||
/**************************************************************************/
|
||||
virtual void subCallback(char *val, uint16_t len) = 0;
|
||||
public:
|
||||
AdafruitIO_MQTT() {}
|
||||
virtual void subCallback(char *val, uint16_t len) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_MQTT_H
|
||||
|
|
|
|||
|
|
@ -1,131 +0,0 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Time.cpp
|
||||
*
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code.
|
||||
* Please support Adafruit and open source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Copyright (c) 2015-2016 Adafruit Industries
|
||||
* Authors: Tony DiCola, Todd Treece
|
||||
* Licensed under the MIT license.
|
||||
*
|
||||
* All text above must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
#include "AdafruitIO_Time.h"
|
||||
#include "AdafruitIO.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up a Adafruit IO Time Service helper.
|
||||
@param io
|
||||
Reference to AdafruitIO.
|
||||
@param f
|
||||
Adafruit IO time format, either AIO_TIME_SECONDS,
|
||||
AIO_TIME_MILLIS, or AIO_TIME_ISO.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Time::AdafruitIO_Time(AdafruitIO *io, aio_time_format_t f)
|
||||
: AdafruitIO_MQTT() {
|
||||
_io = io;
|
||||
_sub = 0;
|
||||
_dataCallback = 0;
|
||||
format = f;
|
||||
|
||||
_init();
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Deconstructor for Adafruit IO time service.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Time::~AdafruitIO_Time() {
|
||||
if (_sub)
|
||||
delete _sub;
|
||||
|
||||
if (data)
|
||||
delete data;
|
||||
|
||||
if (_topic)
|
||||
free(_topic);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up a MQTT message callback.
|
||||
@param cb
|
||||
MQTT callback type.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Time::onMessage(AdafruitIOTimeCallbackType cb) {
|
||||
_dataCallback = cb;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets up a MQTT subscription callback. Calls data callback
|
||||
with data.
|
||||
@param val
|
||||
Data from MQTT topic.
|
||||
@param len
|
||||
Length of MQTT topic data.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Time::subCallback(char *val, uint16_t len) {
|
||||
data = val;
|
||||
|
||||
// call callback with data
|
||||
if (_dataCallback)
|
||||
_dataCallback(data, len);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Initializes AdafruitIO Time MQTT topic and REST URLs.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void AdafruitIO_Time::_init() {
|
||||
|
||||
// dynamically allocate memory for mqtt topic and REST URLs
|
||||
const char *formatString;
|
||||
|
||||
switch (format) {
|
||||
case AIO_TIME_SECONDS:
|
||||
formatString = "seconds";
|
||||
break;
|
||||
case AIO_TIME_MILLIS:
|
||||
formatString = "millis";
|
||||
break;
|
||||
case AIO_TIME_ISO:
|
||||
formatString = "ISO-8601";
|
||||
break;
|
||||
default:
|
||||
formatString = "seconds";
|
||||
break;
|
||||
}
|
||||
|
||||
_topic = (char *)malloc(
|
||||
sizeof(char) * (strlen(formatString) +
|
||||
6)); // 6 extra chars for "time/" and null termination
|
||||
|
||||
if (_topic) {
|
||||
|
||||
// build topic string
|
||||
strcpy(_topic, "time/");
|
||||
strcat(_topic, formatString);
|
||||
|
||||
// setup subscription
|
||||
_sub = new Adafruit_MQTT_Subscribe(_io->_mqtt, _topic);
|
||||
_io->_mqtt->subscribe(_sub);
|
||||
_sub->setCallback(this, &AdafruitIO_MQTT::subCallback);
|
||||
|
||||
} else {
|
||||
|
||||
// malloc failed
|
||||
_topic = 0;
|
||||
_sub = 0;
|
||||
data = 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Time.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
#ifndef ADAFRUITIO_TIME_H
|
||||
#define ADAFRUITIO_TIME_H
|
||||
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "AdafruitIO_MQTT.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Arduino.h"
|
||||
|
||||
// forward declaration
|
||||
class AdafruitIO;
|
||||
|
||||
typedef void (*AdafruitIOTimeCallbackType)(
|
||||
char *value,
|
||||
uint16_t len); /*!< an instance of Adafruit IO's time callback. */
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class that contains functions for interacting with
|
||||
the Adafruit IO Time Service.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_Time : public AdafruitIO_MQTT {
|
||||
|
||||
public:
|
||||
AdafruitIO_Time(AdafruitIO *io, aio_time_format_t f);
|
||||
~AdafruitIO_Time();
|
||||
void onMessage(AdafruitIOTimeCallbackType cb);
|
||||
void subCallback(char *val, uint16_t len);
|
||||
char *data; /*!< Data sent by Adafruit IO's time service. */
|
||||
aio_time_format_t format; /*!< Adafruit IO time format,
|
||||
TIME_SECONDS/TIME_MILLIS/TIME_ISO. */
|
||||
|
||||
private:
|
||||
AdafruitIOTimeCallbackType _dataCallback;
|
||||
void _init();
|
||||
char *_topic;
|
||||
Adafruit_MQTT_Subscribe *_sub;
|
||||
AdafruitIO *_io;
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_FEED_H
|
||||
|
|
@ -1,64 +1,41 @@
|
|||
/*!
|
||||
* @file AdafruitIO_WiFi.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_WIFI_H
|
||||
#define ADAFRUITIO_WIFI_H
|
||||
|
||||
#if defined(ARDUINO_SAMD_MKR1000)
|
||||
|
||||
#include "wifi/AdafruitIO_MKR1000.h"
|
||||
typedef AdafruitIO_MKR1000 AdafruitIO_WiFi;
|
||||
#include "wifi/AdafruitIO_MKR1000.h"
|
||||
typedef AdafruitIO_MKR1000 AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(ARDUINO_SAMD_MKR1010)
|
||||
#elif !defined(ARDUINO_SAMD_MKR1000) && defined(ARDUINO_ARCH_SAMD)
|
||||
|
||||
#include "wifi/AdafruitIO_MKR1010.h"
|
||||
typedef AdafruitIO_MKR1010 AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(ADAFRUIT_METRO_M4_AIRLIFT_LITE) || defined(ADAFRUIT_PYPORTAL) || \
|
||||
defined(USE_AIRLIFT)
|
||||
|
||||
#include "wifi/AdafruitIO_AIRLIFT.h"
|
||||
typedef AdafruitIO_AIRLIFT AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(USE_WINC1500)
|
||||
|
||||
#include "wifi/AdafruitIO_WINC1500.h"
|
||||
typedef AdafruitIO_WINC1500 AdafruitIO_WiFi;
|
||||
#include "wifi/AdafruitIO_WINC1500.h"
|
||||
typedef AdafruitIO_WINC1500 AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
|
||||
#include "wifi/AdafruitIO_ESP32.h"
|
||||
typedef AdafruitIO_ESP32 AdafruitIO_WiFi;
|
||||
#include "wifi/AdafruitIO_ESP32.h"
|
||||
typedef AdafruitIO_ESP32 AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(ESP8266)
|
||||
|
||||
#include "wifi/AdafruitIO_ESP8266.h"
|
||||
typedef AdafruitIO_ESP8266 AdafruitIO_WiFi;
|
||||
#include "wifi/AdafruitIO_ESP8266.h"
|
||||
typedef AdafruitIO_ESP8266 AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(ARDUINO_STM32_FEATHER)
|
||||
|
||||
#include "wifi/AdafruitIO_WICED.h"
|
||||
typedef AdafruitIO_WICED AdafruitIO_WiFi;
|
||||
|
||||
#elif defined(ARDUINO_ARCH_RP2040)
|
||||
|
||||
#include "wifi/AdafruitIO_RP2040.h"
|
||||
typedef AdafruitIO_RP2040 AdafruitIO_WiFi;
|
||||
|
||||
#else
|
||||
|
||||
#warning "Must define USE_AIRLIFT or USE_WINC1500 before including this file."
|
||||
#include "wifi/AdafruitIO_WICED.h"
|
||||
typedef AdafruitIO_WICED AdafruitIO_WiFi;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,68 +1,45 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Block.cpp
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "AdafruitIO_Block.h"
|
||||
#include "AdafruitIO.h"
|
||||
#include "AdafruitIO_Dashboard.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new Block on an Adafruit IO Dashboard.
|
||||
@param d
|
||||
Adafruit IO Dashboard name.
|
||||
@param f
|
||||
Adafruit IO Feed to display on the block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
AdafruitIO_Block::AdafruitIO_Block(AdafruitIO_Dashboard *d,
|
||||
AdafruitIO_Feed *f) {
|
||||
AdafruitIO_Block::AdafruitIO_Block(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
||||
{
|
||||
_dashboard = d;
|
||||
_feed = f;
|
||||
}
|
||||
|
||||
AdafruitIO_Block::~AdafruitIO_Block() {}
|
||||
AdafruitIO_Block::~AdafruitIO_Block(){}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets block properties.
|
||||
@return String containing block's properties.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
String AdafruitIO_Block::properties() {
|
||||
String AdafruitIO_Block::properties()
|
||||
{
|
||||
String props = "{}";
|
||||
return props;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets block dimensions, provided block size (width, height)
|
||||
and block location on dashboard (row, column).
|
||||
@return String containing block's dimensions.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
String AdafruitIO_Block::dimensions() {
|
||||
String AdafruitIO_Block::dimensions()
|
||||
{
|
||||
String dim = "\",\"size_x\":\"";
|
||||
dim += _width();
|
||||
dim += "\",\"size_y\":\"";
|
||||
dim += _height();
|
||||
|
||||
if (_row() > 0) {
|
||||
if(_row() > 0) {
|
||||
dim += "\",\"row\":\"";
|
||||
dim += _row();
|
||||
}
|
||||
|
||||
if (_column() > 0) {
|
||||
if(_column() > 0) {
|
||||
dim += "\",\"column\":\"";
|
||||
dim += _column();
|
||||
}
|
||||
|
|
@ -70,21 +47,13 @@ String AdafruitIO_Block::dimensions() {
|
|||
return dim;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Returns type of Adafruit IO Block.
|
||||
@return Block type
|
||||
*/
|
||||
/**************************************************************************/
|
||||
const char *AdafruitIO_Block::type() { return _visual_type; }
|
||||
const char* AdafruitIO_Block::type()
|
||||
{
|
||||
return _visual_type;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new block on an Adafruit IO dashboard.
|
||||
@return True if successful, False otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
bool AdafruitIO_Block::save() {
|
||||
bool AdafruitIO_Block::save()
|
||||
{
|
||||
HttpClient *http = _dashboard->io()->_http;
|
||||
|
||||
String url = "/api/v2/";
|
||||
|
|
|
|||
|
|
@ -1,90 +1,52 @@
|
|||
/*!
|
||||
* @file AdafruitIO_Block.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_BLOCK_H
|
||||
#define ADAFRUITIO_BLOCK_H
|
||||
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
#include "Arduino.h"
|
||||
#include "AdafruitIO_Definitions.h"
|
||||
|
||||
class AdafruitIO_Dashboard;
|
||||
class AdafruitIO_Feed;
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with and creating Adafruit IO Dashboard
|
||||
blocks.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class AdafruitIO_Block {
|
||||
|
||||
public:
|
||||
AdafruitIO_Block(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~AdafruitIO_Block();
|
||||
public:
|
||||
AdafruitIO_Block(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~AdafruitIO_Block();
|
||||
|
||||
int width = 2; /*!< Dashboard block width. */
|
||||
int height = 2; /*!< Dashboard block height. */
|
||||
int row = 0; /*!< Row location of block on dashboard. */
|
||||
int column = 0; /*!< Column location of block on dashboard. */
|
||||
int width = 2;
|
||||
int height = 2;
|
||||
int row = 0;
|
||||
int column = 0;
|
||||
|
||||
virtual String properties();
|
||||
String dimensions();
|
||||
virtual String properties();
|
||||
String dimensions();
|
||||
|
||||
virtual const char *type();
|
||||
virtual const char* type();
|
||||
|
||||
bool save();
|
||||
bool save();
|
||||
|
||||
protected:
|
||||
AdafruitIO_Dashboard
|
||||
*_dashboard; /*!< Instance of an Adafruit IO Dashboard. */
|
||||
AdafruitIO_Feed *_feed; /*!< Instance of an Adafruit IO Feed. */
|
||||
protected:
|
||||
AdafruitIO_Dashboard *_dashboard;
|
||||
AdafruitIO_Feed *_feed;
|
||||
|
||||
const char *_visual_type; /*!< Block type. */
|
||||
const char *_visual_type;
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns width of block.
|
||||
@return Block width.
|
||||
*/
|
||||
/******************************************/
|
||||
virtual int _width() { return width; }
|
||||
virtual int _width() { return width; }
|
||||
virtual int _height() { return height; }
|
||||
virtual int _row() { return row; }
|
||||
virtual int _column() { return column; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns height of block.
|
||||
@return Block height.
|
||||
*/
|
||||
/******************************************/
|
||||
virtual int _height() { return height; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's row location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard row.
|
||||
*/
|
||||
/******************************************/
|
||||
virtual int _row() { return row; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's column location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard column
|
||||
*/
|
||||
/******************************************/
|
||||
virtual int _column() { return column; }
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_BLOCK_H
|
||||
|
|
|
|||
|
|
@ -1,30 +1,18 @@
|
|||
/*!
|
||||
* @file ChartBlock.cpp
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "ChartBlock.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new Chart Block on an Adafruit IO Dashboard.
|
||||
@param d
|
||||
Adafruit IO Dashboard name.
|
||||
@param f
|
||||
Adafruit IO Feed to display on the chart.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ChartBlock::ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
||||
: AdafruitIO_Block(d, f) {
|
||||
ChartBlock::ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f)
|
||||
{
|
||||
historyHours = 0;
|
||||
xAxisLabel = "X";
|
||||
yAxisLabel = "Y";
|
||||
|
|
@ -32,15 +20,10 @@ ChartBlock::ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
|||
yAxisMax = 100;
|
||||
}
|
||||
|
||||
ChartBlock::~ChartBlock() {}
|
||||
ChartBlock::~ChartBlock(){}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets chart block properties.
|
||||
@return String containing properties of the chart block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
String ChartBlock::properties() {
|
||||
String ChartBlock::properties()
|
||||
{
|
||||
|
||||
String props = "{\"historyHours\":\"";
|
||||
props += historyHours;
|
||||
|
|
|
|||
|
|
@ -1,89 +1,46 @@
|
|||
/*!
|
||||
* @file ChartBlock.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_CHARTBLOCK_H
|
||||
#define ADAFRUITIO_CHARTBLOCK_H
|
||||
|
||||
#include "AdafruitIO_Block.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with the Adafruit IO Dashboard
|
||||
Chart Block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class ChartBlock : public AdafruitIO_Block {
|
||||
|
||||
public:
|
||||
ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~ChartBlock();
|
||||
public:
|
||||
ChartBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~ChartBlock();
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block type
|
||||
@return Block type.
|
||||
*/
|
||||
/******************************************/
|
||||
const char *type() { return _visual_type; }
|
||||
const char* type() { return _visual_type; }
|
||||
|
||||
int historyHours; /*!< Amount of hours to store the chart's history for. */
|
||||
const char *xAxisLabel; /*!< Chart's x-axis label. */
|
||||
const char *yAxisLabel; /*!< Chart's y-axis label. */
|
||||
int yAxisMin; /*!< Chart's y-axis minimum. */
|
||||
int yAxisMax; /*!< Chart's y-axis maximum. */
|
||||
int historyHours;
|
||||
const char *xAxisLabel;
|
||||
const char *yAxisLabel;
|
||||
int yAxisMin;
|
||||
int yAxisMax;
|
||||
|
||||
int width = 6; /*!< Dashboard block width. */
|
||||
int height = 4; /*!< Dashboard block height. */
|
||||
int width = 6;
|
||||
int height = 4;
|
||||
|
||||
String properties();
|
||||
String properties();
|
||||
|
||||
protected:
|
||||
const char *_visual_type = "line_chart"; /*!< Block type. */
|
||||
protected:
|
||||
const char *_visual_type = "line_chart";
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns width of block.
|
||||
@return Block width.
|
||||
*/
|
||||
/******************************************/
|
||||
int _width() { return width; }
|
||||
int _width() { return width; }
|
||||
int _height() { return height; }
|
||||
int _row() { return row; }
|
||||
int _column() { return column; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns height of block.
|
||||
@return Block height.
|
||||
*/
|
||||
/******************************************/
|
||||
int _height() { return height; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's row location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard row.
|
||||
*/
|
||||
/******************************************/
|
||||
int _row() { return row; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's column location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard column
|
||||
*/
|
||||
/******************************************/
|
||||
int _column() { return column; }
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_CHARTBLOCK_H
|
||||
|
|
|
|||
|
|
@ -1,91 +1,40 @@
|
|||
/*!
|
||||
* @file ColorBlock.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_COLORBLOCK_H
|
||||
#define ADAFRUITIO_COLORBLOCK_H
|
||||
|
||||
#include "AdafruitIO_Block.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with the Adafruit IO Dashboard
|
||||
Color Block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class ColorBlock : public AdafruitIO_Block {
|
||||
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new color block on an Adafruit IO Dashboard.
|
||||
@param d
|
||||
Adafruit IO Dashboard name.
|
||||
@param f
|
||||
Adafruit IO Feed to display on the block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ColorBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
||||
: AdafruitIO_Block(d, f) {}
|
||||
~ColorBlock() {}
|
||||
public:
|
||||
ColorBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f) {}
|
||||
~ColorBlock() {}
|
||||
|
||||
int width = 4; /*!< Dashboard block width. */
|
||||
int height = 4; /*!< Dashboard block height. */
|
||||
int width = 4;
|
||||
int height = 4;
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block type
|
||||
@return Block type.
|
||||
*/
|
||||
/******************************************/
|
||||
const char *type() { return _visual_type; }
|
||||
const char* type() { return _visual_type; }
|
||||
|
||||
protected:
|
||||
const char *_visual_type = "color_picker"; /*!< Block type. */
|
||||
protected:
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns width of block.
|
||||
@return Block width.
|
||||
*/
|
||||
/******************************************/
|
||||
int _width() { return width; }
|
||||
const char *_visual_type = "color_picker";
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns height of block.
|
||||
@return Block height.
|
||||
*/
|
||||
/******************************************/
|
||||
int _height() { return height; }
|
||||
int _width() { return width; }
|
||||
int _height() { return height; }
|
||||
int _row() { return row; }
|
||||
int _column() { return column; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's row location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard row.
|
||||
*/
|
||||
/******************************************/
|
||||
int _row() { return row; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's column location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard column
|
||||
*/
|
||||
/******************************************/
|
||||
int _column() { return column; }
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_COLORBLOCK_H
|
||||
|
|
|
|||
|
|
@ -1,48 +1,31 @@
|
|||
/*!
|
||||
* @file GaugeBlock.cpp
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "GaugeBlock.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new Gauge Block on an Adafruit IO Dashboard.
|
||||
@param d
|
||||
Adafruit IO Dashboard name.
|
||||
@param f
|
||||
Adafruit IO Feed to display on the Gauge.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
GaugeBlock::GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
||||
: AdafruitIO_Block(d, f) {
|
||||
GaugeBlock::GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f)
|
||||
{
|
||||
min = 0;
|
||||
max = 100;
|
||||
ringWidth = "thin";
|
||||
label = "Value";
|
||||
}
|
||||
|
||||
GaugeBlock::~GaugeBlock() {}
|
||||
GaugeBlock::~GaugeBlock(){}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets Gauge block properties.
|
||||
@return String containing properties of the Gauge block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
String GaugeBlock::properties() {
|
||||
String GaugeBlock::properties()
|
||||
{
|
||||
int w = 0;
|
||||
|
||||
if (strcmp(ringWidth, "thin")) {
|
||||
if(ringWidth == "thin") {
|
||||
w = 25;
|
||||
} else {
|
||||
w = 50;
|
||||
|
|
|
|||
|
|
@ -1,89 +1,44 @@
|
|||
/*!
|
||||
* @file GaugeBlock.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_GAUGEBLOCK_H
|
||||
#define ADAFRUITIO_GAUGEBLOCK_H
|
||||
|
||||
#include "AdafruitIO_Block.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with the Adafruit IO Dashboard
|
||||
Gauge Block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class GaugeBlock : public AdafruitIO_Block {
|
||||
|
||||
public:
|
||||
GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~GaugeBlock();
|
||||
public:
|
||||
GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
|
||||
~GaugeBlock();
|
||||
|
||||
int min; /*!< Min. value displayed on gauge. */
|
||||
int max; /*!< Max. value displayed on gauge. */
|
||||
int min;
|
||||
int max;
|
||||
|
||||
const char *ringWidth; /*!< Width of gauge's ring. */
|
||||
const char *label; /*!< Gauge text label. */
|
||||
const char *ringWidth;
|
||||
const char *label;
|
||||
|
||||
int width = 4; /*!< Dashboard block width. */
|
||||
int height = 4; /*!< Dashboard block height. */
|
||||
int width = 4;
|
||||
int height = 4;
|
||||
|
||||
String properties();
|
||||
String properties();
|
||||
const char* type() { return _visual_type; }
|
||||
protected:
|
||||
const char *_visual_type = "gauge";
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block type
|
||||
@return Block type.
|
||||
*/
|
||||
/******************************************/
|
||||
const char *type() { return _visual_type; }
|
||||
int _width() { return width; }
|
||||
int _height() { return height; }
|
||||
int _row() { return row; }
|
||||
int _column() { return column; }
|
||||
|
||||
protected:
|
||||
const char *_visual_type = "gauge"; /*!< Block type. */
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns width of block.
|
||||
@return Block width.
|
||||
*/
|
||||
/******************************************/
|
||||
int _width() { return width; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns height of block.
|
||||
@return Block height.
|
||||
*/
|
||||
/******************************************/
|
||||
int _height() { return height; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's row location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard row.
|
||||
*/
|
||||
/******************************************/
|
||||
int _row() { return row; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's column location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard column
|
||||
*/
|
||||
/******************************************/
|
||||
int _column() { return column; }
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_GAUGEBLOCK_H
|
||||
|
|
|
|||
|
|
@ -1,91 +1,38 @@
|
|||
/*!
|
||||
* @file ImageBlock.h
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#ifndef ADAFRUITIO_IMAGEBLOCK_H
|
||||
#define ADAFRUITIO_IMAGEBLOCK_H
|
||||
|
||||
#include "AdafruitIO_Block.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class for interacting with the Adafruit IO Dashboard
|
||||
Image Block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class ImageBlock : public AdafruitIO_Block {
|
||||
|
||||
public:
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new Image Block on an Adafruit IO Dashboard.
|
||||
@param d
|
||||
Adafruit IO Dashboard name.
|
||||
@param f
|
||||
Adafruit IO Feed to display on the image block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
ImageBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
||||
: AdafruitIO_Block(d, f) {}
|
||||
~ImageBlock() {}
|
||||
public:
|
||||
ImageBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f) {}
|
||||
~ImageBlock() {}
|
||||
|
||||
int height = 6; /*!< Dashboard block height. */
|
||||
int width = 4; /*!< Dashboard block width. */
|
||||
int height = 6;
|
||||
int width = 4;
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block type
|
||||
@return Block type.
|
||||
*/
|
||||
/******************************************/
|
||||
const char *type() { return _visual_type; }
|
||||
const char* type() { return _visual_type; }
|
||||
|
||||
protected:
|
||||
const char *_visual_type = "image"; /*!< Block type. */
|
||||
protected:
|
||||
const char *_visual_type = "image";
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns width of block.
|
||||
@return Block width.
|
||||
*/
|
||||
/******************************************/
|
||||
int _width() { return width; }
|
||||
int _width() { return width; }
|
||||
int _height() { return height; }
|
||||
int _row() { return row; }
|
||||
int _column() { return column; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns height of block.
|
||||
@return Block height.
|
||||
*/
|
||||
/******************************************/
|
||||
int _height() { return height; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's row location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard row.
|
||||
*/
|
||||
/******************************************/
|
||||
int _row() { return row; }
|
||||
|
||||
/******************************************/
|
||||
/*!
|
||||
@brief Returns block's column location
|
||||
on an Adafruit IO dashboard.
|
||||
@return Adafruit IO dashboard column
|
||||
*/
|
||||
/******************************************/
|
||||
int _column() { return column; }
|
||||
};
|
||||
|
||||
#endif // ADAFRUITIO_IMAGEBLOCK_H
|
||||
|
|
|
|||
|
|
@ -1,50 +1,32 @@
|
|||
/*!
|
||||
* @file MapBlock.cpp
|
||||
*
|
||||
* This is part of the Adafruit IO library for the Arduino platform.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Tony DiCola, Todd Treece for Adafruit Industries
|
||||
*
|
||||
* MIT license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
//
|
||||
// Adafruit invests time and resources providing this open source code.
|
||||
// Please support Adafruit and open source hardware by purchasing
|
||||
// products from Adafruit!
|
||||
//
|
||||
// Copyright (c) 2015-2016 Adafruit Industries
|
||||
// Authors: Tony DiCola, Todd Treece
|
||||
// Licensed under the MIT license.
|
||||
//
|
||||
// All text above must be included in any redistribution.
|
||||
//
|
||||
#include "MapBlock.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Creates a new map Block on an Adafruit IO Dashboard.
|
||||
@param d
|
||||
Adafruit IO Dashboard name.
|
||||
@param f
|
||||
Adafruit IO Feed to display on the map.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
MapBlock::MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f)
|
||||
: AdafruitIO_Block(d, f) {
|
||||
MapBlock::MapBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f)
|
||||
{
|
||||
historyHours = 0;
|
||||
tile = "contrast";
|
||||
}
|
||||
|
||||
MapBlock::~MapBlock() {}
|
||||
MapBlock::~MapBlock(){}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Sets map block properties.
|
||||
@return String containing properties of the map block.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
String MapBlock::properties() {
|
||||
String MapBlock::properties()
|
||||
{
|
||||
|
||||
if ((strcmp(tile, "contrast") != 0) && (strcmp(tile, "street") != 0) &&
|
||||
(strcmp(tile, "sat") != 0)) {
|
||||
if(tile != "contrast" && tile != "street" && tile != "sat") {
|
||||
tile = "contrast";
|
||||
}
|
||||
|
||||
props = "{\"historyHours\":\"";
|
||||
String props = "{\"historyHours\":\"";
|
||||
props += historyHours;
|
||||
props += "\",\"tile\":\"";
|
||||
props += tile;
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue