Question
· Oct 9, 2022

HTTP request with open stream

Hi Guys,

This link (https://github.com/CassiaNetworks/CassiaSDKGuide/blob/master/node_exampl...)   uses Javascript request to open a a steam and collect data in an array  (screenshot below) and I'm trying to replicate this with Cache script with HTTP request which is connecting Ok but don't know how can I collect data because the code is hanging at Set tSc=Httprequest.Get(HttpURL) and cannot execute BLEConnect=Httprequest.HttpResponse.StatusLine or any line after it.

I think the url call (ac1.mqtt.sx3ac.com/api/gap/nodes?&mac=CC:1B:E0:E1:A6:44&access_token=8f7f44d842cbcadd53713cca2ea36f256b2ec6581658fee4e246d93e28c6feb3&active=1&event=1
) should do that by keeping an open stream because if I run the same url through the browser or Postman it does the same, but how can I get the data the same way this JavaScript code is doing?

 

 

Token=##class(MSDS.SpaceSense.API).GetAuth()
Set Httprequest=##class(%Net.HttpRequest).%New()
Set Httprequest.Server="ac1.mqtt.sx3ac.com"
Set Httprequest.Timeout=30
Set Httprequest.Https=0
set Httprequest.ContentType="application/json"
Do Httprequest.SetHeader("Accept","application/json")
Do Httprequest.SetHeader("Accept-Language","en_US")
Do Httprequest.SetHeader("Authorization","Bearer "_Token)
Set HttpURL="/api/gap/nodes?filter_rssi=-75&chip=1&mac=CC:1B:E0:E2:3C:10&active=1&event=1"
Set tSc=Httprequest.Get(HttpURL)
  BLEConnect=Httprequest.HttpResponse.StatusLine
  

 

 

Thanks

Product version: Ensemble 2014.1
Discussion (9)1
Log in or sign up to continue

At least, you are one step further (in your initial post, you wrote "...because the code is hanging at Set tSc=Httprequest.Get(HttpURL)..."). Maybe the provided MAC number is wrong.  The MAC Number CC:1B:E0:E2:3C:10 belongs to Cassia Networks. Is that the right number?

I know exactly nothing about Cassia Networks and Cassia SDK... sorry.

Try to define your parameters in a structured way:

Set Httprequest.Location="api/gap/nodes"
Do Httprequest.InsertParam("filter_rssi", -75)
Do Httprequest.InsertParam("chip", 1)
Do Httprequest.InsertParam("mac", "CC:1B:E0:E2:3C:10")
Do Httprequest.InsertParam("active", 1)
Do Httprequest.InsertParam("event", 1)
Set tSc=Httprequest.Get()

Also Get has a test parameter, try setting it to 1 to see what's being sent and compare to a successful request.

updated the code as below, but the execution hangs when it comes to line (Set tSc=Httprequest.Get()) and doesn't go any further and not getting any data back.

Token=##class(MSDS.SpaceSense.API).GetAuth()
Set Httprequest=##class(%Net.HttpRequest).%New()
Set Httprequest.Server="ac1.mqtt.sx3ac.com"
Set Httprequest.Timeout=30
Set Httprequest.Https=0
set Httprequest.ContentType="application/json"
Do Httprequest.SetHeader("Accept","application/json")
Do Httprequest.SetHeader("Accept-Language","en_US")
Do Httprequest.SetHeader("Authorization","Bearer "_Token)
Set Httprequest.Location="api/gap/nodes"
    Do Httprequest.InsertParam("filter_rssi", -75)
    Do Httprequest.InsertParam("chip", 1)
    Do Httprequest.InsertParam("mac", "CC:1B:E0:E1:A6:44")
    Do Httprequest.InsertParam("active", 1)
    Do Httprequest.InsertParam("event", 1)

//Set HttpURL="/api/gap/nodes?filter_rssi=-75&chip=1&mac=CC:1B:E0:E1:A6:44&access_token=1aed6596721cb6c23bf2977d0dc2ad85a4e9af5263df10f1f8ac399421642230&active=1&event=1"
 

Set tSc=Httprequest.Get()

^badis="Ok"

BLEConnect=Httprequest.HttpResponse.StatusLine
     
  ^badis("q")=Httprequest.HttpResponse.Data.Read(Httprequest.HttpResponse.Data.Size)

and how do I set a test parameter to 1 and get the request sent, you mean like this

Do Httprequest.InsertParam("test", 1)

and then how do I check the sent request?

Thanks 

if I add Do Httprequest.InsertParam("mac", $zcvt("CC:1B:E0:E1:A6:44", "O", "URI")) I get the following error and I change URI to URL 

and I change URI to URL this error; "gateway's mac is invalid"

is there a way to know the URL call that has been sent in this Get request?

FYI, using this code suppose to get me a live connection to an Open data stream where the then collect data similar to what's in this example using node js  : https://github.com/CassiaNetworks/CassiaSDKGuide/blob/master/node_exampl...

so having my code hanging maybe means the live connection is opened but I'm unable to get data ?

thanks

this is what I get with Set tSc=Httprequest.Get(, 1)

 
US-SERENITY>d ##class(SX3.Bleproc).GetTempFromAC("L")
GET /api/gap/nodes?filter_rssi=-75&chip=1&mac=CC%3A1B%3AE0%3AE1%3AA6%3A44&active=1&event=1 HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; Cache;)
Host: ac1.mqtt.sx3ac.com
Accept-Encoding: gzip
Accept: application/json
Accept-Language: en_US
Authorization: Bearer a09d8dea562cc5cd99ce7076c8b803cd8a3331d53b63d771e3b5d7fd639c5604

The url seems to be fine?