argusy
argusy

Reputation: 11

Automatically trapping a JSON file from a browser, to use in a VB6 program

I can get the following in Firefox (or any other browser) from a device called a Saturn South ESBox, connected to my local LAN every six seconds, by entering"http://esbox/api/devices". It's actually a JSON file. What I don't want to do is sit in front of my PC, doing this once a minute for 24 hours a day, copying this file. Googling for an answer just doesn't answer the following question (been trying for months!!)

What can I do to trap this automatically about every minute so I can use it in a Visual Basic 6 program, (then delete it once parsed)? I'm not worried about parsing it for the info I want - I know exactly what to do, to get that

(about 600 chars of crap removed from the start of the JSON, then four lines similar to the following)

{{"ieee":"001BC502B0102200","status":1,"type":2,"model":"SS9007.2.0_6000_2290_SSHA_R","manuf":"Saturn South","time":{"j":1699407463,"c":1718510500,"r":1718267426,"n":1718510501},"vals":{"cu":15,"en":208630,"po":33,"sw":1,"vo":24029},"ext":{}}

I haven't tried anything, yet, because I don't know how to do this. I wrote a VB6 program years ago using a "Current Cost" device which inputs directly into a PC through USB, but since found out this device was about 20-30% inaccurate through cross modulation. This Esbox from Saturn South has sensors mounted on each phase in the distribution box, is 98% accurate, and detects current flow in both directions, but the transmitter goes through a www source with it's own website. I can access the data through a browser (shown above). I would really love to know how to get this other data, and throw the "Current Cost" device in the bin

Upvotes: 0

Views: 136

Answers (1)

Brian M Stafford
Brian M Stafford

Reputation: 8868

Here is a simple example of pulling JSON from a URL using a timer. You will need to set a reference to Microsoft XML, v6.0.

Option Explicit

Private Sub Timer_Timer()
   Dim http As XMLHTTP60
   
   'make the request
   Set http = New XMLHTTP60
   http.Open "GET", "http://echo.jsontest.com/key/value/one/two"
   http.send

   'now use the json data, or save it to a file,
   'or do whatever else you want with it
   Debug.Print http.responseText
End Sub

Upvotes: 1

Related Questions