Arduino Mega with W5100 ethernet shield
Platform: Web
This is my code.
/*
Cayenne Value Widget Example
This sketch shows how to set up a Value Custom Widget with Cayenne.
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:
- Attach an analog input device (e.g. a temperature sensor) to your Arduino.
- Set the VIRTUAL_CHANNEL value below to a free virtual channel (or the virtual channel of a Value Custom Widget you have added) in the Dashboard.
- Update the CAYENNE_OUT function below to send the data from your sensor.
- Set the Cayenne authentication info to match the authentication info from the Dashboard.
- Compile and upload this sketch.
- Once the Arduino connects to the Dashboard it should automatically create a temporary display widget (or update the Value widget you have added) with data.
To make a temporary widget permanent click the plus sign on the widget. Use the settings gear icon to change between Value, Gauge and Line Chart widgets.
*/
#include <DHT.h>
#define DHTPIN 2 // what pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h> // Change this to use a different communication device. See Communications examples.
DHT dht(DHTPIN, DHTTYPE);
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “----”;
char password = “----”;
char clientID = “----”;
#define VIRTUAL_CHANNEL1 1
#define VIRTUAL_CHANNEL2 2
#define VIRTUAL_CHANNEL3 3
void setup()
{
Serial.begin(9600);
dht.begin();
Cayenne.begin(username, password, clientID);
}
void loop()
{
Cayenne.loop();
}
// This function is called at intervals to send sensor data to Cayenne.
CAYENNE_OUT(VIRTUAL_CHANNEL1)
{
float t = dht.readTemperature();
Cayenne.virtualWrite(VIRTUAL_CHANNEL1, t , TYPE_TEMPERATURE, UNIT_CELSIUS);
}
CAYENNE_OUT(VIRTUAL_CHANNEL2)
{
float h = dht.readHumidity();
Cayenne.virtualWrite(VIRTUAL_CHANNEL2, h , TYPE_TEMPERATURE, UNIT_PASCAL);
}
CAYENNE_OUT(VIRTUAL_CHANNEL3)
{
float t = dht.readTemperature();
Cayenne.virtualWrite(VIRTUAL_CHANNEL3, t , TYPE_TEMPERATURE, UNIT_CELSIUS);
}
and this’s my serial moniter
Can fix it to stable connection ?