ESP EasyRelay little mod

9 years 9 months ago #346 by cdj
Replied by cdj on topic ESP EasyRelay little mod
Pls i really need it, how i can have status of all nodes when i turn on webui, and howto open/close for 200/300ms arduino relay .... just time to activate home relays....

PLEASE ! :)
Dario

Please Log in or Create an account to join the conversation.

9 years 9 months ago #497 by cdj
Replied by cdj on topic ESP EasyRelay little mod
Ok after 1 week i've obtained :

Simulate a button with :

// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
delay(300);
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_OFF:RELAY_ON);

Now it miss photoresistor sensors parts. It is connected to pin 8,9,10,11 and its declared as :

#define PHOTORES_1 8

in setup added :
pinMode(PHOTORES_1, INPUT);
pinMode(PHOTORES_1 + 1, INPUT);
pinMode(PHOTORES_1 + 2, INPUT);
pinMode(PHOTORES_1 + 3, INPUT);

and NOT SURE if is necessary to add :
esp.present(5, S_DIGITAL_INPUT);
esp.present(6, S_DIGITAL_INPUT);
esp.present(7, S_DIGITAL_INPUT);
esp.present(8, S_DIGITAL_INPUT);
and HOW TO ASSIGN PIN to this node (if necessary, but i think NOT)

Igor two weeks ago you told me :

EasyIoT wrote: In program try this:
in declaration:
Esp8266EasyIoTMsg msgRelay(RELAY_1, V_DIGITAL_VALUE);

and then send status of relay based on arduino pin which is connected to relay
esp.send(msgRelay.set((uint8_t)1));
or
esp.send(msgRelay.set((uint8_t)0));


I've a status = digitalRead (PHOTORES_1);

in this case i must use :
esp.send(msgRelay.set((uint8_t)status)); or something similar ?


Thanks
Dario

Please Log in or Create an account to join the conversation.

9 years 9 months ago - 9 years 9 months ago #502 by cdj
Replied by cdj on topic ESP EasyRelay little mod
After two week of work i'm in a dead point.

i have a status var perfectly working and debugged in serial that give me 4 bit with :
0 if the two lamp is off
1 if first lamp is on
2 if second lamp is on
3 if two lamp is on

when i try to set
msgRelay1.set((uint8_t) status & 1 ? 1 : 0);
and esp.send(msgRelay1);
it doesn't work...

How it works Esp8266EasyIoTMsg msgRelay1(RELAY_1, V_DIGITAL_VALUE); and how it works esp send ?
what is the syntax ?

How i can set relay status ONLY from my photores value (status) ? and not from "on" or "off" button...

You set it on void incomingMessage(const Esp8266EasyIoTMsg &message) but this is easyiot that communicate with arduino and not arduino set status to easyiot....

ONLY THIS !
Thanks a lot
Dario

Here is the code :
/*
 V1.0 - first version
 V1.1 - adopt to new library 
 
 Created by Igor Jarc <igor.jarc1@gmail.com>
 See http://iot-playground.com for details
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 version 2 as published by the Free Software Foundation.
 */
 
 /*Cdj Mod
 OUT RELAY PIN 4,5,6,7
 IN SIGNAL PIN 8,9,10,11
 
 MORSETTIERA VERSO ALTO (X =NON COLLEGATO)
 9-12V      IN 5V       OUT220  220V
 |+|X|-|   |4|3|2|1|X|X|4|3|2|1|L|N|               
 
  */
 
#include <Esp8266EasyIoT.h>
#include <SoftwareSerial.h> 

Esp8266EasyIoT esp; 

SoftwareSerial serialEsp(2, 3);


#define RELAY_1  4  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 1  // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
#define PHOTORES_1 8 //Arduino Digital pin INPUT for photoresistor (second on pin+1)

Esp8266EasyIoTMsg msgRelay1(RELAY_1, V_DIGITAL_VALUE);
Esp8266EasyIoTMsg msgRelay2(RELAY_1 + 1, V_DIGITAL_VALUE);
Esp8266EasyIoTMsg msgRelay3(RELAY_1 + 2, V_DIGITAL_VALUE);
Esp8266EasyIoTMsg msgRelay4(RELAY_1 + 3, V_DIGITAL_VALUE);

int status;
int prevstatus=0;

void setup()
{
  serialEsp.begin(9600);
  Serial.begin(115200);  

  Serial.println("EasyIoTEsp init");

  esp.begin(incomingMessage, 3, &serialEsp, &Serial);
  //esp.begin(incomingMessage, 3, &serialEsp);

  pinMode(RELAY_1, OUTPUT);
  pinMode(RELAY_1 + 1, OUTPUT);
  pinMode(RELAY_1 + 2, OUTPUT);
  pinMode(RELAY_1 + 3, OUTPUT);

  pinMode(PHOTORES_1, INPUT);
  pinMode(PHOTORES_1 + 1,INPUT);
  pinMode(PHOTORES_1 + 2,INPUT);
  pinMode(PHOTORES_1 + 3,INPUT);
  
  esp.present(1, S_DIGITAL_OUTPUT);
  esp.present(2, S_DIGITAL_OUTPUT);
  esp.present(3, S_DIGITAL_OUTPUT);
  esp.present(4, S_DIGITAL_OUTPUT);
  

}


void loop()
{
  esp.process();

  //CDJ Here i define status from photores and it works perfectly 

  status = digitalRead(PHOTORES_1)==HIGH ? 1 : 0;
  status |= digitalRead(PHOTORES_1+1)==HIGH ?  2 : 0;
  status |= digitalRead(PHOTORES_1+2)==HIGH ?  4 : 0;
  status |= digitalRead(PHOTORES_1+3)==HIGH ?  8 : 0;

  if (status != prevstatus) {
    msgRelay1.set((uint8_t) status  & 1 ? 1 : 0);
    msgRelay2.set((uint8_t) status  & 2 ? 1 : 0);
    Serial.print("photores status: ");
    Serial.println(status, HEX);
    Serial.print("msgRelay1 value: ");
    Serial.println(msgRelay1.getBool());
    Serial.print("msgRelay2 value: ");
    Serial.println(msgRelay2.getBool());

    esp.send(msgRelay1);
    esp.send(msgRelay2);
    prevstatus = status;
     
  }
  
  delay(500);
  
}

void incomingMessage(const Esp8266EasyIoTMsg &message) {
  // We only expect one type of message from controller. But we better check anyway.
//appena ricevo messaggio dalla wifi ovvero da server easyiot dico ad arduino cosa fare
  Serial.println("New message");
  if (message.type==V_DIGITAL_VALUE) {
    // Change relay state
    int st;
   
    digitalWrite(message.sensor-1+RELAY_1, message.getBool() ? RELAY_ON : RELAY_OFF);
 //CDJ here i simulate button function
    delay(200);
    digitalWrite(message.sensor-1+RELAY_1, RELAY_OFF);
     
    Serial.print("Incoming change for sensor:");
    Serial.print(message.sensor);
    Serial.print(", New status: ");
    Serial.println(message.getBool());
  
    
  }   
}

Please Log in or Create an account to join the conversation.

9 years 9 months ago - 9 years 9 months ago #519 by cdj
Replied by cdj on topic ESP EasyRelay little mod
UPUPUP ! UPUPUP ! UPUPUP ! UPUPUP !

It works with :
Esp8266EasyIoTMsg msgRelay1(RELAY_1 -3 , V_DIGITAL_VALUE); in status (or it change relay 4 ????????????)

is it concerning my define of RELAY_1 on pin 4 ?

this is my code :
if (photoresstatus == 1 ) esp.send(msgRelay1.set((uint8_t)1));

but dunno why if i put more than one Esp8266EasyIoTMsg everything crash... esp reset and some other strange error in serial monitor...

Please don't stop my project now, i'm just at the end of this MOD. Now with some switch and case system work perfectly, i turn on lights in multiple combination with existent relay... and it is only cosmetic things to update status ...

Infact if some lights is turned on by physical switch and i try to turn it on from easyiot nothing happen, and this is perfect, but it's better to esp.send correct status...in this way it is "state of the art" MOD.

thanks
Dario

Please Log in or Create an account to join the conversation.

9 years 8 months ago #609 by EasyIoT
Replied by EasyIoT on topic ESP EasyRelay little mod
declaration
Esp8266EasyIoTMsg msgRelay1(RELAY_1, V_DIGITAL_VALUE);

somewhere in loop or setup
to send switch on status
esp.send(msgRelay1.set((uint8_t)1));
to send switch off status
esp.send(msgRelay1.set((uint8_t)0));

See LED dimmer example how it sends back switch and level status:
void loop()
{
  if (esp.process())
  {
    if (newLevel != currLevel)
    {
      int dir = ( newLevel - currLevel ) < 0 ? -1 : 1;
      currLevel += dir;
      analogWrite( PWM_OUT, (int)(currLevel / 100. * 255) );
      
      if (newLevel == currLevel)
      {
        esp.send(lightMsg.set(newLevel > 0 ? 1 : 0));
        esp.send( dimmerMsg.set(newLevel) );
      }
      delay( FADE_DELAY );
    }
  }
}
The following user(s) said Thank You: cdj

Please Log in or Create an account to join the conversation.

9 years 8 months ago #611 by cdj
Replied by cdj on topic ESP EasyRelay little mod
Ok i try again, but if i use this code WHEN it works it change me status of RELAY1 + 3 and not of RELAY1. I need to put it in loop because if someone change manually status from switches it must be updated ! this is the "cosmetic" things...

Thanks a lot for your answer, i try again.
Dario

Please Log in or Create an account to join the conversation.

Time to create page: 0.248 seconds

Forum latest

  • No posts to display.