Slider upadate problem

I added a custon widget type slider
the same work in the cayenne control but when I send the state to the cayenne server to update
webpage or mobile app
the same after + - 10 seconds
goes to 0 the lamp continues with the status only web page and app
Do not update, follow my code.

const int RELE7_PIN = 9;

CAYENNE_IN (13)
{
const int state = getValue.asInt ();
analogWrite (RELE7_PIN, state);
EEPROM.update (70, state);

}
CAYENNE_OUT (13)
{
Cayenne.virtualWrite (13, state);
delay (250);
}
I do not know what I’m doing wrong please help me
thank you

try below code. i hope you understand what was the mistake rather than just copying it.

int state;

CAYENNE_IN (13)
{
    state = getValue.asInt ();
  analogWrite (RELE7_PIN, state);
  EEPROM.update (70, state);

}
CAYENNE_OUT (13)
{
  Cayenne.virtualWrite (13, state);
}

shramik_salgaonkar
I tried with int, char, double, float and finally const int the last code I posted
But none of them update web and app
and after + - 10 seconds returns to 0 and lamp keep state

that not the issue, can you post your entire code which gave you the issue.

shramik_salgaonkar

Follow my code below
I’m using arduino one and w5100

//#define CAYENNE_DEBUG
//#define CAYENNE_PRINT Serial

#include <CayenneMQTTEthernet.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTTYPE DHT11
#define DHTPIN A0
DHT_Unified dht(DHTPIN, DHTTYPE);
#include <EEPROM.h>
#include “MQ7.h”

char username = “f6070370-ffbf-11e6-86d2-ad2f93147d99”;
char password = “a7b2f014cd572d647bd96f019e81bc8fca2226b7”;
char clientID = “86d36650-eb37-11e8-a254-e163efaadfe8”;

byte arduino_mac = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip(192, 168, 1, 100);
IPAddress dns_ip(8, 8, 8, 8);
IPAddress gateway_ip(192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 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 // UMIDADE
#define VIRTUAL_CHANNEL 9 // LUX_1
#define VIRTUAL_CHANNEL 10 // LUX_2
#define VIRTUAL_CHANNEL 11 // CO2
#define VIRTUAL_CHANNEL 12 // SENSOR UMIDADE
#define VIRTUAL_CHANNEL 13 // DIMER
#define VIRTUAL_CHANNEL 14 // CONTATO SECO PARA PORTA
#define VIRTUAL_CHANNEL 15 // SENSOR LUX

#define RELE1_PIN 2
#define RELE2_PIN 3
#define RELE3_PIN 4
#define RELE4_PIN 5
#define RELE5_PIN 6
#define RELE6_PIN 7
#define RELE7_PIN 9
#define RELE8_PIN 8

#define LDR A1
MQ7 mq7(A2, 5.0);
#define SENSOR_SOLO A3
#define SENSOR_LUX A4
#define BUTTON1_PIN A5

unsigned long lastMillis = 0;
int buttonValue;
int state;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
dht.begin();
sensor_t sensor;

pinMode(RELE1_PIN, OUTPUT);
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(RELE8_PIN, OUTPUT);

pinMode(LDR, INPUT_PULLUP);
pinMode (DHTPIN, INPUT_PULLUP);
pinMode(A2, INPUT_PULLUP);
pinMode(SENSOR_SOLO, INPUT_PULLUP);
pinMode(SENSOR_LUX, INPUT_PULLUP);
pinMode(BUTTON1_PIN, INPUT_PULLUP);

digitalWrite(2, EEPROM.read(10));
digitalWrite(3, EEPROM.read(20));
digitalWrite(4, EEPROM.read(30));
digitalWrite(5, EEPROM.read(40));
digitalWrite(6, EEPROM.read(50));
digitalWrite(7, EEPROM.read(60));
analogWrite(9, EEPROM.read(70));

}
void loop() {

buttonValue = analogRead(BUTTON1_PIN);

if (buttonValue >= 160 && buttonValue <= 180) {
RELE1();
}

if (buttonValue >= 210 && buttonValue <= 220) {
RELE2();
}

if (buttonValue >= 240 && buttonValue <= 260) {
RELE3();
}
if (buttonValue >= 10 && buttonValue <= 30) {
RELE4();
}
if (buttonValue >= 60 && buttonValue <= 80) {
RELE5();
}
if (buttonValue >= 110 && buttonValue <= 130) {
RELE6();
}

if (millis() - lastMillis > 2000){
lastMillis = millis();
Cayenne.loop();

sensors_event_t event;
dht.temperature().getEvent(&event);
Cayenne.celsiusWrite(7, event.temperature);
delay(250);
dht.humidity().getEvent(&event);
Cayenne.virtualWrite(8, event.relative_humidity, “rel_hum”, “p”);
delay(250);
int vout1 = analogRead(LDR);
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.luxWrite(9, lux );
delay(250);
Cayenne.luxWrite(10, lux2 );
delay(100);

Cayenne.virtualWrite(11,mq7.getPPM(),“co2”,“ppm”);
delay(250);
int sensorsolo = analogRead(SENSOR_SOLO)/1023*100;
delay(250);
Cayenne.virtualWrite(12,sensorsolo,“rel_hum”, “p”);
delay(250);
int sensorlux = analogRead(SENSOR_LUX);
delay(250);
Cayenne.luxWrite(15,sensorlux);

Cayenne.virtualWrite(1,digitalRead(2));
delay(250);

Cayenne.virtualWrite(2,digitalRead(3));
delay(250);

Cayenne.virtualWrite(3,digitalRead(4));
delay(250);

Cayenne.virtualWrite(4,digitalRead(5));
delay(250);

Cayenne.virtualWrite(5,digitalRead(6));
delay(250);

Cayenne.virtualWrite(6,digitalRead(7));
delay(250);

Cayenne.virtualWrite(13,state);
delay(250);

Cayenne.virtualWrite(14,digitalRead(8));
delay(250);
}
}

CAYENNE_IN(1)
{
int value = getValue.asInt();
digitalWrite(RELE1_PIN, value);
EEPROM.update(10,digitalRead(2));
}
CAYENNE_IN(2)
{
int value = getValue.asInt();
digitalWrite(RELE2_PIN, value);
EEPROM.update(20,digitalRead(3));
}
CAYENNE_IN(3)
{
int value = getValue.asInt();
digitalWrite(RELE3_PIN, value);
EEPROM.update(30,digitalRead(4));
}
CAYENNE_IN(4)
{
int value = getValue.asInt();
digitalWrite(RELE4_PIN, value);
EEPROM.update(40,digitalRead(5));
}
CAYENNE_IN(5)
{
int value = getValue.asInt();
digitalWrite(RELE5_PIN, value);
EEPROM.update(50,digitalRead(6));
}
CAYENNE_IN(6)
{
int value = getValue.asInt();
digitalWrite(RELE6_PIN, value);
EEPROM.update(60,digitalRead(7));
}
CAYENNE_IN(13)
{
int state = getValue.asInt();

analogWrite(RELE7_PIN,state);
EEPROM.update(70,state);

}

CAYENNE_IN(14)
{
int value = getValue.asInt();
digitalWrite(RELE8_PIN, value);
delay(500);
if ((RELE8_PIN)> 0) {
digitalWrite(RELE8_PIN,LOW);
}
}
void RELE1() {
int state = digitalRead(RELE1_PIN);
digitalWrite(RELE1_PIN,!state);
EEPROM.update(10,digitalRead(2));
}
void RELE2() {
int state = digitalRead(RELE2_PIN);
digitalWrite(RELE2_PIN,!state);
EEPROM.update(20,digitalRead(3));
}
void RELE3() {
int state = digitalRead(RELE3_PIN);
digitalWrite(RELE3_PIN,!state);
EEPROM.update(30,digitalRead(4));
}
void RELE4() {
int state = digitalRead(RELE4_PIN);
digitalWrite(RELE4_PIN,!state);
EEPROM.update(40,digitalRead(5));
}
void RELE5() {
int state = digitalRead(RELE5_PIN);
digitalWrite(RELE5_PIN,!state);
EEPROM.update(50,digitalRead(6));
}
void RELE6() {
int state = digitalRead(RELE6_PIN);
digitalWrite(RELE6_PIN,!state);
EEPROM.update(60,digitalRead(7));
}

Thank you for your attention.

in your code, you have initialized state several times. can you assign a different variable for each reading.

OK I will change the variable with each reading and then I will inform the result
Thank you very much for your attention.

shramik_salgaonkar

Thank you very much
I added a global variable
int valuedimer only to update status and now works perfectly
even when energy drops
when it returns it updates everything
as below

int valuedimer;

void setup ()

analogWrite (9, EEPROM.read (70));
valuedimer = (EEPROM.read (70));

CAYENNE_IN (13)
{
int value = getValue.asInt ();
valuedimer = value;
EEPROM.update (70, valuedimer);
analogWrite (9, value);

}
CAYENNE_OUT (13)
{
Cayenne.virtualWrite (13, valuedimer);
delay (250);
}
Thanks a lot for the help

1 Like

nice to see that you were able to solve the issue on your own.

No you helped me
when you told me
to change the variable
again many thanks

2 Likes

shramik_salgaonkar

First Thanks so much for helping me on my project it works perfectly Days ago I made design changes and the status updates for browser actuators are not working for mobile app this ok What can it be

which mobile app are you using, android or ios. Can you try restarting the app, then waiting for the device to show online and then open the online device. if you keep the app in the background, try restarting the app before using it.

shramik_salgaonkar
First, thank you for your attention.
I’m sorry I’ll explain better
The app is android
In the app everything is working perfect
I will explain better
When I click an actuator through the app the system works the app updates ok
But in the browser not
When I click the actuator by the browser it works and updates in the browser and the app got it
just doesn’t update in browser when i click on actuator by android app

we have noted this bug, and will be fixed.

shramik_salgaonkar
Thank you very much

1 Like

I would like to know when PWA will be available