HTTP call from evothings client

Discuss the company and its products.
andersjj
Posts: 7
Joined: 20:17, 31 Oct 2015

HTTP call from evothings client

Postby andersjj » 20:21, 31 Oct 2015

Is there a way setup to make http calls from the evothings client? I'm looking to log BLE devices that are found, but I keep getting errors. I'm guessing that the pre-compiled viewer app doesn't have a whitelist to allow all http calls? I'm running the Android version.

If there is a way to make http calls from the pre-built Android client, please post some code sample and I could take it from there.

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: HTTP call from evothings client

Postby Fredrik » 10:17, 02 Nov 2015

Our example "hue-lights" does a bunch of HTTP calls using jQuery.

Of note is that all Hue servers send the header "Access-Control-Allow-Origin: *". Your server must also do this, or the client's webview will not accept the responses.

JimB
Posts: 8
Joined: 09:46, 26 Nov 2015

Re: HTTP call from evothings client

Postby JimB » 10:55, 26 Nov 2015

I think I have a related issue. I want to use a remote JSON file (long term is to call an API returning JSON) but it doesn't work. I believe I have set up the CORS correctly but I get nothing back. Would the API be more likely to succeed, or just the same?

alex
Posts: 92
Joined: 00:59, 19 Nov 2013

Re: HTTP call from evothings client

Postby alex » 15:27, 26 Nov 2015

Hi!

If you like to, send us a working code snipped that connects the way you'd want, in order
to test in the Viewer app. We've recently incorporated a HTTP cordova plug-in an experimental build,
that I'd like to try out.

best

Alex

JimB
Posts: 8
Joined: 09:46, 26 Nov 2015

Re: HTTP call from evothings client

Postby JimB » 19:16, 26 Nov 2015

Will do! It's a home project so I'll post on here this evening (NZ time). I'm very much a rookie, despite my age.

alex
Posts: 92
Joined: 00:59, 19 Nov 2013

Re: HTTP call from evothings client

Postby alex » 23:56, 26 Nov 2015

Alternatively, if you have an android device, you can test this extended build (regular Viewer + http plugin)
https://evothings.com/uploads/evothings2/beta2/EvothingsViewer_151120_1346.apk

In order to use the HTTP plugin, you need to invoke the native HTTP GET function in a fashion separate to how to normally pick up data via js:

cordovaHTTP.get("http://somewhere.com/some-path/some-doc", {}, {}, function(response)
{
app.status("HTTP success "+response.status);
app.onMessageArrived(response.data);
}, function(response) {
console.log(JSON.stringify(response));
});

more here: https://github.com/wymsee/cordova-HTTP

JimB
Posts: 8
Joined: 09:46, 26 Nov 2015

Re: HTTP call from evothings client

Postby JimB » 09:28, 27 Nov 2015

I used the extended build but got an error trying to run that code:
LOG: [ERR] Uncaught ReferenceError: cordovaHTTP is not defined

This is the code I'm trying. It works if the JSON file is local,but not otherwise. Any (polite) advice gratefully received.
<!doctype html>
<html>
<head>

<title>How to Parse a JSON file using jQuery</title>

<style>
body{
text-align: center;
font-family: arial;
}

.button{
margin:20px;
font-size:16px;
font-weight: bold;
padding:5px 10px;
}
</style>


</head>
<body>
<a href="http://giveandgo.nz.s3-website-ap-southeast-2.amazonaws.com/location.json">Open JSON file</a><br />
<input type="button" value="Get and parse JSON" class="button" />
<br />
<span id="results">
<select class="tabs">
</select>
</span>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script>

//When DOM loaded we attach click event to button
$(document).ready(function() {

//after button is clicked we download the data
$('.button').click(function(){

//start ajax request
$.ajax({
url: "http://giveandgo.nz.s3-website-ap-southeast-2.amazonaws.com/location.json",
//force to handle it as text
dataType: "json",
success: function(data) {
//data downloaded so we call parseJSON function
//and pass downloaded data
for (var i = 0, len = data.locationlist.location.length; i < len; i++) {
//You can now access individual properties like this:
//var json = $.parseJSON(data.locationlist.location[i]);
if (i==0){var output='';}
$('#results select').append('<option value=' + data.locationlist.location[i].locationID + '>' + data.locationlist.location[i].name + '</option>');
}
}
});
});
});
</script>

</body>
</html>

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: HTTP call from evothings client

Postby Fredrik » 09:44, 27 Nov 2015

Add this to your <head>:

Code: Select all

<script src="cordova.js"></script>

JimB
Posts: 8
Joined: 09:46, 26 Nov 2015

Re: HTTP call from evothings client

Postby JimB » 10:56, 27 Nov 2015

I'll have to do some rewriting to make that go. But it appears my issue (at least in part) is that the Origin header isn't being passed and I'm not sure how to make it.

Thank you.

Fredrik
Site Admin
Posts: 196
Joined: 15:00, 18 Nov 2013

Re: HTTP call from evothings client

Postby Fredrik » 11:15, 27 Nov 2015

Looks like you're using Amazon S3. They have a guide for enabling CORS.


Return to “General discussion”

Who is online

Users browsing this forum: No registered users and 1 guest