Professional Documents
Culture Documents
This sketch connects to the Cayenne server using an ESP8266 WiFi module as a shield
connected via a hardware serial to an Arduino.
The CayenneMQTT Library is required to run this sketch. If you have not already
done so you can install it from the Arduino IDE Library Manager.
Steps:
1. Install the ESP8266SerialLibrary.zip library via the Arduino IDE (Sketch-
>Include Library->Add .ZIP Library) from the Cayenne extras/libraries
folder (e.g. My Documents\Arduino\libraries\CayenneMQTT\extras\libraries) to
compile this example.
2. Connect the ESP8266 as a shield to your Arduino. This example uses the Serial1
hardware serial pins available on the Mega. You can also try
using a software serial, though it may be less stable.
3. Set the Cayenne authentication info to match the authentication info from the
Dashboard.
4. Set the network name and password.
5. Compile and upload the sketch.
6. A temporary widget will be automatically generated in the Cayenne Dashboard. To
make the widget permanent click the plus sign on the widget.
NOTE: This code requires ESP8266 firmware version 1.0.0 (AT v0.22) or later.
*/
int thermoDO = 4;
int thermoCS = 5;
int thermoCLK = 6;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";
// Set ESP8266 Serial object. In this example we use the Serial1 hardware serial
which is available on boards like the Arduino Mega.
#define EspSerial Serial1
ESP8266 wifi(&EspSerial);
void setup()
{
Serial.begin(9600);
delay(10);
void loop()
{
Cayenne.loop();
}
Cayenne.celsiusWrite(1, thermocouple.readCelsius());
//Cayenne.virtualWrite(2, thermocouple.readFahrenheit());
}
// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel
1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG("Channel %u, value %s", request.channel, getValue.asString());
//Process message here. If there is an error set an error message using
getValue.setError(), e.g getValue.setError("Error message");
}