10514 questions

12522 answers

19448 comments

22054 members

0 votes
947 views 2 comments
by

Hi,

So I am writing an application on Ubuntu 16.04 in C++ using QT framework.

I can access RTU955 from terminal using curl as per instructions given by you here: JSON Access

When I send a curl command from within my application I receive a response that there is a parsing error:

{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}

My guess is that I have done something really stupid with an escape character, any help would be appreciated, so my code, I create a QString that holds the curl command:

jsonAuthenticate = "curl -d";
jsonAuthenticate += " \"{ "jsonrpc": "2.0", "id": 1, "method": "call", "params": [ "00000000000000000000000000000000", "session", "login", { "username": "root", "password": "********" } ] }\"";
jsonAuthenticate += " http://192.168.2.1/ubus ";

Then I use QProcess
QString prErrors = ""; QString prStandard = "";
QProcess process;
process.start(jsonAuthenticate);
process.waitForFinished(5000); process.exitStatus();
prErrors = process.readAllStandardError();
prStandard = process.readAllStandardOutput();

 


I then tried to access via a QT class called QNetqorkAccessManager, but get the following error:

"<h1>Bad Request</h1>Invalid Request"

My Code:

jsonString = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"call\",\"params\":[\"00000000000000000000000000000000\",\"session\",\"login\",{\"username\":\"root\",\"password\":\"*********\"}]}";
networkManager = new QNetworkAccessManager(this);
serviceUrl = QUrl("http://192.168.2.1/ubus");
request.setUrl(serviceUrl);

request.setRawHeader("Content-Type","application/json");
request.setRawHeader("Content-Length",postDataSize);
QEventLoop eventLoop;
networkManager->post(request,jsonString);
reply = networkManager->get(request);
connect(reply,SIGNAL(finished()),&eventLoop,SLOT(quit()));
eventLoop.exec();
QByteArray data = reply->readAll();

1 Answer

0 votes
by

Could you please provide the firmware version you're currently running?

Also, have you tried sending this from the terminal?

curl -d '{ "jsonrpc":"2.0", "id":1, "method":"call", "params": [ "00000000000000000000000000000000", "session", "login", { "username":"root", "password":"<PASSWORD>" } ] }' 192.168.1.1/ubus

Do you know what kind of message you've formed and send? Is it possible you could print it out before sending it?

by
Thanks for your response, the command worked from the terminal but not from the programme space, it turned out that the command I was using was I bedding a couple of extra characters into the stream, once I was able to locate them I was able to handle it. So now I am able to send a json argument and get all the sim signal information that I need.

Many thanks
by
That was my first guess too, glad it turned out okay in the end!

If you have any other questions - don't be shy.