comment executé la requete
2 participants
Page 1 sur 1
comment executé la requete
Bonjour stephane,
comment exécuté cette requete http avec la fonction avatar client
http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=Off
j'ai essayer la fonction Avatar.runApp , ca ne se passe rien
merci d'avance
comment exécuté cette requete http avec la fonction avatar client
http://127.0.0.1:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=Off
j'ai essayer la fonction Avatar.runApp , ca ne se passe rien
merci d'avance
halim- Messages : 92
Date d'inscription : 19/11/2022
Re: comment executé la requete
Est-ce que tu as essayé de mettre dans ta requête une adresse IP plutôt que le localhost et utiliser ensuite une fonction request ?
Avatar- Messages : 80
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse
Re: comment executé la requete
bonjour stephane,
si je colle l'url sur le navigateur edge ou je suis connecté avec mon compte outlook la commande s'execute avec l'ip locale ou l'ip de l'appareil ou est installer le logiciel domoticz,
http://192.168.1.1XX:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On
http://127.0.0.1:8080/:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On
sur d'autre navigateur google ou firefox, erreur d"autorisation
mais avec ca sur le navigateur edge, soit erreur sur la requete soit pas d'autorisation
xboxOn : function() {
Avatar.runApp('http://192.168.1.1XX:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On', null, data.client, () => {
Avatar.Speech.end(data.client);
});
},
fetch('http://192.168.1.1XX:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=Off')
.then(response => {
if (!response.ok) {
throw new Error('la response du réseau n\'est pas ok');
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('probleme avec la requete fetch', error);
});
si je colle l'url sur le navigateur edge ou je suis connecté avec mon compte outlook la commande s'execute avec l'ip locale ou l'ip de l'appareil ou est installer le logiciel domoticz,
http://192.168.1.1XX:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On
http://127.0.0.1:8080/:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On
sur d'autre navigateur google ou firefox, erreur d"autorisation
mais avec ca sur le navigateur edge, soit erreur sur la requete soit pas d'autorisation
xboxOn : function() {
Avatar.runApp('http://192.168.1.1XX:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=On', null, data.client, () => {
Avatar.Speech.end(data.client);
});
},
fetch('http://192.168.1.1XX:8080/json.htm?type=command¶m=switchlight&idx=20&switchcmd=Off')
.then(response => {
if (!response.ok) {
throw new Error('la response du réseau n\'est pas ok');
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('probleme avec la requete fetch', error);
});
halim- Messages : 92
Date d'inscription : 19/11/2022
Re: comment executé la requete
Je comprend pas ton dev.
Tu fais un runapp et un fetch derrière... avec les mêmes paramètres ?
Ecoute, tu ne devrais pas t'emballer.
Dans un 1er temps, tu fais un truc très basic avec une fonction request basique.
Tu as des exemples dans le plugin eeDomus au cas où...
Dans le fichier node_modules\lib-avatar\eedomus.js
Ensuite si ca ne fonctionne pas, tu cherches sur le net des infos concernant ton problème. De ce que je comprend, c'est une passerelle Domoticz ? Ben ca c'est un truc sur lequel tu peux trouver facilement. Et ciblé peut-etre "authent" pourquoi pas, vu ce que tu me dis.
Et seulement ensuite lorsque ca fonctionne, tu améliores ton dev si tu veux en utilisant des trucs "super high level"... :-) En dev, c'est une bonne approche, crois-moi.
A+, bon courage
Tu fais un runapp et un fetch derrière... avec les mêmes paramètres ?
Ecoute, tu ne devrais pas t'emballer.
Dans un 1er temps, tu fais un truc très basic avec une fonction request basique.
Tu as des exemples dans le plugin eeDomus au cas où...
Dans le fichier node_modules\lib-avatar\eedomus.js
Ensuite si ca ne fonctionne pas, tu cherches sur le net des infos concernant ton problème. De ce que je comprend, c'est une passerelle Domoticz ? Ben ca c'est un truc sur lequel tu peux trouver facilement. Et ciblé peut-etre "authent" pourquoi pas, vu ce que tu me dis.
Et seulement ensuite lorsque ca fonctionne, tu améliores ton dev si tu veux en utilisant des trucs "super high level"... :-) En dev, c'est une bonne approche, crois-moi.
A+, bon courage
Avatar- Messages : 80
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse
Re: comment executé la requete
non stephane , j'ai fait 2 fonctions, j'ai tester avec un runapp ensuite avec une autre fonction avec une requete en fetch,
domoticz c'est un logiciele sur une page internet, pas une passerelle,
je pense je vais faire ce que tu m'as dit il faut avec une authentification, je vais faire une recherche sur le net
merci encore pour ton aide, stephane
domoticz c'est un logiciele sur une page internet, pas une passerelle,
je pense je vais faire ce que tu m'as dit il faut avec une authentification, je vais faire une recherche sur le net
merci encore pour ton aide, stephane
halim- Messages : 92
Date d'inscription : 19/11/2022
Re: comment executé la requete
je parlais d'une passerelle puisque tu veux te connecter à domoticz depuis avatar.
J'ai regardé vite fait et il y a des modules nodejs qui font ca très bien.
Et effectivement en regardant le code, il faut un login/passwd
Tape "domoticz nodejs github" dans un navigateur, tu vas trouver ton bonheur, voir au pire de très bon exemples si tu veux développer toi même ton intégration.
J'ai regardé vite fait et il y a des modules nodejs qui font ca très bien.
Et effectivement en regardant le code, il faut un login/passwd
Tape "domoticz nodejs github" dans un navigateur, tu vas trouver ton bonheur, voir au pire de très bon exemples si tu veux développer toi même ton intégration.
Avatar- Messages : 80
Date d'inscription : 01/09/2020
Age : 58
Localisation : Toulouse
Re: comment executé la requete
oui exactement stephane, je veux me connecter a domoticz depuis avatar ou plus precisément, je veux creer un simple plugin domoticz associer le harmony hub de logitech, pour l'assistant avatar
le plugin seras developper avec le plugin studio toujour en multiroom, comme tu me conseille toujours je vais aller doucement
le code seras quelque chose comme ca:
exports.init = function () {
parametres = {
ip_domoticz : Config.modules.Domoticz.ip_domoticz,
}
}
exports.action = function(data, callback){
if (!parametres.ip_domoticz) {
Avatar.speak("La configuration de l'ip domoticz est manquante", data.client, () => {
Avatar.Speech.end(data.client);
});
return;
}
var tblCommand = {
tvOn : function() {
// state = "On";
return toggleOnOff ("On", data, client,)
},
tvOff : function() {
return toggleOnOff ("Off", data, client);
},
hdmi1 : function() {
return toggleOnOff (data, client,)
},
hdmi2 : function() {
return toggleOnOff (data, client);
},
hdmi3 : function() {
return toggleOnOff (data, client);
},
xboxOn : function() {
return toggleOnOff ("On", data, client);
},
xboxOff : function() {
return toggleOnOff ("Off", data, client);
}
};
function toggleOnOff(data, client, state) {
const idx = Config.modules.Domoticz.clients[client][data.action.command];
Avatar.runApp(`http://${parametres.ip_domoticz}/json.htm?type=command¶m=switchlight&idx=${idx}&switchcmd=${state}`, null, data.client, () => {
Avatar.speak(Config.modules.Domoticz.tts, data.client, function(){
Avatar.Speech.end(data.client);
});
});
}
let client = setClient(data);
info("Domoticz:", data.action.command, "From:", data.client, "To:", client);
tblCommand[data.action.command]();
callback();
}
function setClient (data) {
var client = data.client;
if (data.action.room)
client = (data.action.room != 'current') ? data.action.room : (Avatar.currentRoom) ? Avatar.currentRoom : Config.default.client;
if (data.action.setRoom)
client = data.action.setRoom;
return client;
}
/*
ou bien j'utilise une requete http en fetch
// ici je creer une fonction je pense
const url ='http://192.168.1.1XX:8080/json.htm?';
fetch(url, {
method: "POST",
body: JSON.stringify({type: "command", param: "switchlight", idx: 20, switchcmd: "Off"})
})
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
})
.then(response => (response))
*/
merci encore stephane toujours présent a aider
le plugin seras developper avec le plugin studio toujour en multiroom, comme tu me conseille toujours je vais aller doucement
le code seras quelque chose comme ca:
exports.init = function () {
parametres = {
ip_domoticz : Config.modules.Domoticz.ip_domoticz,
}
}
exports.action = function(data, callback){
if (!parametres.ip_domoticz) {
Avatar.speak("La configuration de l'ip domoticz est manquante", data.client, () => {
Avatar.Speech.end(data.client);
});
return;
}
var tblCommand = {
tvOn : function() {
// state = "On";
return toggleOnOff ("On", data, client,)
},
tvOff : function() {
return toggleOnOff ("Off", data, client);
},
hdmi1 : function() {
return toggleOnOff (data, client,)
},
hdmi2 : function() {
return toggleOnOff (data, client);
},
hdmi3 : function() {
return toggleOnOff (data, client);
},
xboxOn : function() {
return toggleOnOff ("On", data, client);
},
xboxOff : function() {
return toggleOnOff ("Off", data, client);
}
};
function toggleOnOff(data, client, state) {
const idx = Config.modules.Domoticz.clients[client][data.action.command];
Avatar.runApp(`http://${parametres.ip_domoticz}/json.htm?type=command¶m=switchlight&idx=${idx}&switchcmd=${state}`, null, data.client, () => {
Avatar.speak(Config.modules.Domoticz.tts, data.client, function(){
Avatar.Speech.end(data.client);
});
});
}
let client = setClient(data);
info("Domoticz:", data.action.command, "From:", data.client, "To:", client);
tblCommand[data.action.command]();
callback();
}
function setClient (data) {
var client = data.client;
if (data.action.room)
client = (data.action.room != 'current') ? data.action.room : (Avatar.currentRoom) ? Avatar.currentRoom : Config.default.client;
if (data.action.setRoom)
client = data.action.setRoom;
return client;
}
/*
ou bien j'utilise une requete http en fetch
// ici je creer une fonction je pense
const url ='http://192.168.1.1XX:8080/json.htm?';
fetch(url, {
method: "POST",
body: JSON.stringify({type: "command", param: "switchlight", idx: 20, switchcmd: "Off"})
})
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.json();
})
.then(response => (response))
*/
merci encore stephane toujours présent a aider
halim- Messages : 92
Date d'inscription : 19/11/2022
Page 1 sur 1
Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum