Czujnik zalania

Masz pomysł na funkcjonalność lub koncepcję na rozwój projektu. Opisz wszystko tutaj.
adgl
Posty: 52
Rejestracja: śr lip 24, 2019 5:14 pm
Lokalizacja: Tychy

Prośba o informacje co teraz polecacie na czujnik zalania. Jak soft z GG ustawić ?
Zibi
Posty: 614
Rejestracja: śr lip 31, 2019 9:20 am
Lokalizacja: Białogard

Czujnik zalania dla wygody swobodnego rozmieszczenia i bezpieczeństwa powinien być zasilany z baterii. Wgrywając GG raczej tego nie uzyskasz szybko układ skończy swoją prace ze względu na pobór ESP.
W sieci są różne czujniki ale jakoś nie miałem przekonania.
Ja zrobiłem to od podstaw.
Nadajnik procek + układ radiowy hc12 wykrycie wody wysyła sygnał do odbiornika leci powiadomienie na tel. Co 5 dni czujnik wysyła raport o napięciu baterii na telegram, kiedy chce znać napięcie to odpytuje czujniki, jeśli bateria spadnie poniżej danego progu to czujnik sam wyślę powiadomienie na tel że czas wyjąć i naładować aku. Już ratował życie chodzi rok bez zastrzeżeń.
Załączniki
IMG_20220514_195223.jpg
IMG_20220514_195223.jpg (1.62 MiB) Przejrzano 819 razy
Screenshot_2023-02-05-23-31-32-513_org.telegram.messenger.jpg
Screenshot_2023-02-05-23-31-32-513_org.telegram.messenger.jpg (343.56 KiB) Przejrzano 819 razy
adgl
Posty: 52
Rejestracja: śr lip 24, 2019 5:14 pm
Lokalizacja: Tychy

Kolego to już pełna kontrola :), ale ja takiego sprzętu nie zbuduję i nie oprogramuję. Szukam prostszego rozwiązania, ale dziękuję za profesjonalną propozycję.
LukiSpajder
Posty: 282
Rejestracja: wt sie 18, 2020 2:22 pm

Witam ja mam 5 takich czujników https://allegro.pl/oferta/czujnik-zalan ... 8121110884
Połączonych z bramką Sonoff RF Bridge. Do tego powiadomienie połączone wszystko skryptami z zaworem odcinającym wodę.
mmiikk
Posty: 439
Rejestracja: pn sie 06, 2018 1:27 pm

A dlaczego nie kupisz czujnika tuya z pierwszych stron tego wątku i nie grasz biharki elmaya też z początku tego wątku?
Tutaj dalej wszystko działa jak działało.
rafalekkalwak@wp.pl
Posty: 428
Rejestracja: pn lut 06, 2023 8:56 am

Hi @elmaya,

do you remember which GPIO is connected to the Reed switch/water sensor in that devices from first pages? I bought one, I can easily flash it and wanted to write my own soft for this to use it as trigger for water pump.
To wake it up on reed switch toggled, read status and send data to Supla, then go to sleep.
elmaya
Posty: 1482
Rejestracja: śr cze 27, 2018 5:48 pm
Lokalizacja: El Saucejo - Sevilla

rafalekkalwak@wp.pl pisze: wt wrz 19, 2023 11:28 am Hi @elmaya,

do you remember which GPIO is connected to the Reed switch/water sensor in that devices from first pages? I bought one, I can easily flash it and wanted to write my own soft for this to use it as trigger for water pump.
To wake it up on reed switch toggled, read status and send data to Supla, then go to sleep.
The sensor is not connected to ESP8266, it is connected to STC8F1K08S2 MCU.
This auxiliary MCU communicates with ESP8266 through TX-RX and controls the power supply of the ESP8266.
I attach the source code of my project so you can analyze how it works.
good luck.

Kod: Zaznacz cały

#include "LittleFS.h" // LittleFS is declared       
#include <WiFiClientSecure.h>
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <WiFiManager.h>     
#include <ArduinoJson.h> // V 6
#include <Ticker.h>    

WiFiClientSecure client;
Ticker ticker;

const char* host = "leakage";
const int httpsPort = 443;
int state =0;  
char link_server[51];
char D_Link_1[121];
char D_Link_2[121];
byte mac[6];
String url = "/";
int batState = -1;
bool shouldSaveConfig = false;
bool initialConfig = false;
bool successfull =false;
long int timer1 = 0;         

#define Tuya_Debug false
/*
 * Commands:
 *   tuyasend 1,0,0     Get device info from MCU
 *   tuyasend 2,1,0     fast blink LED
 *   tuyasend 2,1,1     start AP/config mode, power stays on, slow blink LED
 *   tuyasend 2,1,2     LED blink off
 *   tuyasend 2,1,3     ??
 *   tuyasend 2,1,4     Get device status from MCU
*/

// Function to Read serial input
void Tuya_serial(){
  if(Serial.available()){
    byte status = Tuya_Read(1);
    if(status < 64){ // only continue when the device was not started using the device 'connect' button
      if(status & 2){        
      }
    }else{
      state =5;
      }          
  }  
}

// Send a serial message according to Tuya serial protocol, with headers and checksum calculation
byte Tuya_Send(byte cmd, byte len, byte value, byte wait)
{
  while (Serial.available())
    Serial.read();

  Serial.write(0x55);
  Serial.write(0xAA);
  Serial.write(0x00);
  Serial.write(cmd);
  Serial.write(0x00);
  Serial.write(len);
  if(len == 1)
    Serial.write(value);
  byte cs = 0xff + cmd + len + value;
  Serial.write(cs);
  Serial.flush();

  return Tuya_Read(wait);

}

// Read serial output from the Tuya MCU, wait for a given time in mSec. Returns 0 if no reply within the wait time
byte Tuya_Read(int wait)
{
  if(wait == 0)
    wait=500;

  // wait max 'wait' mSec for reply
  for (int x = 0; x < wait; x++){
    if (Serial.available())
      break;
    delay(1);
  }

  #if Tuya_Debug
    // prepare for debug logging
    String reply = "";
  #endif
  
  byte count = 0;       // count number of bytes received within a message
  byte msgType = 0;     // stores message type (byte 4)
  byte length = 0;      // length of entire message as provided by MCU
  byte devState = 0;    // subtype ?
  byte event = 255;     // event state of device, like door open/close
  byte status = 0;      // return value
    //bit 0   0 = no reply (all other bits should be zero too), 1 = reply received
    //bit 1   0 = no event, 1 = event (like open/close, pir move)
    //bit 2   event state, 0 = door open or PIR detect, 1 = door closed
    //bit 3   reserved
    //bit 4   reserved
    //bit 5   battery LOW, not in use, need to investigate protocol
    //bit 6   device button pressed to start device
    //bit 7   not used
     
    // MCU replies
    // 55 aa 0 2 0 0 1  basic confirm
    // 55 aa 0 3 0 0 2  this is received only when the sensor was activated using 5 seconds button press, additional reply after tuyasend 2,1,2

    // Status messages from door sensor: (1.0.0.4)
    // 1  2  3 4 5 6 7 8 9 10 11 12
    // 55 aa 0 5 0 5 1 1 0 1  1  d  door open
    // 55 aa 0 5 0 5 1 1 0 1  0  c  door closed
    // 55 aa 0 5 0 5 3 4 0 1  2  13 battery OK
    // 55 aa 0 5 0 5 3 4 0 1  0  11 battery low (around 2.5 Volts, DoorSensor keeps working until 2.3 Volts)

    // 55 aa 0 5 0 5 1 4 0 1 0 f  PIR

    // Tuya firmware 1.0.0.0:
    // 1  2  3 4 5 6 7  8 9 10 11 12
    // 55 AA 0 5 0 5 65 1 0 1  1  71 door open
    // 55 AA 0 5 0 5 65 1 0 1  0  70 door closed
    // 55 AA 0 5 0 8 67 2 0 4  0  0  0 4C C5  batt?

    // 55 aa 0 5 0 5 1 4 0 1 0 f  WATER LEAKAGE
    // 55 aa 0 5 0 5 1 4 0 1 1 10 NO WATER LEAKAGE

  // process reply
  while (Serial.available()){
    count++;
    byte data = Serial.read();

    if(count == 4) // byte 4 contains message type
      msgType = data;
    if(count == 6) // byte 6 contains data length
      length = data;
    
    if(msgType == 5){ // msg type 5 is a status message
      if (count == 7){ // byte 7 contains status indicator
        devState = data;
      }
      if(count == 11) // byte 11 status indicator value
        event = data;
    }

    #if Tuya_Debug
      // add to logging, msg type 1 is readable text containing device info in json format
      if(msgType == 1){
        if(count > 6 && data != 0){
          reply += (char)data;
        }
      }
      else{ // other msg types are binary, so display as HEX
        reply += String(data, HEX);
        reply += " ";
      }
   #endif
    
    // Check if message is complete, based on msg length (header + checksum = 7 bytes)
    if(count == length + 7){
      
      // We have a complete message, start calculating return value
      
      status |= 1; //set bit 1 to confirm valid response
      
      if(msgType == 3){
        status |= 64; // set bit 6, sensor button pressed for 5 seconds
        state =5;
      }

      if(msgType == 5 && (devState && 3) == 1){ // msg type 5 is a status message, devState 1 (with mask 3) indicates the open/close state
        status |= 2; // set bit 2, event received
        if(event)
          status |= 4; //set event state bit 3
         if(event == 0)state =1;
         if(event == 1)state =2;
          
      }
      if ((devState == 3) && (msgType == 5) && (length == 5)){
          if (event == 0){Serial.println("batery LOW");batState = 0;}
          if (event == 1){Serial.println("batery Medium");batState = 1;}
          if (event == 2){Serial.println("batery HIGH");batState = 2;}
        }
      if(msgType == 5 && (devState && 3) == 3){ // msg type 5 is a status message, devState 3 (with mask 3) indicates battery info
        Serial.print("event 3: ");Serial.println(event);
        if(event == 0){
          status |= 32; //set battery low bit 5
          Serial.println("batery LOW event");
          batState = 0;
        }
        if(event == 1){
          status |= 32; //set battery low bit 5
          Serial.println("batery Medium event");
          batState = 1;
        }
        if(event == 2){
          status |= 32; //set battery low bit 5
          Serial.println("batery HIGH event");
          batState = 2;
        }
      }

      #if Tuya_Debug
        // add to logging string
        if(devState != 0){
          reply += " devState:";
          reply += devState;
        }
        reply += " msg:";
        reply += msgType;
        reply += " length:";
        reply += length;
        if(event != 255){
          reply += " event:";
          reply += event;
        }
        if ((devState == 3) && (msgType == 5) && (length == 5)){
          if (event == 0){Serial.println("batery LOW");batState = 0;}
          if (event == 1){Serial.println("batery Medium");batState = 1;}
          if (event == 2){Serial.println("batery HIGH");batState = 2;}
        }
        // report logging
        Serial.print("Debug! reply ");Serial.println(reply);
        reply = "";
      #endif
      
      // reset counters, status bytes, etc..  for next message to process
      count = 0;
      length = 0;
      msgType = 0;
      devState = 0;
    }
    if(!Serial.available())
      delay(2); // wait for next serial char, timing based on 9600 baud
  }

  return status;

}

void tick(){
   Tuya_Send(2,1,1,500);  //  power stays on, slow blink LED    
}
void saveConfigCallback () {
  shouldSaveConfig = true;
}
void ondemandwifiCallback () {

  client.stop();
  ticker.attach(60.0, tick);

  WiFiManagerParameter custom_link_server("server", "supla server", link_server, 51);
  WiFiManagerParameter custom_D_Link_1("LinkA", "Direct Link 1", D_Link_1, 121);
  WiFiManagerParameter custom_D_Link_2("LinkB", "Direct Link 2", D_Link_2, 121);

  WiFiManager wifiManager;
  wifiManager.setBreakAfterConfig(true);
  wifiManager.setSaveConfigCallback(saveConfigCallback);
  
  wifiManager.addParameter(&custom_link_server);
  wifiManager.addParameter(&custom_D_Link_1);
  wifiManager.addParameter(&custom_D_Link_2);;

  wifiManager.setCustomHeadElement("<style>html{ background-color: #01DF3A;}</style><div class='s'><svg version='1.1' id='l' x='0' y='0' viewBox='0 0 200 200' xml:space='preserve'><path d='M59.3,2.5c18.1,0.6,31.8,8,40.2,23.5c3.1,5.7,4.3,11.9,4.1,18.3c-0.1,3.6-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81z M89,42.6c0.1-2.5-0.4-5.4-1.5-8.1C83,23.1,74.2,16.9,61.7,15.8c-10-0.9-18.6,2.4-25.3,9.7c-8.4,9-9.3,22.4-2.2,32.4c6.8,9.6,19.1,14.2,31.4,11.9C79.2,67.1,89,55.9,89,42.6z M102.1,188.6c0.6,0.1,1.5-0.1,2.4-0.2c9.5-1.4,15.3-10.9,11.6-19.2c-2.6-5.9-9.4-9.6-16.8-8.6c-8.3,1.2-14.1,8.9-12.4,16.6C88.2,183.9,94.4,188.6,102.1,188.6z M167.7,88.5c-1,0-2.1,0.1-3.1,0.3c-9,1.7-14.2,10.6-10.8,18.6c2.9,6.8,11.4,10.3,19,7.8c7.1-2.3,11.1-9.1,9.6-15.9C180.9,93,174.8,88.5,167.7,88.5z'/></svg>");

  wifiManager.setMinimumSignalQuality();

    wifiManager.setConfigPortalTimeout(180);

    if (!wifiManager.startConfigPortal("Supla_leakage")) {
      Serial.println("failed to connect and hit timeout");
      delay(5000);
    }
    Serial.println("connected...yeey :)");
    
    strcpy(link_server, custom_link_server.getValue());
    strcpy(D_Link_1, custom_D_Link_1.getValue());
    strcpy(D_Link_2, custom_D_Link_2.getValue());

    ticker.detach();
  
}

void setup() {  //------------------------------------------------ Setup ----------------------------------------------

  Serial.begin(9600);
  state =0; 
    
  if (WiFi.SSID()==""){   
    initialConfig = true; 
  }

  Serial.println("send 1,0,0 ");
  byte status = Tuya_Send(1,0,0,500);  // Get device info from MCU
  Serial.print("status: "); Serial.println(status);

  if (LittleFS.begin()) {  // ------------------------- wificonfig read -----------------
   // Serial.println("mounted file system");
    if (LittleFS.exists("/config.json")) {
    //  Serial.println("reading config file");
       File configFile = LittleFS.open("/config.json", "r");
      if (configFile) {
       // Serial.println("opened config file");
         size_t size = configFile.size();
         std::unique_ptr<char[]> buf(new char[size]);
         configFile.readBytes(buf.get(), size);
        DynamicJsonDocument json(1024);
        DeserializationError deserializeError = deserializeJson(json, buf.get());
       // serializeJsonPretty(json, Serial);
        if (!deserializeError) {Serial.println("\nparsed json");         
          if (json.containsKey("link_server")) strcpy(link_server, json["link_server"]);
          if (json.containsKey("D_Link_1")) strcpy(D_Link_1, json["D_Link_1"]);
          if (json.containsKey("D_Link_2")) strcpy(D_Link_2, json["D_Link_2"]);       
        } else {
        //  Serial.println("failed to load json config");
           initialConfig = true;
        }
        configFile.close(); 
      }
    }
   } else {
    Serial.println("failed to mount FS");
  } 
  
  host = link_server;
  WiFi.mode(WIFI_STA);
  Tuya_Send(2,1,2,500);  // LED blink off 
  WiFi_up();
  client.setInsecure();
  
}

void loop() { 
  if (shouldSaveConfig) {
  //  Serial.println(" config...");  
    DynamicJsonDocument json(1024);
    json["link_server"] = link_server;
    json["D_Link_1"] = D_Link_1;
    json["D_Link_2"] = D_Link_2;
    File configFile = LittleFS.open("/config.json", "w");
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }
    serializeJsonPretty(json, Serial);
    serializeJson(json, configFile);
    configFile.close();
    Serial.println("config saved");
    shouldSaveConfig = false;
    ticker.detach();
    Tuya_Send(2,1,2,500);  // LED blink off
    Tuya_Send(2,1,3,500);  // device successfully connects to the router.
    Tuya_Send(2,1,4,500);  // Get device status from MCU
    delay(5000);
    WiFi.mode(WIFI_STA);
     
    ESP.restart();
      delay(5000); 
    }
    
  if ((state) == 5 || (initialConfig))  {
    Tuya_Send(2,1,1,500);  //  power stays on, slow blink LED
     Serial.println("state 5 or initialConfig start WiFiConfig");
    ondemandwifiCallback () ; 
  }
  
  if ((WiFi.status() == WL_CONNECTED) && (millis() > timer1))  {
    if (!successfull){
                 Serial.println("send 2,1,3 ");
                byte statuse = Tuya_Send(2,1,3,500);  // device successfully connects to the router.
                Serial.print("status: "); Serial.println(statuse);
                  Serial.print("connecting to ");
                Serial.print(host);
                if (!client.connect(host, httpsPort)) {
                 Serial.println(" connection failed");
                }else{
                 Serial.println(" connected");
                 Serial.println("send 2,1,4 ");
                 statuse = Tuya_Send(2,1,4,500);  // Get device status from MCU
                 Serial.print("status: "); Serial.println(statuse);
                }
      timer1 = millis() + 1000;
    }
  }

  Tuya_serial();
  delay(2);
  Tuya_serial();

  if ((state) == 1 )   {
    url = D_Link_1;
    direct_Link() ;
    state =0; 
  }
   if ((state) == 2 )  {
    url = D_Link_2;
    direct_Link() ;
    state =0; 
  } 
}

void WiFi_up() 
{
  long int StartTime=millis();
  WiFi.mode(WIFI_STA); 
  WiFi.begin();
  Serial.println("conecting WiFi "); 
  while (WiFi.status() != WL_CONNECTED){   
  yield();
  if ((StartTime+5000) > millis()) break;
  }  
}
void direct_Link() {

  Serial.print("requesting URL: ");
  if (batState == 0) url = url + " low batery";
  if (batState == 1) url = url + " medium batery";
  if (batState == 2) url = url + " full batery";
  Serial.println(url);

  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "User-Agent: ESP8266\r\n" +
               "Connection: close\r\n\r\n");

  Serial.println("request sent");
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line == "\r") {
      Serial.println("headers received");
      break;
    }
  }
  String line = client.readStringUntil('}');
  line = line + "}";
  if (line.indexOf("true") >0) { 
    Serial.println("successfull!"); 
    successfull = true;
  } else {
    Serial.println("failed");
    successfull = false;
  }
 #if Tuya_Debug 
  Serial.println("reply was:");Serial.println("==========");  
  Serial.println(line);
  Serial.println("==========");Serial.println("closing connection");
 #endif 
  Serial.print("milis: ");Serial.println(millis()); 
}
rafalekkalwak@wp.pl
Posty: 428
Rejestracja: pn lut 06, 2023 8:56 am

@elmaya thanks a lot, I will give it a try 😉
Awatar użytkownika
myxhir
Posty: 360
Rejestracja: czw sty 07, 2021 12:16 pm
Lokalizacja: Skórzewo, Poznań

Dzisiaj przyszedł do mnie czujnik zalania jednak jest tam inny układ i płytka też:-/ czy da się to osuplowac w jakiś sposób?
Załączniki
20231123_134311.jpg
20231123_134311.jpg (6.82 MiB) Przejrzano 204 razy
20231123_134040.jpg
20231123_134040.jpg (1.76 MiB) Przejrzano 204 razy
Pietras81
Posty: 1702
Rejestracja: ndz lut 17, 2019 6:56 am
Lokalizacja: Osielsko

myxhir pisze: czw lis 23, 2023 12:45 pm Dzisiaj przyszedł do mnie czujnik zalania jednak jest tam inny układ i płytka też:-/ czy da się to osuplowac w jakiś sposób?
Jedyne co możesz zrobić to go wymienić na ESP ale nie wiem czy będzie to działało. Ja robiłem to w zaworze do wody i śmiga ale tutaj nie wiem. Z drugiej strony jak nie spróbujesz to się nie dowiesz. :D
Powodzenia
https://pietras-81.aqi.eco/
ODPOWIEDZ

Wróć do „Pomysły i koncepcje”