Note de ce sujet :
  • Moyenne : 0 (0 vote(s))
  • 1
  • 2
  • 3
  • 4
  • 5
Notification envoyé par le routeur
#1
j avais besoin d avoir des notifications
j ai fait quelque modifications pour recevoir des notification sur smartphone meme si le routeur n est que en local.

j ai fait pour faire le moins de modif du code existant.

sur smartphone faut installer l appli  ntfy  qui est gratuite sans pub  et sans enregistrement  d email 

hyper facile a utiliser faut juste ajouter un sujet  avec unb nom difficile a trouver et s abonner
[Image: Screenshot-20260111-205740-ntfy.jpg]

pour les modif du code 

faut modifer le fichier Actions.cpp  
au debut de la fonctions CallExterne    (ligne 304)  apres if (url != ""){   rajouter

Code :
if (host.startsWith("notif-")) {   
      String chemin = host.substring(6)                  
      send_ntfy_notification(Titre, chemin, !On, port, OrdreOn, OrdreOff);
      return;                                       
    }     
dans  Actions.h
apres la derniere ligne 69  rajouter 
 
Code :
extern void send_ntfy_notification(String titre, String topic, bool state, int port , String sOrdreOn, String sOrdreOff );
voila les modif ducode original.

rajouter  le fichier ntfy.ino
Code :
void send_ntfy_notification(String titre, String topic, bool state, int port , String sOrdreOn, String sOrdreOff ) {
  String ntfy_host = "ntfy.sh";
  int ntfy_port = 443; 
 
  int Priority;
  if (port > 0 && port < 6){
       Priority = port;
  } else {
        Priority = 3;
  }

  String message = titre + " ";
  if (state) {
    message += sOrdreOn;
  } else {
    message += sOrdreOff;
  }
  String notification_title = state ? "ON - Routeur Solaire" : "OFF - Routeur Solaire";
 
  String tags = state ? "white_check_mark,sunny" : "x,moon";
  WiFiClientSecure client;
  client.setInsecure();
  if (!client.connect(ntfy_host.c_str(), ntfy_port, 5000)) {
    StockMessage("Connexion ntfy failed: " + ntfy_host);
    client.stop();
    return;
  }
  String request = "POST /" + topic + " HTTP/1.1\r\n";
  request += "Host: " + ntfy_host + "\r\n";
  request += "Content-Type: text/plain; charset=utf-8\r\n";
  request += "Title: " + notification_title + "\r\n";
  request += "Priority: " + String(Priority) + "\r\n";
  request += "Tags: " + tags + "\r\n";
  request += "Content-Length: " + String(message.length()) + "\r\n";
  request += "Connection: close\r\n";
  request += "\r\n";
  request += message;
  client.print(request);
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      StockMessage("Timeout ntfy");
      client.stop();
      return;
    }
    delay(10);
  }
  bool success = false;
  while (client.connected()) {
    String line = client.readStringUntil('\n');
    if (line.indexOf("200") >= 0) {
      success = true;
      break;
    }
    if (line == "\r") break;
  }
  client.stop();
  if (success) {
    StockMessage("Notification ntfy OK: " + topic +" " + message);
  } else {
    StockMessage("Notification ntfy erreur");
  }
}
voila c est  tous 

comment faire pour le routeur en une notif?

exemple pour envoyer une notif si sonde de temps depasse 60•c
[Image: Screenshot-20260111-213810-Samsung-Internet.jpg]
il faut cree une action avec gpio externe .

Host :doit commencer avec notif-   puis le nom du sujet ntfy ici routeur_azertyui .

Port :c est le type de notif compris de 1 a 5  
1 niveau faible , 5 urgent son + vibrations

ordre on :le texte dans la notif
Répondre



Atteindre :


Utilisateur(s) parcourant ce sujet :
1 visiteur(s)

Moteur MyBB, © 2002-2026 Melroy van den Berg.