@xenon Danke
@mr-moose probiere mal
const http = require("http");
const path = `http://10.10.10.30/cnf?cmd=set_ajax_meter&dev_id=M5`;
const result = http.get(path);
console.log(result);
Im Log kommt dann:
javascript.0 (25313) script.js.PV_/_Strom.Zähler_an_Wallbox: {'_events':{},'_eventsCount':1,'_maxListeners':100,'output':['GET /cnf?cmd=set_ajax_meter&dev_id=M5 HTTP/1.1\r\nHost: 10.10.10.30\r\nConnection: close\r\n\r\n'],'outputEncodings':['latin1'],'outputCallbacks':[null],'outputSize':88,'writable':true,'_last':true,'chunkedEncoding':false,'shouldKeepAlive':false,'useChunkedEncodingByDefault':false,'sendDate':false,'_removedConnection':false,'_removedContLen':false,'_removedTE':false,'_contentLength':0,'_hasBody':true,'_trailer':'','finished':true,'_headerSent':true,'socket':null,'connection':null,'_header':'GET /cnf?cmd=set_ajax_meter&dev_id=M5 HTTP/1.1\r\nHost: 10.10.10.30\r\nConnection: close\r\n\r\n','agent':{'_events':{},'_eventsCount':1,'defaultPort':80,'protocol':'http:','options':{'path':null},'requests':{},'sockets':{'10.10.10.30:80:':[{'connecting':true,'_hadError':false,'_handle':{'reading':false,'onconnection':null},'_parent':null,'_host':null,'_readableState':{'objectMode':false,'highWaterMark':16384,'buffer':{'head':null,'tail':null,'length':0},'length':0,'pipes':null,'pipesCount':0,'flowing':null,'ended':false,'endEmitted':false,'reading':false,'sync':true,'needReadable':false,'emittedReadable':false,'readableListening':false,'resumeScheduled':false,'paused':true,'emitClose':false,'autoDestroy':false,'destroyed':false,'defaultEncoding':'utf8','awaitDrain':0,'readingMore':false,'decoder':null,'encoding':null},'readable':false,'_events':{},'_eventsCount':5,'_maxListeners':100,'_writableState':{'objectMode':false,'highWaterMark':16384,'finalCalled':false,'needDrain':false,'ending':false,'ended':false,'finished':false,'destroyed':false,'decodeStrings':false,'defaultEncoding':'utf8','length':0,'writing':false,'corked':0,'sync':true,'bufferProcessing':false,'writecb':null,'writelen':0,'bufferedRequest':null,'lastBufferedRequest':null,'pendingcb':0,'prefinished':false,'errorEmitted':false,'emitClose':false,'autoDestroy':false,'bufferedRequestCount':0,'corkedRequestsFree':{'next':null,'entry':null}},'writable':true,'allowHalfOpen':false,'_sockname':null,'_pendingData':null,'_pendingEncoding':'','server':null,'_server':null}]},'freeSockets':{},'keepAliveMsecs':1000,'keepAlive':false,'maxSockets':null,'maxFreeSockets':256},'method':'GET','path':'/cnf?cmd=set_ajax_meter&dev_id=M5','_ended':false,'res':null,'timeoutCb':null,'upgradeOrConnect':false,'parser':null,'maxHeadersCount':null}
alternativ das hier: (Dafür musst du aber das Modul "xmlhttprequest" in deiner Javascript Instanz eintragen!!!)
var xmlhttprequest = require("xmlhttprequest").XMLHttpRequest;
let url = "http://10.10.10.30/cnf?cmd=set_ajax_meter&dev_id=M5";
let xhr = new xmlhttprequest();
xhr.open("POST", url);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
}};
var data = '{"import_vah" : 10000 , "power_va": 500}';
xhr.send(data);
steht nun was in der Console log Ausgabe bei dir?
xmlhttprequest habe ich oben bei "zusätzliche NPM-Module" eingetragen.
Im Log kommt:
08:34:54.732 info javascript.0 (18929) script.js.PV_/_Strom.Zähler_an_Wallbox: 401
08:34:54.733 info javascript.0 (18929) script.js.PV_/_Strom.Zähler_an_Wallbox: Unauthorized