Compare commits

...

27 Commits

Author SHA1 Message Date
Limor "Ladyada" Fried a4e1ee0133
Merge pull request #110 from abachman/abachman-update-IO-tls-fingerprint
update IO TLS fingerprint
2018-02-05 17:17:02 -05:00
Adam Bachman c25d31f813
update IO TLS fingerprint 2018-02-05 17:08:40 -05:00
ladyada 7fffb1e769 bump fix for winc1500 2018-01-29 14:37:03 -05:00
ladyada f0e97737f7 update to wifi101 library 2018-01-29 14:27:41 -05:00
ladyada 5b25a96d1b typo 2018-01-10 00:27:24 -05:00
ladyada 13854f6487 bump! 2018-01-10 00:26:31 -05:00
Limor "Ladyada" Fried a3f09cfa4c
Merge pull request #107 from jerryneedell/patch-1
Update Adafruit_MQTT_Client.cpp to remove use of min()
2018-01-06 19:46:31 -05:00
jerryneedell 2d384b9697
Update Adafruit_MQTT_Client.cpp to remove use of min()
see https://github.com/adafruit/Adafruit_MQTT_Library/issues/106  for discussion of link failures after upgrading esp8266 community library  BSP to version 2.4.0  --  removing the use of min() allows for successful compilation,link and execution.

Replace call to min() with ternary statement to accomplish same action.
2018-01-06 17:52:40 -05:00
Limor "Ladyada" Fried 974f4b8713
Merge pull request #95 from fpistm/min_STL
Fix min() usage when using STL C++
2017-11-21 10:34:32 -05:00
Frederic.Pillon ce9bcab0b4 Fix min() usage when using STL C++
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
2017-10-20 16:15:05 +02:00
Limor "Ladyada" Fried 786ca3fdb2 Merge pull request #87 from per1234/fix-keywords
Use correct separator in keywords.txt
2017-09-02 13:01:03 -04:00
per1234 564f34a84b Use correct separator in keywords.txt
The Arduino IDE requires the use of a tab separator between the name and identifier. Without this tab the keyword is not highlighted.

Reference: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#keywords
2017-09-02 07:56:17 -07:00
Justin Cooper 8a8c0b1228 Update Adafruit IO SSL Fingerprint 2017-08-15 09:31:22 -05:00
Justin Cooper 1e3fb01778 Remove reference to cc3000 2017-08-10 09:28:15 -05:00
Justin Cooper f5bb4e4e97 Remove references to cc3000 2017-08-10 09:27:05 -05:00
Todd Treece 47ebe871e4 Merge pull request #65 from adafruit/io_callbacks
Adafruit IO MQTT Callbacks
2017-02-15 11:39:30 -05:00
Todd Treece 08a4d8bdee Merge branch 'master' of github.com:adafruit/Adafruit_MQTT_Library into io_callbacks 2017-02-15 10:47:41 -05:00
Todd Treece c5233ead52 remove cc3k from supported boards 2016-12-29 16:09:17 -05:00
Todd Treece 3553074d45 bump lib to 0.17.0 2016-12-29 16:09:07 -05:00
Todd Treece c50f42c563 bump version define in Adafruit_MQTT.h 2016-11-21 14:11:52 -05:00
Todd Treece ac37a6e132 bump version in library.properties 2016-11-21 14:11:06 -05:00
Todd Treece ae18e8a6c4 add platform ifdef for subscription length limit 2016-11-20 19:57:21 -05:00
Todd Treece ceeedc2b3c bump to 0.16.1 2016-08-15 17:11:54 -04:00
Todd Treece faad8998f6 simplify feeds in examples 2016-08-15 15:25:08 -04:00
Limor "Ladyada" Fried 5e46585e25 Merge pull request #53 from adafruit/progmem_fixes
Remove FlashStringHelper Methods
2016-08-15 13:19:05 -04:00
Todd Treece e0c88d8d2c remove progmem from examples 2016-08-15 13:06:17 -04:00
Todd Treece b61d7e7024 remove flashstring helper constructors & methods 2016-08-15 13:05:51 -04:00
21 changed files with 48 additions and 571 deletions

View File

@ -204,13 +204,6 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass)
return connect();
}
int8_t Adafruit_MQTT::connect(const __FlashStringHelper *user, const __FlashStringHelper *pass)
{
username = (const char*)user;
password = (const char*)pass;
return connect();
}
uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) {
uint16_t len;
while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) {
@ -444,7 +437,7 @@ void Adafruit_MQTT::processPackets(int16_t timeout) {
else if (sub->callback_io != NULL) {
// huh lets do the callback in io mode
//Serial.print("*** calling io instance callback with : "); Serial.println((char *)sub->lastread);
((sub->io_feed)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);
((sub->io_mqtt)->*(sub->callback_io))((char *)sub->lastread, sub->datalen);
}
}
@ -782,14 +775,6 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
topic = feed;
qos = q;
}
Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
const __FlashStringHelper *feed, uint8_t q) {
mqtt = mqttserver;
topic = (const char *)feed;
qos = q;
}
bool Adafruit_MQTT_Publish::publish(int32_t i) {
char payload[12];
ltoa(i, payload, 10);
@ -831,19 +816,7 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
callback_buffer = 0;
callback_double = 0;
callback_io = 0;
io_feed = 0;
}
Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
const __FlashStringHelper *feed, uint8_t q) {
mqtt = mqttserver;
topic = (const char *)feed;
qos = q;
datalen = 0;
callback_uint32t = 0;
callback_buffer = 0;
callback_io = 0;
io_feed = 0;
io_mqtt = 0;
}
void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackUInt32Type cb) {
@ -858,9 +831,9 @@ void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackBufferType cb) {
callback_buffer = cb;
}
void Adafruit_MQTT_Subscribe::setCallback(AdafruitIO_Feed *f, SubscribeCallbackIOType cb) {
void Adafruit_MQTT_Subscribe::setCallback(AdafruitIO_MQTT *io, SubscribeCallbackIOType cb) {
callback_io = cb;
io_feed = f;
io_mqtt= io;
}
void Adafruit_MQTT_Subscribe::removeCallback(void) {
@ -868,5 +841,5 @@ void Adafruit_MQTT_Subscribe::removeCallback(void) {
callback_buffer = 0;
callback_double = 0;
callback_io = 0;
io_feed = 0;
io_mqtt = 0;
}

View File

@ -30,7 +30,7 @@
#endif
#define ADAFRUIT_MQTT_VERSION_MAJOR 0
#define ADAFRUIT_MQTT_VERSION_MINOR 16
#define ADAFRUIT_MQTT_VERSION_MINOR 17
#define ADAFRUIT_MQTT_VERSION_PATCH 0
// Uncomment/comment to turn on/off debug output messages.
@ -110,9 +110,13 @@
// how much data we save in a subscription object
// eg max-subscription-payload-size
#define SUBSCRIPTIONDATALEN 20
#if defined (__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__)
#define SUBSCRIPTIONDATALEN 20
#else
#define SUBSCRIPTIONDATALEN 100
#endif
class AdafruitIO_Feed; // forward decl
class AdafruitIO_MQTT; // forward decl
//Function pointer that returns an int
typedef void (*SubscribeCallbackUInt32Type)(uint32_t);
@ -121,7 +125,7 @@ typedef void (*SubscribeCallbackDoubleType)(double);
// returns a chunk of raw data
typedef void (*SubscribeCallbackBufferType)(char *str, uint16_t len);
// returns an io data wrapper instance
typedef void (AdafruitIO_Feed::*SubscribeCallbackIOType)(char *str, uint16_t len);
typedef void (AdafruitIO_MQTT::*SubscribeCallbackIOType)(char *str, uint16_t len);
extern void printBuffer(uint8_t *buffer, uint16_t len);
@ -154,7 +158,6 @@ class Adafruit_MQTT {
// error.
int8_t connect();
int8_t connect(const char *user, const char *pass);
int8_t connect(const __FlashStringHelper *user, const __FlashStringHelper *pass);
// Return a printable string version of the error code returned by
// connect(). This returns a __FlashStringHelper*, which points to a
@ -172,19 +175,11 @@ class Adafruit_MQTT {
// to be called before connect() because it is sent as part of the
// connect control packet.
bool will(const char *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0);
bool will(const __FlashStringHelper *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0) {
return will((const char *)topic, payload, qos, retain);
}
// Publish a message to a topic using the specified QoS level. Returns true
// if the message was published, false otherwise.
// The topic must be stored in PROGMEM. It can either be a
// char*, or a __FlashStringHelper* (the result of the F() macro).
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
bool publish(const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos = 0);
bool publish(const __FlashStringHelper *topic, const char *payload, uint8_t qos = 0) {
return publish((const char *)topic, payload, qos);
}
// Add a subscription to receive messages for a topic. Returns true if the
// subscription could be added or was already present, false otherwise.
@ -260,7 +255,6 @@ class Adafruit_MQTT {
class Adafruit_MQTT_Publish {
public:
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed, uint8_t qos = 0);
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feed, uint8_t qos = 0);
bool publish(const char *s);
bool publish(double f, uint8_t precision=2); // Precision controls the minimum number of digits after decimal.
@ -279,12 +273,11 @@ private:
class Adafruit_MQTT_Subscribe {
public:
Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const char *feedname, uint8_t q=0);
Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feedname, uint8_t q=0);
void setCallback(SubscribeCallbackUInt32Type callb);
void setCallback(SubscribeCallbackDoubleType callb);
void setCallback(SubscribeCallbackBufferType callb);
void setCallback(AdafruitIO_Feed *io, SubscribeCallbackIOType callb);
void setCallback(AdafruitIO_MQTT *io, SubscribeCallbackIOType callb);
void removeCallback(void);
const char *topic;
@ -300,7 +293,7 @@ class Adafruit_MQTT_Subscribe {
SubscribeCallbackBufferType callback_buffer;
SubscribeCallbackIOType callback_io;
AdafruitIO_Feed *io_feed;
AdafruitIO_MQTT *io_mqtt;
private:
Adafruit_MQTT *mqtt;

View File

@ -1,152 +0,0 @@
// The MIT License (MIT)
//
// Copyright (c) 2015 Adafruit Industries
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef _ADAFRUIT_MQTT_CC3000_H_
#define _ADAFRUIT_MQTT_CC3000_H_
#include <Adafruit_SleepyDog.h>
#include <Adafruit_CC3000.h>
#include "Adafruit_MQTT.h"
// delay in ms between calls of available()
#define MQTT_CC3000_INTERAVAILDELAY 10
// CC3000-specific version of the Adafruit_MQTT class.
// Note that this is defined as a header-only class to prevent issues with using
// the library on non-CC3000 platforms (since Arduino will include all .cpp files
// in the compilation of the library).
class Adafruit_MQTT_CC3000 : public Adafruit_MQTT {
public:
Adafruit_MQTT_CC3000(Adafruit_CC3000 *cc3k, const char *server, uint16_t port,
const char *cid, const char *user, const char *pass):
Adafruit_MQTT(server, port, cid, user, pass),
cc3000(cc3k)
{}
Adafruit_MQTT_CC3000(Adafruit_CC3000 *cc3k, const char *server, uint16_t port,
const char *user = "", const char *pass = ""):
Adafruit_MQTT(server, port, user, pass),
cc3000(cc3k)
{}
bool connectServer() {
uint32_t ip = 0;
Watchdog.reset();
// look up IP address
if (serverip == 0) {
// Try looking up the website's IP address using CC3K's built in getHostByName
strcpy_P((char *)buffer, servername);
Serial.print((char *)buffer); Serial.print(F(" -> "));
uint8_t dnsretries = 5;
Watchdog.reset();
while (ip == 0) {
if (! cc3000->getHostByName((char *)buffer, &ip)) {
Serial.println(F("Couldn't resolve!"));
dnsretries--;
Watchdog.reset();
}
//Serial.println("OK"); Serial.println(ip, HEX);
if (!dnsretries) return false;
delay(500);
}
serverip = ip;
cc3000->printIPdotsRev(serverip);
Serial.println();
}
Watchdog.reset();
// connect to server
DEBUG_PRINTLN(F("Connecting to TCP"));
mqttclient = cc3000->connectTCP(serverip, portnum);
return mqttclient.connected();
}
bool disconnectServer() {
if (connected()) {
return (mqttclient.close() == 0);
}
else {
return true;
}
}
bool connected() {
return mqttclient.connected();
}
uint16_t readPacket(uint8_t *buffer, uint16_t maxlen, int16_t timeout) {
/* Read data until either the connection is closed, or the idle timeout is reached. */
uint16_t len = 0;
int16_t t = timeout;
while (mqttclient.connected() && (timeout >= 0)) {
//DEBUG_PRINT('.');
while (mqttclient.available()) {
//DEBUG_PRINT('!');
char c = mqttclient.read();
timeout = t; // reset the timeout
buffer[len] = c;
//DEBUG_PRINTLN((uint8_t)c, HEX);
len++;
if (len == maxlen) { // we read all we want, bail
DEBUG_PRINT(F("Read packet:\t"));
DEBUG_PRINTBUFFER(buffer, len);
return len;
}
}
Watchdog.reset();
timeout -= MQTT_CC3000_INTERAVAILDELAY;
delay(MQTT_CC3000_INTERAVAILDELAY);
}
return len;
}
bool sendPacket(uint8_t *buffer, uint16_t len) {
if (mqttclient.connected()) {
uint16_t ret = mqttclient.write(buffer, (size_t)len);
DEBUG_PRINT(F("sendPacket returned: ")); DEBUG_PRINTLN(ret);
if (ret != len) {
DEBUG_PRINTLN("Failed to send complete packet.")
return false;
}
} else {
DEBUG_PRINTLN(F("Connection failed!"));
return false;
}
return true;
}
private:
uint32_t serverip;
Adafruit_CC3000 *cc3000;
Adafruit_CC3000_Client mqttclient;
};
#endif

View File

@ -81,7 +81,7 @@ bool Adafruit_MQTT_Client::sendPacket(uint8_t *buffer, uint16_t len) {
if (client->connected()) {
// send 250 bytes at most at a time, can adjust this later based on Client
uint16_t sendlen = min(len, 250);
uint16_t sendlen = len > 250 ? 250 : len;
//Serial.print("Sending: "); Serial.println(sendlen);
ret = client->write(buffer, sendlen);
DEBUG_PRINT(F("Client sendPacket returned: ")); DEBUG_PRINTLN(ret);

View File

@ -1,7 +1,7 @@
# Adafruit MQTT Library [![Build Status](https://travis-ci.org/adafruit/Adafruit_MQTT_Library.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit_MQTT_Library)
Arduino library for MQTT support, including access to Adafruit IO. Works with
the Adafruit CC3000, FONA, Arduino Yun, ESP8266 Arduino platforms, and anything that supports
the Adafruit FONA, Arduino Yun, ESP8266 Arduino platforms, and anything that supports
Arduino's Client interface (like Ethernet shield).
See included examples for how to use the library to access an MQTT service to
@ -11,10 +11,7 @@ spec but is intended to support enough for QoS 0 and 1 publishing.
Depends on the following other libraries depending on the target platform:
- [Adafruit SleepyDog](https://github.com/adafruit/Adafruit_SleepyDog), watchdog
library used by FONA and CC3000 code for reliability.
- [Adafruit CC3000](https://github.com/adafruit/Adafruit_CC3000_Library), required
for the CC3000 hardware.
library used by FONA code for reliability.
- [Adafruit FONA](https://github.com/adafruit/Adafruit_FONA_Library), required for
the FONA hardware.

View File

@ -39,33 +39,22 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");
// Setup a feed called 'onoff' for subscribing to changes.
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
/*************************** Error Reporting *********************************/
const char ERROR_FEED[] PROGMEM = AIO_USERNAME "/errors";
Adafruit_MQTT_Subscribe errors = Adafruit_MQTT_Subscribe(&mqtt, ERROR_FEED);
const char THROTTLE_FEED[] PROGMEM = AIO_USERNAME "/throttle";
Adafruit_MQTT_Subscribe throttle = Adafruit_MQTT_Subscribe(&mqtt, THROTTLE_FEED);
Adafruit_MQTT_Subscribe errors = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/errors");
Adafruit_MQTT_Subscribe throttle = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/throttle");
/*************************** Sketch Code ************************************/

View File

@ -37,24 +37,18 @@
// WiFiFlientSecure for SSL/TLS support
WiFiClientSecure client;
// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
// io.adafruit.com SHA1 fingerprint
const char* fingerprint = "26 96 1C 2A 51 07 FD 15 80 96 93 AE F7 32 CE B9 0D 01 55 C4";
// io.adafruit.com SHA1 fingerprint. Current fingerprint can be verified via:
// 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"
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Setup a feed called 'test' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char TEST_FEED[] PROGMEM = AIO_USERNAME "/feeds/test";
Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, TEST_FEED);
Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/test");
/*************************** Sketch Code ************************************/

View File

@ -43,23 +43,14 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
// Setup a feed called 'onoff' for subscribing to changes.
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
const char SLIDER_FEED[] PROGMEM = AIO_USERNAME "/feeds/slider";
Adafruit_MQTT_Subscribe slider = Adafruit_MQTT_Subscribe(&mqtt, SLIDER_FEED);
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
Adafruit_MQTT_Subscribe slider = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/slider");
/*************************** Sketch Code ************************************/
@ -163,4 +154,4 @@ void MQTT_connect() {
}
}
Serial.println("MQTT Connected!");
}
}

View File

@ -40,20 +40,14 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = ARB_SERVER;
const char MQTT_USERNAME[] PROGMEM = ARB_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = ARB_PW;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, ARB_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
Adafruit_MQTT_Client mqtt(&client, ARB_SERVER, ARB_SERVERPORT, ARB_USERNAME, ARB_PW);
/****************************** Feeds ***************************************/
// Setup a feed called 'arb_packet' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char ARB_FEED[] PROGMEM = "/feeds/arb_packet";
#define ARB_FEED "/feeds/arb_packet"
Adafruit_MQTT_Publish ap = Adafruit_MQTT_Publish(&mqtt, ARB_FEED);

View File

@ -1,131 +0,0 @@
#include <Adafruit_SleepyDog.h>
#include <Adafruit_CC3000.h>
#include <ccspi.h>
#include <SPI.h>
//#define STATICIP
#define halt(s) { Serial.println(F( s )); while(1); }
uint16_t checkFirmwareVersion(void);
bool displayConnectionDetails(void);
extern Adafruit_CC3000 cc3000;
boolean CC3000connect(const char* wlan_ssid, const char* wlan_pass, uint8_t wlan_security) {
Watchdog.reset();
// Check for compatible firmware
if (checkFirmwareVersion() < 0x113) halt("Wrong firmware version!");
// Delete any old connection data on the module
Serial.println(F("\nDeleting old connection profiles"));
if (!cc3000.deleteProfiles()) halt("Failed!");
#ifdef STATICIP
Serial.println(F("Setting static IP"));
uint32_t ipAddress = cc3000.IP2U32(10, 0, 1, 19);
uint32_t netMask = cc3000.IP2U32(255, 255, 255, 0);
uint32_t defaultGateway = cc3000.IP2U32(10, 0, 1, 1);
uint32_t dns = cc3000.IP2U32(8, 8, 4, 4);
if (!cc3000.setStaticIPAddress(ipAddress, netMask, defaultGateway, dns)) {
Serial.println(F("Failed to set static IP!"));
while(1);
}
#endif
// Attempt to connect to an access point
Serial.print(F("\nAttempting to connect to "));
Serial.print(wlan_ssid); Serial.print(F("..."));
Watchdog.disable();
// try 3 times
if (!cc3000.connectToAP(wlan_ssid, wlan_pass, wlan_security, 3)) {
return false;
}
Watchdog.enable(8000);
Serial.println(F("Connected!"));
uint8_t retries;
#ifndef STATICIP
/* Wait for DHCP to complete */
Serial.println(F("Requesting DHCP"));
retries = 10;
while (!cc3000.checkDHCP())
{
Watchdog.reset();
delay(1000);
retries--;
if (!retries) return false;
}
#endif
/* Display the IP address DNS, Gateway, etc. */
retries = 10;
while (! displayConnectionDetails()) {
Watchdog.reset();
delay(1000);
retries--;
if (!retries) return false;
}
Watchdog.reset();
return true;
}
/**************************************************************************/
/*!
@brief Tries to read the CC3000's internal firmware patch ID
*/
/**************************************************************************/
uint16_t checkFirmwareVersion(void)
{
uint8_t major, minor;
uint16_t version;
if(!cc3000.getFirmwareVersion(&major, &minor))
{
Serial.println(F("Unable to retrieve the firmware version!\r\n"));
version = 0;
}
else
{
Serial.print(F("Firmware V. : "));
Serial.print(major); Serial.print(F(".")); Serial.println(minor);
version = major; version <<= 8; version |= minor;
}
return version;
}
/**************************************************************************/
/*!
@brief Tries to read the IP address and other connection details
*/
/**************************************************************************/
bool displayConnectionDetails(void)
{
uint32_t ipAddress, netmask, gateway, dhcpserv, dnsserv;
if(!cc3000.getIPAddress(&ipAddress, &netmask, &gateway, &dhcpserv, &dnsserv))
{
Serial.println(F("Unable to retrieve the IP Address!\r\n"));
return false;
}
else
{
Serial.print(F("\nIP Addr: ")); cc3000.printIPdotsRev(ipAddress);
Serial.print(F("\nNetmask: ")); cc3000.printIPdotsRev(netmask);
Serial.print(F("\nGateway: ")); cc3000.printIPdotsRev(gateway);
Serial.print(F("\nDHCPsrv: ")); cc3000.printIPdotsRev(dhcpserv);
Serial.print(F("\nDNSserv: ")); cc3000.printIPdotsRev(dnsserv);
Serial.println();
return true;
}
}

View File

@ -1,155 +0,0 @@
/***************************************************
Adafruit MQTT Library CC3000 Example
Designed specifically to work with the Adafruit WiFi products:
----> https://www.adafruit.com/products/1469
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_SleepyDog.h>
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "utility/debug.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_CC3000.h"
/*************************** CC3000 Pins ***********************************/
#define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin!
#define ADAFRUIT_CC3000_VBAT 5 // VBAT & CS can be any digital pins.
#define ADAFRUIT_CC3000_CS 10
// Use hardware SPI for the remaining pins
// On an UNO, SCK = 13, MISO = 12, and MOSI = 11
/************************* WiFi Access Point *********************************/
#define WLAN_SSID "...your SSID..." // can't be longer than 32 characters!
#define WLAN_PASS "...your password..."
#define WLAN_SECURITY WLAN_SEC_WPA2 // Can be: WLAN_SEC_UNSEC, WLAN_SEC_WEP,
// WLAN_SEC_WPA or WLAN_SEC_WPA2
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER "io.adafruit.com"
#define AIO_SERVERPORT 1883
#define AIO_USERNAME "...your AIO username (see https://accounts.adafruit.com)..."
#define AIO_KEY "...your AIO key..."
/************ Global State (you don't need to change this!) ******************/
// Setup the main CC3000 class, just like a normal CC3000 sketch.
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT);
// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the CC3000 MQTT class by passing in the CC3000 class and MQTT server and login details.
Adafruit_MQTT_CC3000 mqtt(&cc3000, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
// You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1); }
// CC3000connect is a helper function that sets up the CC3000 and connects to
// the WiFi network. See the cc3000helper.cpp tab above for the source!
boolean CC3000connect(const char* wlan_ssid, const char* wlan_pass, uint8_t wlan_security);
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
// Setup a feed called 'onoff' for subscribing to changes.
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
/*************************** Sketch Code ************************************/
void setup() {
Serial.begin(115200);
Serial.println(F("Adafruit MQTT demo"));
Serial.print(F("Free RAM: ")); Serial.println(getFreeRam(), DEC);
// Initialise the CC3000 module
Serial.print(F("\nInit the CC3000..."));
if (!cc3000.begin())
halt("Failed");
mqtt.subscribe(&onoffbutton);
while (! CC3000connect(WLAN_SSID, WLAN_PASS, WLAN_SECURITY)) {
Serial.println(F("Retrying WiFi"));
delay(1000);
}
}
uint32_t x=0;
void loop() {
// Make sure to reset watchdog every loop iteration!
Watchdog.reset();
// Ensure the connection to the MQTT server is alive (this will make the first
// connection and automatically reconnect when disconnected). See the MQTT_connect
// function definition further below.
MQTT_connect();
// this is our 'wait for incoming subscription packets' busy subloop
Adafruit_MQTT_Subscribe *subscription;
while ((subscription = mqtt.readSubscription(1000))) {
if (subscription == &onoffbutton) {
Serial.print(F("Got: "));
Serial.println((char *)onoffbutton.lastread);
}
}
// Now we can publish stuff!
Serial.print(F("\nSending photocell val "));
Serial.print(x);
Serial.print("...");
if (! photocell.publish(x++)) {
Serial.println(F("Failed"));
} else {
Serial.println(F("OK!"));
}
// ping the server to keep the mqtt connection alive
if(! mqtt.ping()) {
Serial.println(F("MQTT Ping failed."));
}
}
// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
int8_t ret;
// Stop if already connected.
if (mqtt.connected()) {
return;
}
Serial.print("Connecting to MQTT... ");
while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
Serial.println(mqtt.connectErrorString(ret));
if (ret < 0)
CC3000connect(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); // y0w, lets connect to wifi again
Serial.println("Retrying MQTT connection in 5 seconds...");
mqtt.disconnect();
delay(5000); // wait 5 seconds
}
Serial.println("MQTT Connected!");
}

View File

@ -38,25 +38,17 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");
// Setup a feed called 'onoff' for subscribing to changes.
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
/*************************** Sketch Code ************************************/
@ -152,4 +144,4 @@ void MQTT_connect() {
}
}
Serial.println("MQTT Connected!");
}
}

View File

@ -67,12 +67,10 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char PHOTOCELL_FEED[] = AIO_USERNAME "/feeds/photocell";
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");
// Setup a feed called 'onoff' for subscribing to changes.
const char ONOFF_FEED[] = AIO_USERNAME "/feeds/onoff";
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
/*************************** Sketch Code ************************************/

View File

@ -11,8 +11,7 @@
#include <SPI.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <Adafruit_WINC1500.h>
#include <WiFi101.h>
/************************* WiFI Setup *****************************/
#define WINC_CS 8
@ -20,8 +19,6 @@
#define WINC_RST 4
#define WINC_EN 2 // or, tie EN to VCC
Adafruit_WINC1500 WiFi(WINC_CS, WINC_IRQ, WINC_RST);
char ssid[] = "yournetwork"; // your network SSID (name)
char pass[] = "yourpassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
@ -38,7 +35,7 @@ int status = WL_IDLE_STATUS;
/************ Global State (you don't need to change this!) ******************/
//Set up the wifi client
Adafruit_WINC1500Client client;
WiFiClient client;
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
@ -60,10 +57,7 @@ Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAM
void setup() {
#ifdef WINC_EN
pinMode(WINC_EN, OUTPUT);
digitalWrite(WINC_EN, HIGH);
#endif
WiFi.setPins(WINC_CS, WINC_IRQ, WINC_RST, WINC_EN);
while (!Serial);
Serial.begin(115200);
@ -154,4 +148,4 @@ void MQTT_connect() {
delay(5000); // wait 5 seconds
}
Serial.println("MQTT Connected!");
}
}

View File

@ -3,7 +3,7 @@ Adafruit_MQTT_CC3000 KEYWORD1
Adafruit_MQTT_FONA KEYWORD1
Adafruit_MQTT_Client KEYWORD1
Adafruit_MQTT_Publish KEYWORD1
Adafruit_MQTT_Subscribe KEYWORD1
Adafruit_MQTT_Subscribe KEYWORD1
connect KEYWORD2
connectErrorString KEYWORD2
disconnect KEYWORD2

View File

@ -1,8 +1,8 @@
name=Adafruit MQTT Library
version=0.16.0
version=0.20.1
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=MQTT library that supports the CC3000, FONA, ESP8266, Yun, and generic Arduino Client hardware.
sentence=MQTT library that supports the FONA, ESP8266, Yun, and generic Arduino Client hardware.
paragraph=Simple MQTT library that supports the bare minimum to publish and subscribe to topics.
category=Communication
url=https://github.com/adafruit/Adafruit_MQTT_Library