Multi devices eventor

My bad, there’s wrong ground… Sorry

I gonna try to explain…

I’ve my to devices : 1 - relay / 2 - sensor , with bridge between them. Dependent wich i strart first i’ve problem with them.

Exemple : if i restart relay devices i’ve blue led ( on devices 2 ) which is blinking quickly and no lot of power ( little blinking ) and no value on my sensor.

To fix it i’ve to change ground postition of DS18B20 on devices 2… Really i don’t understand at all…

I’m wondering if it would be better if you wrote in your own language and let us use Google translate or deepl, as I can’t understand what your problem is.
You clearly need to use many more words to explain the issue in much greater depth, but maybe it’s your lack of English that’s holding you back in this area?

Pete.

I will try to explain,

I have two devices which I call devices master (receiver) and diveces slave (sender). With a blynk bridge in between.

Depending on which one I start first I have a problem.

For example, if I restart the master device, the blue led of the second flashes quickly and shines little and I have no value from my temperature probes

To avoid this I noticed that if I change the pin ground of my temperature probes it fixes the problem.

I really do not understand

Sorry i will use the translator more often

Try taking a step back and looking at the questions and comments that you’ve asked and made within this topic.

Is it possible for anyone to look at the information available and make any sense of it?
Your latest example has no code relating to an LED, but you are using your OneWire bus on GPIO2, which is the pin that the onboard physical LED of a NodeMCU is connected to (poor choice of OneWire pin).
However, there is no reason to be running OneWire on the receiving device, as your sensors are connected to your sending device.

BTW, the sending device is usually referred to as the master, and the receiving device as the slave.

Then you have 4 timers all running every 500ms (far to fast in my opinion) and the timers will all try to execute at exactly the same time, rather than you staggering the timers so that they execute one after another.
But why are you using 4 timers at all? Why not have one function which reads each sensor in turn and pushes that sensor’s result to Blynk?

Then, you ask random questions about code dumped in your void loop, and when you’re told that the code should also be called with a time per you respond with a random statement about void setup, then don’t clarify that, then jump to a different question.

Your communication is all over the place, and written in a language that is almost incomprehensible.

I’m happy to try to help you, but I’m not going to keep asking you what your comments mean, and asking for clarification and receiving random comments in return.
If you wnat my help, your communication needs to be far more structured, comprehensive and explanatory than what I’m seeing from you at present - hence my suggestion to be more verbose in your native language.

I’ll take a step back from your questions until you start communicating in a way that I can understand.

Pete.

I totally understand. I am by nature quite confused and will try to remedy it because you are a great help to me.

With each of your answers I learn a little more. You don’t try to teach me, you teach me.
Without you I would still be in my infancy. AND I have come a long way from then this first post Blynk-client invalid token

These projects are important to me, it’s my only activity because of my health.

I spent my day restructuring and simplifying my codes so that they were readable and easy to study.

so from this problem I just changed the pins of my relay to avoid using the one wire.
All my project is working well so far.

Now that my probes are working and that the sensors divisions (MASTER) send the values ​​to the relay devices (SLAVE) your term of hysteresis interests me. Because indeed when the temperature varies between max and max - 0.5 the order and relight, sometimes every three seconds.
It is true that for some system the number of engagement can wear out the contactors prematurely.

I did some research on the internet without really finding an answer. From what I understand the hysteresis is just a value that represents n - x. But I can’t find how to implement it in my code

and here is my new code which is cleaner and more functional (well I think, if there is something to improve don’t hesitate to tell me!)

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
WidgetBridge bridge1(V0);
BLYNK_CONNECTED() {
  bridge1.setAuthToken("ZXNyOmxGYuFkReodok-DRIPaaYASbCE-");
}

//DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2        // This is the ESP8266 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
DeviceAddress tempSensor1 = { 0x28, 0xFF, 0x3A, 0xD4, 0x89, 0x16, 0x3, 0x36 };
DeviceAddress tempSensor2 = { 0x28, 0xFF, 0xF, 0x6E, 0xA2, 0x16, 0x4, 0x3C };
DeviceAddress tempSensor3 = { 0x28, 0xFF, 0xD7, 0x22, 0x8A, 0x16, 0x3, 0x9C };
DeviceAddress tempSensor4 = {0x28,  0xFF,  0x87,  0xCB,  0x89,  0x16,  0x3,  0x37  };
int temperature1;
int temperature2;
int temperature3;
int temperature4;

//DHT11

#include <DHT.h>
#define DHTPIN 14
#define DHTTYPE DHT11  // DHT TYPE ( 21 / 22 )
DHT dht(DHTPIN, DHTTYPE);

//TSL

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_TSL2561_U.h>
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);

char auth[] = "xxx";
char ssid[] = "xxx";
char pass[] = "xxx";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  while (Blynk.connect() == false) {
  }
  //DS18B20
  sensors.begin();
  sensors.setResolution(tempSensor1, 10);
  sensors.setResolution(tempSensor2, 10);
  sensors.setResolution(tempSensor3, 10);
  sensors.setResolution(tempSensor4, 10);
  timer.setInterval(1000L, sendDS18B20);
  //DHT11
  dht.begin();
  timer.setInterval(1000L, sendDHT);
  //TSL2561
  timer.setInterval(1000L, sendTSL);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void sendDS18B20 ()

{
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures();
  Serial.println("DONE");

  Serial.print("Temperature is: ");
  Serial.println(sensors.getTempC(tempSensor1));

  temperature1 = sensors.getTempC(tempSensor1);
  Blynk.virtualWrite(V10, temperature1);

  temperature2 = sensors.getTempC(tempSensor2);
  Blynk.virtualWrite(V11, temperature2);

  temperature3 = sensors.getTempC(tempSensor3);
  Blynk.virtualWrite(V12, temperature3);
  bridge1.virtualWrite(V0, temperature3);

  temperature4 = sensors.getTempC(tempSensor4);
  Blynk.virtualWrite(V13, temperature4);
}

void sendDHT()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  }

  else {
    Serial.println("DHT sensor OK");
  }

  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V21, h);
  Blynk.virtualWrite(V22, t);
}

void sendTSL()
{

  sensors_event_t event;
  tsl.getEvent(&event);
  tsl.enableAutoRange(true);
  tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS);

  Serial.println("");
  if (!tsl.begin())
  {
    Serial.print("No TSL2561 detected");
  }

  if (event.light)
  {
    Serial.print(event.light);
    Serial.println(" lux");
  }
  else
  {
    Serial.println("Sensor overload");
  }

  {
    Blynk.virtualWrite(V20, event.light);
  }
}

So the 50+ instances where it’s discussed in this forum didn’t help?…

https://community.blynk.cc/search?q=hysteresis%20

I’ve already mentioned the fact that you are reading your sensors to often, your timers are coinciding and that you don’t really need 3 timers anyway. Plus the fact that GPIO2 isn’t a great OneWire pin choice.

Pete.

That’s settled

Tomorrow I will continue to find out about the hysterise

   void relaisTemp()   //boucle temperature

{
  Serial.print(TempSom);
  Serial.println("°C");


  if (TempSom >= (MaxTemp + 1))
  {

    digitalWrite(relais1, LOW);
  }

  if else (TempSom <= (MaxTemp - 1))
  {
    digitalWrite(relais1, HIGH);
  }
}

Sound good? Seems like that just shifts the problem. The variations that existed between 29.9 and 30 are the same between 28.9 and 29

My system managing the cooling of a small volume when the extraction turns on I quickly fall below MaxTemp. Sometimes even several times in one minute. Wouldn’t be a good idea to add a delay of X seconds to avoid several starts in a row

I don’t understand where these numbers are coming from.

In you code snippet, if the target temperature (MaxTemp) is set to 30 degrees then the relay will go LOW at 31 degrees and HIGH at 29 degrees, giving a two degree latitude.

Pete.

So this is ok

I got confused… Sorry

For the rest I would like to make a programmer, is it a good idea to replace a mechanical programmer with one coded on an esp8266?

I guess it depends on your reasons for doing it.
Mechanical thermostats that use bi-metallic strips have built-in hysteresis because of the way they work and their lag in responding to changes. There is very little to go wrong, so are very reliable. We have one in our house that is over 25 years old and still works perfectly.

Obviously it can’t be used to turn the heating on/off remotely or set the temperature remotely.

Any system is only as good as it’s weakest part (which for a smart system includes the code it’s running) and the more components you have the greater the risk of failure.

Pete.

I understand, I still want to try, since my goal is to learn, and I also see the advantage that in the event of a long power cut, a programmer based on esp8266 will reset itself on the PSTN time.

Can the RTC time be based on the server? in this way there is a power cut and a disconnection from the internet the program will restore the RTC time

Which library do you recommend for me to do this? (in 24 hour format)

You can use a hardware RTC with built-in battery backup.

Yes, but with local server how are you going to ensure that this is correct?

TimeLib

Pete.

Because it’s either always on or internet based I believe

I’m thinking of doing something like this:

If time = 07.00 → relay on
delay 18 hours
relay off

does it work well?

void setup1
{
  if (hour = 7)
     digitalWrite (15, LOW);
     delay(28000000)
     digitalWrite(15, HIGH);
}

    void setup2
    {
      if (hour = 7)
         digitalWrite (15, LOW);
         delay(43200000)
         digitalWrite(15, HIGH);
    }

delay(28000000) : the best is to put a delay or to call 15:00?

Only always on in a power cut if you have a UPS big enough to keep it running.
If you’ve set the Pi up to synchronise to a NTP server and set the timezone correctly then it will synchronise when an internet connection becomes available, but you could do the same for your ESP device too.

No, not really.

Might be best to stick with the mechanical controller you already have.

Pete.

Never !

Does this one look good to you?

#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

char auth[] = "xxx";
char ssid[] = "xxxx";
char pass[] = "xxx";

BlynkTimer timer;

WidgetRTC rtc;


BLYNK_CONNECTED() {
  // Synchronize time on connection
  
}

int OnHours = 7;
int OffHours = 25;


void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass, IPAddress(10, 3, 141, 1), 8080);
  rtc.begin();

  setSyncInterval(800);

  timer.setInterval(1000L, clockDisplay);
  timer.setInterval(1000L, cycle1);
}

void loop()
{
  Blynk.run();
  timer.run();
}

void clockDisplay()
{

  String currentTime = String(hour()) + ":" + minute() + ":" + second();
  String currentDate = String(day()) + " / " + month() + " / " + year();
  Serial.print("Current time: ");
  Serial.print(currentTime);
  Serial.print(" ");
  Serial.print(currentDate);
  Serial.println();

  // Send time to the App
  Blynk.virtualWrite(V1, currentTime);
  // Send date to the App
  Blynk.virtualWrite(V2, currentDate);
}

void cycle1()
{

  int Hours = second();
  if (Hours == OnHours)
  {
    Serial.print("debut de cylcle ");
    digitalWrite (15, HIGH);
    Serial.println ("lampe on");
  }

  if (Hours == OffHours)
  {
    Serial.print("fin de cylcle ");
    digitalWrite (15, LOW);
    Serial.println ("lampe off");
  }


}

No, it doesn’t.

I’m really not going to engage in this conversation any further, but I’ll leave you with a few pointers regarding the glaring problems…

Overlapping timers…

25 hour days…

Hours = second() ???..

Hard-coded start/stop times…

Blocking code so that your heating won’t work independently of your Blynk local server…

Not using sprintf to sort out your time formatting…

Good luck!

Pete.

As I said before I use seconds to do my tests, I can’t see myself waiting 18 to see if it works.

I don’t want they work without server

What do you mean? I don’t understand

I will find out about the differences between the two.