Hi ,
We defined a project in Cayenne some time ago and it worked fine until a week ago but now we can not connect to mqtt servers and the dashboard tells us that you are offline.
Our university project is a smart greenhouse and we will provide the related code below.
Is there a problem with Cayenne’s servers ?!
Please guide us soon.
Thanks
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP32.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 26
#define DHTTYPE DHT11
#define VIRTUAL_CHANNEL_5 5
DHT_Unified dht(DHTPIN, DHTTYPE);
int maxx=4095 ;
int maxk=4095 ;
int w;
#define relay 12
#define led1 27
#define led2 22
#define led3 23
unsigned long lastMillis = 0;
#define Humsensor 5
char ssid = “";
char wifiPassword[] = "*”;
char username = “";
char password[] = "”;
char clientID = “***”;
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(12 , OUTPUT); //relay
pinMode(led1 , OUTPUT); //led1
pinMode(led2 , OUTPUT); //led2
pinMode(led3 , OUTPUT); //led3
delay(10);
digitalWrite(relay , LOW);
digitalWrite(led1 , LOW);
digitalWrite(led2 , LOW);
digitalWrite(led3 , LOW);
}
void loop() {
Cayenne.loop();
int x = analogRead(Humsensor);
if (x<maxx)
maxx = x ;
int y = map(x, 4095, maxx , 0, 100);
Cayenne.virtualWrite(1,y, “soil_moist” , “p” ); //channel 1
sensors_event_t event;
dht.temperature().getEvent(&event);
Cayenne.celsiusWrite(2, event.temperature); //channel 2,3
dht.humidity().getEvent(&event);
Cayenne.virtualWrite(3, event.relative_humidity, “rel_hum”, “p”);
int sensorValue = analogRead(34);
int w = map(sensorValue, 1, 4095 , 0,100);
Cayenne.virtualWrite(8, w, "lum" , "p" );
delay(200);
}
CAYENNE_IN(4) //pump
{
int currentValuep = getValue.asInt();
if (currentValuep == 1)
{
//do whatever you want when you turn on the button on cayenne dashboard
digitalWrite(relay, HIGH);
}
else
{
//do whatever you want when you turn off the button on cayenne dashboard
digitalWrite(relay, LOW);
}
}
CAYENNE_IN(5) //led1
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
//do whatever you want when you turn on the button on cayenne dashboard
digitalWrite(led1, HIGH);
}
else
{
//do whatever you want when you turn off the button on cayenne dashboard
digitalWrite(led1, LOW);
}
}
CAYENNE_IN(6) //led2
{
int currentValue2 = getValue.asInt();
if (currentValue2 == 1)
{
//do whatever you want when you turn on the button on cayenne dashboard
digitalWrite(led2, HIGH);
}
else
{
//do whatever you want when you turn off the button on cayenne dashboard
digitalWrite(led2, LOW);
}
}
CAYENNE_IN(7) //led3
{
int currentValue3 = getValue.asInt();
if (currentValue3 == 1)
{
//do whatever you want when you turn on the button on cayenne dashboard
digitalWrite(led3, HIGH);
}
else
{
//do whatever you want when you turn off the button on cayenne dashboard
digitalWrite(led3, LOW);
}
}
same here
What to do ?
I just checked and my device is connected. Is it showing online now?
What does the serial monitor output?
MQTT connect failed, error -1
No, My dashboard is offline.!!!
Is your ISP blocking port 1883?
Try to telnet to the port to confirm. If it works you should see:
If it’s blocked you should see:
How do I know if I was blocked or not? what is the method?
The answer is in the post above
how did you do it pls
i need help
how do we check it pls