Arduino uno and Shield W5100 events not working


#21

this feature is something we are working on right now.


#22

Okay, thank you so much, I’m waiting.
and thank you for the attention


#23

shramik

I altered the library CayenneArduinoMQTTClient.h
original pattern

void connect() {
		CAYENNE_LOG("Connecting to %s:%d", CAYENNE_DOMAIN, CAYENNE_PORT);
		int error = MQTT_FAILURE;
		do {
			if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {
				CAYENNE_LOG("Network connect failed");
				delay(1000);
			}
			else if ((error = CayenneMQTTConnect(&_mqttClient)) != MQTT_SUCCESS) {
				CAYENNE_LOG("MQTT connect failed, error %d", error);
				NetworkDisconnect(&_network);
				delay(1000);
			}
		}
		while (error != MQTT_SUCCESS);

CayenneArduinoMQTTClient.h
Changed

void connect() {
		CAYENNE_LOG("Connecting to %s:%d", CAYENNE_DOMAIN, CAYENNE_PORT);
		int error = MQTT_FAILURE;
		
			if (!NetworkConnect(&_network, CAYENNE_DOMAIN, CAYENNE_PORT)) {
				CAYENNE_LOG("Network connect failed");
				int error = MQTT_FAILURE;
				delay(1000);
			}
			else if ((error = CayenneMQTTConnect(&_mqttClient)) != MQTT_SUCCESS) {
				CAYENNE_LOG("MQTT connect failed, error %d", error);
				NetworkDisconnect(&_network);
				delay(1000);
			}

Now button physique works online and offline and when cayenne connected updates status

This change may cause some bug

I ran some tests and it looks ok
Any information I appreciate

Thank you very much for your attention


#24

Great work @jlcamilo77. i tested it out and it seems to be working perfectly.


#25

shramik
I’ve run several tests and it’s working
Testes me every time
The physical button begins to appear after + - 60 seconds
When reconnecting it updates in 10 seconds
I do not see any problem in this case but I will try to reduce the time of 60 for less
know where to look in the library


#26

the publishing time difference between two instances is set to a specific time so as to avoid hitting the rate limit and have the device disconnected. have a look at this topic Sending MQTT messages within rate limits


#27

Thank you
My arduino is disconnecting
It is beyond the limit of messages I will correct my code
Thank you very much.


#28

shramiksalgaonkar
Can you help me
I tried varies times but cayene still disconnects me
Can I show my code?
I’m doing something wrong, you help me.


#29

Yes, share your code.


#30
#include <CayenneMQTTEthernet.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN A0
#define DHTTYPE DHT11
DHT_Unified dht(DHTPIN, DHTTYPE);
#include <EEPROM.h>
#include "MQ7.h"
char username[] = "f6070370-ffbf-11e6-86d2-XXXXXXX";
char password[] = "a7b2f014cd572d647bd96f019eXXXXXXX";
char clientID[] = "dc605c00-afa4-11e8-ab9c-7XXXXXXXXXX";
unsigned long lastMillis = 0;

#define VIRTUAL_CHANNEL 1  // RELE1
#define VIRTUAL_CHANNEL 2  // RELE2
#define VIRTUAL_CHANNEL 3  // RELE3
#define VIRTUAL_CHANNEL 4  // RELE4
#define VIRTUAL_CHANNEL 5  // RELE5
#define VIRTUAL_CHANNEL 6  // RELE6
#define VIRTUAL_CHANNEL 7  // TEMPERATURA
#define VIRTUAL_CHANNEL 8  // HUMIDADE

#define VIRTUAL_CHANNEL 9  // LUX_1
#define VIRTUAL_CHANNEL 10 // LUX_2
#define VIRTUAL_CHANNEL 11 // CO2

#define RELE2_PIN 2
#define RELE3_PIN 3
#define RELE4_PIN 4
#define RELE5_PIN 5
#define RELE6_PIN 6
#define RELE7_PIN 7
#define BUTTON1_PIN 8
#define LDR A1

MQ7 mq7(A2,5.0);
void setup() {
  Serial.begin(9600);
Cayenne.begin(username, password, clientID);
  dht.begin();
  sensor_t sensor;

 pinMode(RELE2_PIN, OUTPUT);
 pinMode(RELE3_PIN, OUTPUT);
 pinMode(RELE4_PIN, OUTPUT);
 pinMode(RELE5_PIN, OUTPUT);
 pinMode(RELE6_PIN, OUTPUT);
 pinMode(RELE7_PIN, OUTPUT);
 
 pinMode(LDR,INPUT_PULLUP);
 pinMode (DHTPIN,INPUT_PULLUP);
 pinMode(A2,INPUT_PULLUP);    
 pinMode(BUTTON1_PIN, INPUT_PULLUP);
          
 digitalWrite(2,EEPROM.read(1));        
 digitalWrite(3,EEPROM.read(2));        
 digitalWrite(4,EEPROM.read(3));        
 digitalWrite(5,EEPROM.read(4));        
 digitalWrite(6,EEPROM.read(5)); 
 digitalWrite(7,EEPROM.read(6)); 

}

void loop(){ 

    
if (digitalRead(BUTTON1_PIN)==LOW){
int state = digitalRead(RELE2_PIN);
digitalWrite(RELE2_PIN,!state);
}

  Cayenne.loop();

if (millis() - lastMillis > 1000) {
 lastMillis = millis(); 
    sensors_event_t event;  
    dht.temperature().getEvent(&event);
    Cayenne.celsiusWrite(7, event.temperature);
       delay(50);
    dht.humidity().getEvent(&event);
    Cayenne.virtualWrite(8, event.relative_humidity, "rel_hum", "p");
           delay(50);
   int vout1 = analogRead(A1);
float vout = vout1/204.6;
float R = (11000-vout*2200)/vout;
//float R = pow( X, -1);
float lux = (pow( R, (1/-0.8616)))/(pow( 10, (5.118/-0.8616)));
float lux2 = 65.9 * (pow( vout1, 0.352));
  Cayenne.virtualWrite(9, lux );   
       delay(50);
  Cayenne.virtualWrite(10, lux2 );   
         delay(50);
  Cayenne.virtualWrite(11, mq7.getPPM() );  
       delay(50);
  Cayenne.virtualWrite(1,digitalRead(2));  
       delay(50);
  Cayenne.virtualWrite(2, digitalRead(3));  
       delay(50); 
  Cayenne.virtualWrite(3, digitalRead(4));  
             delay(50);  
   Cayenne.virtualWrite(4,digitalRead(5)); 
       delay(50);            
  Cayenne.virtualWrite(5,digitalRead(6));      
       delay(50);
  Cayenne.virtualWrite(6,digitalRead(7));  
       
  }
}
CAYENNE_IN(1)
{
 int value = getValue.asInt();
 digitalWrite(RELE2_PIN, value);
         delay(50);
         EEPROM.update(1,digitalRead(2)); 
}
CAYENNE_IN(2)
{
  int value = getValue.asInt();
  digitalWrite(RELE3_PIN, value);
      delay(50);
         EEPROM.update(2,digitalRead(3)); 
}
CAYENNE_IN(3)
{
  int value = getValue.asInt();  
  digitalWrite(RELE4_PIN, value);
        delay(50);
      EEPROM.update(3,digitalRead(4)); 
}
CAYENNE_IN(4)
{
  int value = getValue.asInt();  
  digitalWrite(RELE5_PIN, value);
      delay(50);
        EEPROM.update(4,digitalRead(5)); 
}
CAYENNE_IN(5)
{
  int value = getValue.asInt();  
  digitalWrite(RELE6_PIN, value);
        delay(50);
        EEPROM.update(5,digitalRead(6)); 
}
CAYENNE_IN(6)
{
  int value = getValue.asInt();  
  digitalWrite(RELE7_PIN, value);
         delay(50);
        EEPROM.update(6,digitalRead(7)); 
}


Already tried if (millis() - lastMillis > 1000) 2000, 3000, 4000 and 50000
Please take a look at me.
Thank you

#31

add this two lines and check what is causing the disconnect in your serial monitor

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial