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.
HTTP call from evothings client
Re: HTTP call from evothings client
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.
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.
Re: HTTP call from evothings client
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?
Re: HTTP call from evothings client
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
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
Re: HTTP call from evothings client
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.
Re: HTTP call from evothings client
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
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
Re: HTTP call from evothings client
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.
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>
Re: HTTP call from evothings client
Add this to your <head>:
Code: Select all
<script src="cordova.js"></script>
Re: HTTP call from evothings client
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.
Thank you.
Re: HTTP call from evothings client
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 3 guests