You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-07-30 13:23:06 +03:00
remove cc3k from supported boards
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,147 +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);
|
||||
|
||||
// Setup the CC3000 MQTT class by passing in the CC3000 class and MQTT server and login details.
|
||||
Adafruit_MQTT_CC3000 mqtt(&cc3000, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
|
||||
|
||||
// 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>
|
||||
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell");
|
||||
|
||||
// Setup a feed called 'onoff' for subscribing to changes.
|
||||
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/onoff");
|
||||
|
||||
/*************************** 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!");
|
||||
}
|
Reference in New Issue
Block a user