ESP 32 Telegram Bot: risparmio energetico e pannello solare con batteria

Salve, sto realizzando il seguente progetto: ho collegato come da immagine, un'esp32(nello specifico una esp32-Wroorm-32) con una scheda ethernet W5500 ad una coppia di relay "meccanici" e ad un relay SSR.

Il codice è il seguente:

#include <SPI.h>
#include <Ethernet.h>
#include <SSLClient.h>
#include <WiFi.h>

#include <AsyncTelegram2.h>
#include <tg_certificate.h>

const char* token =  "XXXXXX:XXXXXX-XXXXX";

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 1, 177);
IPAddress myDns(192, 168, 1, 1);

EthernetClient base_client;
SSLClient client(base_client, TAs, (size_t)TAs_NUM, A0, 1, SSLClient::SSL_ERROR );

AsyncTelegram2 myBot(client);
ReplyKeyboard myReplyKbd;

#define RELAY_CANCELLO       21
#define RELAY_PEDONALE       22
#define RELAY_TRASFORMATORE  33

#define CHAT_ID_1     XXXXXX
#define CHAT_ID_2      XXXXXX
#define CHAT_ID_3       XXXXXX

int64_t chat_ids[] = {CHAT_ID_1, CHAT_ID_2, CHAT_ID_3} ;

bool isAuthorized(int64_t theId) {
  for (int i = 0; i < sizeof(chat_ids) / sizeof(int64_t ); i++) {
    if (chat_ids[i] == theId)
      return true;
  }
  return false;
}

void setup() {
  pinMode(RELAY_CANCELLO, OUTPUT);
  pinMode(RELAY_PEDONALE, OUTPUT);
  pinMode(RELAY_TRASFORMATORE, OUTPUT);

  digitalWrite(RELAY_CANCELLO, HIGH);
  digitalWrite(RELAY_PEDONALE, HIGH);
  digitalWrite(RELAY_TRASFORMATORE, LOW);

  SPI.begin();
  // You can use Ethernet.init(pin) to configure the CS pin
  Ethernet.init(5);  // Most Arduino shields

  // Open serial communications and wait for port to open:
  Serial.begin(115200);   //###

  // start the Ethernet connection:
  //Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");    //###
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");    //###
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");   //###
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
  } else {
    Serial.print("  DHCP assigned IP ");    //###
    Serial.println(Ethernet.localIP());   //###
  }
  delay(1000);

  // Set the Telegram bot properties
  myBot.setUpdateTime(1000);
  myBot.setTelegramToken(token);

  // Check if all things are ok
  Serial.print("\nTest Telegram connection... ");   //###
  myBot.begin() ? Serial.println("OK") : Serial.println("NOK");   //###

  myReplyKbd.addButton("/cancello");
  myReplyKbd.addButton("/pedonale");
  myReplyKbd.addButton("/box_lettere");

  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}


void loop() {
  TBMessage msg;

  if (myBot.getNewMessage(msg)) {
    String msgText = msg.text;

    if (isAuthorized(msg.sender.id)) {
      String msgText = msg.text;

      if (msgText.equals("/cancello")) {
        digitalWrite(RELAY_CANCELLO, LOW);
        myBot.sendMessage(msg, "Cancello aperto/chiuso");
        delay(500);
        digitalWrite(RELAY_CANCELLO, HIGH);
      }
      else if (msgText.equals("/pulsanti")) {
        myBot.sendMessage(msg, "Pulsanti attivati", myReplyKbd);
      }
      else if (msgText.equals("/pedonale")) {
        digitalWrite(RELAY_PEDONALE, LOW);
        myBot.sendMessage(msg, "Cancello pedonale aperto");
        delay(500);
        digitalWrite(RELAY_PEDONALE, HIGH);
      }
      else if (msgText.equals("/box_lettere")) {
        myBot.sendMessage(msg, "Box lettere aperto");
        digitalWrite(RELAY_TRASFORMATORE, HIGH);
        delay(50);
        digitalWrite(RELAY_TRASFORMATORE, LOW);

        delay(500);
      }
      else {
        String reply;
        reply = "Welcome " ;
        reply += msg.sender.username;
        reply += ".\nProva /cancello, /pedonale, o /box_lettere";
        reply += ".\nOppure /pulsanti per attivare i pulsanti";
        myBot.sendMessage(msg, reply);
      }
    }
    else {
      myBot.sendMessage(msg, "Accesso non autorizzato");
    }
  }
}

Volevo chiedere due informazioni/consigli riguardo:

  1. ottimizzazione del codice per ridurre al minimo i consumi

  2. implementazione di un pannello solare(caratteristiche: Potenza = 20W, Voltaggio = 6V, Intensità di corrente elettrica = 5.8A, Tensione circuito aperto = 7.2V, Corrente di corto circuito = 6.7A, Tolleranza potenza = +/- 3%) con l’ausilio di, per quanto ho visto su internet, un CN3791 e di una o più batterie 18650 poste in parallelo.

Per quanto riguarda la 1) ho dato un’occhiata su internet ed mi è sembrato di capire che è possibile ridurre i consumi “disabilitando” i GPIO non utilizzati, ma non mi è ben chiaro quale sia il metodo più corretto. Inoltre volevo completamente disabilitare l’uso del WiFi e del Bluetooth. Qualsiasi altra tecnica di risparmio energia sarebbe utilissima.

Invece per quanto riguarda la 2) non ho capito se collegare due batterie in parallelo(che siano dello stesso lotto, abbiano le stesse caratteristiche, etc.) può essere fatto senza alcun controllo, ad esempio nel caso di collegamento in serie utilizzare un BSM oppure è necessario una sorta di fusibile e di un controllo/controllore di carica. In ogni caso anche qualsiasi altra accortezza è ben accettata.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.