1 (edited by domenico 2023-03-15 06:24:58)

Topic: Cloud

hello I have a small project with esp8266 that works in the cloud (remotexy server). the problem is the following: I have two switches that turn the lamps on and off, when I activate the switches from on to off and vice versa most of the time the switches go back to their starting position by themselves so they don't turn the lamps on and off. do i have to delay?

my file


#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>

const int oneWireBus = 14; //assegnazione pin sensore
const int fanPin = D4; // assegnazione pin ventole
const int peltPin = D6; // assegnazione pin fresh
float Temperatura = Temperatura; //riquadro temperatura digit

OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
//////////////////////////////////////////////
//        RemoteXY include library          //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266WIFI_LIB_CLOUD
#include <ESP8266WiFi.h>

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_WIFI_SSID "S"
#define REMOTEXY_WIFI_PASSWORD "my pass"
#define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
#define REMOTEXY_CLOUD_PORT 6376
#define REMOTEXY_CLOUD_TOKEN "my token"


// RemoteXY configurate 
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =   // 169 bytes
  { 255,6,0,5,0,162,0,16,4,1,71,60,10,10,42,42,8,1,24,21,
  135,0,0,0,0,0,0,112,66,0,0,32,65,0,0,32,65,0,0,0,
  64,24,0,7,13,22,43,20,5,8,16,2,3,129,0,27,37,6,6,6,
  194,176,67,0,129,0,7,1,48,6,8,84,101,109,112,101,114,97,116,117,
  114,97,32,66,111,120,0,70,16,18,56,9,9,1,12,0,2,0,31,55,
  22,11,2,26,31,31,79,78,0,79,70,70,0,70,16,18,72,9,9,1,
  12,0,2,0,31,72,22,11,2,26,31,31,79,78,0,79,70,70,0,69,
  1,27,87,10,10,129,0,3,58,10,6,6,70,97,110,0,129,0,1,73,
  16,6,6,70,114,101,115,104,0 };
 
// this structure defines all the variables and events of your control interface
struct {

    // input variables
  float Temperatura;
  uint8_t switch_1; // =1 if switch ON and =0 if OFF
  uint8_t switch_2; // =1 if switch ON and =0 if OFF

    // output variables
  int8_t oneWireBus;  // from 0 to 60
  uint8_t fanPin; // led state 0 .. 1
  uint8_t peltPin; // led state 0 .. 1
  int16_t alarm; // =0 no sound, else ID of sound, =1001 for example, look sound list in app

    // other variable
  uint8_t connect_flag;  // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
//           END RemoteXY include          //
/////////////////////////////////////////////

#define PIN_SWITCH_1 D4
#define PIN_SWITCH_2 D6


void setup() {
  // put your setup code here, to run once:
  RemoteXY_Init ();
 
  pinMode (PIN_SWITCH_1, OUTPUT);
  pinMode (PIN_SWITCH_2, OUTPUT);
  pinMode (oneWireBus, INPUT);
  pinMode (fanPin, OUTPUT); //led fan
  pinMode (peltPin, OUTPUT); // Led frigo
  digitalWrite(fanPin, LOW); // led fan a 0
  digitalWrite(peltPin, LOW); // led frigo a 0
  Serial.begin(9600); // start monitor seriale
  sensors.begin(); // start sensore DS18b20

}

void loop() {
  // put your main code here, to run repeatedly:
  RemoteXY_Handler ();

  sensors.requestTemperatures();
  float temperatureC = sensors.getTempCByIndex(0);
  RemoteXY.oneWireBus = temperatureC;
  RemoteXY.Temperatura = temperatureC;
 
  digitalWrite(PIN_SWITCH_1, (RemoteXY.switch_1==0)?LOW:HIGH); 
  digitalWrite(PIN_SWITCH_2, (RemoteXY.switch_2==0)?LOW:HIGH);
 
  RemoteXY.fanPin = RemoteXY.switch_1;
  RemoteXY.peltPin = RemoteXY.switch_2;

  if (digitalRead(fanPin) == LOW && digitalRead(peltPin) == HIGH) {
    RemoteXY.alarm = RemoteXY.alarm = 2011;
  } else {
    RemoteXY.alarm = RemoteXY.alarm = 0;
    }
}