Android Question Read data from URL into variables

DKHDKH

Member
Licensed User
I get the following data from my energy meter via http://190.160.1.12/restAPI?get=Actual
The data:

{
"Timestamp": "190924184540S"
, "Energy_Delivered": "16021.018"
, "Energy_Returned": "0.000"
, "Gas_Delivered": "2393.86"
, "Energy_Delivered_Tariff1": "9646.286"
, "Energy_Delivered_Tariff2": "6374.731"
, "Energy_Returned_Tariff1": "0.000"
, "Energy_Returned_Tariff2": "0.000"
, "Power_Delivered": "2.892"
, "Power_Returned": "0.000"
, "Voltage_l1": "0.0"
, "Current_l1": "12"
, "Voltage_l2": "0.0"
, "Current_l2": "0"
, "Voltage_l3": "0.0"
, "Current_l3": "0"
, "Power_Delivered_l1": "2892"
, "Power_Returned_l1": "0"
, "Power_Delivered_l2": "0"
, "Power_Returned_l2": "0"
, "Power_Delivered_l3": "0"
, "Power_Returned_l3": "0"
}

I would like to display this data differently. I am unable to write this data in variables.
Many demos and posts viewed and tried. For example:
https://www.b4x.com/android/forum/t...-json-response-from-an-api-web-request.45822/
https://www.b4x.com/android/forum/t...-services-are-now-even-simpler.18992/#content

So now the question to you if someone can help me on my way. Thanks in advance.
Dirk
 

DKHDKH

Member
Licensed User
Thanks for the help and patience.
I get the desired data despite the error. I will continue with this.
Thanks again everyone.
 
Upvote 0

DKHDKH

Member
Licensed User
This is clutching at straws, but... what happens if you add a delay (and Log) after the Wait For, eg:
B4X:
Dim job As HttpJob
job.Initialize("", Me)
job.Download2("http://190.160.1.12/restAPI", Array As String("get", "Actual"))
Wait For (job) JobDone(job As HttpJob)
Sleep(100)                             'add this
Log("job.Success = " & job.Success)    'and this

I become the same error.
 
Upvote 0

DKHDKH

Member
Licensed User
I have now put it on local network and also tried HTTPS and the same error remains.
I get the desired data despite the error. I will continue with this.
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
The only two things I noticed in your code:

1) As you're using Wait For you don't need your separate JobDone subroutine, remove it (though I doubt if this will confuse things).
2) I don't see a Job.Release anywhere in your parsing block (I'd put it right after your Dim Response = job.getstring if you're done using the object).
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I have adjusted the following rule and now the error is gone. I do not send any parameters to the URL so DOWNLOAD must be used and not DOWNLOAD2.
It was:
job.download2("http://192.168.0.38/restAPI?get=Actual", Array As String("get", "Actual"))

Changed in:
job.download("http://192.168.0.38/restAPI?get=Actual")

that’s because you used Download2 incorrectly. Take out the ?get=Actual. That is what Download2 creates with the array. As you have it, Download2 generates
So no, Download must not be used, Download2 just needs to be used properly. Or you can use Download and worry about properly formatting your URL parameters yourself, something Download2 does gladly for you.
 
Upvote 0
Top