Forwarding decimal value from provision function to some php script

Hi,

I need to find a way to forward some decimal value from the provision script that is triggered by 8 DIAGNOSTICS COMPLETE event to the extension function and then to forward that same value to some external php script that has AJAX call and access to some web GUI (to put decimal value into the GUI).

Is this theoretically possible to do? If yes, how?

Best regards,

Tarik

You can use external script to send values. I use an external script to send values to a database but I’m pretty sure you could send it to an API.

It’s not my expertise but it seems like you want to do is some kind of API that will update the frontend when receiving new data on the API but I think you need something in between because I think frontend fetch information but don’t allow to push the information directly to the frontend. If I’m right, you could add a backend API that would receive the information and store it until the frontend fetch it.

Personnaly, I think the closer to what you describe would be to query back the API every X seconds until the diagnostic value change to “completed” and then get through the API the needed values for the diagnostic.

Call an extension script from your provision script.

thank you mike99 for your answer and for suggesting the easier way to collect the value. I already imeplemented it but this option is a bit slower beacuse you need to query the value of the TR-143 parameter from time to time to check whether its status has changed ant in this way you generate unneccessary GPV TR-069 method calls. I would like to use the 8 DIAGNOSTICS COMPLETE event for this purpose and without any addtional GPVs methods

I created this extension script:

const http = require(‘http’);

/**

Sends a decimal value and IMEI to a local PHP endpoint using a GET request

to save the result for the frontend client.

@param {number} decimalValue The decimal number to send.

@param {string} imei The IMEI associated with the diagnostic run.

@param {function} callback A function to execute upon completion: (error, data) => void.*/function sendDecimalToPHP(decimalValue, imei, callback){

const phpEndpoint = ‘/IMEI_SPV_RunDiagnostic4.php’;

const pathWithQuery = ${phpEndpoint}?imei=${encodeURIComponent(imei)}&value=${encodeURIComponent(decimalValue)};

const options = {hostname: ‘localhost’,port: 80,path: pathWithQuery,method: ‘GET’,};

const req = http.request(options, (res) => {let responseBody = ‘’;res.setEncoding(‘utf8’);

 res.on('data', (chunk) => {
     responseBody += chunk;
 });

 res.on('end', () => {
     if (res.statusCode >= 200 && res.statusCode < 300) {
         // Success: Value has been saved to the server file
         callback(null, responseBody);
     } else {
         // Error (e.g., PHP returned 400 or 500)
         callback(new Error(`PHP returned status ${res.statusCode}: ${responseBody}`));
     }
 });

});

// Handle system errors (e.g., connection refused)req.on(‘error’, (e) => {callback(e);});

req.end();}

exports.sendDecimalToPHP = sendDecimalToPHP;

and calls it from the provision script by:

ext(“decimal_value_forwarding”, “sendDecimalToPHP”, m, IMEI, “arg2”);

where “m” is the decimal value and “IMEI” is the IMEI but I got this error message in the log files:

faultCode=“ext.TypeError” faultMessage=“callback is not a function”

Can you please help me in resolving thise issue?

Best regards,

Tarik

Please review the extension script documentation and follow it more closely.

It seems to me that the error was that I used 3 arguments whan calling extension script. When I used only 2 of them (first of them is decimal value and the second one is callback function) I didn’t get the error. However I hardcoded the value of the IMEI in the extension script and that is not a viable solution. Is there some way to pass to values to the extension script. I tried with array that has 2 elements (decimal value and IMEI), but then I got this error: faultCode=“ext.Error” faultMessage="connect ECONNREFUSED 127.0.0.1:80

sorry, I mistyped in the prevoius post: Is there some way to pass two values to the extension script?

Pass an object?

function sendDecimalToPHP({ decimalValue, imei }, callback){
   ...
}

Mind you, the ECONNREFUSED error suggests that your API isn’t responding.

let myData = ext('scriptFileName', 'methodName', JSON.stringify(myParams));