Response code 7

Hi,

I’m trying to read the temperature from the device and send it to a server which accepts the details in a JSON and requires authorization which I’m hard coding here just for testing. So here is the code:

// Agent Code (sending temperature)

function postReading(reading) { // reading is the data (squirrel table) passed from the device

// Define a table with the JASON info
 local AM_Data =  [
{
    metricCode="testMetric1",
    values=[
        {
                metricValue= reading.temp,
                detectionTime="2015-11-05T13=15=30Z"
        },
        {
                metricValue= reading.temp,
                detectionTime="2015-11-05T13=15=30Z"
        }
    ]
},
{
    metricCode="testMetric2",
    values=[
        {
                metricValue= "test",
                detectionTime="2015-11-05T13=15=30Z"
        }
    ]
}

]

// encode data into JSON and log
local body = http.jsonencode(AM_Data);
server.log(body);

local url = "http://mytest.com:8580/agentapi/assetmetrics";
local headers = {"Content-Type": "application/json", "Authorization": "Basic ZGYwNGFjNWEtNGQ4Zi00NjllLTg4MjEtYTU3YTAxNzRiZWRkOg=="};

local request = http.post(url, headers, body);
local response = request.sendsync();
server.log(response.statuscode);

}
device.on(“reading”, postReading);

So running this I get :

2015-12-24 13:57:25 UTC-5 [Status] Agent restarted: reload.
2015-12-24 13:57:25 UTC-5 [Status] Device connected
2015-12-24 13:57:25 UTC-5 [Device] Got temperature: 26.5 deg C
2015-12-24 13:57:25 UTC-5 [Agent] [ { “values”: [ { “metricValue”: 26.456, “detectionTime”: “2015-11-05T13=15=30Z” }, { “metricValue”: 26.456, “detectionTime”: “2015-11-05T13=15=30Z” } ], “metricCode”: “testMetric1” }, { “values”: [ { “metricValue”: “test”, “detectionTime”: “2015-11-05T13=15=30Z” } ], “metricCode”: “testMetric2” } ]
2015-12-24 13:58:29 UTC-5 [Agent] 7

and it doesn’t add any records to the database.

I know 7 means CURLE_COULDNT_CONNECT (7) : Failed to connect() to host or proxy.

But I’m not sure why. Using the same URL, headers and JSON on postman it works fine.

I would appreciate any ideas that might help.

Thanks.

I can’t telnet to that host (mytest.com port 8580), the connect just times out.

Is mytest.com somewhere on your local network? The agent is running in AWS, so it can only talk to servers generally accessible from the cloud.

Hi Hugo,

Yes, it’s a private server, I changed the name to share the code but it’s working fine, no problem there.

Thanks

Ok, issue solved.
It had to do with the firewall. Sorry.

Thanks.

Hi,
I am facing same issue.
I have one local DB server running and I am trying to push data in it using httppost request
I am getting statuscode as 7.
Could you please help me ?

The server has to be accessible on the internet - the agent code is not running on the imp, it’s running on a server in AWS.