simplify Client

This commit is contained in:
ladyada 2016-08-09 21:12:49 -04:00
parent 665395482e
commit 7886b7243c
2 changed files with 4 additions and 16 deletions

View File

@ -25,7 +25,7 @@
bool Adafruit_MQTT_Client::connectServer() { bool Adafruit_MQTT_Client::connectServer() {
// Grab server name from flash and copy to buffer for name resolution. // Grab server name from flash and copy to buffer for name resolution.
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
strcpy_P((char *)buffer, servername); strcpy((char *)buffer, servername);
DEBUG_PRINT(F("Connecting to: ")); DEBUG_PRINTLN((char *)buffer); DEBUG_PRINT(F("Connecting to: ")); DEBUG_PRINTLN((char *)buffer);
// Connect and check for success (0 result). // Connect and check for success (0 result).
int r = client->connect((char *)buffer, portnum); int r = client->connect((char *)buffer, portnum);

View File

@ -41,17 +41,7 @@ byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
//Set up the ethernet client //Set up the ethernet client
EthernetClient client; EthernetClient client;
// Store the MQTT server, client ID, username, and password in flash memory. Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);
// You don't need to change anything below this line! // You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1); } #define halt(s) { Serial.println(F( s )); while(1); }
@ -61,12 +51,10 @@ Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, M
// Setup a feed called 'photocell' for publishing. // Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // 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, AIO_USERNAME "/feeds/photocell");
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
// Setup a feed called 'onoff' for subscribing to changes. // 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, AIO_USERNAME "/feeds/onoff");
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/