Connection Domoticz avec GET /json.htm?
Connection Domoticz avec GET /json.htm?
Comment débugger une connection avec Domoticz?
J'ai mis le code suivant dans mon ESP8266:
Le but est d'informer un switch Domoticz sur l'état d'une porte.
void InfoDomo()
{
// Lecture de la pin 14 (D5), Switch de la porte
int door = digitalRead(14);
if (client.connect(domoticz_server,port)) {
Serial.println("Sending Values to server...:");
Serial.println("idx,door,server,port:");
Serial.println(idx);
Serial.println(door);
Serial.println(domoticz_server);
Serial.println(":");
Serial.println(port);
client.print("GET /json.htm?type=command¶m=udevice&idx=");
client.print(idx);
client.print("&nvalue=0&svalue=");
client.print(door);
client.println(" HTTP/1.1");
client.print( "Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.println();
client.stop();
}
}
Le moniteur série m'affiche correctement mes lignes d'informations, mais je ne vois rien dans le log de Domoticz
Si je met dans mon browser l'url suivante :
http://192.168.90.10:8084/json.htm?type ... 0&svalue=1
Cela m'affiche :
{
"status" : "OK",
"title" : "Update Device"
}
Mais toujours rien dans le log de Domoticz.
J'ai lu des dizaines d'exemples tous ressemble au code ci-dessus.
Comment peut-on débugger ce genre de problème?
Merci d'avance pour votre aide.
J'ai mis le code suivant dans mon ESP8266:
Le but est d'informer un switch Domoticz sur l'état d'une porte.
void InfoDomo()
{
// Lecture de la pin 14 (D5), Switch de la porte
int door = digitalRead(14);
if (client.connect(domoticz_server,port)) {
Serial.println("Sending Values to server...:");
Serial.println("idx,door,server,port:");
Serial.println(idx);
Serial.println(door);
Serial.println(domoticz_server);
Serial.println(":");
Serial.println(port);
client.print("GET /json.htm?type=command¶m=udevice&idx=");
client.print(idx);
client.print("&nvalue=0&svalue=");
client.print(door);
client.println(" HTTP/1.1");
client.print( "Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.println();
client.stop();
}
}
Le moniteur série m'affiche correctement mes lignes d'informations, mais je ne vois rien dans le log de Domoticz
Si je met dans mon browser l'url suivante :
http://192.168.90.10:8084/json.htm?type ... 0&svalue=1
Cela m'affiche :
{
"status" : "OK",
"title" : "Update Device"
}
Mais toujours rien dans le log de Domoticz.
J'ai lu des dizaines d'exemples tous ressemble au code ci-dessus.
Comment peut-on débugger ce genre de problème?
Merci d'avance pour votre aide.
Re: Connection Domoticz avec GET /json.htm?
Bonjour
j'ai le même problème.
pour ma part c'est lié aux codes d'accès à Domoticz, (pas au réseau local, qui se passe bien)
si je mets un mdp, l'accès est refusé.
si pas de mdp alors le capteur est reçu
il y a des info ici: https://www.domoticz.com/wiki/Domoticz_ ... s#Security
mais je ne sais quel code écrire sous l'IDE Arduino ...
je cherche ....
avez vous trouvé?
j'ai le même problème.
pour ma part c'est lié aux codes d'accès à Domoticz, (pas au réseau local, qui se passe bien)
si je mets un mdp, l'accès est refusé.
si pas de mdp alors le capteur est reçu
il y a des info ici: https://www.domoticz.com/wiki/Domoticz_ ... s#Security
mais je ne sais quel code écrire sous l'IDE Arduino ...
je cherche ....
avez vous trouvé?
-
Chrominator
- Messages : 1042
- Inscription : 19 déc. 2015, 07:29
- Localisation : France
Re: Connection Domoticz avec GET /json.htm?
Pas de source pour vérifier ton code, mais s'il s'agit d'un appel à l'API de DZ, la syntaxe figure dans le wiki :
Si la connexion à DZ est faite à partir du lan ou du wlan, on peut aussi paramétrer DZ pour qu'il ne demande pas de mot de passe dans ce cas spécifique (Dans Setup/Settings/System) :
Si la connexion à DZ est faite à partir du lan ou du wlan, on peut aussi paramétrer DZ pour qu'il ne demande pas de mot de passe dans ce cas spécifique (Dans Setup/Settings/System) :
Un bon frein vaut mieux que deux sparadraps.
Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Re: Connection Domoticz avec GET /json.htm?
Bonjour
Merci pour ce retour rapide.
en effet ça marche bien sur ma démo.
mais DZ sera dans un local associatif, je pense que l'on va vouloir garder l'auth.
mon code pour un ESP32, ci dessous.
on est connecté mais DZ ignore les données semble-t-il.
j'ai lu le wiki mais je ne vois pas comment faire l'authentification dans le code IDE arduino ?
Merci pour ce retour rapide.
en effet ça marche bien sur ma démo.
mais DZ sera dans un local associatif, je pense que l'on va vouloir garder l'auth.
mon code pour un ESP32, ci dessous.
on est connecté mais DZ ignore les données semble-t-il.
j'ai lu le wiki mais je ne vois pas comment faire l'authentification dans le code IDE arduino ?
Code : Tout sélectionner
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
......
WiFiClient client;
......
void printInfo()
{
// Domoticz format alerte /json.htm?type=command¶m=udevice&idx= IDX &nvalue= LEVEL &svalue= TEXT
// IDX = id of your device (This number can be found in the devices tab in the column "IDX")
// Level = (0=gray, 1=green, 2=yellow, 3=orange, 4=red)
// TEXT = Text you want to display
if (client.connect(domoticz_server,port))
{
// Serial.println("Tx to DOMOTICZ");
// Serial.println(Level);
// Serial.println(Text);
client.print("GET /json.htm?type=command¶m=udevice&idx=");
client.print(idx);
client.print("&nvalue=");
client.print(Level);
client.print("&svalue=");
client.print(Text);
client.println(" HTTP/1.1");
client.print("Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
Serial.println("end Tx to Domoticz");
}
else
{Serial.println("no access to DOMOTICZ!!!"); // Domoticz pas lancé.
}
}
Dernière modification par Keros le 12 févr. 2021, 20:47, modifié 1 fois.
Raison : Merci d'utiliser les balises code pour afficher votre script
Raison : Merci d'utiliser les balises code pour afficher votre script
-
Chrominator
- Messages : 1042
- Inscription : 19 déc. 2015, 07:29
- Localisation : France
Re: Connection Domoticz avec GET /json.htm?
Je n'utilise pas l'IDE Arduino, je préfère Visual Studio Code / Platformio.
Si la bibliothèque ESP8266httpUpdate est disponible dans ton environnement, tu peux mettre en œuvre la fonction que j’utilise pour les appels à l'API json de DZ.
La bibliothèque :
La déclaration :
Il faut juste former l'url et appeler la fonction ensuite :
Bien sûr, il faut encoder l'url, j'utilise cette fonction :
Et par exemple pour inscrire du texte dans le log de DZ, je fais comme ça :
En espérant que ça t'aide. 
Si la bibliothèque ESP8266httpUpdate est disponible dans ton environnement, tu peux mettre en œuvre la fonction que j’utilise pour les appels à l'API json de DZ.
La bibliothèque :
Code : Tout sélectionner
#include <ESP8266httpUpdate.h>Code : Tout sélectionner
HTTPClient http;Code : Tout sélectionner
/*****************************************************************
* Call Domoticz JSON API *
*****************************************************************/
String sendDomoticz(String url){
String reply = "";
if (DEBUG) {
Serial.print("connecting to ");
Serial.println(host);
Serial.print("Requesting URL: ");
Serial.println(url);
}
http.begin(host, port, url);
int httpCode = http.GET();
if (httpCode) {
if (httpCode == 200) {
reply = http.getString();
if (DEBUG) {
Serial.println("Domoticz response ");
Serial.println(reply);
}
}
}
if (DEBUG) { Serial.println("closing connection"); }
http.end();
return reply;
Code : Tout sélectionner
/*****************************************************************
* encode url *
*****************************************************************/
String urlencode(String str)
{
String encodedString="";
char c;
char code0;
char code1;
char code2;
for (uint8 i =0; i < str.length(); i++){
c=str.charAt(i);
if (c == ' '){
encodedString+= '+';
} else if (isalnum(c)){
encodedString+=c;
} else{
code1=(c & 0xf)+'0';
if ((c & 0xf) >9){
code1=(c & 0xf) - 10 + 'A';
}
c=(c>>4)&0xf;
code0=c+'0';
if (c > 9){
code0=c - 10 + 'A';
}
code2='\0';
encodedString+='%';
encodedString+=code0;
encodedString+=code1;
//encodedString+=code2;
}
yield();
}
return encodedString;
}
Code : Tout sélectionner
/*****************************************************************
* Add log to Domoticz *
*****************************************************************/
void write2log(String msg, const int level){
if (level <= DEBUG_LEVEL) {
if (DEBUG) { Serial.println(msg); }
sendDomoticz("/json.htm?type=command¶m=addlogmessage&message="+urlencode(String(msg));
}
}Un bon frein vaut mieux que deux sparadraps.
Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Ubuntu 24.04.3 LTS - Domoticz 2025.1 (build 16782)
Pentium G3220T 2.6GHz - 4Go DDR3
RFXtrx433 USB Ver Pro1/1043
Z-Stick GEN5 Version: 1.6-1136-g07ea22bb
Rtl433 RTL-SDR receiver
RFLink Gateway
Zigbee SLZB-06
Re: Connection Domoticz avec GET /json.htm?
OK.
oh! il va falloir que je digère ça ...
oui la librairie existe pour l'IDE Arduino, je l'ai installée
en fait, j'arrive bien a passer le message type alerte à DZ : mais comment faire pour passer la barrière du mot de passe quand il est activé dans DZ ?
comment passer les ID et Pswd ?
en tout cas , en copiant le navigateur Web, le format de la commande ci dessous ça marche.
http://<username:password@>domoticz-ip<:port>/json.htm?type=command¶m=udevice&idx=1&nvalue=2&svalue=TEXT
maintenant il faut que ce soit le ESP32 qui fasse le job. voilà j'espère avoir été plus clair.
oh! il va falloir que je digère ça ...
oui la librairie existe pour l'IDE Arduino, je l'ai installée
en fait, j'arrive bien a passer le message type alerte à DZ : mais comment faire pour passer la barrière du mot de passe quand il est activé dans DZ ?
comment passer les ID et Pswd ?
en tout cas , en copiant le navigateur Web, le format de la commande ci dessous ça marche.
http://<username:password@>domoticz-ip<:port>/json.htm?type=command¶m=udevice&idx=1&nvalue=2&svalue=TEXT
maintenant il faut que ce soit le ESP32 qui fasse le job. voilà j'espère avoir été plus clair.
Re: Connection Domoticz avec GET /json.htm?
bonsoir,
finalement j'ai trouvé:
cle "id : pswd" à générer avec l'algo base64
To encode a string using base64 you could use : codebeautify.org/base64-encode
ligne a mettre dans le code C++ ESP32: client.println("Authorization: Basic <clé base64>");
..........
client.println(" HTTP/1.1");
client.print("Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("Authorization: Basic <clé base64>");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
..............
https://www.domoticz.com/wiki/Domoticz_ ... parameters
https://forum.arduino.cc/index.php?topic=131722.0
à bientôt !
Mike_78
finalement j'ai trouvé:
cle "id : pswd" à générer avec l'algo base64
To encode a string using base64 you could use : codebeautify.org/base64-encode
ligne a mettre dans le code C++ ESP32: client.println("Authorization: Basic <clé base64>");
..........
client.println(" HTTP/1.1");
client.print("Host: ");
client.print(domoticz_server);
client.print(":");
client.println(port);
client.println("Authorization: Basic <clé base64>");
client.println("User-Agent: Arduino-ethernet");
client.println("Connection: close");
client.println();
client.stop();
..............
https://www.domoticz.com/wiki/Domoticz_ ... parameters
https://forum.arduino.cc/index.php?topic=131722.0
à bientôt !
Mike_78